blob: 2a3b807b994aad02528573d65355919e6174ab3e [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * This file contains codegen for the Thumb2 ISA and is intended to be
19 * includes by:
20 *
21 * Codegen-$(TARGET_ARCH_VARIANT).c
22 *
23 */
24
buzbeece302932011-10-04 14:32:18 -070025#define SLOW_FIELD_PATH (cUnit->enableDebug & (1 << kDebugSlowFieldPath))
26#define SLOW_INVOKE_PATH (cUnit->enableDebug & (1 << kDebugSlowInvokePath))
27#define SLOW_STRING_PATH (cUnit->enableDebug & (1 << kDebugSlowStringPath))
28#define SLOW_TYPE_PATH (cUnit->enableDebug & (1 << kDebugSlowTypePath))
29#define EXERCISE_SLOWEST_FIELD_PATH (cUnit->enableDebug & \
30 (1 << kDebugSlowestFieldPath))
31#define EXERCISE_SLOWEST_STRING_PATH (cUnit->enableDebug & \
32 (1 << kDebugSlowestStringPath))
buzbee34c77ad2012-01-11 13:01:32 -080033#define EXERCISE_RESOLVE_METHOD (cUnit->enableDebug & \
34 (1 << kDebugExerciseResolveMethod))
buzbeece302932011-10-04 14:32:18 -070035
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080036namespace art {
37
buzbeece302932011-10-04 14:32:18 -070038STATIC RegLocation getRetLoc(CompilationUnit* cUnit);
buzbee34cd9e52011-09-08 14:31:52 -070039
Elliott Hughes81bc5092011-09-30 17:25:59 -070040void warnIfUnresolved(CompilationUnit* cUnit, int fieldIdx, Field* field) {
41 if (field == NULL) {
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080042 const DexFile::FieldId& field_id = cUnit->dex_file->GetFieldId(fieldIdx);
Elliott Hughes95572412011-12-13 18:14:20 -080043 std::string class_name(cUnit->dex_file->GetFieldDeclaringClassDescriptor(field_id));
44 std::string field_name(cUnit->dex_file->GetFieldName(field_id));
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080045 LOG(INFO) << "Field " << PrettyDescriptor(class_name) << "." << field_name
Elliott Hughes95572412011-12-13 18:14:20 -080046 << " unresolved at compile time";
Elliott Hughes81bc5092011-09-30 17:25:59 -070047 } else {
48 // We also use the slow path for wide volatile fields.
49 }
50}
51
buzbee67bf8852011-08-17 17:51:35 -070052/*
53 * Construct an s4 from two consecutive half-words of switch data.
54 * This needs to check endianness because the DEX optimizer only swaps
55 * half-words in instruction stream.
56 *
57 * "switchData" must be 32-bit aligned.
58 */
59#if __BYTE_ORDER == __LITTLE_ENDIAN
buzbeeed3e9302011-09-23 17:34:19 -070060STATIC inline s4 s4FromSwitchData(const void* switchData) {
buzbee67bf8852011-08-17 17:51:35 -070061 return *(s4*) switchData;
62}
63#else
buzbeeed3e9302011-09-23 17:34:19 -070064STATIC inline s4 s4FromSwitchData(const void* switchData) {
buzbee67bf8852011-08-17 17:51:35 -070065 u2* data = switchData;
66 return data[0] | (((s4) data[1]) << 16);
67}
68#endif
69
buzbeeed3e9302011-09-23 17:34:19 -070070STATIC ArmLIR* callRuntimeHelper(CompilationUnit* cUnit, int reg)
buzbeeec5adf32011-09-11 15:25:43 -070071{
buzbee6181f792011-09-29 11:14:04 -070072 oatClobberCalleeSave(cUnit);
buzbeeec5adf32011-09-11 15:25:43 -070073 return opReg(cUnit, kOpBlx, reg);
74}
75
buzbee1b4c8592011-08-31 10:43:51 -070076/* Generate unconditional branch instructions */
buzbeeed3e9302011-09-23 17:34:19 -070077STATIC ArmLIR* genUnconditionalBranch(CompilationUnit* cUnit, ArmLIR* target)
buzbee1b4c8592011-08-31 10:43:51 -070078{
79 ArmLIR* branch = opNone(cUnit, kOpUncondBr);
80 branch->generic.target = (LIR*) target;
81 return branch;
82}
83
buzbee67bf8852011-08-17 17:51:35 -070084/*
85 * Generate a Thumb2 IT instruction, which can nullify up to
86 * four subsequent instructions based on a condition and its
87 * inverse. The condition applies to the first instruction, which
88 * is executed if the condition is met. The string "guide" consists
89 * of 0 to 3 chars, and applies to the 2nd through 4th instruction.
90 * A "T" means the instruction is executed if the condition is
91 * met, and an "E" means the instruction is executed if the condition
92 * is not met.
93 */
buzbeeed3e9302011-09-23 17:34:19 -070094STATIC ArmLIR* genIT(CompilationUnit* cUnit, ArmConditionCode code,
buzbee67bf8852011-08-17 17:51:35 -070095 const char* guide)
96{
97 int mask;
98 int condBit = code & 1;
99 int altBit = condBit ^ 1;
100 int mask3 = 0;
101 int mask2 = 0;
102 int mask1 = 0;
103
104 //Note: case fallthroughs intentional
105 switch(strlen(guide)) {
106 case 3:
107 mask1 = (guide[2] == 'T') ? condBit : altBit;
108 case 2:
109 mask2 = (guide[1] == 'T') ? condBit : altBit;
110 case 1:
111 mask3 = (guide[0] == 'T') ? condBit : altBit;
112 break;
113 case 0:
114 break;
115 default:
116 LOG(FATAL) << "OAT: bad case in genIT";
117 }
118 mask = (mask3 << 3) | (mask2 << 2) | (mask1 << 1) |
119 (1 << (3 - strlen(guide)));
120 return newLIR2(cUnit, kThumb2It, code, mask);
121}
122
123/*
124 * Insert a kArmPseudoCaseLabel at the beginning of the Dalvik
125 * offset vaddr. This label will be used to fix up the case
126 * branch table during the assembly phase. Be sure to set
127 * all resource flags on this to prevent code motion across
128 * target boundaries. KeyVal is just there for debugging.
129 */
buzbeeed3e9302011-09-23 17:34:19 -0700130STATIC ArmLIR* insertCaseLabel(CompilationUnit* cUnit, int vaddr, int keyVal)
buzbee67bf8852011-08-17 17:51:35 -0700131{
buzbee85d8c1e2012-01-27 15:52:35 -0800132 std::map<unsigned int, LIR*>::iterator it;
133 it = cUnit->boundaryMap.find(vaddr);
134 if (it == cUnit->boundaryMap.end()) {
135 LOG(FATAL) << "Error: didn't find vaddr 0x" << std::hex << vaddr;
buzbee67bf8852011-08-17 17:51:35 -0700136 }
buzbeeba938cb2012-02-03 14:47:55 -0800137 ArmLIR* newLabel = (ArmLIR*)oatNew(cUnit, sizeof(ArmLIR), true, kAllocLIR);
buzbee85d8c1e2012-01-27 15:52:35 -0800138 newLabel->generic.dalvikOffset = vaddr;
139 newLabel->opcode = kArmPseudoCaseLabel;
140 newLabel->operands[0] = keyVal;
141 oatInsertLIRAfter(it->second, (LIR*)newLabel);
142 return newLabel;
buzbee67bf8852011-08-17 17:51:35 -0700143}
144
buzbeeed3e9302011-09-23 17:34:19 -0700145STATIC void markPackedCaseLabels(CompilationUnit* cUnit, SwitchTable *tabRec)
buzbee67bf8852011-08-17 17:51:35 -0700146{
147 const u2* table = tabRec->table;
148 int baseVaddr = tabRec->vaddr;
149 int *targets = (int*)&table[4];
150 int entries = table[1];
151 int lowKey = s4FromSwitchData(&table[2]);
152 for (int i = 0; i < entries; i++) {
153 tabRec->targets[i] = insertCaseLabel(cUnit, baseVaddr + targets[i],
154 i + lowKey);
155 }
156}
157
buzbeeed3e9302011-09-23 17:34:19 -0700158STATIC void markSparseCaseLabels(CompilationUnit* cUnit, SwitchTable *tabRec)
buzbee67bf8852011-08-17 17:51:35 -0700159{
160 const u2* table = tabRec->table;
161 int baseVaddr = tabRec->vaddr;
162 int entries = table[1];
163 int* keys = (int*)&table[2];
164 int* targets = &keys[entries];
165 for (int i = 0; i < entries; i++) {
166 tabRec->targets[i] = insertCaseLabel(cUnit, baseVaddr + targets[i],
167 keys[i]);
168 }
169}
170
171void oatProcessSwitchTables(CompilationUnit* cUnit)
172{
173 GrowableListIterator iterator;
174 oatGrowableListIteratorInit(&cUnit->switchTables, &iterator);
175 while (true) {
176 SwitchTable *tabRec = (SwitchTable *) oatGrowableListIteratorNext(
177 &iterator);
178 if (tabRec == NULL) break;
179 if (tabRec->table[0] == kPackedSwitchSignature)
180 markPackedCaseLabels(cUnit, tabRec);
181 else if (tabRec->table[0] == kSparseSwitchSignature)
182 markSparseCaseLabels(cUnit, tabRec);
183 else {
184 LOG(FATAL) << "Invalid switch table";
185 }
186 }
187}
188
buzbeeed3e9302011-09-23 17:34:19 -0700189STATIC void dumpSparseSwitchTable(const u2* table)
buzbee67bf8852011-08-17 17:51:35 -0700190 /*
191 * Sparse switch data format:
192 * ushort ident = 0x0200 magic value
193 * ushort size number of entries in the table; > 0
194 * int keys[size] keys, sorted low-to-high; 32-bit aligned
195 * int targets[size] branch targets, relative to switch opcode
196 *
197 * Total size is (2+size*4) 16-bit code units.
198 */
199{
200 u2 ident = table[0];
201 int entries = table[1];
202 int* keys = (int*)&table[2];
203 int* targets = &keys[entries];
204 LOG(INFO) << "Sparse switch table - ident:0x" << std::hex << ident <<
205 ", entries: " << std::dec << entries;
206 for (int i = 0; i < entries; i++) {
207 LOG(INFO) << " Key[" << keys[i] << "] -> 0x" << std::hex <<
208 targets[i];
209 }
210}
211
buzbeeed3e9302011-09-23 17:34:19 -0700212STATIC void dumpPackedSwitchTable(const u2* table)
buzbee67bf8852011-08-17 17:51:35 -0700213 /*
214 * Packed switch data format:
215 * ushort ident = 0x0100 magic value
216 * ushort size number of entries in the table
217 * int first_key first (and lowest) switch case value
218 * int targets[size] branch targets, relative to switch opcode
219 *
220 * Total size is (4+size*2) 16-bit code units.
221 */
222{
223 u2 ident = table[0];
224 int* targets = (int*)&table[4];
225 int entries = table[1];
226 int lowKey = s4FromSwitchData(&table[2]);
227 LOG(INFO) << "Packed switch table - ident:0x" << std::hex << ident <<
228 ", entries: " << std::dec << entries << ", lowKey: " << lowKey;
229 for (int i = 0; i < entries; i++) {
230 LOG(INFO) << " Key[" << (i + lowKey) << "] -> 0x" << std::hex <<
231 targets[i];
232 }
233}
234
235/*
236 * The sparse table in the literal pool is an array of <key,displacement>
237 * pairs. For each set, we'll load them as a pair using ldmia.
238 * This means that the register number of the temp we use for the key
239 * must be lower than the reg for the displacement.
240 *
241 * The test loop will look something like:
242 *
243 * adr rBase, <table>
244 * ldr rVal, [rSP, vRegOff]
245 * mov rIdx, #tableSize
246 * lp:
247 * ldmia rBase!, {rKey, rDisp}
248 * sub rIdx, #1
249 * cmp rVal, rKey
250 * ifeq
251 * add rPC, rDisp ; This is the branch from which we compute displacement
252 * cbnz rIdx, lp
253 */
buzbeeed3e9302011-09-23 17:34:19 -0700254STATIC void genSparseSwitch(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700255 RegLocation rlSrc)
256{
257 const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB;
258 if (cUnit->printMe) {
259 dumpSparseSwitchTable(table);
260 }
261 // Add the table to the list - we'll process it later
buzbeeba938cb2012-02-03 14:47:55 -0800262 SwitchTable *tabRec = (SwitchTable *)oatNew(cUnit, sizeof(SwitchTable),
buzbee5abfa3e2012-01-31 17:01:43 -0800263 true, kAllocData);
buzbee67bf8852011-08-17 17:51:35 -0700264 tabRec->table = table;
265 tabRec->vaddr = mir->offset;
266 int size = table[1];
buzbeeba938cb2012-02-03 14:47:55 -0800267 tabRec->targets = (ArmLIR* *)oatNew(cUnit, size * sizeof(ArmLIR*), true,
buzbee5abfa3e2012-01-31 17:01:43 -0800268 kAllocLIR);
buzbeeba938cb2012-02-03 14:47:55 -0800269 oatInsertGrowableList(cUnit, &cUnit->switchTables, (intptr_t)tabRec);
buzbee67bf8852011-08-17 17:51:35 -0700270
271 // Get the switch value
272 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
273 int rBase = oatAllocTemp(cUnit);
274 /* Allocate key and disp temps */
275 int rKey = oatAllocTemp(cUnit);
276 int rDisp = oatAllocTemp(cUnit);
277 // Make sure rKey's register number is less than rDisp's number for ldmia
278 if (rKey > rDisp) {
279 int tmp = rDisp;
280 rDisp = rKey;
281 rKey = tmp;
282 }
283 // Materialize a pointer to the switch table
buzbee03fa2632011-09-20 17:10:57 -0700284 newLIR3(cUnit, kThumb2Adr, rBase, 0, (intptr_t)tabRec);
buzbee67bf8852011-08-17 17:51:35 -0700285 // Set up rIdx
286 int rIdx = oatAllocTemp(cUnit);
287 loadConstant(cUnit, rIdx, size);
288 // Establish loop branch target
289 ArmLIR* target = newLIR0(cUnit, kArmPseudoTargetLabel);
290 target->defMask = ENCODE_ALL;
291 // Load next key/disp
292 newLIR2(cUnit, kThumb2LdmiaWB, rBase, (1 << rKey) | (1 << rDisp));
293 opRegReg(cUnit, kOpCmp, rKey, rlSrc.lowReg);
294 // Go if match. NOTE: No instruction set switch here - must stay Thumb2
295 genIT(cUnit, kArmCondEq, "");
296 ArmLIR* switchBranch = newLIR1(cUnit, kThumb2AddPCR, rDisp);
297 tabRec->bxInst = switchBranch;
298 // Needs to use setflags encoding here
299 newLIR3(cUnit, kThumb2SubsRRI12, rIdx, rIdx, 1);
300 ArmLIR* branch = opCondBranch(cUnit, kArmCondNe);
301 branch->generic.target = (LIR*)target;
302}
303
304
buzbeeed3e9302011-09-23 17:34:19 -0700305STATIC void genPackedSwitch(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700306 RegLocation rlSrc)
307{
308 const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB;
309 if (cUnit->printMe) {
310 dumpPackedSwitchTable(table);
311 }
312 // Add the table to the list - we'll process it later
buzbeeba938cb2012-02-03 14:47:55 -0800313 SwitchTable *tabRec = (SwitchTable *)oatNew(cUnit, sizeof(SwitchTable),
buzbee5abfa3e2012-01-31 17:01:43 -0800314 true, kAllocData);
buzbee67bf8852011-08-17 17:51:35 -0700315 tabRec->table = table;
316 tabRec->vaddr = mir->offset;
317 int size = table[1];
buzbeeba938cb2012-02-03 14:47:55 -0800318 tabRec->targets = (ArmLIR* *)oatNew(cUnit, size * sizeof(ArmLIR*), true,
buzbee5abfa3e2012-01-31 17:01:43 -0800319 kAllocLIR);
buzbeeba938cb2012-02-03 14:47:55 -0800320 oatInsertGrowableList(cUnit, &cUnit->switchTables, (intptr_t)tabRec);
buzbee67bf8852011-08-17 17:51:35 -0700321
322 // Get the switch value
323 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
324 int tableBase = oatAllocTemp(cUnit);
325 // Materialize a pointer to the switch table
buzbee03fa2632011-09-20 17:10:57 -0700326 newLIR3(cUnit, kThumb2Adr, tableBase, 0, (intptr_t)tabRec);
buzbee67bf8852011-08-17 17:51:35 -0700327 int lowKey = s4FromSwitchData(&table[2]);
328 int keyReg;
329 // Remove the bias, if necessary
330 if (lowKey == 0) {
331 keyReg = rlSrc.lowReg;
332 } else {
333 keyReg = oatAllocTemp(cUnit);
334 opRegRegImm(cUnit, kOpSub, keyReg, rlSrc.lowReg, lowKey);
335 }
336 // Bounds check - if < 0 or >= size continue following switch
337 opRegImm(cUnit, kOpCmp, keyReg, size-1);
338 ArmLIR* branchOver = opCondBranch(cUnit, kArmCondHi);
339
340 // Load the displacement from the switch table
341 int dispReg = oatAllocTemp(cUnit);
342 loadBaseIndexed(cUnit, tableBase, keyReg, dispReg, 2, kWord);
343
344 // ..and go! NOTE: No instruction set switch here - must stay Thumb2
345 ArmLIR* switchBranch = newLIR1(cUnit, kThumb2AddPCR, dispReg);
346 tabRec->bxInst = switchBranch;
347
348 /* branchOver target here */
349 ArmLIR* target = newLIR0(cUnit, kArmPseudoTargetLabel);
350 target->defMask = ENCODE_ALL;
351 branchOver->generic.target = (LIR*)target;
352}
353
354/*
355 * Array data table format:
356 * ushort ident = 0x0300 magic value
357 * ushort width width of each element in the table
358 * uint size number of elements in the table
359 * ubyte data[size*width] table of data values (may contain a single-byte
360 * padding at the end)
361 *
362 * Total size is 4+(width * size + 1)/2 16-bit code units.
363 */
buzbeeed3e9302011-09-23 17:34:19 -0700364STATIC void genFillArrayData(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700365 RegLocation rlSrc)
366{
367 const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB;
368 // Add the table to the list - we'll process it later
369 FillArrayData *tabRec = (FillArrayData *)
buzbeeba938cb2012-02-03 14:47:55 -0800370 oatNew(cUnit, sizeof(FillArrayData), true, kAllocData);
buzbee67bf8852011-08-17 17:51:35 -0700371 tabRec->table = table;
372 tabRec->vaddr = mir->offset;
373 u2 width = tabRec->table[1];
374 u4 size = tabRec->table[2] | (((u4)tabRec->table[3]) << 16);
375 tabRec->size = (size * width) + 8;
376
buzbeeba938cb2012-02-03 14:47:55 -0800377 oatInsertGrowableList(cUnit, &cUnit->fillArrayData, (intptr_t)tabRec);
buzbee67bf8852011-08-17 17:51:35 -0700378
379 // Making a call - use explicit registers
380 oatFlushAllRegs(cUnit); /* Everything to home location */
381 loadValueDirectFixed(cUnit, rlSrc, r0);
382 loadWordDisp(cUnit, rSELF,
buzbee1b4c8592011-08-31 10:43:51 -0700383 OFFSETOF_MEMBER(Thread, pHandleFillArrayDataFromCode), rLR);
buzbeee6d61962011-08-27 11:58:19 -0700384 // Materialize a pointer to the fill data image
buzbee03fa2632011-09-20 17:10:57 -0700385 newLIR3(cUnit, kThumb2Adr, r1, 0, (intptr_t)tabRec);
Ian Rogersff1ed472011-09-20 13:46:24 -0700386 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -0700387}
388
389/*
390 * Mark garbage collection card. Skip if the value we're storing is null.
391 */
buzbeeed3e9302011-09-23 17:34:19 -0700392STATIC void markGCCard(CompilationUnit* cUnit, int valReg, int tgtAddrReg)
buzbee67bf8852011-08-17 17:51:35 -0700393{
394 int regCardBase = oatAllocTemp(cUnit);
395 int regCardNo = oatAllocTemp(cUnit);
396 ArmLIR* branchOver = genCmpImmBranch(cUnit, kArmCondEq, valReg, 0);
buzbeec143c552011-08-20 17:38:58 -0700397 loadWordDisp(cUnit, rSELF, Thread::CardTableOffset().Int32Value(),
buzbee67bf8852011-08-17 17:51:35 -0700398 regCardBase);
399 opRegRegImm(cUnit, kOpLsr, regCardNo, tgtAddrReg, GC_CARD_SHIFT);
400 storeBaseIndexed(cUnit, regCardBase, regCardNo, regCardBase, 0,
401 kUnsignedByte);
402 ArmLIR* target = newLIR0(cUnit, kArmPseudoTargetLabel);
403 target->defMask = ENCODE_ALL;
404 branchOver->generic.target = (LIR*)target;
405 oatFreeTemp(cUnit, regCardBase);
406 oatFreeTemp(cUnit, regCardNo);
407}
408
buzbeeed3e9302011-09-23 17:34:19 -0700409STATIC void genIGet(CompilationUnit* cUnit, MIR* mir, OpSize size,
Ian Rogers1bddec32012-02-04 12:27:34 -0800410 RegLocation rlDest, RegLocation rlObj,
411 bool isLongOrDouble, bool isObject)
buzbee67bf8852011-08-17 17:51:35 -0700412{
Ian Rogers1bddec32012-02-04 12:27:34 -0800413 int fieldOffset;
414 bool isVolatile;
415 uint32_t fieldIdx = mir->dalvikInsn.vC;
416 bool fastPath =
417 cUnit->compiler->ComputeInstanceFieldInfo(fieldIdx, cUnit,
418 fieldOffset, isVolatile);
419 if (fastPath && !SLOW_FIELD_PATH) {
420 RegLocation rlResult;
421 RegisterClass regClass = oatRegClassBySize(size);
422 DCHECK_GE(fieldOffset, 0);
buzbee34cd9e52011-09-08 14:31:52 -0700423 rlObj = loadValue(cUnit, rlObj, kCoreReg);
Ian Rogers1bddec32012-02-04 12:27:34 -0800424 if (isLongOrDouble) {
425 DCHECK(rlDest.wide);
426 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null obj? */
427 int regPtr = oatAllocTemp(cUnit);
428 opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset);
429 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
430 loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg);
431 if (isVolatile) {
432 oatGenMemBarrier(cUnit, kSY);
433 }
434 oatFreeTemp(cUnit, regPtr);
435 storeValueWide(cUnit, rlDest, rlResult);
436 } else {
437 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
438 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null object? */
439 loadBaseDisp(cUnit, mir, rlObj.lowReg, fieldOffset, rlResult.lowReg,
440 kWord, rlObj.sRegLow);
441 if (isVolatile) {
442 oatGenMemBarrier(cUnit, kSY);
443 }
444 storeValue(cUnit, rlDest, rlResult);
buzbee34cd9e52011-09-08 14:31:52 -0700445 }
Ian Rogers1bddec32012-02-04 12:27:34 -0800446 } else {
447 int getterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pGet64Instance) :
448 (isObject ? OFFSETOF_MEMBER(Thread, pGetObjInstance)
449 : OFFSETOF_MEMBER(Thread, pGet32Instance));
450 loadWordDisp(cUnit, rSELF, getterOffset, rLR);
451 loadValueDirect(cUnit, rlObj, r1);
452 loadConstant(cUnit, r0, fieldIdx);
453 callRuntimeHelper(cUnit, rLR);
454 if (isLongOrDouble) {
455 RegLocation rlResult = oatGetReturnWide(cUnit);
456 storeValueWide(cUnit, rlDest, rlResult);
457 } else {
458 RegLocation rlResult = oatGetReturn(cUnit);
459 storeValue(cUnit, rlDest, rlResult);
460 }
buzbee67bf8852011-08-17 17:51:35 -0700461 }
buzbee67bf8852011-08-17 17:51:35 -0700462}
463
buzbeeed3e9302011-09-23 17:34:19 -0700464STATIC void genIPut(CompilationUnit* cUnit, MIR* mir, OpSize size,
Ian Rogers1bddec32012-02-04 12:27:34 -0800465 RegLocation rlSrc, RegLocation rlObj,
466 bool isLongOrDouble, bool isObject)
buzbee67bf8852011-08-17 17:51:35 -0700467{
Ian Rogers1bddec32012-02-04 12:27:34 -0800468 int fieldOffset;
469 bool isVolatile;
470 uint32_t fieldIdx = mir->dalvikInsn.vC;
471 bool fastPath =
472 cUnit->compiler->ComputeInstanceFieldInfo(fieldIdx, cUnit,
473 fieldOffset, isVolatile);
474 if (fastPath && !SLOW_FIELD_PATH) {
475 RegisterClass regClass = oatRegClassBySize(size);
476 DCHECK_GE(fieldOffset, 0);
buzbee34cd9e52011-09-08 14:31:52 -0700477 rlObj = loadValue(cUnit, rlObj, kCoreReg);
Ian Rogers1bddec32012-02-04 12:27:34 -0800478 if (isLongOrDouble) {
479 int regPtr;
480 rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg);
481 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null obj? */
482 regPtr = oatAllocTemp(cUnit);
483 opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset);
484 if (isVolatile) {
485 oatGenMemBarrier(cUnit, kST);
486 }
487 storePair(cUnit, regPtr, rlSrc.lowReg, rlSrc.highReg);
488 if (isVolatile) {
489 oatGenMemBarrier(cUnit, kSY);
490 }
491 oatFreeTemp(cUnit, regPtr);
492 } else {
493 rlSrc = loadValue(cUnit, rlSrc, regClass);
494 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null obj? */
495 if (isVolatile) {
496 oatGenMemBarrier(cUnit, kST);
497 }
498 storeBaseDisp(cUnit, rlObj.lowReg, fieldOffset, rlSrc.lowReg, kWord);
499 if (isVolatile) {
500 oatGenMemBarrier(cUnit, kSY);
501 }
buzbee34cd9e52011-09-08 14:31:52 -0700502 }
Ian Rogers1bddec32012-02-04 12:27:34 -0800503 } else {
504 int setterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pSet64Instance) :
505 (isObject ? OFFSETOF_MEMBER(Thread, pSetObjInstance)
506 : OFFSETOF_MEMBER(Thread, pSet32Instance));
507 loadWordDisp(cUnit, rSELF, setterOffset, rLR);
508 loadValueDirect(cUnit, rlObj, r1);
509 if (isLongOrDouble) {
510 loadValueDirectWide(cUnit, rlSrc, r2, r3);
511 } else {
512 loadValueDirect(cUnit, rlSrc, r2);
buzbee12246b82011-09-29 14:15:05 -0700513 }
Ian Rogers1bddec32012-02-04 12:27:34 -0800514 loadConstant(cUnit, r0, fieldIdx);
515 callRuntimeHelper(cUnit, rLR);
buzbee34cd9e52011-09-08 14:31:52 -0700516 }
buzbee67bf8852011-08-17 17:51:35 -0700517}
518
buzbeeed3e9302011-09-23 17:34:19 -0700519STATIC void genConstClass(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700520 RegLocation rlDest, RegLocation rlSrc)
521{
Ian Rogers28ad40d2011-10-27 15:19:26 -0700522 uint32_t type_idx = mir->dalvikInsn.vB;
buzbee1b4c8592011-08-31 10:43:51 -0700523 int mReg = loadCurrMethod(cUnit);
524 int resReg = oatAllocTemp(cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700525 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
Ian Rogersa3760aa2011-11-14 14:32:37 -0800526 if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
527 cUnit->dex_cache,
528 *cUnit->dex_file,
529 type_idx)) {
530 // Call out to helper which resolves type and verifies access.
531 // Resolved type returned in r0.
532 loadWordDisp(cUnit, rSELF,
533 OFFSETOF_MEMBER(Thread, pInitializeTypeAndVerifyAccessFromCode),
534 rLR);
535 genRegCopy(cUnit, r1, mReg);
536 loadConstant(cUnit, r0, type_idx);
537 callRuntimeHelper(cUnit, rLR);
538 RegLocation rlResult = oatGetReturn(cUnit);
539 storeValue(cUnit, rlDest, rlResult);
buzbee1b4c8592011-08-31 10:43:51 -0700540 } else {
Ian Rogers28ad40d2011-10-27 15:19:26 -0700541 // We're don't need access checks, load type from dex cache
542 int32_t dex_cache_offset = Method::DexCacheResolvedTypesOffset().Int32Value();
543 loadWordDisp(cUnit, mReg, dex_cache_offset, resReg);
544 int32_t offset_of_type = Array::DataOffset().Int32Value() + (sizeof(Class*) * type_idx);
545 loadWordDisp(cUnit, resReg, offset_of_type, rlResult.lowReg);
Ian Rogersa3760aa2011-11-14 14:32:37 -0800546 if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->dex_cache,
547 type_idx) ||
Ian Rogers28ad40d2011-10-27 15:19:26 -0700548 SLOW_TYPE_PATH) {
549 // Slow path, at runtime test if the type is null and if so initialize
550 oatFlushAllRegs(cUnit);
551 ArmLIR* branch1 = genCmpImmBranch(cUnit, kArmCondEq, rlResult.lowReg, 0);
552 // Resolved, store and hop over following code
553 storeValue(cUnit, rlDest, rlResult);
554 ArmLIR* branch2 = genUnconditionalBranch(cUnit,0);
555 // TUNING: move slow path to end & remove unconditional branch
556 ArmLIR* target1 = newLIR0(cUnit, kArmPseudoTargetLabel);
557 target1->defMask = ENCODE_ALL;
558 // Call out to helper, which will return resolved type in r0
559 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pInitializeTypeFromCode), rLR);
560 genRegCopy(cUnit, r1, mReg);
561 loadConstant(cUnit, r0, type_idx);
562 callRuntimeHelper(cUnit, rLR);
563 RegLocation rlResult = oatGetReturn(cUnit);
564 storeValue(cUnit, rlDest, rlResult);
565 // Rejoin code paths
566 ArmLIR* target2 = newLIR0(cUnit, kArmPseudoTargetLabel);
567 target2->defMask = ENCODE_ALL;
568 branch1->generic.target = (LIR*)target1;
569 branch2->generic.target = (LIR*)target2;
570 } else {
571 // Fast path, we're done - just store result
572 storeValue(cUnit, rlDest, rlResult);
573 }
buzbee1b4c8592011-08-31 10:43:51 -0700574 }
buzbee67bf8852011-08-17 17:51:35 -0700575}
576
buzbeeed3e9302011-09-23 17:34:19 -0700577STATIC void genConstString(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700578 RegLocation rlDest, RegLocation rlSrc)
579{
buzbeece302932011-10-04 14:32:18 -0700580 /* NOTE: Most strings should be available at compile time */
Ian Rogers28ad40d2011-10-27 15:19:26 -0700581 uint32_t string_idx = mir->dalvikInsn.vB;
582 int32_t offset_of_string = Array::DataOffset().Int32Value() + (sizeof(String*) * string_idx);
Ian Rogersa3760aa2011-11-14 14:32:37 -0800583 if (!cUnit->compiler->CanAssumeStringIsPresentInDexCache(cUnit->dex_cache, string_idx) ||
Ian Rogers28ad40d2011-10-27 15:19:26 -0700584 SLOW_STRING_PATH) {
585 // slow path, resolve string if not in dex cache
buzbeece302932011-10-04 14:32:18 -0700586 oatFlushAllRegs(cUnit);
587 oatLockCallTemps(cUnit); // Using explicit registers
588 loadCurrMethodDirect(cUnit, r2);
Ian Rogers28ad40d2011-10-27 15:19:26 -0700589 loadWordDisp(cUnit, r2, Method::DexCacheStringsOffset().Int32Value(), r0);
buzbeece302932011-10-04 14:32:18 -0700590 // Might call out to helper, which will return resolved string in r0
Ian Rogers28ad40d2011-10-27 15:19:26 -0700591 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pResolveStringFromCode), rLR);
592 loadWordDisp(cUnit, r0, offset_of_string, r0);
593 loadConstant(cUnit, r1, string_idx);
buzbeece302932011-10-04 14:32:18 -0700594 opRegImm(cUnit, kOpCmp, r0, 0); // Is resolved?
595 genBarrier(cUnit);
596 // For testing, always force through helper
597 if (!EXERCISE_SLOWEST_STRING_PATH) {
598 genIT(cUnit, kArmCondEq, "T");
599 }
600 genRegCopy(cUnit, r0, r2); // .eq
601 opReg(cUnit, kOpBlx, rLR); // .eq, helper(Method*, string_idx)
602 genBarrier(cUnit);
603 storeValue(cUnit, rlDest, getRetLoc(cUnit));
604 } else {
605 int mReg = loadCurrMethod(cUnit);
606 int resReg = oatAllocTemp(cUnit);
607 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
Ian Rogers28ad40d2011-10-27 15:19:26 -0700608 loadWordDisp(cUnit, mReg, Method::DexCacheStringsOffset().Int32Value(), resReg);
609 loadWordDisp(cUnit, resReg, offset_of_string, rlResult.lowReg);
buzbeece302932011-10-04 14:32:18 -0700610 storeValue(cUnit, rlDest, rlResult);
611 }
buzbee67bf8852011-08-17 17:51:35 -0700612}
613
buzbeedfd3d702011-08-28 12:56:51 -0700614/*
615 * Let helper function take care of everything. Will
616 * call Class::NewInstanceFromCode(type_idx, method);
617 */
buzbeeed3e9302011-09-23 17:34:19 -0700618STATIC void genNewInstance(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700619 RegLocation rlDest)
620{
buzbeedfd3d702011-08-28 12:56:51 -0700621 oatFlushAllRegs(cUnit); /* Everything to home location */
Ian Rogers28ad40d2011-10-27 15:19:26 -0700622 uint32_t type_idx = mir->dalvikInsn.vB;
623 // alloc will always check for resolution, do we also need to verify access because the
624 // verifier was unable to?
Ian Rogersd4135902012-02-03 18:05:08 -0800625 if (cUnit->compiler->CanAccessInstantiableTypeWithoutChecks(cUnit->method_idx,
626 cUnit->dex_cache,
627 *cUnit->dex_file,
628 type_idx)) {
Ian Rogers28ad40d2011-10-27 15:19:26 -0700629 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pAllocObjectFromCode), rLR);
630 } else {
631 loadWordDisp(cUnit, rSELF,
632 OFFSETOF_MEMBER(Thread, pAllocObjectFromCodeWithAccessCheck), rLR);
633 }
634 loadCurrMethodDirect(cUnit, r1); // arg1 <= Method*
635 loadConstant(cUnit, r0, type_idx); // arg0 <- type_idx
Ian Rogersff1ed472011-09-20 13:46:24 -0700636 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -0700637 RegLocation rlResult = oatGetReturn(cUnit);
638 storeValue(cUnit, rlDest, rlResult);
639}
640
641void genThrow(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
642{
buzbee6181f792011-09-29 11:14:04 -0700643 oatFlushAllRegs(cUnit);
Ian Rogers28ad40d2011-10-27 15:19:26 -0700644 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pDeliverException), rLR);
Ian Rogersbdb03912011-09-14 00:55:44 -0700645 loadValueDirectFixed(cUnit, rlSrc, r0); // Get exception object
Ian Rogersff1ed472011-09-20 13:46:24 -0700646 callRuntimeHelper(cUnit, rLR); // art_deliver_exception(exception);
buzbee67bf8852011-08-17 17:51:35 -0700647}
648
buzbeeed3e9302011-09-23 17:34:19 -0700649STATIC void genInstanceof(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest,
buzbee67bf8852011-08-17 17:51:35 -0700650 RegLocation rlSrc)
651{
buzbee6181f792011-09-29 11:14:04 -0700652 oatFlushAllRegs(cUnit);
buzbee2a475e72011-09-07 17:19:17 -0700653 // May generate a call - use explicit registers
654 oatLockCallTemps(cUnit);
Ian Rogers28ad40d2011-10-27 15:19:26 -0700655 uint32_t type_idx = mir->dalvikInsn.vC;
buzbee2a475e72011-09-07 17:19:17 -0700656 loadCurrMethodDirect(cUnit, r1); // r1 <= current Method*
Ian Rogers28ad40d2011-10-27 15:19:26 -0700657 int classReg = r2; // r2 will hold the Class*
Ian Rogersa3760aa2011-11-14 14:32:37 -0800658 if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
659 cUnit->dex_cache,
660 *cUnit->dex_file,
661 type_idx)) {
Ian Rogersb093c6b2011-10-31 16:19:55 -0700662 // Check we have access to type_idx and if not throw IllegalAccessError,
663 // returns Class* in r0
664 loadWordDisp(cUnit, rSELF,
665 OFFSETOF_MEMBER(Thread, pInitializeTypeAndVerifyAccessFromCode),
666 rLR);
667 loadConstant(cUnit, r0, type_idx);
668 callRuntimeHelper(cUnit, rLR); // InitializeTypeAndVerifyAccess(idx, method)
669 genRegCopy(cUnit, classReg, r0); // Align usage with fast path
Ian Rogers6a996782011-10-31 17:06:39 -0700670 loadValueDirectFixed(cUnit, rlSrc, r0); // r0 <= ref
Ian Rogers28ad40d2011-10-27 15:19:26 -0700671 } else {
672 // Load dex cache entry into classReg (r2)
Ian Rogers6a996782011-10-31 17:06:39 -0700673 loadValueDirectFixed(cUnit, rlSrc, r0); // r0 <= ref
Ian Rogers28ad40d2011-10-27 15:19:26 -0700674 loadWordDisp(cUnit, r1, Method::DexCacheResolvedTypesOffset().Int32Value(), classReg);
675 int32_t offset_of_type = Array::DataOffset().Int32Value() + (sizeof(Class*) * type_idx);
676 loadWordDisp(cUnit, classReg, offset_of_type, classReg);
Ian Rogersa3760aa2011-11-14 14:32:37 -0800677 if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->dex_cache, type_idx)) {
Ian Rogers28ad40d2011-10-27 15:19:26 -0700678 // Need to test presence of type in dex cache at runtime
679 ArmLIR* hopBranch = genCmpImmBranch(cUnit, kArmCondNe, classReg, 0);
680 // Not resolved
681 // Call out to helper, which will return resolved type in r0
682 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pInitializeTypeFromCode), rLR);
683 loadConstant(cUnit, r0, type_idx);
Ian Rogersb093c6b2011-10-31 16:19:55 -0700684 callRuntimeHelper(cUnit, rLR); // InitializeTypeFromCode(idx, method)
Ian Rogers28ad40d2011-10-27 15:19:26 -0700685 genRegCopy(cUnit, r2, r0); // Align usage with fast path
686 loadValueDirectFixed(cUnit, rlSrc, r0); /* reload Ref */
687 // Rejoin code paths
688 ArmLIR* hopTarget = newLIR0(cUnit, kArmPseudoTargetLabel);
689 hopTarget->defMask = ENCODE_ALL;
690 hopBranch->generic.target = (LIR*)hopTarget;
691 }
buzbee67bf8852011-08-17 17:51:35 -0700692 }
buzbee991e3ac2011-09-29 15:44:22 -0700693 /* r0 is ref, r2 is class. If ref==null, use directly as bool result */
694 ArmLIR* branch1 = genCmpImmBranch(cUnit, kArmCondEq, r0, 0);
buzbee2a475e72011-09-07 17:19:17 -0700695 /* load object->clazz */
buzbeeed3e9302011-09-23 17:34:19 -0700696 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
buzbee991e3ac2011-09-29 15:44:22 -0700697 loadWordDisp(cUnit, r0, Object::ClassOffset().Int32Value(), r1);
698 /* r0 is ref, r1 is ref->clazz, r2 is class */
Ian Rogers28ad40d2011-10-27 15:19:26 -0700699 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pInstanceofNonTrivialFromCode), rLR);
buzbee991e3ac2011-09-29 15:44:22 -0700700 opRegReg(cUnit, kOpCmp, r1, r2); // Same?
701 genBarrier(cUnit);
702 genIT(cUnit, kArmCondEq, "EE"); // if-convert the test
703 loadConstant(cUnit, r0, 1); // .eq case - load true
704 genRegCopy(cUnit, r0, r2); // .ne case - arg0 <= class
705 opReg(cUnit, kOpBlx, rLR); // .ne case: helper(class, ref->class)
706 genBarrier(cUnit);
707 oatClobberCalleeSave(cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700708 /* branch target here */
709 ArmLIR* target = newLIR0(cUnit, kArmPseudoTargetLabel);
710 target->defMask = ENCODE_ALL;
buzbee2a475e72011-09-07 17:19:17 -0700711 RegLocation rlResult = oatGetReturn(cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700712 storeValue(cUnit, rlDest, rlResult);
713 branch1->generic.target = (LIR*)target;
buzbee67bf8852011-08-17 17:51:35 -0700714}
715
buzbeeed3e9302011-09-23 17:34:19 -0700716STATIC void genCheckCast(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
buzbee67bf8852011-08-17 17:51:35 -0700717{
buzbee6181f792011-09-29 11:14:04 -0700718 oatFlushAllRegs(cUnit);
buzbee2a475e72011-09-07 17:19:17 -0700719 // May generate a call - use explicit registers
720 oatLockCallTemps(cUnit);
Ian Rogers28ad40d2011-10-27 15:19:26 -0700721 uint32_t type_idx = mir->dalvikInsn.vB;
buzbee2a475e72011-09-07 17:19:17 -0700722 loadCurrMethodDirect(cUnit, r1); // r1 <= current Method*
Ian Rogers28ad40d2011-10-27 15:19:26 -0700723 int classReg = r2; // r2 will hold the Class*
Ian Rogersa3760aa2011-11-14 14:32:37 -0800724 if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
725 cUnit->dex_cache,
726 *cUnit->dex_file,
727 type_idx)) {
Ian Rogersb093c6b2011-10-31 16:19:55 -0700728 // Check we have access to type_idx and if not throw IllegalAccessError,
729 // returns Class* in r0
730 loadWordDisp(cUnit, rSELF,
731 OFFSETOF_MEMBER(Thread, pInitializeTypeAndVerifyAccessFromCode),
732 rLR);
733 loadConstant(cUnit, r0, type_idx);
734 callRuntimeHelper(cUnit, rLR); // InitializeTypeAndVerifyAccess(idx, method)
735 genRegCopy(cUnit, classReg, r0); // Align usage with fast path
Ian Rogers28ad40d2011-10-27 15:19:26 -0700736 } else {
737 // Load dex cache entry into classReg (r2)
738 loadWordDisp(cUnit, r1, Method::DexCacheResolvedTypesOffset().Int32Value(), classReg);
739 int32_t offset_of_type = Array::DataOffset().Int32Value() + (sizeof(Class*) * type_idx);
740 loadWordDisp(cUnit, classReg, offset_of_type, classReg);
Ian Rogersa3760aa2011-11-14 14:32:37 -0800741 if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->dex_cache, type_idx)) {
Ian Rogers28ad40d2011-10-27 15:19:26 -0700742 // Need to test presence of type in dex cache at runtime
743 ArmLIR* hopBranch = genCmpImmBranch(cUnit, kArmCondNe, classReg, 0);
744 // Not resolved
745 // Call out to helper, which will return resolved type in r0
746 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pInitializeTypeFromCode), rLR);
747 loadConstant(cUnit, r0, type_idx);
Ian Rogersb093c6b2011-10-31 16:19:55 -0700748 callRuntimeHelper(cUnit, rLR); // InitializeTypeFromCode(idx, method)
749 genRegCopy(cUnit, classReg, r0); // Align usage with fast path
Ian Rogers28ad40d2011-10-27 15:19:26 -0700750 // Rejoin code paths
751 ArmLIR* hopTarget = newLIR0(cUnit, kArmPseudoTargetLabel);
752 hopTarget->defMask = ENCODE_ALL;
753 hopBranch->generic.target = (LIR*)hopTarget;
754 }
buzbee67bf8852011-08-17 17:51:35 -0700755 }
Ian Rogers28ad40d2011-10-27 15:19:26 -0700756 // At this point, classReg (r2) has class
757 loadValueDirectFixed(cUnit, rlSrc, r0); // r0 <= ref
buzbee2a475e72011-09-07 17:19:17 -0700758 /* Null is OK - continue */
759 ArmLIR* branch1 = genCmpImmBranch(cUnit, kArmCondEq, r0, 0);
760 /* load object->clazz */
buzbeeed3e9302011-09-23 17:34:19 -0700761 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
buzbee2a475e72011-09-07 17:19:17 -0700762 loadWordDisp(cUnit, r0, Object::ClassOffset().Int32Value(), r1);
763 /* r1 now contains object->clazz */
Ian Rogers28ad40d2011-10-27 15:19:26 -0700764 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pCheckCastFromCode), rLR);
Ian Rogersb093c6b2011-10-31 16:19:55 -0700765 opRegReg(cUnit, kOpCmp, r1, classReg);
buzbee2a475e72011-09-07 17:19:17 -0700766 ArmLIR* branch2 = opCondBranch(cUnit, kArmCondEq); /* If equal, trivial yes */
767 genRegCopy(cUnit, r0, r1);
768 genRegCopy(cUnit, r1, r2);
Ian Rogersff1ed472011-09-20 13:46:24 -0700769 callRuntimeHelper(cUnit, rLR);
buzbee2a475e72011-09-07 17:19:17 -0700770 /* branch target here */
buzbee67bf8852011-08-17 17:51:35 -0700771 ArmLIR* target = newLIR0(cUnit, kArmPseudoTargetLabel);
772 target->defMask = ENCODE_ALL;
773 branch1->generic.target = (LIR*)target;
774 branch2->generic.target = (LIR*)target;
775}
776
buzbeeed3e9302011-09-23 17:34:19 -0700777STATIC void genNegFloat(CompilationUnit* cUnit, RegLocation rlDest,
buzbee67bf8852011-08-17 17:51:35 -0700778 RegLocation rlSrc)
779{
780 RegLocation rlResult;
781 rlSrc = loadValue(cUnit, rlSrc, kFPReg);
782 rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true);
783 newLIR2(cUnit, kThumb2Vnegs, rlResult.lowReg, rlSrc.lowReg);
784 storeValue(cUnit, rlDest, rlResult);
785}
786
buzbeeed3e9302011-09-23 17:34:19 -0700787STATIC void genNegDouble(CompilationUnit* cUnit, RegLocation rlDest,
buzbee67bf8852011-08-17 17:51:35 -0700788 RegLocation rlSrc)
789{
790 RegLocation rlResult;
791 rlSrc = loadValueWide(cUnit, rlSrc, kFPReg);
792 rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true);
793 newLIR2(cUnit, kThumb2Vnegd, S2D(rlResult.lowReg, rlResult.highReg),
794 S2D(rlSrc.lowReg, rlSrc.highReg));
795 storeValueWide(cUnit, rlDest, rlResult);
796}
797
buzbeeed3e9302011-09-23 17:34:19 -0700798STATIC void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
buzbee439c4fa2011-08-27 15:59:07 -0700799 RegLocation rlFree)
buzbee67bf8852011-08-17 17:51:35 -0700800{
buzbee6181f792011-09-29 11:14:04 -0700801 if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) &&
802 (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) {
803 // No overlap, free both
buzbee439c4fa2011-08-27 15:59:07 -0700804 oatFreeTemp(cUnit, rlFree.lowReg);
buzbee6181f792011-09-29 11:14:04 -0700805 oatFreeTemp(cUnit, rlFree.highReg);
806 }
buzbee67bf8852011-08-17 17:51:35 -0700807}
808
buzbeeed3e9302011-09-23 17:34:19 -0700809STATIC void genLong3Addr(CompilationUnit* cUnit, MIR* mir, OpKind firstOp,
buzbee67bf8852011-08-17 17:51:35 -0700810 OpKind secondOp, RegLocation rlDest,
811 RegLocation rlSrc1, RegLocation rlSrc2)
812{
buzbee9e0f9b02011-08-24 15:32:46 -0700813 /*
814 * NOTE: This is the one place in the code in which we might have
815 * as many as six live temporary registers. There are 5 in the normal
816 * set for Arm. Until we have spill capabilities, temporarily add
817 * lr to the temp set. It is safe to do this locally, but note that
818 * lr is used explicitly elsewhere in the code generator and cannot
819 * normally be used as a general temp register.
820 */
buzbee67bf8852011-08-17 17:51:35 -0700821 RegLocation rlResult;
buzbee9e0f9b02011-08-24 15:32:46 -0700822 oatMarkTemp(cUnit, rLR); // Add lr to the temp pool
823 oatFreeTemp(cUnit, rLR); // and make it available
buzbee67bf8852011-08-17 17:51:35 -0700824 rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg);
825 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
826 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
buzbeec0ecd652011-09-25 18:11:54 -0700827 // The longs may overlap - use intermediate temp if so
828 if (rlResult.lowReg == rlSrc1.highReg) {
buzbeec0ecd652011-09-25 18:11:54 -0700829 int tReg = oatAllocTemp(cUnit);
830 genRegCopy(cUnit, tReg, rlSrc1.highReg);
831 opRegRegReg(cUnit, firstOp, rlResult.lowReg, rlSrc1.lowReg,
832 rlSrc2.lowReg);
833 opRegRegReg(cUnit, secondOp, rlResult.highReg, tReg,
834 rlSrc2.highReg);
835 oatFreeTemp(cUnit, tReg);
836 } else {
837 opRegRegReg(cUnit, firstOp, rlResult.lowReg, rlSrc1.lowReg,
838 rlSrc2.lowReg);
839 opRegRegReg(cUnit, secondOp, rlResult.highReg, rlSrc1.highReg,
840 rlSrc2.highReg);
841 }
buzbee439c4fa2011-08-27 15:59:07 -0700842 /*
843 * NOTE: If rlDest refers to a frame variable in a large frame, the
844 * following storeValueWide might need to allocate a temp register.
845 * To further work around the lack of a spill capability, explicitly
846 * free any temps from rlSrc1 & rlSrc2 that aren't still live in rlResult.
847 * Remove when spill is functional.
848 */
849 freeRegLocTemps(cUnit, rlResult, rlSrc1);
850 freeRegLocTemps(cUnit, rlResult, rlSrc2);
buzbee67bf8852011-08-17 17:51:35 -0700851 storeValueWide(cUnit, rlDest, rlResult);
buzbee9e0f9b02011-08-24 15:32:46 -0700852 oatClobber(cUnit, rLR);
853 oatUnmarkTemp(cUnit, rLR); // Remove lr from the temp pool
buzbee67bf8852011-08-17 17:51:35 -0700854}
855
856void oatInitializeRegAlloc(CompilationUnit* cUnit)
857{
858 int numRegs = sizeof(coreRegs)/sizeof(*coreRegs);
859 int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs);
860 int numTemps = sizeof(coreTemps)/sizeof(*coreTemps);
861 int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs);
862 int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps);
buzbeeba938cb2012-02-03 14:47:55 -0800863 RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true,
buzbee5abfa3e2012-01-31 17:01:43 -0800864 kAllocRegAlloc);
buzbee67bf8852011-08-17 17:51:35 -0700865 cUnit->regPool = pool;
866 pool->numCoreRegs = numRegs;
867 pool->coreRegs = (RegisterInfo *)
buzbeeba938cb2012-02-03 14:47:55 -0800868 oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs),
869 true, kAllocRegAlloc);
buzbee67bf8852011-08-17 17:51:35 -0700870 pool->numFPRegs = numFPRegs;
871 pool->FPRegs = (RegisterInfo *)
buzbeeba938cb2012-02-03 14:47:55 -0800872 oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true,
873 kAllocRegAlloc);
buzbee67bf8852011-08-17 17:51:35 -0700874 oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs);
875 oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs);
876 // Keep special registers from being allocated
877 for (int i = 0; i < numReserved; i++) {
buzbeec0ecd652011-09-25 18:11:54 -0700878 if (NO_SUSPEND && (reservedRegs[i] == rSUSPEND)) {
879 //To measure cost of suspend check
880 continue;
881 }
buzbee67bf8852011-08-17 17:51:35 -0700882 oatMarkInUse(cUnit, reservedRegs[i]);
883 }
884 // Mark temp regs - all others not in use can be used for promotion
885 for (int i = 0; i < numTemps; i++) {
886 oatMarkTemp(cUnit, coreTemps[i]);
887 }
888 for (int i = 0; i < numFPTemps; i++) {
889 oatMarkTemp(cUnit, fpTemps[i]);
890 }
buzbeec0ecd652011-09-25 18:11:54 -0700891 // Construct the alias map.
buzbeeba938cb2012-02-03 14:47:55 -0800892 cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs *
buzbee5abfa3e2012-01-31 17:01:43 -0800893 sizeof(cUnit->phiAliasMap[0]), false,
894 kAllocDFInfo);
buzbeec0ecd652011-09-25 18:11:54 -0700895 for (int i = 0; i < cUnit->numSSARegs; i++) {
896 cUnit->phiAliasMap[i] = i;
897 }
898 for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) {
899 int defReg = phi->ssaRep->defs[0];
900 for (int i = 0; i < phi->ssaRep->numUses; i++) {
901 for (int j = 0; j < cUnit->numSSARegs; j++) {
902 if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) {
903 cUnit->phiAliasMap[j] = defReg;
904 }
905 }
906 }
907 }
buzbee67bf8852011-08-17 17:51:35 -0700908}
909
910/*
911 * Handle simple case (thin lock) inline. If it's complicated, bail
912 * out to the heavyweight lock/unlock routines. We'll use dedicated
913 * registers here in order to be in the right position in case we
914 * to bail to dvm[Lock/Unlock]Object(self, object)
915 *
916 * r0 -> self pointer [arg0 for dvm[Lock/Unlock]Object
917 * r1 -> object [arg1 for dvm[Lock/Unlock]Object
918 * r2 -> intial contents of object->lock, later result of strex
919 * r3 -> self->threadId
920 * r12 -> allow to be used by utilities as general temp
921 *
922 * The result of the strex is 0 if we acquire the lock.
923 *
924 * See comments in Sync.c for the layout of the lock word.
925 * Of particular interest to this code is the test for the
926 * simple case - which we handle inline. For monitor enter, the
927 * simple case is thin lock, held by no-one. For monitor exit,
928 * the simple case is thin lock, held by the unlocking thread with
929 * a recurse count of 0.
930 *
931 * A minor complication is that there is a field in the lock word
932 * unrelated to locking: the hash state. This field must be ignored, but
933 * preserved.
934 *
935 */
buzbeeed3e9302011-09-23 17:34:19 -0700936STATIC void genMonitorEnter(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700937 RegLocation rlSrc)
938{
939 ArmLIR* target;
940 ArmLIR* hopTarget;
941 ArmLIR* branch;
942 ArmLIR* hopBranch;
943
944 oatFlushAllRegs(cUnit);
Elliott Hughes5f791332011-09-15 17:45:30 -0700945 DCHECK_EQ(LW_SHAPE_THIN, 0);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700946 loadValueDirectFixed(cUnit, rlSrc, r0); // Get obj
buzbee2e748f32011-08-29 21:02:19 -0700947 oatLockCallTemps(cUnit); // Prepare for explicit register usage
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700948 genNullCheck(cUnit, rlSrc.sRegLow, r0, mir);
949 loadWordDisp(cUnit, rSELF, Thread::ThinLockIdOffset().Int32Value(), r2);
950 newLIR3(cUnit, kThumb2Ldrex, r1, r0,
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700951 Object::MonitorOffset().Int32Value() >> 2); // Get object->lock
buzbeec143c552011-08-20 17:38:58 -0700952 // Align owner
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700953 opRegImm(cUnit, kOpLsl, r2, LW_LOCK_OWNER_SHIFT);
buzbee67bf8852011-08-17 17:51:35 -0700954 // Is lock unheld on lock or held by us (==threadId) on unlock?
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700955 newLIR4(cUnit, kThumb2Bfi, r2, r1, 0, LW_LOCK_OWNER_SHIFT - 1);
956 newLIR3(cUnit, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1);
957 hopBranch = newLIR2(cUnit, kThumb2Cbnz, r1, 0);
958 newLIR4(cUnit, kThumb2Strex, r1, r2, r0,
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700959 Object::MonitorOffset().Int32Value() >> 2);
buzbee67bf8852011-08-17 17:51:35 -0700960 oatGenMemBarrier(cUnit, kSY);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700961 branch = newLIR2(cUnit, kThumb2Cbz, r1, 0);
buzbee67bf8852011-08-17 17:51:35 -0700962
963 hopTarget = newLIR0(cUnit, kArmPseudoTargetLabel);
964 hopTarget->defMask = ENCODE_ALL;
965 hopBranch->generic.target = (LIR*)hopTarget;
966
buzbee1b4c8592011-08-31 10:43:51 -0700967 // Go expensive route - artLockObjectFromCode(self, obj);
968 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pLockObjectFromCode),
buzbee67bf8852011-08-17 17:51:35 -0700969 rLR);
Ian Rogersff1ed472011-09-20 13:46:24 -0700970 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -0700971
972 // Resume here
973 target = newLIR0(cUnit, kArmPseudoTargetLabel);
974 target->defMask = ENCODE_ALL;
975 branch->generic.target = (LIR*)target;
976}
977
978/*
979 * For monitor unlock, we don't have to use ldrex/strex. Once
980 * we've determined that the lock is thin and that we own it with
981 * a zero recursion count, it's safe to punch it back to the
982 * initial, unlock thin state with a store word.
983 */
buzbeeed3e9302011-09-23 17:34:19 -0700984STATIC void genMonitorExit(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -0700985 RegLocation rlSrc)
986{
987 ArmLIR* target;
988 ArmLIR* branch;
989 ArmLIR* hopTarget;
990 ArmLIR* hopBranch;
991
Elliott Hughes5f791332011-09-15 17:45:30 -0700992 DCHECK_EQ(LW_SHAPE_THIN, 0);
buzbee67bf8852011-08-17 17:51:35 -0700993 oatFlushAllRegs(cUnit);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700994 loadValueDirectFixed(cUnit, rlSrc, r0); // Get obj
buzbee2e748f32011-08-29 21:02:19 -0700995 oatLockCallTemps(cUnit); // Prepare for explicit register usage
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700996 genNullCheck(cUnit, rlSrc.sRegLow, r0, mir);
997 loadWordDisp(cUnit, r0, Object::MonitorOffset().Int32Value(), r1); // Get lock
998 loadWordDisp(cUnit, rSELF, Thread::ThinLockIdOffset().Int32Value(), r2);
buzbee67bf8852011-08-17 17:51:35 -0700999 // Is lock unheld on lock or held by us (==threadId) on unlock?
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001000 opRegRegImm(cUnit, kOpAnd, r3, r1, (LW_HASH_STATE_MASK << LW_HASH_STATE_SHIFT));
buzbeec143c552011-08-20 17:38:58 -07001001 // Align owner
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001002 opRegImm(cUnit, kOpLsl, r2, LW_LOCK_OWNER_SHIFT);
1003 newLIR3(cUnit, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1);
1004 opRegReg(cUnit, kOpSub, r1, r2);
buzbee67bf8852011-08-17 17:51:35 -07001005 hopBranch = opCondBranch(cUnit, kArmCondNe);
1006 oatGenMemBarrier(cUnit, kSY);
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001007 storeWordDisp(cUnit, r0, Object::MonitorOffset().Int32Value(), r3);
buzbee67bf8852011-08-17 17:51:35 -07001008 branch = opNone(cUnit, kOpUncondBr);
1009
1010 hopTarget = newLIR0(cUnit, kArmPseudoTargetLabel);
1011 hopTarget->defMask = ENCODE_ALL;
1012 hopBranch->generic.target = (LIR*)hopTarget;
1013
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001014 // Go expensive route - UnlockObjectFromCode(obj);
buzbee1b4c8592011-08-31 10:43:51 -07001015 loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pUnlockObjectFromCode),
buzbee67bf8852011-08-17 17:51:35 -07001016 rLR);
Ian Rogersff1ed472011-09-20 13:46:24 -07001017 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -07001018
1019 // Resume here
1020 target = newLIR0(cUnit, kArmPseudoTargetLabel);
1021 target->defMask = ENCODE_ALL;
1022 branch->generic.target = (LIR*)target;
1023}
1024
1025/*
1026 * 64-bit 3way compare function.
1027 * mov rX, #-1
1028 * cmp op1hi, op2hi
1029 * blt done
1030 * bgt flip
1031 * sub rX, op1lo, op2lo (treat as unsigned)
1032 * beq done
1033 * ite hi
1034 * mov(hi) rX, #-1
1035 * mov(!hi) rX, #1
1036 * flip:
1037 * neg rX
1038 * done:
1039 */
buzbeeed3e9302011-09-23 17:34:19 -07001040STATIC void genCmpLong(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -07001041 RegLocation rlDest, RegLocation rlSrc1,
1042 RegLocation rlSrc2)
1043{
buzbee67bf8852011-08-17 17:51:35 -07001044 ArmLIR* target1;
1045 ArmLIR* target2;
1046 rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg);
1047 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
buzbeeb29e4d12011-09-26 15:05:48 -07001048 int tReg = oatAllocTemp(cUnit);
1049 loadConstant(cUnit, tReg, -1);
buzbee67bf8852011-08-17 17:51:35 -07001050 opRegReg(cUnit, kOpCmp, rlSrc1.highReg, rlSrc2.highReg);
1051 ArmLIR* branch1 = opCondBranch(cUnit, kArmCondLt);
1052 ArmLIR* branch2 = opCondBranch(cUnit, kArmCondGt);
buzbeeb29e4d12011-09-26 15:05:48 -07001053 opRegRegReg(cUnit, kOpSub, tReg, rlSrc1.lowReg, rlSrc2.lowReg);
buzbee67bf8852011-08-17 17:51:35 -07001054 ArmLIR* branch3 = opCondBranch(cUnit, kArmCondEq);
1055
1056 genIT(cUnit, kArmCondHi, "E");
buzbeeb29e4d12011-09-26 15:05:48 -07001057 newLIR2(cUnit, kThumb2MovImmShift, tReg, modifiedImmediate(-1));
1058 loadConstant(cUnit, tReg, 1);
buzbee67bf8852011-08-17 17:51:35 -07001059 genBarrier(cUnit);
1060
1061 target2 = newLIR0(cUnit, kArmPseudoTargetLabel);
1062 target2->defMask = -1;
buzbeeb29e4d12011-09-26 15:05:48 -07001063 opRegReg(cUnit, kOpNeg, tReg, tReg);
buzbee67bf8852011-08-17 17:51:35 -07001064
1065 target1 = newLIR0(cUnit, kArmPseudoTargetLabel);
1066 target1->defMask = -1;
1067
buzbeeb29e4d12011-09-26 15:05:48 -07001068 RegLocation rlTemp = LOC_C_RETURN; // Just using as template, will change
1069 rlTemp.lowReg = tReg;
buzbee67bf8852011-08-17 17:51:35 -07001070 storeValue(cUnit, rlDest, rlTemp);
buzbeeb29e4d12011-09-26 15:05:48 -07001071 oatFreeTemp(cUnit, tReg);
buzbee67bf8852011-08-17 17:51:35 -07001072
1073 branch1->generic.target = (LIR*)target1;
1074 branch2->generic.target = (LIR*)target2;
1075 branch3->generic.target = branch1->generic.target;
1076}
1077
buzbeeed3e9302011-09-23 17:34:19 -07001078STATIC void genMultiplyByTwoBitMultiplier(CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -07001079 RegLocation rlSrc, RegLocation rlResult, int lit,
1080 int firstBit, int secondBit)
1081{
1082 opRegRegRegShift(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, rlSrc.lowReg,
1083 encodeShift(kArmLsl, secondBit - firstBit));
1084 if (firstBit != 0) {
1085 opRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlResult.lowReg, firstBit);
1086 }
1087}
1088
buzbeeed3e9302011-09-23 17:34:19 -07001089STATIC bool genConversionCall(CompilationUnit* cUnit, MIR* mir, int funcOffset,
buzbee67bf8852011-08-17 17:51:35 -07001090 int srcSize, int tgtSize)
1091{
1092 /*
1093 * Don't optimize the register usage since it calls out to support
1094 * functions
1095 */
1096 RegLocation rlSrc;
1097 RegLocation rlDest;
1098 oatFlushAllRegs(cUnit); /* Send everything to home location */
1099 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1100 if (srcSize == 1) {
1101 rlSrc = oatGetSrc(cUnit, mir, 0);
1102 loadValueDirectFixed(cUnit, rlSrc, r0);
1103 } else {
1104 rlSrc = oatGetSrcWide(cUnit, mir, 0, 1);
1105 loadValueDirectWideFixed(cUnit, rlSrc, r0, r1);
1106 }
Ian Rogersff1ed472011-09-20 13:46:24 -07001107 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -07001108 if (tgtSize == 1) {
1109 RegLocation rlResult;
1110 rlDest = oatGetDest(cUnit, mir, 0);
1111 rlResult = oatGetReturn(cUnit);
1112 storeValue(cUnit, rlDest, rlResult);
1113 } else {
1114 RegLocation rlResult;
1115 rlDest = oatGetDestWide(cUnit, mir, 0, 1);
1116 rlResult = oatGetReturnWide(cUnit);
1117 storeValueWide(cUnit, rlDest, rlResult);
1118 }
1119 return false;
1120}
1121
buzbeeed3e9302011-09-23 17:34:19 -07001122STATIC bool genArithOpFloatPortable(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -07001123 RegLocation rlDest, RegLocation rlSrc1,
1124 RegLocation rlSrc2)
1125{
1126 RegLocation rlResult;
1127 int funcOffset;
1128
1129 switch (mir->dalvikInsn.opcode) {
1130 case OP_ADD_FLOAT_2ADDR:
1131 case OP_ADD_FLOAT:
1132 funcOffset = OFFSETOF_MEMBER(Thread, pFadd);
1133 break;
1134 case OP_SUB_FLOAT_2ADDR:
1135 case OP_SUB_FLOAT:
1136 funcOffset = OFFSETOF_MEMBER(Thread, pFsub);
1137 break;
1138 case OP_DIV_FLOAT_2ADDR:
1139 case OP_DIV_FLOAT:
1140 funcOffset = OFFSETOF_MEMBER(Thread, pFdiv);
1141 break;
1142 case OP_MUL_FLOAT_2ADDR:
1143 case OP_MUL_FLOAT:
1144 funcOffset = OFFSETOF_MEMBER(Thread, pFmul);
1145 break;
1146 case OP_REM_FLOAT_2ADDR:
1147 case OP_REM_FLOAT:
1148 funcOffset = OFFSETOF_MEMBER(Thread, pFmodf);
1149 break;
1150 case OP_NEG_FLOAT: {
1151 genNegFloat(cUnit, rlDest, rlSrc1);
1152 return false;
1153 }
1154 default:
1155 return true;
1156 }
1157 oatFlushAllRegs(cUnit); /* Send everything to home location */
1158 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1159 loadValueDirectFixed(cUnit, rlSrc1, r0);
1160 loadValueDirectFixed(cUnit, rlSrc2, r1);
Ian Rogersff1ed472011-09-20 13:46:24 -07001161 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -07001162 rlResult = oatGetReturn(cUnit);
1163 storeValue(cUnit, rlDest, rlResult);
1164 return false;
1165}
1166
buzbeeed3e9302011-09-23 17:34:19 -07001167STATIC bool genArithOpDoublePortable(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -07001168 RegLocation rlDest, RegLocation rlSrc1,
1169 RegLocation rlSrc2)
1170{
1171 RegLocation rlResult;
1172 int funcOffset;
1173
1174 switch (mir->dalvikInsn.opcode) {
1175 case OP_ADD_DOUBLE_2ADDR:
1176 case OP_ADD_DOUBLE:
1177 funcOffset = OFFSETOF_MEMBER(Thread, pDadd);
1178 break;
1179 case OP_SUB_DOUBLE_2ADDR:
1180 case OP_SUB_DOUBLE:
1181 funcOffset = OFFSETOF_MEMBER(Thread, pDsub);
1182 break;
1183 case OP_DIV_DOUBLE_2ADDR:
1184 case OP_DIV_DOUBLE:
1185 funcOffset = OFFSETOF_MEMBER(Thread, pDdiv);
1186 break;
1187 case OP_MUL_DOUBLE_2ADDR:
1188 case OP_MUL_DOUBLE:
1189 funcOffset = OFFSETOF_MEMBER(Thread, pDmul);
1190 break;
1191 case OP_REM_DOUBLE_2ADDR:
1192 case OP_REM_DOUBLE:
1193 funcOffset = OFFSETOF_MEMBER(Thread, pFmod);
1194 break;
1195 case OP_NEG_DOUBLE: {
1196 genNegDouble(cUnit, rlDest, rlSrc1);
1197 return false;
1198 }
1199 default:
1200 return true;
1201 }
1202 oatFlushAllRegs(cUnit); /* Send everything to home location */
1203 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1204 loadValueDirectWideFixed(cUnit, rlSrc1, r0, r1);
1205 loadValueDirectWideFixed(cUnit, rlSrc2, r2, r3);
Ian Rogersff1ed472011-09-20 13:46:24 -07001206 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -07001207 rlResult = oatGetReturnWide(cUnit);
1208 storeValueWide(cUnit, rlDest, rlResult);
1209 return false;
1210}
1211
buzbeeed3e9302011-09-23 17:34:19 -07001212STATIC bool genConversionPortable(CompilationUnit* cUnit, MIR* mir)
buzbee67bf8852011-08-17 17:51:35 -07001213{
1214 Opcode opcode = mir->dalvikInsn.opcode;
1215
1216 switch (opcode) {
1217 case OP_INT_TO_FLOAT:
1218 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pI2f),
1219 1, 1);
1220 case OP_FLOAT_TO_INT:
1221 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pF2iz),
1222 1, 1);
1223 case OP_DOUBLE_TO_FLOAT:
1224 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pD2f),
1225 2, 1);
1226 case OP_FLOAT_TO_DOUBLE:
1227 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pF2d),
1228 1, 2);
1229 case OP_INT_TO_DOUBLE:
1230 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pI2d),
1231 1, 2);
1232 case OP_DOUBLE_TO_INT:
1233 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pD2iz),
1234 2, 1);
1235 case OP_FLOAT_TO_LONG:
1236 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread,
buzbee1b4c8592011-08-31 10:43:51 -07001237 pF2l), 1, 2);
buzbee67bf8852011-08-17 17:51:35 -07001238 case OP_LONG_TO_FLOAT:
1239 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pL2f),
1240 2, 1);
1241 case OP_DOUBLE_TO_LONG:
1242 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread,
buzbee1b4c8592011-08-31 10:43:51 -07001243 pD2l), 2, 2);
buzbee67bf8852011-08-17 17:51:35 -07001244 case OP_LONG_TO_DOUBLE:
1245 return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pL2d),
1246 2, 2);
1247 default:
1248 return true;
1249 }
1250 return false;
1251}
1252
1253/* Generate conditional branch instructions */
buzbeeed3e9302011-09-23 17:34:19 -07001254STATIC ArmLIR* genConditionalBranch(CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -07001255 ArmConditionCode cond,
1256 ArmLIR* target)
1257{
1258 ArmLIR* branch = opCondBranch(cUnit, cond);
1259 branch->generic.target = (LIR*) target;
1260 return branch;
1261}
1262
buzbee67bf8852011-08-17 17:51:35 -07001263/*
1264 * Generate array store
1265 *
1266 */
buzbeeed3e9302011-09-23 17:34:19 -07001267STATIC void genArrayObjPut(CompilationUnit* cUnit, MIR* mir,
buzbee1b4c8592011-08-31 10:43:51 -07001268 RegLocation rlArray, RegLocation rlIndex,
1269 RegLocation rlSrc, int scale)
buzbee67bf8852011-08-17 17:51:35 -07001270{
1271 RegisterClass regClass = oatRegClassBySize(kWord);
buzbeec143c552011-08-20 17:38:58 -07001272 int lenOffset = Array::LengthOffset().Int32Value();
1273 int dataOffset = Array::DataOffset().Int32Value();
buzbee67bf8852011-08-17 17:51:35 -07001274
buzbee6181f792011-09-29 11:14:04 -07001275 oatFlushAllRegs(cUnit);
buzbee67bf8852011-08-17 17:51:35 -07001276 /* Make sure it's a legal object Put. Use direct regs at first */
1277 loadValueDirectFixed(cUnit, rlArray, r1);
1278 loadValueDirectFixed(cUnit, rlSrc, r0);
1279
1280 /* null array object? */
buzbee43a36422011-09-14 14:00:13 -07001281 genNullCheck(cUnit, rlArray.sRegLow, r1, mir);
buzbee67bf8852011-08-17 17:51:35 -07001282 loadWordDisp(cUnit, rSELF,
buzbee1b4c8592011-08-31 10:43:51 -07001283 OFFSETOF_MEMBER(Thread, pCanPutArrayElementFromCode), rLR);
buzbee67bf8852011-08-17 17:51:35 -07001284 /* Get the array's clazz */
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001285 loadWordDisp(cUnit, r1, Object::ClassOffset().Int32Value(), r1);
Ian Rogersff1ed472011-09-20 13:46:24 -07001286 callRuntimeHelper(cUnit, rLR);
buzbee6181f792011-09-29 11:14:04 -07001287 oatFreeTemp(cUnit, r0);
1288 oatFreeTemp(cUnit, r1);
buzbee67bf8852011-08-17 17:51:35 -07001289
1290 // Now, redo loadValues in case they didn't survive the call
1291
1292 int regPtr;
1293 rlArray = loadValue(cUnit, rlArray, kCoreReg);
1294 rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
1295
1296 if (oatIsTemp(cUnit, rlArray.lowReg)) {
1297 oatClobber(cUnit, rlArray.lowReg);
1298 regPtr = rlArray.lowReg;
1299 } else {
1300 regPtr = oatAllocTemp(cUnit);
1301 genRegCopy(cUnit, regPtr, rlArray.lowReg);
1302 }
1303
buzbee43a36422011-09-14 14:00:13 -07001304 if (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
buzbee67bf8852011-08-17 17:51:35 -07001305 int regLen = oatAllocTemp(cUnit);
1306 //NOTE: max live temps(4) here.
1307 /* Get len */
1308 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen);
1309 /* regPtr -> array data */
1310 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
buzbeeec5adf32011-09-11 15:25:43 -07001311 genRegRegCheck(cUnit, kArmCondCs, rlIndex.lowReg, regLen, mir,
buzbee5ade1d22011-09-09 14:44:52 -07001312 kArmThrowArrayBounds);
buzbee67bf8852011-08-17 17:51:35 -07001313 oatFreeTemp(cUnit, regLen);
1314 } else {
1315 /* regPtr -> array data */
1316 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
1317 }
1318 /* at this point, regPtr points to array, 2 live temps */
1319 rlSrc = loadValue(cUnit, rlSrc, regClass);
1320 storeBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlSrc.lowReg,
1321 scale, kWord);
1322}
1323
1324/*
1325 * Generate array load
1326 */
buzbeeed3e9302011-09-23 17:34:19 -07001327STATIC void genArrayGet(CompilationUnit* cUnit, MIR* mir, OpSize size,
buzbee67bf8852011-08-17 17:51:35 -07001328 RegLocation rlArray, RegLocation rlIndex,
1329 RegLocation rlDest, int scale)
1330{
1331 RegisterClass regClass = oatRegClassBySize(size);
buzbeec143c552011-08-20 17:38:58 -07001332 int lenOffset = Array::LengthOffset().Int32Value();
1333 int dataOffset = Array::DataOffset().Int32Value();
buzbee67bf8852011-08-17 17:51:35 -07001334 RegLocation rlResult;
1335 rlArray = loadValue(cUnit, rlArray, kCoreReg);
1336 rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
1337 int regPtr;
1338
1339 /* null object? */
buzbee43a36422011-09-14 14:00:13 -07001340 genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, mir);
buzbee67bf8852011-08-17 17:51:35 -07001341
1342 regPtr = oatAllocTemp(cUnit);
1343
buzbee43a36422011-09-14 14:00:13 -07001344 if (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
buzbee67bf8852011-08-17 17:51:35 -07001345 int regLen = oatAllocTemp(cUnit);
1346 /* Get len */
1347 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen);
1348 /* regPtr -> array data */
1349 opRegRegImm(cUnit, kOpAdd, regPtr, rlArray.lowReg, dataOffset);
buzbeeec5adf32011-09-11 15:25:43 -07001350 genRegRegCheck(cUnit, kArmCondCs, rlIndex.lowReg, regLen, mir,
buzbee5ade1d22011-09-09 14:44:52 -07001351 kArmThrowArrayBounds);
buzbee67bf8852011-08-17 17:51:35 -07001352 oatFreeTemp(cUnit, regLen);
1353 } else {
1354 /* regPtr -> array data */
1355 opRegRegImm(cUnit, kOpAdd, regPtr, rlArray.lowReg, dataOffset);
1356 }
buzbeee9a72f62011-09-04 17:59:07 -07001357 oatFreeTemp(cUnit, rlArray.lowReg);
buzbee67bf8852011-08-17 17:51:35 -07001358 if ((size == kLong) || (size == kDouble)) {
1359 if (scale) {
1360 int rNewIndex = oatAllocTemp(cUnit);
1361 opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale);
1362 opRegReg(cUnit, kOpAdd, regPtr, rNewIndex);
1363 oatFreeTemp(cUnit, rNewIndex);
1364 } else {
1365 opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg);
1366 }
buzbeee9a72f62011-09-04 17:59:07 -07001367 oatFreeTemp(cUnit, rlIndex.lowReg);
buzbee67bf8852011-08-17 17:51:35 -07001368 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
1369
1370 loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg);
1371
1372 oatFreeTemp(cUnit, regPtr);
1373 storeValueWide(cUnit, rlDest, rlResult);
1374 } else {
1375 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
1376
1377 loadBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlResult.lowReg,
1378 scale, size);
1379
1380 oatFreeTemp(cUnit, regPtr);
1381 storeValue(cUnit, rlDest, rlResult);
1382 }
1383}
1384
1385/*
1386 * Generate array store
1387 *
1388 */
buzbeeed3e9302011-09-23 17:34:19 -07001389STATIC void genArrayPut(CompilationUnit* cUnit, MIR* mir, OpSize size,
buzbee67bf8852011-08-17 17:51:35 -07001390 RegLocation rlArray, RegLocation rlIndex,
1391 RegLocation rlSrc, int scale)
1392{
1393 RegisterClass regClass = oatRegClassBySize(size);
buzbeec143c552011-08-20 17:38:58 -07001394 int lenOffset = Array::LengthOffset().Int32Value();
1395 int dataOffset = Array::DataOffset().Int32Value();
buzbee67bf8852011-08-17 17:51:35 -07001396
1397 int regPtr;
1398 rlArray = loadValue(cUnit, rlArray, kCoreReg);
1399 rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
1400
1401 if (oatIsTemp(cUnit, rlArray.lowReg)) {
1402 oatClobber(cUnit, rlArray.lowReg);
1403 regPtr = rlArray.lowReg;
1404 } else {
1405 regPtr = oatAllocTemp(cUnit);
1406 genRegCopy(cUnit, regPtr, rlArray.lowReg);
1407 }
1408
1409 /* null object? */
buzbee43a36422011-09-14 14:00:13 -07001410 genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, mir);
buzbee67bf8852011-08-17 17:51:35 -07001411
buzbee43a36422011-09-14 14:00:13 -07001412 if (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
buzbee67bf8852011-08-17 17:51:35 -07001413 int regLen = oatAllocTemp(cUnit);
1414 //NOTE: max live temps(4) here.
1415 /* Get len */
1416 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen);
1417 /* regPtr -> array data */
1418 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
buzbeeec5adf32011-09-11 15:25:43 -07001419 genRegRegCheck(cUnit, kArmCondCs, rlIndex.lowReg, regLen, mir,
buzbee5ade1d22011-09-09 14:44:52 -07001420 kArmThrowArrayBounds);
buzbee67bf8852011-08-17 17:51:35 -07001421 oatFreeTemp(cUnit, regLen);
1422 } else {
1423 /* regPtr -> array data */
1424 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
1425 }
1426 /* at this point, regPtr points to array, 2 live temps */
1427 if ((size == kLong) || (size == kDouble)) {
buzbee5ade1d22011-09-09 14:44:52 -07001428 //TUNING: specific wide routine that can handle fp regs
buzbee67bf8852011-08-17 17:51:35 -07001429 if (scale) {
1430 int rNewIndex = oatAllocTemp(cUnit);
1431 opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale);
1432 opRegReg(cUnit, kOpAdd, regPtr, rNewIndex);
1433 oatFreeTemp(cUnit, rNewIndex);
1434 } else {
1435 opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg);
1436 }
1437 rlSrc = loadValueWide(cUnit, rlSrc, regClass);
1438
1439 storePair(cUnit, regPtr, rlSrc.lowReg, rlSrc.highReg);
1440
1441 oatFreeTemp(cUnit, regPtr);
1442 } else {
1443 rlSrc = loadValue(cUnit, rlSrc, regClass);
1444
1445 storeBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlSrc.lowReg,
1446 scale, size);
1447 }
1448}
1449
buzbeeed3e9302011-09-23 17:34:19 -07001450STATIC bool genShiftOpLong(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -07001451 RegLocation rlDest, RegLocation rlSrc1,
1452 RegLocation rlShift)
1453{
buzbee54330722011-08-23 16:46:55 -07001454 int funcOffset;
buzbee67bf8852011-08-17 17:51:35 -07001455
buzbee67bf8852011-08-17 17:51:35 -07001456 switch( mir->dalvikInsn.opcode) {
1457 case OP_SHL_LONG:
1458 case OP_SHL_LONG_2ADDR:
buzbee54330722011-08-23 16:46:55 -07001459 funcOffset = OFFSETOF_MEMBER(Thread, pShlLong);
buzbee67bf8852011-08-17 17:51:35 -07001460 break;
1461 case OP_SHR_LONG:
1462 case OP_SHR_LONG_2ADDR:
buzbee54330722011-08-23 16:46:55 -07001463 funcOffset = OFFSETOF_MEMBER(Thread, pShrLong);
buzbee67bf8852011-08-17 17:51:35 -07001464 break;
1465 case OP_USHR_LONG:
1466 case OP_USHR_LONG_2ADDR:
buzbee54330722011-08-23 16:46:55 -07001467 funcOffset = OFFSETOF_MEMBER(Thread, pUshrLong);
buzbee67bf8852011-08-17 17:51:35 -07001468 break;
1469 default:
buzbee54330722011-08-23 16:46:55 -07001470 LOG(FATAL) << "Unexpected case";
buzbee67bf8852011-08-17 17:51:35 -07001471 return true;
1472 }
buzbee54330722011-08-23 16:46:55 -07001473 oatFlushAllRegs(cUnit); /* Send everything to home location */
1474 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1475 loadValueDirectWideFixed(cUnit, rlSrc1, r0, r1);
1476 loadValueDirect(cUnit, rlShift, r2);
Ian Rogersff1ed472011-09-20 13:46:24 -07001477 callRuntimeHelper(cUnit, rLR);
buzbee54330722011-08-23 16:46:55 -07001478 RegLocation rlResult = oatGetReturnWide(cUnit);
buzbee67bf8852011-08-17 17:51:35 -07001479 storeValueWide(cUnit, rlDest, rlResult);
1480 return false;
1481}
1482
buzbeeed3e9302011-09-23 17:34:19 -07001483STATIC bool genArithOpLong(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -07001484 RegLocation rlDest, RegLocation rlSrc1,
1485 RegLocation rlSrc2)
1486{
1487 RegLocation rlResult;
1488 OpKind firstOp = kOpBkpt;
1489 OpKind secondOp = kOpBkpt;
1490 bool callOut = false;
buzbee58f92742011-10-01 11:22:17 -07001491 bool checkZero = false;
buzbee67bf8852011-08-17 17:51:35 -07001492 int funcOffset;
1493 int retReg = r0;
1494
1495 switch (mir->dalvikInsn.opcode) {
1496 case OP_NOT_LONG:
1497 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
1498 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
buzbeeb29e4d12011-09-26 15:05:48 -07001499 // Check for destructive overlap
1500 if (rlResult.lowReg == rlSrc2.highReg) {
1501 int tReg = oatAllocTemp(cUnit);
1502 genRegCopy(cUnit, tReg, rlSrc2.highReg);
1503 opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg);
1504 opRegReg(cUnit, kOpMvn, rlResult.highReg, tReg);
1505 oatFreeTemp(cUnit, tReg);
1506 } else {
1507 opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg);
1508 opRegReg(cUnit, kOpMvn, rlResult.highReg, rlSrc2.highReg);
1509 }
buzbee67bf8852011-08-17 17:51:35 -07001510 storeValueWide(cUnit, rlDest, rlResult);
1511 return false;
1512 break;
1513 case OP_ADD_LONG:
1514 case OP_ADD_LONG_2ADDR:
1515 firstOp = kOpAdd;
1516 secondOp = kOpAdc;
1517 break;
1518 case OP_SUB_LONG:
1519 case OP_SUB_LONG_2ADDR:
1520 firstOp = kOpSub;
1521 secondOp = kOpSbc;
1522 break;
1523 case OP_MUL_LONG:
1524 case OP_MUL_LONG_2ADDR:
buzbee439c4fa2011-08-27 15:59:07 -07001525 callOut = true;
1526 retReg = r0;
1527 funcOffset = OFFSETOF_MEMBER(Thread, pLmul);
1528 break;
buzbee67bf8852011-08-17 17:51:35 -07001529 case OP_DIV_LONG:
1530 case OP_DIV_LONG_2ADDR:
1531 callOut = true;
buzbee58f92742011-10-01 11:22:17 -07001532 checkZero = true;
buzbee67bf8852011-08-17 17:51:35 -07001533 retReg = r0;
1534 funcOffset = OFFSETOF_MEMBER(Thread, pLdivmod);
1535 break;
1536 /* NOTE - result is in r2/r3 instead of r0/r1 */
1537 case OP_REM_LONG:
1538 case OP_REM_LONG_2ADDR:
1539 callOut = true;
buzbee58f92742011-10-01 11:22:17 -07001540 checkZero = true;
buzbee67bf8852011-08-17 17:51:35 -07001541 funcOffset = OFFSETOF_MEMBER(Thread, pLdivmod);
1542 retReg = r2;
1543 break;
1544 case OP_AND_LONG_2ADDR:
1545 case OP_AND_LONG:
1546 firstOp = kOpAnd;
1547 secondOp = kOpAnd;
1548 break;
1549 case OP_OR_LONG:
1550 case OP_OR_LONG_2ADDR:
1551 firstOp = kOpOr;
1552 secondOp = kOpOr;
1553 break;
1554 case OP_XOR_LONG:
1555 case OP_XOR_LONG_2ADDR:
1556 firstOp = kOpXor;
1557 secondOp = kOpXor;
1558 break;
1559 case OP_NEG_LONG: {
buzbee67bf8852011-08-17 17:51:35 -07001560 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
1561 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
buzbeeb29e4d12011-09-26 15:05:48 -07001562 int zReg = oatAllocTemp(cUnit);
1563 loadConstantNoClobber(cUnit, zReg, 0);
1564 // Check for destructive overlap
1565 if (rlResult.lowReg == rlSrc2.highReg) {
1566 int tReg = oatAllocTemp(cUnit);
1567 opRegRegReg(cUnit, kOpSub, rlResult.lowReg,
1568 zReg, rlSrc2.lowReg);
1569 opRegRegReg(cUnit, kOpSbc, rlResult.highReg,
1570 zReg, tReg);
1571 oatFreeTemp(cUnit, tReg);
1572 } else {
1573 opRegRegReg(cUnit, kOpSub, rlResult.lowReg,
1574 zReg, rlSrc2.lowReg);
1575 opRegRegReg(cUnit, kOpSbc, rlResult.highReg,
1576 zReg, rlSrc2.highReg);
1577 }
1578 oatFreeTemp(cUnit, zReg);
buzbee67bf8852011-08-17 17:51:35 -07001579 storeValueWide(cUnit, rlDest, rlResult);
1580 return false;
1581 }
1582 default:
1583 LOG(FATAL) << "Invalid long arith op";
1584 }
1585 if (!callOut) {
1586 genLong3Addr(cUnit, mir, firstOp, secondOp, rlDest, rlSrc1, rlSrc2);
1587 } else {
buzbee67bf8852011-08-17 17:51:35 -07001588 oatFlushAllRegs(cUnit); /* Send everything to home location */
buzbee58f92742011-10-01 11:22:17 -07001589 if (checkZero) {
1590 loadValueDirectWideFixed(cUnit, rlSrc2, r2, r3);
1591 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1592 loadValueDirectWideFixed(cUnit, rlSrc1, r0, r1);
1593 int tReg = oatAllocTemp(cUnit);
1594 newLIR4(cUnit, kThumb2OrrRRRs, tReg, r2, r3, 0);
1595 oatFreeTemp(cUnit, tReg);
1596 genCheck(cUnit, kArmCondEq, mir, kArmThrowDivZero);
1597 } else {
1598 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1599 loadValueDirectWideFixed(cUnit, rlSrc1, r0, r1);
1600 loadValueDirectWideFixed(cUnit, rlSrc2, r2, r3);
1601 }
Ian Rogersff1ed472011-09-20 13:46:24 -07001602 callRuntimeHelper(cUnit, rLR);
buzbee58f92742011-10-01 11:22:17 -07001603 // Adjust return regs in to handle case of rem returning r2/r3
buzbee67bf8852011-08-17 17:51:35 -07001604 if (retReg == r0)
1605 rlResult = oatGetReturnWide(cUnit);
1606 else
1607 rlResult = oatGetReturnWideAlt(cUnit);
1608 storeValueWide(cUnit, rlDest, rlResult);
1609 }
1610 return false;
1611}
1612
buzbeeed3e9302011-09-23 17:34:19 -07001613STATIC bool genArithOpInt(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -07001614 RegLocation rlDest, RegLocation rlSrc1,
1615 RegLocation rlSrc2)
1616{
1617 OpKind op = kOpBkpt;
1618 bool callOut = false;
1619 bool checkZero = false;
1620 bool unary = false;
1621 int retReg = r0;
1622 int funcOffset;
1623 RegLocation rlResult;
1624 bool shiftOp = false;
1625
1626 switch (mir->dalvikInsn.opcode) {
1627 case OP_NEG_INT:
1628 op = kOpNeg;
1629 unary = true;
1630 break;
1631 case OP_NOT_INT:
1632 op = kOpMvn;
1633 unary = true;
1634 break;
1635 case OP_ADD_INT:
1636 case OP_ADD_INT_2ADDR:
1637 op = kOpAdd;
1638 break;
1639 case OP_SUB_INT:
1640 case OP_SUB_INT_2ADDR:
1641 op = kOpSub;
1642 break;
1643 case OP_MUL_INT:
1644 case OP_MUL_INT_2ADDR:
1645 op = kOpMul;
1646 break;
1647 case OP_DIV_INT:
1648 case OP_DIV_INT_2ADDR:
1649 callOut = true;
1650 checkZero = true;
1651 funcOffset = OFFSETOF_MEMBER(Thread, pIdiv);
1652 retReg = r0;
1653 break;
1654 /* NOTE: returns in r1 */
1655 case OP_REM_INT:
1656 case OP_REM_INT_2ADDR:
1657 callOut = true;
1658 checkZero = true;
1659 funcOffset = OFFSETOF_MEMBER(Thread, pIdivmod);
1660 retReg = r1;
1661 break;
1662 case OP_AND_INT:
1663 case OP_AND_INT_2ADDR:
1664 op = kOpAnd;
1665 break;
1666 case OP_OR_INT:
1667 case OP_OR_INT_2ADDR:
1668 op = kOpOr;
1669 break;
1670 case OP_XOR_INT:
1671 case OP_XOR_INT_2ADDR:
1672 op = kOpXor;
1673 break;
1674 case OP_SHL_INT:
1675 case OP_SHL_INT_2ADDR:
1676 shiftOp = true;
1677 op = kOpLsl;
1678 break;
1679 case OP_SHR_INT:
1680 case OP_SHR_INT_2ADDR:
1681 shiftOp = true;
1682 op = kOpAsr;
1683 break;
1684 case OP_USHR_INT:
1685 case OP_USHR_INT_2ADDR:
1686 shiftOp = true;
1687 op = kOpLsr;
1688 break;
1689 default:
1690 LOG(FATAL) << "Invalid word arith op: " <<
1691 (int)mir->dalvikInsn.opcode;
1692 }
1693 if (!callOut) {
1694 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
1695 if (unary) {
1696 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1697 opRegReg(cUnit, op, rlResult.lowReg,
1698 rlSrc1.lowReg);
1699 } else {
1700 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
1701 if (shiftOp) {
1702 int tReg = oatAllocTemp(cUnit);
1703 opRegRegImm(cUnit, kOpAnd, tReg, rlSrc2.lowReg, 31);
1704 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1705 opRegRegReg(cUnit, op, rlResult.lowReg,
1706 rlSrc1.lowReg, tReg);
1707 oatFreeTemp(cUnit, tReg);
1708 } else {
1709 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1710 opRegRegReg(cUnit, op, rlResult.lowReg,
1711 rlSrc1.lowReg, rlSrc2.lowReg);
1712 }
1713 }
1714 storeValue(cUnit, rlDest, rlResult);
1715 } else {
1716 RegLocation rlResult;
1717 oatFlushAllRegs(cUnit); /* Send everything to home location */
1718 loadValueDirectFixed(cUnit, rlSrc2, r1);
1719 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1720 loadValueDirectFixed(cUnit, rlSrc1, r0);
1721 if (checkZero) {
buzbee5ade1d22011-09-09 14:44:52 -07001722 genImmedCheck(cUnit, kArmCondEq, r1, 0, mir, kArmThrowDivZero);
buzbee67bf8852011-08-17 17:51:35 -07001723 }
Ian Rogersff1ed472011-09-20 13:46:24 -07001724 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -07001725 if (retReg == r0)
1726 rlResult = oatGetReturn(cUnit);
1727 else
1728 rlResult = oatGetReturnAlt(cUnit);
1729 storeValue(cUnit, rlDest, rlResult);
1730 }
1731 return false;
1732}
1733
buzbeec1f45042011-09-21 16:03:19 -07001734/* Check if we need to check for pending suspend request */
buzbeeed3e9302011-09-23 17:34:19 -07001735STATIC void genSuspendTest(CompilationUnit* cUnit, MIR* mir)
buzbeec1f45042011-09-21 16:03:19 -07001736{
Ian Rogersa3760aa2011-11-14 14:32:37 -08001737 if (NO_SUSPEND || (mir->optimizationFlags & MIR_IGNORE_SUSPEND_CHECK)) {
buzbeec1f45042011-09-21 16:03:19 -07001738 return;
1739 }
buzbee6181f792011-09-29 11:14:04 -07001740 oatFlushAllRegs(cUnit);
buzbeec1f45042011-09-21 16:03:19 -07001741 newLIR2(cUnit, kThumbSubRI8, rSUSPEND, 1);
1742 ArmLIR* branch = opCondBranch(cUnit, kArmCondEq);
1743 ArmLIR* retLab = newLIR0(cUnit, kArmPseudoTargetLabel);
1744 retLab->defMask = ENCODE_ALL;
buzbeeba938cb2012-02-03 14:47:55 -08001745 ArmLIR* target = (ArmLIR*)oatNew(cUnit, sizeof(ArmLIR), true, kAllocLIR);
buzbeec1f45042011-09-21 16:03:19 -07001746 target->generic.dalvikOffset = cUnit->currentDalvikOffset;
1747 target->opcode = kArmPseudoSuspendTarget;
1748 target->operands[0] = (intptr_t)retLab;
1749 target->operands[1] = mir->offset;
1750 branch->generic.target = (LIR*)target;
buzbeeba938cb2012-02-03 14:47:55 -08001751 oatInsertGrowableList(cUnit, &cUnit->suspendLaunchpads, (intptr_t)target);
buzbeec1f45042011-09-21 16:03:19 -07001752}
1753
buzbee67bf8852011-08-17 17:51:35 -07001754/*
1755 * The following are the first-level codegen routines that analyze the format
1756 * of each bytecode then either dispatch special purpose codegen routines
1757 * or produce corresponding Thumb instructions directly.
1758 */
1759
buzbeeed3e9302011-09-23 17:34:19 -07001760STATIC bool isPowerOfTwo(int x)
buzbee67bf8852011-08-17 17:51:35 -07001761{
1762 return (x & (x - 1)) == 0;
1763}
1764
1765// Returns true if no more than two bits are set in 'x'.
buzbeeed3e9302011-09-23 17:34:19 -07001766STATIC bool isPopCountLE2(unsigned int x)
buzbee67bf8852011-08-17 17:51:35 -07001767{
1768 x &= x - 1;
1769 return (x & (x - 1)) == 0;
1770}
1771
1772// Returns the index of the lowest set bit in 'x'.
buzbeeed3e9302011-09-23 17:34:19 -07001773STATIC int lowestSetBit(unsigned int x) {
buzbee67bf8852011-08-17 17:51:35 -07001774 int bit_posn = 0;
1775 while ((x & 0xf) == 0) {
1776 bit_posn += 4;
1777 x >>= 4;
1778 }
1779 while ((x & 1) == 0) {
1780 bit_posn++;
1781 x >>= 1;
1782 }
1783 return bit_posn;
1784}
1785
1786// Returns true if it added instructions to 'cUnit' to divide 'rlSrc' by 'lit'
1787// and store the result in 'rlDest'.
buzbeeed3e9302011-09-23 17:34:19 -07001788STATIC bool handleEasyDivide(CompilationUnit* cUnit, Opcode dalvikOpcode,
buzbee67bf8852011-08-17 17:51:35 -07001789 RegLocation rlSrc, RegLocation rlDest, int lit)
1790{
1791 if (lit < 2 || !isPowerOfTwo(lit)) {
1792 return false;
1793 }
1794 int k = lowestSetBit(lit);
1795 if (k >= 30) {
1796 // Avoid special cases.
1797 return false;
1798 }
1799 bool div = (dalvikOpcode == OP_DIV_INT_LIT8 ||
1800 dalvikOpcode == OP_DIV_INT_LIT16);
1801 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1802 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1803 if (div) {
1804 int tReg = oatAllocTemp(cUnit);
1805 if (lit == 2) {
1806 // Division by 2 is by far the most common division by constant.
1807 opRegRegImm(cUnit, kOpLsr, tReg, rlSrc.lowReg, 32 - k);
1808 opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg);
1809 opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k);
1810 } else {
1811 opRegRegImm(cUnit, kOpAsr, tReg, rlSrc.lowReg, 31);
1812 opRegRegImm(cUnit, kOpLsr, tReg, tReg, 32 - k);
1813 opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg);
1814 opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k);
1815 }
1816 } else {
1817 int cReg = oatAllocTemp(cUnit);
1818 loadConstant(cUnit, cReg, lit - 1);
1819 int tReg1 = oatAllocTemp(cUnit);
1820 int tReg2 = oatAllocTemp(cUnit);
1821 if (lit == 2) {
1822 opRegRegImm(cUnit, kOpLsr, tReg1, rlSrc.lowReg, 32 - k);
1823 opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg);
1824 opRegRegReg(cUnit, kOpAnd, tReg2, tReg2, cReg);
1825 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1);
1826 } else {
1827 opRegRegImm(cUnit, kOpAsr, tReg1, rlSrc.lowReg, 31);
1828 opRegRegImm(cUnit, kOpLsr, tReg1, tReg1, 32 - k);
1829 opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg);
1830 opRegRegReg(cUnit, kOpAnd, tReg2, tReg2, cReg);
1831 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1);
1832 }
1833 }
1834 storeValue(cUnit, rlDest, rlResult);
1835 return true;
1836}
1837
1838// Returns true if it added instructions to 'cUnit' to multiply 'rlSrc' by 'lit'
1839// and store the result in 'rlDest'.
buzbeeed3e9302011-09-23 17:34:19 -07001840STATIC bool handleEasyMultiply(CompilationUnit* cUnit,
buzbee67bf8852011-08-17 17:51:35 -07001841 RegLocation rlSrc, RegLocation rlDest, int lit)
1842{
1843 // Can we simplify this multiplication?
1844 bool powerOfTwo = false;
1845 bool popCountLE2 = false;
1846 bool powerOfTwoMinusOne = false;
1847 if (lit < 2) {
1848 // Avoid special cases.
1849 return false;
1850 } else if (isPowerOfTwo(lit)) {
1851 powerOfTwo = true;
1852 } else if (isPopCountLE2(lit)) {
1853 popCountLE2 = true;
1854 } else if (isPowerOfTwo(lit + 1)) {
1855 powerOfTwoMinusOne = true;
1856 } else {
1857 return false;
1858 }
1859 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1860 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1861 if (powerOfTwo) {
1862 // Shift.
1863 opRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlSrc.lowReg,
1864 lowestSetBit(lit));
1865 } else if (popCountLE2) {
1866 // Shift and add and shift.
1867 int firstBit = lowestSetBit(lit);
1868 int secondBit = lowestSetBit(lit ^ (1 << firstBit));
1869 genMultiplyByTwoBitMultiplier(cUnit, rlSrc, rlResult, lit,
1870 firstBit, secondBit);
1871 } else {
1872 // Reverse subtract: (src << (shift + 1)) - src.
buzbeeed3e9302011-09-23 17:34:19 -07001873 DCHECK(powerOfTwoMinusOne);
buzbee5ade1d22011-09-09 14:44:52 -07001874 // TUNING: rsb dst, src, src lsl#lowestSetBit(lit + 1)
buzbee67bf8852011-08-17 17:51:35 -07001875 int tReg = oatAllocTemp(cUnit);
1876 opRegRegImm(cUnit, kOpLsl, tReg, rlSrc.lowReg, lowestSetBit(lit + 1));
1877 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg, rlSrc.lowReg);
1878 }
1879 storeValue(cUnit, rlDest, rlResult);
1880 return true;
1881}
1882
buzbeeed3e9302011-09-23 17:34:19 -07001883STATIC bool genArithOpIntLit(CompilationUnit* cUnit, MIR* mir,
buzbee67bf8852011-08-17 17:51:35 -07001884 RegLocation rlDest, RegLocation rlSrc,
1885 int lit)
1886{
1887 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
1888 RegLocation rlResult;
1889 OpKind op = (OpKind)0; /* Make gcc happy */
1890 int shiftOp = false;
1891 bool isDiv = false;
1892 int funcOffset;
1893
1894 switch (dalvikOpcode) {
1895 case OP_RSUB_INT_LIT8:
1896 case OP_RSUB_INT: {
1897 int tReg;
1898 //TUNING: add support for use of Arm rsub op
1899 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1900 tReg = oatAllocTemp(cUnit);
1901 loadConstant(cUnit, tReg, lit);
1902 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1903 opRegRegReg(cUnit, kOpSub, rlResult.lowReg,
1904 tReg, rlSrc.lowReg);
1905 storeValue(cUnit, rlDest, rlResult);
1906 return false;
1907 break;
1908 }
1909
1910 case OP_ADD_INT_LIT8:
1911 case OP_ADD_INT_LIT16:
1912 op = kOpAdd;
1913 break;
1914 case OP_MUL_INT_LIT8:
1915 case OP_MUL_INT_LIT16: {
1916 if (handleEasyMultiply(cUnit, rlSrc, rlDest, lit)) {
1917 return false;
1918 }
1919 op = kOpMul;
1920 break;
1921 }
1922 case OP_AND_INT_LIT8:
1923 case OP_AND_INT_LIT16:
1924 op = kOpAnd;
1925 break;
1926 case OP_OR_INT_LIT8:
1927 case OP_OR_INT_LIT16:
1928 op = kOpOr;
1929 break;
1930 case OP_XOR_INT_LIT8:
1931 case OP_XOR_INT_LIT16:
1932 op = kOpXor;
1933 break;
1934 case OP_SHL_INT_LIT8:
1935 lit &= 31;
1936 shiftOp = true;
1937 op = kOpLsl;
1938 break;
1939 case OP_SHR_INT_LIT8:
1940 lit &= 31;
1941 shiftOp = true;
1942 op = kOpAsr;
1943 break;
1944 case OP_USHR_INT_LIT8:
1945 lit &= 31;
1946 shiftOp = true;
1947 op = kOpLsr;
1948 break;
1949
1950 case OP_DIV_INT_LIT8:
1951 case OP_DIV_INT_LIT16:
1952 case OP_REM_INT_LIT8:
1953 case OP_REM_INT_LIT16:
1954 if (lit == 0) {
buzbee5ade1d22011-09-09 14:44:52 -07001955 genImmedCheck(cUnit, kArmCondAl, 0, 0, mir, kArmThrowDivZero);
buzbee67bf8852011-08-17 17:51:35 -07001956 return false;
1957 }
1958 if (handleEasyDivide(cUnit, dalvikOpcode, rlSrc, rlDest, lit)) {
1959 return false;
1960 }
1961 oatFlushAllRegs(cUnit); /* Everything to home location */
1962 loadValueDirectFixed(cUnit, rlSrc, r0);
1963 oatClobber(cUnit, r0);
1964 if ((dalvikOpcode == OP_DIV_INT_LIT8) ||
1965 (dalvikOpcode == OP_DIV_INT_LIT16)) {
1966 funcOffset = OFFSETOF_MEMBER(Thread, pIdiv);
1967 isDiv = true;
1968 } else {
1969 funcOffset = OFFSETOF_MEMBER(Thread, pIdivmod);
1970 isDiv = false;
1971 }
1972 loadWordDisp(cUnit, rSELF, funcOffset, rLR);
1973 loadConstant(cUnit, r1, lit);
Ian Rogersff1ed472011-09-20 13:46:24 -07001974 callRuntimeHelper(cUnit, rLR);
buzbee67bf8852011-08-17 17:51:35 -07001975 if (isDiv)
1976 rlResult = oatGetReturn(cUnit);
1977 else
1978 rlResult = oatGetReturnAlt(cUnit);
1979 storeValue(cUnit, rlDest, rlResult);
1980 return false;
1981 break;
1982 default:
1983 return true;
1984 }
1985 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1986 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1987 // Avoid shifts by literal 0 - no support in Thumb. Change to copy
1988 if (shiftOp && (lit == 0)) {
1989 genRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg);
1990 } else {
1991 opRegRegImm(cUnit, op, rlResult.lowReg, rlSrc.lowReg, lit);
1992 }
1993 storeValue(cUnit, rlDest, rlResult);
1994 return false;
1995}
1996
1997/* Architectural-specific debugging helpers go here */
1998void oatArchDump(void)
1999{
2000 /* Print compiled opcode in this VM instance */
2001 int i, start, streak;
Elliott Hughes3b6baaa2011-10-14 19:13:56 -07002002 std::string buf;
buzbee67bf8852011-08-17 17:51:35 -07002003
2004 streak = i = 0;
buzbee67bf8852011-08-17 17:51:35 -07002005 while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
2006 i++;
2007 }
2008 if (i == kNumPackedOpcodes) {
2009 return;
2010 }
2011 for (start = i++, streak = 1; i < kNumPackedOpcodes; i++) {
2012 if (opcodeCoverage[i]) {
2013 streak++;
2014 } else {
2015 if (streak == 1) {
Elliott Hughes3b6baaa2011-10-14 19:13:56 -07002016 StringAppendF(&buf, "%x,", start);
buzbee67bf8852011-08-17 17:51:35 -07002017 } else {
Elliott Hughes3b6baaa2011-10-14 19:13:56 -07002018 StringAppendF(&buf, "%x-%x,", start, start + streak - 1);
buzbee67bf8852011-08-17 17:51:35 -07002019 }
2020 streak = 0;
2021 while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
2022 i++;
2023 }
2024 if (i < kNumPackedOpcodes) {
2025 streak = 1;
2026 start = i;
2027 }
2028 }
2029 }
2030 if (streak) {
2031 if (streak == 1) {
Elliott Hughes3b6baaa2011-10-14 19:13:56 -07002032 StringAppendF(&buf, "%x", start);
buzbee67bf8852011-08-17 17:51:35 -07002033 } else {
Elliott Hughes3b6baaa2011-10-14 19:13:56 -07002034 StringAppendF(&buf, "%x-%x", start, start + streak - 1);
buzbee67bf8852011-08-17 17:51:35 -07002035 }
2036 }
Elliott Hughes3b6baaa2011-10-14 19:13:56 -07002037 if (!buf.empty()) {
buzbee67bf8852011-08-17 17:51:35 -07002038 LOG(INFO) << "dalvik.vm.oat.op = " << buf;
2039 }
2040}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -08002041
2042} // namespace art