blob: 7d76e890f6cba4497dddf0431dfb3f74f400e7d9 [file] [log] [blame]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001/*
2 * Copyright (C) 2009 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
Bill Buzbee50a6bf22009-07-08 13:08:04 -070017/*
18 * This file contains codegen and support common to all supported
19 * ARM variants. It is included by:
20 *
21 * Codegen-$(TARGET_ARCH_VARIANT).c
22 *
23 * which combines this common code with specific support found in the
24 * applicable directory below this one.
25 */
26
buzbee919eb062010-07-12 12:59:22 -070027/*
28 * Mark garbage collection card. Skip if the value we're storing is null.
29 */
30static void markCard(CompilationUnit *cUnit, int valReg, int tgtAddrReg)
31{
32 int regCardBase = dvmCompilerAllocTemp(cUnit);
33 int regCardNo = dvmCompilerAllocTemp(cUnit);
buzbee8f8109a2010-08-31 10:16:35 -070034 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondEq, valReg, 0);
Ben Cheng20d7e6c2011-02-18 17:12:42 -080035 loadWordDisp(cUnit, r6SELF, offsetof(Thread, cardTable),
buzbee919eb062010-07-12 12:59:22 -070036 regCardBase);
37 opRegRegImm(cUnit, kOpLsr, regCardNo, tgtAddrReg, GC_CARD_SHIFT);
38 storeBaseIndexed(cUnit, regCardBase, regCardNo, regCardBase, 0,
39 kUnsignedByte);
40 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
41 target->defMask = ENCODE_ALL;
42 branchOver->generic.target = (LIR *)target;
buzbeebaf196a2010-08-04 10:13:15 -070043 dvmCompilerFreeTemp(cUnit, regCardBase);
44 dvmCompilerFreeTemp(cUnit, regCardNo);
buzbee919eb062010-07-12 12:59:22 -070045}
46
Ben Cheng5d90c202009-11-22 23:31:11 -080047static bool genConversionCall(CompilationUnit *cUnit, MIR *mir, void *funct,
48 int srcSize, int tgtSize)
49{
50 /*
51 * Don't optimize the register usage since it calls out to template
52 * functions
53 */
54 RegLocation rlSrc;
55 RegLocation rlDest;
Bill Buzbeec6f10662010-02-09 11:16:15 -080056 dvmCompilerFlushAllRegs(cUnit); /* Send everything to home location */
Ben Cheng5d90c202009-11-22 23:31:11 -080057 if (srcSize == 1) {
Bill Buzbeec6f10662010-02-09 11:16:15 -080058 rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Ben Cheng5d90c202009-11-22 23:31:11 -080059 loadValueDirectFixed(cUnit, rlSrc, r0);
60 } else {
Bill Buzbeec6f10662010-02-09 11:16:15 -080061 rlSrc = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
Ben Cheng5d90c202009-11-22 23:31:11 -080062 loadValueDirectWideFixed(cUnit, rlSrc, r0, r1);
63 }
Ben Chengbd1326d2010-04-02 15:04:53 -070064 LOAD_FUNC_ADDR(cUnit, r2, (int)funct);
Ben Cheng5d90c202009-11-22 23:31:11 -080065 opReg(cUnit, kOpBlx, r2);
Elliott Hughes6a555132010-02-25 15:41:42 -080066 dvmCompilerClobberCallRegs(cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -080067 if (tgtSize == 1) {
68 RegLocation rlResult;
Bill Buzbeec6f10662010-02-09 11:16:15 -080069 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
70 rlResult = dvmCompilerGetReturn(cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -080071 storeValue(cUnit, rlDest, rlResult);
72 } else {
73 RegLocation rlResult;
Bill Buzbeec6f10662010-02-09 11:16:15 -080074 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
75 rlResult = dvmCompilerGetReturnWide(cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -080076 storeValueWide(cUnit, rlDest, rlResult);
77 }
78 return false;
79}
Ben Chengba4fc8b2009-06-01 13:00:29 -070080
Ben Cheng5d90c202009-11-22 23:31:11 -080081static bool genArithOpFloatPortable(CompilationUnit *cUnit, MIR *mir,
82 RegLocation rlDest, RegLocation rlSrc1,
83 RegLocation rlSrc2)
84{
85 RegLocation rlResult;
86 void* funct;
87
Dan Bornstein9a1f8162010-12-01 17:02:26 -080088 switch (mir->dalvikInsn.opcode) {
Ben Cheng5d90c202009-11-22 23:31:11 -080089 case OP_ADD_FLOAT_2ADDR:
90 case OP_ADD_FLOAT:
91 funct = (void*) __aeabi_fadd;
92 break;
93 case OP_SUB_FLOAT_2ADDR:
94 case OP_SUB_FLOAT:
95 funct = (void*) __aeabi_fsub;
96 break;
97 case OP_DIV_FLOAT_2ADDR:
98 case OP_DIV_FLOAT:
99 funct = (void*) __aeabi_fdiv;
100 break;
101 case OP_MUL_FLOAT_2ADDR:
102 case OP_MUL_FLOAT:
103 funct = (void*) __aeabi_fmul;
104 break;
105 case OP_REM_FLOAT_2ADDR:
106 case OP_REM_FLOAT:
107 funct = (void*) fmodf;
108 break;
109 case OP_NEG_FLOAT: {
110 genNegFloat(cUnit, rlDest, rlSrc1);
111 return false;
112 }
113 default:
114 return true;
115 }
Bill Buzbeec6f10662010-02-09 11:16:15 -0800116 dvmCompilerFlushAllRegs(cUnit); /* Send everything to home location */
Ben Cheng5d90c202009-11-22 23:31:11 -0800117 loadValueDirectFixed(cUnit, rlSrc1, r0);
118 loadValueDirectFixed(cUnit, rlSrc2, r1);
Ben Chengbd1326d2010-04-02 15:04:53 -0700119 LOAD_FUNC_ADDR(cUnit, r2, (int)funct);
Ben Cheng5d90c202009-11-22 23:31:11 -0800120 opReg(cUnit, kOpBlx, r2);
Elliott Hughes6a555132010-02-25 15:41:42 -0800121 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800122 rlResult = dvmCompilerGetReturn(cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800123 storeValue(cUnit, rlDest, rlResult);
124 return false;
125}
126
127static bool genArithOpDoublePortable(CompilationUnit *cUnit, MIR *mir,
128 RegLocation rlDest, RegLocation rlSrc1,
129 RegLocation rlSrc2)
130{
131 RegLocation rlResult;
132 void* funct;
133
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800134 switch (mir->dalvikInsn.opcode) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800135 case OP_ADD_DOUBLE_2ADDR:
136 case OP_ADD_DOUBLE:
137 funct = (void*) __aeabi_dadd;
138 break;
139 case OP_SUB_DOUBLE_2ADDR:
140 case OP_SUB_DOUBLE:
141 funct = (void*) __aeabi_dsub;
142 break;
143 case OP_DIV_DOUBLE_2ADDR:
144 case OP_DIV_DOUBLE:
145 funct = (void*) __aeabi_ddiv;
146 break;
147 case OP_MUL_DOUBLE_2ADDR:
148 case OP_MUL_DOUBLE:
149 funct = (void*) __aeabi_dmul;
150 break;
151 case OP_REM_DOUBLE_2ADDR:
152 case OP_REM_DOUBLE:
153 funct = (void*) fmod;
154 break;
155 case OP_NEG_DOUBLE: {
156 genNegDouble(cUnit, rlDest, rlSrc1);
157 return false;
158 }
159 default:
160 return true;
161 }
Bill Buzbeec6f10662010-02-09 11:16:15 -0800162 dvmCompilerFlushAllRegs(cUnit); /* Send everything to home location */
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800163 LOAD_FUNC_ADDR(cUnit, r14lr, (int)funct);
Ben Cheng5d90c202009-11-22 23:31:11 -0800164 loadValueDirectWideFixed(cUnit, rlSrc1, r0, r1);
165 loadValueDirectWideFixed(cUnit, rlSrc2, r2, r3);
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800166 opReg(cUnit, kOpBlx, r14lr);
Elliott Hughes6a555132010-02-25 15:41:42 -0800167 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800168 rlResult = dvmCompilerGetReturnWide(cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800169 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengd72564c2011-02-08 17:09:25 -0800170#if defined(WITH_SELF_VERIFICATION)
171 cUnit->usesLinkRegister = true;
172#endif
Ben Cheng5d90c202009-11-22 23:31:11 -0800173 return false;
174}
175
176static bool genConversionPortable(CompilationUnit *cUnit, MIR *mir)
177{
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800178 Opcode opcode = mir->dalvikInsn.opcode;
Ben Cheng5d90c202009-11-22 23:31:11 -0800179
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800180 switch (opcode) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800181 case OP_INT_TO_FLOAT:
182 return genConversionCall(cUnit, mir, (void*)__aeabi_i2f, 1, 1);
183 case OP_FLOAT_TO_INT:
184 return genConversionCall(cUnit, mir, (void*)__aeabi_f2iz, 1, 1);
185 case OP_DOUBLE_TO_FLOAT:
186 return genConversionCall(cUnit, mir, (void*)__aeabi_d2f, 2, 1);
187 case OP_FLOAT_TO_DOUBLE:
188 return genConversionCall(cUnit, mir, (void*)__aeabi_f2d, 1, 2);
189 case OP_INT_TO_DOUBLE:
190 return genConversionCall(cUnit, mir, (void*)__aeabi_i2d, 1, 2);
191 case OP_DOUBLE_TO_INT:
192 return genConversionCall(cUnit, mir, (void*)__aeabi_d2iz, 2, 1);
193 case OP_FLOAT_TO_LONG:
194 return genConversionCall(cUnit, mir, (void*)dvmJitf2l, 1, 2);
195 case OP_LONG_TO_FLOAT:
196 return genConversionCall(cUnit, mir, (void*)__aeabi_l2f, 2, 1);
197 case OP_DOUBLE_TO_LONG:
198 return genConversionCall(cUnit, mir, (void*)dvmJitd2l, 2, 2);
199 case OP_LONG_TO_DOUBLE:
200 return genConversionCall(cUnit, mir, (void*)__aeabi_l2d, 2, 2);
201 default:
202 return true;
203 }
204 return false;
205}
Ben Chengba4fc8b2009-06-01 13:00:29 -0700206
Jeff Hao97319a82009-08-12 16:57:15 -0700207#if defined(WITH_SELF_VERIFICATION)
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800208static void selfVerificationBranchInsert(LIR *currentLIR, ArmOpcode opcode,
jeffhao9e45c0b2010-02-03 10:24:05 -0800209 int dest, int src1)
Jeff Hao97319a82009-08-12 16:57:15 -0700210{
Carl Shapirofc75f3e2010-12-07 11:43:38 -0800211 ArmLIR *insn = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800212 insn->opcode = opcode;
jeffhao9e45c0b2010-02-03 10:24:05 -0800213 insn->operands[0] = dest;
214 insn->operands[1] = src1;
215 setupResourceMasks(insn);
216 dvmCompilerInsertLIRBefore(currentLIR, (LIR *) insn);
Jeff Hao97319a82009-08-12 16:57:15 -0700217}
218
Ben Chengd72564c2011-02-08 17:09:25 -0800219/*
220 * Example where r14 (LR) is preserved around a heap access under
221 * self-verification mode in Thumb2:
222 *
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800223 * D/dalvikvm( 1538): 0x59414c5e (0026): ldr r14, [r15pc, #220] <-hoisted
Ben Chengd72564c2011-02-08 17:09:25 -0800224 * D/dalvikvm( 1538): 0x59414c62 (002a): mla r4, r0, r8, r4
225 * D/dalvikvm( 1538): 0x59414c66 (002e): adds r3, r4, r3
226 * D/dalvikvm( 1538): 0x59414c6a (0032): push <r5, r14> ---+
227 * D/dalvikvm( 1538): 0x59414c6c (0034): blx_1 0x5940f494 |
228 * D/dalvikvm( 1538): 0x59414c6e (0036): blx_2 see above <-MEM_OP_DECODE
229 * D/dalvikvm( 1538): 0x59414c70 (0038): ldr r10, [r9, #0] |
230 * D/dalvikvm( 1538): 0x59414c74 (003c): pop <r5, r14> ---+
231 * D/dalvikvm( 1538): 0x59414c78 (0040): mov r11, r10
232 * D/dalvikvm( 1538): 0x59414c7a (0042): asr r12, r11, #31
233 * D/dalvikvm( 1538): 0x59414c7e (0046): movs r0, r2
234 * D/dalvikvm( 1538): 0x59414c80 (0048): movs r1, r3
235 * D/dalvikvm( 1538): 0x59414c82 (004a): str r2, [r5, #16]
236 * D/dalvikvm( 1538): 0x59414c84 (004c): mov r2, r11
237 * D/dalvikvm( 1538): 0x59414c86 (004e): str r3, [r5, #20]
238 * D/dalvikvm( 1538): 0x59414c88 (0050): mov r3, r12
239 * D/dalvikvm( 1538): 0x59414c8a (0052): str r11, [r5, #24]
240 * D/dalvikvm( 1538): 0x59414c8e (0056): str r12, [r5, #28]
241 * D/dalvikvm( 1538): 0x59414c92 (005a): blx r14 <-use of LR
242 *
243 */
jeffhao9e45c0b2010-02-03 10:24:05 -0800244static void selfVerificationBranchInsertPass(CompilationUnit *cUnit)
Jeff Hao97319a82009-08-12 16:57:15 -0700245{
jeffhao9e45c0b2010-02-03 10:24:05 -0800246 ArmLIR *thisLIR;
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800247 TemplateOpcode opcode = TEMPLATE_MEM_OP_DECODE;
Jeff Hao97319a82009-08-12 16:57:15 -0700248
jeffhao9e45c0b2010-02-03 10:24:05 -0800249 for (thisLIR = (ArmLIR *) cUnit->firstLIRInsn;
250 thisLIR != (ArmLIR *) cUnit->lastLIRInsn;
251 thisLIR = NEXT_LIR(thisLIR)) {
Ben Chengd72564c2011-02-08 17:09:25 -0800252 if (!thisLIR->flags.isNop && thisLIR->flags.insertWrapper) {
253 /*
254 * Push r5(FP) and r14(LR) onto stack. We need to make sure that
255 * SP is 8-byte aligned, and we use r5 as a temp to restore LR
256 * for Thumb-only target since LR cannot be directly accessed in
257 * Thumb mode. Another reason to choose r5 here is it is the Dalvik
258 * frame pointer and cannot be the target of the emulated heap
259 * load.
260 */
261 if (cUnit->usesLinkRegister) {
262 genSelfVerificationPreBranch(cUnit, thisLIR);
263 }
264
jeffhao9e45c0b2010-02-03 10:24:05 -0800265 /* Branch to mem op decode template */
266 selfVerificationBranchInsert((LIR *) thisLIR, kThumbBlx1,
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800267 (int) gDvmJit.codeCache + templateEntryOffsets[opcode],
268 (int) gDvmJit.codeCache + templateEntryOffsets[opcode]);
jeffhao9e45c0b2010-02-03 10:24:05 -0800269 selfVerificationBranchInsert((LIR *) thisLIR, kThumbBlx2,
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800270 (int) gDvmJit.codeCache + templateEntryOffsets[opcode],
271 (int) gDvmJit.codeCache + templateEntryOffsets[opcode]);
Ben Chengd72564c2011-02-08 17:09:25 -0800272
273 /* Restore LR */
274 if (cUnit->usesLinkRegister) {
275 genSelfVerificationPostBranch(cUnit, thisLIR);
276 }
Jeff Hao97319a82009-08-12 16:57:15 -0700277 }
278 }
Jeff Hao97319a82009-08-12 16:57:15 -0700279}
Jeff Hao97319a82009-08-12 16:57:15 -0700280#endif
281
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800282/* Generate conditional branch instructions */
283static ArmLIR *genConditionalBranch(CompilationUnit *cUnit,
284 ArmConditionCode cond,
285 ArmLIR *target)
286{
287 ArmLIR *branch = opCondBranch(cUnit, cond);
288 branch->generic.target = (LIR *) target;
289 return branch;
290}
291
Ben Chengba4fc8b2009-06-01 13:00:29 -0700292/* Generate a unconditional branch to go to the interpreter */
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700293static inline ArmLIR *genTrap(CompilationUnit *cUnit, int dOffset,
294 ArmLIR *pcrLabel)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700295{
Bill Buzbee1465db52009-09-23 17:17:35 -0700296 ArmLIR *branch = opNone(cUnit, kOpUncondBr);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700297 return genCheckCommon(cUnit, dOffset, branch, pcrLabel);
298}
299
300/* Load a wide field from an object instance */
301static void genIGetWide(CompilationUnit *cUnit, MIR *mir, int fieldOffset)
302{
Bill Buzbeec6f10662010-02-09 11:16:15 -0800303 RegLocation rlObj = dvmCompilerGetSrc(cUnit, mir, 0);
304 RegLocation rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -0700305 RegLocation rlResult;
306 rlObj = loadValue(cUnit, rlObj, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800307 int regPtr = dvmCompilerAllocTemp(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700308
Bill Buzbee1465db52009-09-23 17:17:35 -0700309 assert(rlDest.wide);
Ben Chenge9695e52009-06-16 16:11:47 -0700310
Bill Buzbee1465db52009-09-23 17:17:35 -0700311 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir->offset,
312 NULL);/* null object? */
313 opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800314 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kAnyReg, true);
Ben Cheng11d8f142010-03-24 15:24:19 -0700315
316 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700317 loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg);
Ben Cheng11d8f142010-03-24 15:24:19 -0700318 HEAP_ACCESS_SHADOW(false);
319
Bill Buzbeec6f10662010-02-09 11:16:15 -0800320 dvmCompilerFreeTemp(cUnit, regPtr);
Bill Buzbee1465db52009-09-23 17:17:35 -0700321 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700322}
323
324/* Store a wide field to an object instance */
325static void genIPutWide(CompilationUnit *cUnit, MIR *mir, int fieldOffset)
326{
Bill Buzbeec6f10662010-02-09 11:16:15 -0800327 RegLocation rlSrc = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
328 RegLocation rlObj = dvmCompilerGetSrc(cUnit, mir, 2);
Bill Buzbee1465db52009-09-23 17:17:35 -0700329 rlObj = loadValue(cUnit, rlObj, kCoreReg);
330 int regPtr;
331 rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg);
332 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir->offset,
333 NULL);/* null object? */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800334 regPtr = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700335 opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset);
Ben Cheng11d8f142010-03-24 15:24:19 -0700336
337 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700338 storePair(cUnit, regPtr, rlSrc.lowReg, rlSrc.highReg);
Ben Cheng11d8f142010-03-24 15:24:19 -0700339 HEAP_ACCESS_SHADOW(false);
340
Bill Buzbeec6f10662010-02-09 11:16:15 -0800341 dvmCompilerFreeTemp(cUnit, regPtr);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700342}
343
344/*
345 * Load a field from an object instance
346 *
Ben Chengba4fc8b2009-06-01 13:00:29 -0700347 */
Bill Buzbee270c1d62009-08-13 16:58:07 -0700348static void genIGet(CompilationUnit *cUnit, MIR *mir, OpSize size,
buzbeeecf8f6e2010-07-20 14:53:42 -0700349 int fieldOffset, bool isVolatile)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700350{
Bill Buzbee1465db52009-09-23 17:17:35 -0700351 RegLocation rlResult;
Bill Buzbee749e8162010-07-07 06:55:56 -0700352 RegisterClass regClass = dvmCompilerRegClassBySize(size);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800353 RegLocation rlObj = dvmCompilerGetSrc(cUnit, mir, 0);
354 RegLocation rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -0700355 rlObj = loadValue(cUnit, rlObj, kCoreReg);
Bill Buzbee749e8162010-07-07 06:55:56 -0700356 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, regClass, true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700357 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir->offset,
358 NULL);/* null object? */
Ben Cheng11d8f142010-03-24 15:24:19 -0700359
360 HEAP_ACCESS_SHADOW(true);
Ben Cheng5d90c202009-11-22 23:31:11 -0800361 loadBaseDisp(cUnit, mir, rlObj.lowReg, fieldOffset, rlResult.lowReg,
362 size, rlObj.sRegLow);
Ben Cheng11d8f142010-03-24 15:24:19 -0700363 HEAP_ACCESS_SHADOW(false);
buzbeeecf8f6e2010-07-20 14:53:42 -0700364 if (isVolatile) {
buzbee2ce33c92010-11-01 15:53:27 -0700365 dvmCompilerGenMemBarrier(cUnit, kSY);
buzbeeecf8f6e2010-07-20 14:53:42 -0700366 }
Ben Cheng11d8f142010-03-24 15:24:19 -0700367
Bill Buzbee1465db52009-09-23 17:17:35 -0700368 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700369}
370
371/*
372 * Store a field to an object instance
373 *
Ben Chengba4fc8b2009-06-01 13:00:29 -0700374 */
Bill Buzbee270c1d62009-08-13 16:58:07 -0700375static void genIPut(CompilationUnit *cUnit, MIR *mir, OpSize size,
buzbeeecf8f6e2010-07-20 14:53:42 -0700376 int fieldOffset, bool isObject, bool isVolatile)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700377{
Bill Buzbee749e8162010-07-07 06:55:56 -0700378 RegisterClass regClass = dvmCompilerRegClassBySize(size);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800379 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
380 RegLocation rlObj = dvmCompilerGetSrc(cUnit, mir, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -0700381 rlObj = loadValue(cUnit, rlObj, kCoreReg);
Bill Buzbee749e8162010-07-07 06:55:56 -0700382 rlSrc = loadValue(cUnit, rlSrc, regClass);
Bill Buzbee1465db52009-09-23 17:17:35 -0700383 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir->offset,
384 NULL);/* null object? */
Ben Cheng11d8f142010-03-24 15:24:19 -0700385
buzbeeecf8f6e2010-07-20 14:53:42 -0700386 if (isVolatile) {
buzbee2ce33c92010-11-01 15:53:27 -0700387 dvmCompilerGenMemBarrier(cUnit, kSY);
buzbeeecf8f6e2010-07-20 14:53:42 -0700388 }
Ben Cheng11d8f142010-03-24 15:24:19 -0700389 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700390 storeBaseDisp(cUnit, rlObj.lowReg, fieldOffset, rlSrc.lowReg, size);
Ben Cheng11d8f142010-03-24 15:24:19 -0700391 HEAP_ACCESS_SHADOW(false);
buzbee919eb062010-07-12 12:59:22 -0700392 if (isObject) {
393 /* NOTE: marking card based on object head */
394 markCard(cUnit, rlSrc.lowReg, rlObj.lowReg);
395 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700396}
397
398
Ben Chengba4fc8b2009-06-01 13:00:29 -0700399/*
400 * Generate array load
Ben Chengba4fc8b2009-06-01 13:00:29 -0700401 */
Bill Buzbee270c1d62009-08-13 16:58:07 -0700402static void genArrayGet(CompilationUnit *cUnit, MIR *mir, OpSize size,
Bill Buzbee1465db52009-09-23 17:17:35 -0700403 RegLocation rlArray, RegLocation rlIndex,
404 RegLocation rlDest, int scale)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700405{
Bill Buzbee749e8162010-07-07 06:55:56 -0700406 RegisterClass regClass = dvmCompilerRegClassBySize(size);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700407 int lenOffset = offsetof(ArrayObject, length);
408 int dataOffset = offsetof(ArrayObject, contents);
Bill Buzbee1465db52009-09-23 17:17:35 -0700409 RegLocation rlResult;
410 rlArray = loadValue(cUnit, rlArray, kCoreReg);
411 rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
412 int regPtr;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700413
414 /* null object? */
Ben Cheng4238ec22009-08-24 16:32:22 -0700415 ArmLIR * pcrLabel = NULL;
416
417 if (!(mir->OptimizationFlags & MIR_IGNORE_NULL_CHECK)) {
Bill Buzbee1465db52009-09-23 17:17:35 -0700418 pcrLabel = genNullCheck(cUnit, rlArray.sRegLow,
419 rlArray.lowReg, mir->offset, NULL);
Ben Cheng4238ec22009-08-24 16:32:22 -0700420 }
421
Bill Buzbeec6f10662010-02-09 11:16:15 -0800422 regPtr = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700423
Ben Cheng4238ec22009-08-24 16:32:22 -0700424 if (!(mir->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800425 int regLen = dvmCompilerAllocTemp(cUnit);
Ben Cheng4238ec22009-08-24 16:32:22 -0700426 /* Get len */
Bill Buzbee1465db52009-09-23 17:17:35 -0700427 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen);
428 /* regPtr -> array data */
429 opRegRegImm(cUnit, kOpAdd, regPtr, rlArray.lowReg, dataOffset);
430 genBoundsCheck(cUnit, rlIndex.lowReg, regLen, mir->offset,
431 pcrLabel);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800432 dvmCompilerFreeTemp(cUnit, regLen);
Ben Cheng4238ec22009-08-24 16:32:22 -0700433 } else {
Bill Buzbee1465db52009-09-23 17:17:35 -0700434 /* regPtr -> array data */
435 opRegRegImm(cUnit, kOpAdd, regPtr, rlArray.lowReg, dataOffset);
Ben Cheng4238ec22009-08-24 16:32:22 -0700436 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700437 if ((size == kLong) || (size == kDouble)) {
438 if (scale) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800439 int rNewIndex = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700440 opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale);
441 opRegReg(cUnit, kOpAdd, regPtr, rNewIndex);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800442 dvmCompilerFreeTemp(cUnit, rNewIndex);
Bill Buzbee1465db52009-09-23 17:17:35 -0700443 } else {
444 opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg);
445 }
Bill Buzbee749e8162010-07-07 06:55:56 -0700446 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, regClass, true);
Ben Cheng11d8f142010-03-24 15:24:19 -0700447
448 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700449 loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg);
Ben Cheng11d8f142010-03-24 15:24:19 -0700450 HEAP_ACCESS_SHADOW(false);
451
Bill Buzbeec6f10662010-02-09 11:16:15 -0800452 dvmCompilerFreeTemp(cUnit, regPtr);
Bill Buzbee1465db52009-09-23 17:17:35 -0700453 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700454 } else {
Bill Buzbee749e8162010-07-07 06:55:56 -0700455 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, regClass, true);
Ben Cheng11d8f142010-03-24 15:24:19 -0700456
457 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700458 loadBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlResult.lowReg,
459 scale, size);
Ben Cheng11d8f142010-03-24 15:24:19 -0700460 HEAP_ACCESS_SHADOW(false);
461
Bill Buzbeec6f10662010-02-09 11:16:15 -0800462 dvmCompilerFreeTemp(cUnit, regPtr);
Bill Buzbee1465db52009-09-23 17:17:35 -0700463 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700464 }
465}
466
Ben Chengba4fc8b2009-06-01 13:00:29 -0700467/*
468 * Generate array store
469 *
Ben Chengba4fc8b2009-06-01 13:00:29 -0700470 */
Bill Buzbee270c1d62009-08-13 16:58:07 -0700471static void genArrayPut(CompilationUnit *cUnit, MIR *mir, OpSize size,
Bill Buzbee1465db52009-09-23 17:17:35 -0700472 RegLocation rlArray, RegLocation rlIndex,
473 RegLocation rlSrc, int scale)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700474{
Bill Buzbee749e8162010-07-07 06:55:56 -0700475 RegisterClass regClass = dvmCompilerRegClassBySize(size);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700476 int lenOffset = offsetof(ArrayObject, length);
477 int dataOffset = offsetof(ArrayObject, contents);
478
Bill Buzbee1465db52009-09-23 17:17:35 -0700479 int regPtr;
480 rlArray = loadValue(cUnit, rlArray, kCoreReg);
481 rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
Ben Chenge9695e52009-06-16 16:11:47 -0700482
Bill Buzbeec6f10662010-02-09 11:16:15 -0800483 if (dvmCompilerIsTemp(cUnit, rlArray.lowReg)) {
484 dvmCompilerClobber(cUnit, rlArray.lowReg);
Bill Buzbee1465db52009-09-23 17:17:35 -0700485 regPtr = rlArray.lowReg;
486 } else {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800487 regPtr = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700488 genRegCopy(cUnit, regPtr, rlArray.lowReg);
489 }
Ben Chenge9695e52009-06-16 16:11:47 -0700490
Ben Cheng1efc9c52009-06-08 18:25:27 -0700491 /* null object? */
Ben Cheng4238ec22009-08-24 16:32:22 -0700492 ArmLIR * pcrLabel = NULL;
493
494 if (!(mir->OptimizationFlags & MIR_IGNORE_NULL_CHECK)) {
Bill Buzbee1465db52009-09-23 17:17:35 -0700495 pcrLabel = genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg,
496 mir->offset, NULL);
Ben Cheng4238ec22009-08-24 16:32:22 -0700497 }
498
499 if (!(mir->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800500 int regLen = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700501 //NOTE: max live temps(4) here.
Ben Cheng4238ec22009-08-24 16:32:22 -0700502 /* Get len */
Bill Buzbee1465db52009-09-23 17:17:35 -0700503 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen);
504 /* regPtr -> array data */
505 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
506 genBoundsCheck(cUnit, rlIndex.lowReg, regLen, mir->offset,
507 pcrLabel);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800508 dvmCompilerFreeTemp(cUnit, regLen);
Ben Cheng4238ec22009-08-24 16:32:22 -0700509 } else {
Bill Buzbee1465db52009-09-23 17:17:35 -0700510 /* regPtr -> array data */
511 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
Ben Cheng4238ec22009-08-24 16:32:22 -0700512 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700513 /* at this point, regPtr points to array, 2 live temps */
Bill Buzbee1465db52009-09-23 17:17:35 -0700514 if ((size == kLong) || (size == kDouble)) {
515 //TODO: need specific wide routine that can handle fp regs
516 if (scale) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800517 int rNewIndex = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700518 opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale);
519 opRegReg(cUnit, kOpAdd, regPtr, rNewIndex);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800520 dvmCompilerFreeTemp(cUnit, rNewIndex);
Bill Buzbee1465db52009-09-23 17:17:35 -0700521 } else {
522 opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg);
523 }
Bill Buzbee749e8162010-07-07 06:55:56 -0700524 rlSrc = loadValueWide(cUnit, rlSrc, regClass);
Ben Cheng11d8f142010-03-24 15:24:19 -0700525
526 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700527 storePair(cUnit, regPtr, rlSrc.lowReg, rlSrc.highReg);
Ben Cheng11d8f142010-03-24 15:24:19 -0700528 HEAP_ACCESS_SHADOW(false);
529
Bill Buzbeec6f10662010-02-09 11:16:15 -0800530 dvmCompilerFreeTemp(cUnit, regPtr);
Bill Buzbee270c1d62009-08-13 16:58:07 -0700531 } else {
Bill Buzbee749e8162010-07-07 06:55:56 -0700532 rlSrc = loadValue(cUnit, rlSrc, regClass);
Ben Cheng11d8f142010-03-24 15:24:19 -0700533
534 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700535 storeBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlSrc.lowReg,
536 scale, size);
Ben Cheng11d8f142010-03-24 15:24:19 -0700537 HEAP_ACCESS_SHADOW(false);
jeffhao9e45c0b2010-02-03 10:24:05 -0800538 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700539}
540
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800541/*
542 * Generate array object store
543 * Must use explicit register allocation here because of
544 * call-out to dvmCanPutArrayElement
545 */
546static void genArrayObjectPut(CompilationUnit *cUnit, MIR *mir,
547 RegLocation rlArray, RegLocation rlIndex,
548 RegLocation rlSrc, int scale)
549{
550 int lenOffset = offsetof(ArrayObject, length);
551 int dataOffset = offsetof(ArrayObject, contents);
552
553 dvmCompilerFlushAllRegs(cUnit);
554
555 int regLen = r0;
556 int regPtr = r4PC; /* Preserved across call */
557 int regArray = r1;
558 int regIndex = r7; /* Preserved across call */
559
560 loadValueDirectFixed(cUnit, rlArray, regArray);
561 loadValueDirectFixed(cUnit, rlIndex, regIndex);
562
563 /* null object? */
564 ArmLIR * pcrLabel = NULL;
565
566 if (!(mir->OptimizationFlags & MIR_IGNORE_NULL_CHECK)) {
567 pcrLabel = genNullCheck(cUnit, rlArray.sRegLow, regArray,
568 mir->offset, NULL);
569 }
570
571 if (!(mir->OptimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
572 /* Get len */
573 loadWordDisp(cUnit, regArray, lenOffset, regLen);
574 /* regPtr -> array data */
575 opRegRegImm(cUnit, kOpAdd, regPtr, regArray, dataOffset);
576 genBoundsCheck(cUnit, regIndex, regLen, mir->offset,
577 pcrLabel);
578 } else {
579 /* regPtr -> array data */
580 opRegRegImm(cUnit, kOpAdd, regPtr, regArray, dataOffset);
581 }
582
583 /* Get object to store */
584 loadValueDirectFixed(cUnit, rlSrc, r0);
Ben Chengbd1326d2010-04-02 15:04:53 -0700585 LOAD_FUNC_ADDR(cUnit, r2, (int)dvmCanPutArrayElement);
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800586
587 /* Are we storing null? If so, avoid check */
buzbee8f8109a2010-08-31 10:16:35 -0700588 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondEq, r0, 0);
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800589
590 /* Make sure the types are compatible */
591 loadWordDisp(cUnit, regArray, offsetof(Object, clazz), r1);
592 loadWordDisp(cUnit, r0, offsetof(Object, clazz), r0);
593 opReg(cUnit, kOpBlx, r2);
594 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbee900a3af2010-03-16 12:41:43 -0700595
596 /*
597 * Using fixed registers here, and counting on r4 and r7 being
598 * preserved across the above call. Tell the register allocation
599 * utilities about the regs we are using directly
600 */
601 dvmCompilerLockTemp(cUnit, regPtr); // r4PC
602 dvmCompilerLockTemp(cUnit, regIndex); // r7
603 dvmCompilerLockTemp(cUnit, r0);
buzbee919eb062010-07-12 12:59:22 -0700604 dvmCompilerLockTemp(cUnit, r1);
Bill Buzbee900a3af2010-03-16 12:41:43 -0700605
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800606 /* Bad? - roll back and re-execute if so */
607 genRegImmCheck(cUnit, kArmCondEq, r0, 0, mir->offset, pcrLabel);
608
buzbee919eb062010-07-12 12:59:22 -0700609 /* Resume here - must reload element & array, regPtr & index preserved */
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800610 loadValueDirectFixed(cUnit, rlSrc, r0);
buzbee919eb062010-07-12 12:59:22 -0700611 loadValueDirectFixed(cUnit, rlArray, r1);
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800612
613 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
614 target->defMask = ENCODE_ALL;
615 branchOver->generic.target = (LIR *) target;
616
Ben Cheng11d8f142010-03-24 15:24:19 -0700617 HEAP_ACCESS_SHADOW(true);
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800618 storeBaseIndexed(cUnit, regPtr, regIndex, r0,
619 scale, kWord);
Ben Cheng11d8f142010-03-24 15:24:19 -0700620 HEAP_ACCESS_SHADOW(false);
buzbee919eb062010-07-12 12:59:22 -0700621
buzbeebaf196a2010-08-04 10:13:15 -0700622 dvmCompilerFreeTemp(cUnit, regPtr);
623 dvmCompilerFreeTemp(cUnit, regIndex);
624
buzbee919eb062010-07-12 12:59:22 -0700625 /* NOTE: marking card here based on object head */
626 markCard(cUnit, r0, r1);
Bill Buzbeebe6534f2010-03-12 16:01:35 -0800627}
628
Ben Cheng5d90c202009-11-22 23:31:11 -0800629static bool genShiftOpLong(CompilationUnit *cUnit, MIR *mir,
630 RegLocation rlDest, RegLocation rlSrc1,
631 RegLocation rlShift)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700632{
Ben Chenge9695e52009-06-16 16:11:47 -0700633 /*
634 * Don't mess with the regsiters here as there is a particular calling
635 * convention to the out-of-line handler.
636 */
Bill Buzbee1465db52009-09-23 17:17:35 -0700637 RegLocation rlResult;
638
639 loadValueDirectWideFixed(cUnit, rlSrc1, r0, r1);
640 loadValueDirect(cUnit, rlShift, r2);
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800641 switch( mir->dalvikInsn.opcode) {
Ben Chenge9695e52009-06-16 16:11:47 -0700642 case OP_SHL_LONG:
643 case OP_SHL_LONG_2ADDR:
644 genDispatchToHandler(cUnit, TEMPLATE_SHL_LONG);
645 break;
646 case OP_SHR_LONG:
647 case OP_SHR_LONG_2ADDR:
648 genDispatchToHandler(cUnit, TEMPLATE_SHR_LONG);
649 break;
650 case OP_USHR_LONG:
651 case OP_USHR_LONG_2ADDR:
652 genDispatchToHandler(cUnit, TEMPLATE_USHR_LONG);
653 break;
654 default:
655 return true;
656 }
Bill Buzbeec6f10662010-02-09 11:16:15 -0800657 rlResult = dvmCompilerGetReturnWide(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700658 storeValueWide(cUnit, rlDest, rlResult);
Ben Chenge9695e52009-06-16 16:11:47 -0700659 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700660}
Ben Chenge9695e52009-06-16 16:11:47 -0700661
Ben Cheng5d90c202009-11-22 23:31:11 -0800662static bool genArithOpLong(CompilationUnit *cUnit, MIR *mir,
663 RegLocation rlDest, RegLocation rlSrc1,
664 RegLocation rlSrc2)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700665{
Bill Buzbee1465db52009-09-23 17:17:35 -0700666 RegLocation rlResult;
667 OpKind firstOp = kOpBkpt;
668 OpKind secondOp = kOpBkpt;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700669 bool callOut = false;
670 void *callTgt;
671 int retReg = r0;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700672
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800673 switch (mir->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700674 case OP_NOT_LONG:
Bill Buzbee1465db52009-09-23 17:17:35 -0700675 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800676 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700677 opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg);
678 opRegReg(cUnit, kOpMvn, rlResult.highReg, rlSrc2.highReg);
679 storeValueWide(cUnit, rlDest, rlResult);
680 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700681 break;
682 case OP_ADD_LONG:
683 case OP_ADD_LONG_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700684 firstOp = kOpAdd;
685 secondOp = kOpAdc;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700686 break;
687 case OP_SUB_LONG:
688 case OP_SUB_LONG_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700689 firstOp = kOpSub;
690 secondOp = kOpSbc;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700691 break;
692 case OP_MUL_LONG:
693 case OP_MUL_LONG_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700694 genMulLong(cUnit, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700695 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700696 case OP_DIV_LONG:
697 case OP_DIV_LONG_2ADDR:
698 callOut = true;
699 retReg = r0;
700 callTgt = (void*)__aeabi_ldivmod;
701 break;
702 /* NOTE - result is in r2/r3 instead of r0/r1 */
703 case OP_REM_LONG:
704 case OP_REM_LONG_2ADDR:
705 callOut = true;
706 callTgt = (void*)__aeabi_ldivmod;
707 retReg = r2;
708 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700709 case OP_AND_LONG_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700710 case OP_AND_LONG:
711 firstOp = kOpAnd;
712 secondOp = kOpAnd;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700713 break;
714 case OP_OR_LONG:
715 case OP_OR_LONG_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700716 firstOp = kOpOr;
717 secondOp = kOpOr;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700718 break;
719 case OP_XOR_LONG:
720 case OP_XOR_LONG_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700721 firstOp = kOpXor;
722 secondOp = kOpXor;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700723 break;
Ben Chenge9695e52009-06-16 16:11:47 -0700724 case OP_NEG_LONG: {
Bill Buzbee51ecf602010-01-14 14:27:52 -0800725 //TUNING: can improve this using Thumb2 code
Bill Buzbeec6f10662010-02-09 11:16:15 -0800726 int tReg = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700727 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800728 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -0700729 loadConstantNoClobber(cUnit, tReg, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -0700730 opRegRegReg(cUnit, kOpSub, rlResult.lowReg,
Bill Buzbee51ecf602010-01-14 14:27:52 -0800731 tReg, rlSrc2.lowReg);
732 opRegReg(cUnit, kOpSbc, tReg, rlSrc2.highReg);
733 genRegCopy(cUnit, rlResult.highReg, tReg);
Bill Buzbee1465db52009-09-23 17:17:35 -0700734 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700735 return false;
Ben Chenge9695e52009-06-16 16:11:47 -0700736 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700737 default:
738 LOGE("Invalid long arith op");
Bill Buzbeefc519dc2010-03-06 23:30:57 -0800739 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700740 }
741 if (!callOut) {
Bill Buzbee80cef862010-03-25 10:38:34 -0700742 genLong3Addr(cUnit, mir, firstOp, secondOp, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700743 } else {
Bill Buzbee1465db52009-09-23 17:17:35 -0700744 // Adjust return regs in to handle case of rem returning r2/r3
Bill Buzbeec6f10662010-02-09 11:16:15 -0800745 dvmCompilerFlushAllRegs(cUnit); /* Send everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -0700746 loadValueDirectWideFixed(cUnit, rlSrc1, r0, r1);
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800747 LOAD_FUNC_ADDR(cUnit, r14lr, (int) callTgt);
Bill Buzbee1465db52009-09-23 17:17:35 -0700748 loadValueDirectWideFixed(cUnit, rlSrc2, r2, r3);
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800749 opReg(cUnit, kOpBlx, r14lr);
Elliott Hughes6a555132010-02-25 15:41:42 -0800750 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700751 if (retReg == r0)
Bill Buzbeec6f10662010-02-09 11:16:15 -0800752 rlResult = dvmCompilerGetReturnWide(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700753 else
Bill Buzbeec6f10662010-02-09 11:16:15 -0800754 rlResult = dvmCompilerGetReturnWideAlt(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700755 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengd72564c2011-02-08 17:09:25 -0800756#if defined(WITH_SELF_VERIFICATION)
757 cUnit->usesLinkRegister = true;
758#endif
Ben Chengba4fc8b2009-06-01 13:00:29 -0700759 }
760 return false;
761}
762
Ben Cheng5d90c202009-11-22 23:31:11 -0800763static bool genArithOpInt(CompilationUnit *cUnit, MIR *mir,
764 RegLocation rlDest, RegLocation rlSrc1,
765 RegLocation rlSrc2)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700766{
Bill Buzbee1465db52009-09-23 17:17:35 -0700767 OpKind op = kOpBkpt;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700768 bool callOut = false;
769 bool checkZero = false;
Bill Buzbee1465db52009-09-23 17:17:35 -0700770 bool unary = false;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700771 int retReg = r0;
772 void *callTgt;
Bill Buzbee1465db52009-09-23 17:17:35 -0700773 RegLocation rlResult;
Bill Buzbee0e605272009-12-01 14:28:05 -0800774 bool shiftOp = false;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700775
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800776 switch (mir->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700777 case OP_NEG_INT:
Bill Buzbee1465db52009-09-23 17:17:35 -0700778 op = kOpNeg;
779 unary = true;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700780 break;
781 case OP_NOT_INT:
Bill Buzbee1465db52009-09-23 17:17:35 -0700782 op = kOpMvn;
783 unary = true;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700784 break;
785 case OP_ADD_INT:
786 case OP_ADD_INT_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700787 op = kOpAdd;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700788 break;
789 case OP_SUB_INT:
790 case OP_SUB_INT_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700791 op = kOpSub;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700792 break;
793 case OP_MUL_INT:
794 case OP_MUL_INT_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700795 op = kOpMul;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700796 break;
797 case OP_DIV_INT:
798 case OP_DIV_INT_2ADDR:
799 callOut = true;
800 checkZero = true;
801 callTgt = __aeabi_idiv;
802 retReg = r0;
803 break;
804 /* NOTE: returns in r1 */
805 case OP_REM_INT:
806 case OP_REM_INT_2ADDR:
807 callOut = true;
808 checkZero = true;
809 callTgt = __aeabi_idivmod;
810 retReg = r1;
811 break;
812 case OP_AND_INT:
813 case OP_AND_INT_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700814 op = kOpAnd;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700815 break;
816 case OP_OR_INT:
817 case OP_OR_INT_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700818 op = kOpOr;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700819 break;
820 case OP_XOR_INT:
821 case OP_XOR_INT_2ADDR:
Bill Buzbee1465db52009-09-23 17:17:35 -0700822 op = kOpXor;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700823 break;
824 case OP_SHL_INT:
825 case OP_SHL_INT_2ADDR:
Bill Buzbee0e605272009-12-01 14:28:05 -0800826 shiftOp = true;
Bill Buzbee1465db52009-09-23 17:17:35 -0700827 op = kOpLsl;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700828 break;
829 case OP_SHR_INT:
830 case OP_SHR_INT_2ADDR:
Bill Buzbee0e605272009-12-01 14:28:05 -0800831 shiftOp = true;
Bill Buzbee1465db52009-09-23 17:17:35 -0700832 op = kOpAsr;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700833 break;
834 case OP_USHR_INT:
835 case OP_USHR_INT_2ADDR:
Bill Buzbee0e605272009-12-01 14:28:05 -0800836 shiftOp = true;
Bill Buzbee1465db52009-09-23 17:17:35 -0700837 op = kOpLsr;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700838 break;
839 default:
840 LOGE("Invalid word arith op: 0x%x(%d)",
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800841 mir->dalvikInsn.opcode, mir->dalvikInsn.opcode);
Bill Buzbeefc519dc2010-03-06 23:30:57 -0800842 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700843 }
844 if (!callOut) {
Bill Buzbee1465db52009-09-23 17:17:35 -0700845 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
846 if (unary) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800847 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -0700848 opRegReg(cUnit, op, rlResult.lowReg,
849 rlSrc1.lowReg);
Ben Chenge9695e52009-06-16 16:11:47 -0700850 } else {
Bill Buzbee1465db52009-09-23 17:17:35 -0700851 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
Bill Buzbee0e605272009-12-01 14:28:05 -0800852 if (shiftOp) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800853 int tReg = dvmCompilerAllocTemp(cUnit);
Bill Buzbee0e605272009-12-01 14:28:05 -0800854 opRegRegImm(cUnit, kOpAnd, tReg, rlSrc2.lowReg, 31);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800855 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee0e605272009-12-01 14:28:05 -0800856 opRegRegReg(cUnit, op, rlResult.lowReg,
857 rlSrc1.lowReg, tReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800858 dvmCompilerFreeTemp(cUnit, tReg);
Bill Buzbee0e605272009-12-01 14:28:05 -0800859 } else {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800860 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee0e605272009-12-01 14:28:05 -0800861 opRegRegReg(cUnit, op, rlResult.lowReg,
862 rlSrc1.lowReg, rlSrc2.lowReg);
863 }
Ben Chenge9695e52009-06-16 16:11:47 -0700864 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700865 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700866 } else {
Bill Buzbee1465db52009-09-23 17:17:35 -0700867 RegLocation rlResult;
Bill Buzbeec6f10662010-02-09 11:16:15 -0800868 dvmCompilerFlushAllRegs(cUnit); /* Send everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -0700869 loadValueDirectFixed(cUnit, rlSrc2, r1);
Ben Chengbd1326d2010-04-02 15:04:53 -0700870 LOAD_FUNC_ADDR(cUnit, r2, (int) callTgt);
Bill Buzbee1465db52009-09-23 17:17:35 -0700871 loadValueDirectFixed(cUnit, rlSrc1, r0);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700872 if (checkZero) {
Bill Buzbee1465db52009-09-23 17:17:35 -0700873 genNullCheck(cUnit, rlSrc2.sRegLow, r1, mir->offset, NULL);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700874 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700875 opReg(cUnit, kOpBlx, r2);
Elliott Hughes6a555132010-02-25 15:41:42 -0800876 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700877 if (retReg == r0)
Bill Buzbeec6f10662010-02-09 11:16:15 -0800878 rlResult = dvmCompilerGetReturn(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700879 else
Bill Buzbeec6f10662010-02-09 11:16:15 -0800880 rlResult = dvmCompilerGetReturnAlt(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -0700881 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700882 }
883 return false;
884}
885
Ben Cheng5d90c202009-11-22 23:31:11 -0800886static bool genArithOp(CompilationUnit *cUnit, MIR *mir)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700887{
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800888 Opcode opcode = mir->dalvikInsn.opcode;
Bill Buzbee1465db52009-09-23 17:17:35 -0700889 RegLocation rlDest;
890 RegLocation rlSrc1;
891 RegLocation rlSrc2;
892 /* Deduce sizes of operands */
893 if (mir->ssaRep->numUses == 2) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800894 rlSrc1 = dvmCompilerGetSrc(cUnit, mir, 0);
895 rlSrc2 = dvmCompilerGetSrc(cUnit, mir, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -0700896 } else if (mir->ssaRep->numUses == 3) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800897 rlSrc1 = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
898 rlSrc2 = dvmCompilerGetSrc(cUnit, mir, 2);
Bill Buzbee1465db52009-09-23 17:17:35 -0700899 } else {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800900 rlSrc1 = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
901 rlSrc2 = dvmCompilerGetSrcWide(cUnit, mir, 2, 3);
Bill Buzbee1465db52009-09-23 17:17:35 -0700902 assert(mir->ssaRep->numUses == 4);
903 }
904 if (mir->ssaRep->numDefs == 1) {
Bill Buzbeec6f10662010-02-09 11:16:15 -0800905 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -0700906 } else {
907 assert(mir->ssaRep->numDefs == 2);
Bill Buzbeec6f10662010-02-09 11:16:15 -0800908 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -0700909 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700910
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800911 if ((opcode >= OP_ADD_LONG_2ADDR) && (opcode <= OP_XOR_LONG_2ADDR)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800912 return genArithOpLong(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700913 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800914 if ((opcode >= OP_ADD_LONG) && (opcode <= OP_XOR_LONG)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800915 return genArithOpLong(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700916 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800917 if ((opcode >= OP_SHL_LONG_2ADDR) && (opcode <= OP_USHR_LONG_2ADDR)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800918 return genShiftOpLong(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700919 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800920 if ((opcode >= OP_SHL_LONG) && (opcode <= OP_USHR_LONG)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800921 return genShiftOpLong(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700922 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800923 if ((opcode >= OP_ADD_INT_2ADDR) && (opcode <= OP_USHR_INT_2ADDR)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800924 return genArithOpInt(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700925 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800926 if ((opcode >= OP_ADD_INT) && (opcode <= OP_USHR_INT)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800927 return genArithOpInt(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700928 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800929 if ((opcode >= OP_ADD_FLOAT_2ADDR) && (opcode <= OP_REM_FLOAT_2ADDR)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800930 return genArithOpFloat(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700931 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800932 if ((opcode >= OP_ADD_FLOAT) && (opcode <= OP_REM_FLOAT)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800933 return genArithOpFloat(cUnit, mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700934 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800935 if ((opcode >= OP_ADD_DOUBLE_2ADDR) && (opcode <= OP_REM_DOUBLE_2ADDR)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800936 return genArithOpDouble(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700937 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -0800938 if ((opcode >= OP_ADD_DOUBLE) && (opcode <= OP_REM_DOUBLE)) {
Ben Cheng5d90c202009-11-22 23:31:11 -0800939 return genArithOpDouble(cUnit,mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700940 }
941 return true;
942}
943
Bill Buzbee1465db52009-09-23 17:17:35 -0700944/* Generate unconditional branch instructions */
945static ArmLIR *genUnconditionalBranch(CompilationUnit *cUnit, ArmLIR *target)
946{
947 ArmLIR *branch = opNone(cUnit, kOpUncondBr);
948 branch->generic.target = (LIR *) target;
949 return branch;
950}
951
Bill Buzbee1465db52009-09-23 17:17:35 -0700952/* Perform the actual operation for OP_RETURN_* */
953static void genReturnCommon(CompilationUnit *cUnit, MIR *mir)
954{
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800955 genDispatchToHandler(cUnit, gDvmJit.methodTraceSupport ?
956 TEMPLATE_RETURN_PROF : TEMPLATE_RETURN);
Ben Cheng978738d2010-05-13 13:45:57 -0700957#if defined(WITH_JIT_TUNING)
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800958 gDvmJit.returnOp++;
Bill Buzbee1465db52009-09-23 17:17:35 -0700959#endif
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800960 int dPC = (int) (cUnit->method->insns + mir->offset);
961 /* Insert branch, but defer setting of target */
962 ArmLIR *branch = genUnconditionalBranch(cUnit, NULL);
963 /* Set up the place holder to reconstruct this Dalvik PC */
964 ArmLIR *pcrLabel = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
965 pcrLabel->opcode = kArmPseudoPCReconstructionCell;
966 pcrLabel->operands[0] = dPC;
967 pcrLabel->operands[1] = mir->offset;
968 /* Insert the place holder to the growable list */
969 dvmInsertGrowableList(&cUnit->pcReconstructionList, (intptr_t) pcrLabel);
970 /* Branch to the PC reconstruction code */
971 branch->generic.target = (LIR *) pcrLabel;
Bill Buzbee1465db52009-09-23 17:17:35 -0700972}
973
Ben Chengba4fc8b2009-06-01 13:00:29 -0700974static void genProcessArgsNoRange(CompilationUnit *cUnit, MIR *mir,
975 DecodedInstruction *dInsn,
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700976 ArmLIR **pcrLabel)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700977{
978 unsigned int i;
979 unsigned int regMask = 0;
Bill Buzbee1465db52009-09-23 17:17:35 -0700980 RegLocation rlArg;
981 int numDone = 0;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700982
Bill Buzbee1465db52009-09-23 17:17:35 -0700983 /*
984 * Load arguments to r0..r4. Note that these registers may contain
985 * live values, so we clobber them immediately after loading to prevent
986 * them from being used as sources for subsequent loads.
987 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800988 dvmCompilerLockAllTemps(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700989 for (i = 0; i < dInsn->vA; i++) {
990 regMask |= 1 << i;
Bill Buzbeec6f10662010-02-09 11:16:15 -0800991 rlArg = dvmCompilerGetSrc(cUnit, mir, numDone++);
Bill Buzbee1465db52009-09-23 17:17:35 -0700992 loadValueDirectFixed(cUnit, rlArg, i);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700993 }
994 if (regMask) {
995 /* Up to 5 args are pushed on top of FP - sizeofStackSaveArea */
Ben Cheng20d7e6c2011-02-18 17:12:42 -0800996 opRegRegImm(cUnit, kOpSub, r7, r5FP,
Bill Buzbee1465db52009-09-23 17:17:35 -0700997 sizeof(StackSaveArea) + (dInsn->vA << 2));
Ben Chengba4fc8b2009-06-01 13:00:29 -0700998 /* generate null check */
999 if (pcrLabel) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001000 *pcrLabel = genNullCheck(cUnit, dvmCompilerSSASrc(mir, 0), r0,
Bill Buzbee1465db52009-09-23 17:17:35 -07001001 mir->offset, NULL);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001002 }
Bill Buzbee270c1d62009-08-13 16:58:07 -07001003 storeMultiple(cUnit, r7, regMask);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001004 }
1005}
1006
1007static void genProcessArgsRange(CompilationUnit *cUnit, MIR *mir,
1008 DecodedInstruction *dInsn,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001009 ArmLIR **pcrLabel)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001010{
1011 int srcOffset = dInsn->vC << 2;
1012 int numArgs = dInsn->vA;
1013 int regMask;
Bill Buzbee1465db52009-09-23 17:17:35 -07001014
1015 /*
1016 * Note: here, all promoted registers will have been flushed
1017 * back to the Dalvik base locations, so register usage restrictins
1018 * are lifted. All parms loaded from original Dalvik register
1019 * region - even though some might conceivably have valid copies
1020 * cached in a preserved register.
1021 */
Bill Buzbeec6f10662010-02-09 11:16:15 -08001022 dvmCompilerLockAllTemps(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07001023
Ben Chengba4fc8b2009-06-01 13:00:29 -07001024 /*
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001025 * r4PC : &r5FP[vC]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001026 * r7: &newFP[0]
1027 */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001028 opRegRegImm(cUnit, kOpAdd, r4PC, r5FP, srcOffset);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001029 /* load [r0 .. min(numArgs,4)] */
1030 regMask = (1 << ((numArgs < 4) ? numArgs : 4)) - 1;
Ben Chengd7d426a2009-09-22 11:23:36 -07001031 /*
1032 * Protect the loadMultiple instruction from being reordered with other
1033 * Dalvik stack accesses.
jeffhao71eee1f2011-01-04 14:18:54 -08001034 *
1035 * This code is also shared by the invoke jumbo instructions, and this
1036 * does not need to be done if the invoke jumbo has no arguments.
Ben Chengd7d426a2009-09-22 11:23:36 -07001037 */
jeffhao71eee1f2011-01-04 14:18:54 -08001038 if (numArgs != 0) loadMultiple(cUnit, r4PC, regMask);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001039
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001040 opRegRegImm(cUnit, kOpSub, r7, r5FP,
Bill Buzbee1465db52009-09-23 17:17:35 -07001041 sizeof(StackSaveArea) + (numArgs << 2));
Ben Chengba4fc8b2009-06-01 13:00:29 -07001042 /* generate null check */
1043 if (pcrLabel) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001044 *pcrLabel = genNullCheck(cUnit, dvmCompilerSSASrc(mir, 0), r0,
Bill Buzbee1465db52009-09-23 17:17:35 -07001045 mir->offset, NULL);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001046 }
1047
1048 /*
1049 * Handle remaining 4n arguments:
1050 * store previously loaded 4 values and load the next 4 values
1051 */
1052 if (numArgs >= 8) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001053 ArmLIR *loopLabel = NULL;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001054 /*
1055 * r0 contains "this" and it will be used later, so push it to the stack
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001056 * first. Pushing r5FP is just for stack alignment purposes.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001057 */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001058 opImm(cUnit, kOpPush, (1 << r0 | 1 << r5FP));
Ben Chengba4fc8b2009-06-01 13:00:29 -07001059 /* No need to generate the loop structure if numArgs <= 11 */
1060 if (numArgs > 11) {
1061 loadConstant(cUnit, 5, ((numArgs - 4) >> 2) << 2);
Bill Buzbee1465db52009-09-23 17:17:35 -07001062 loopLabel = newLIR0(cUnit, kArmPseudoTargetLabel);
Ben Chengd7d426a2009-09-22 11:23:36 -07001063 loopLabel->defMask = ENCODE_ALL;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001064 }
Bill Buzbee270c1d62009-08-13 16:58:07 -07001065 storeMultiple(cUnit, r7, regMask);
Ben Chengd7d426a2009-09-22 11:23:36 -07001066 /*
1067 * Protect the loadMultiple instruction from being reordered with other
1068 * Dalvik stack accesses.
1069 */
Bill Buzbee270c1d62009-08-13 16:58:07 -07001070 loadMultiple(cUnit, r4PC, regMask);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001071 /* No need to generate the loop structure if numArgs <= 11 */
1072 if (numArgs > 11) {
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001073 opRegImm(cUnit, kOpSub, r5FP, 4);
Bill Buzbee1465db52009-09-23 17:17:35 -07001074 genConditionalBranch(cUnit, kArmCondNe, loopLabel);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001075 }
1076 }
1077
1078 /* Save the last batch of loaded values */
jeffhao71eee1f2011-01-04 14:18:54 -08001079 if (numArgs != 0) storeMultiple(cUnit, r7, regMask);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001080
1081 /* Generate the loop epilogue - don't use r0 */
1082 if ((numArgs > 4) && (numArgs % 4)) {
1083 regMask = ((1 << (numArgs & 0x3)) - 1) << 1;
Ben Chengd7d426a2009-09-22 11:23:36 -07001084 /*
1085 * Protect the loadMultiple instruction from being reordered with other
1086 * Dalvik stack accesses.
1087 */
Bill Buzbee270c1d62009-08-13 16:58:07 -07001088 loadMultiple(cUnit, r4PC, regMask);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001089 }
1090 if (numArgs >= 8)
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001091 opImm(cUnit, kOpPop, (1 << r0 | 1 << r5FP));
Ben Chengba4fc8b2009-06-01 13:00:29 -07001092
1093 /* Save the modulo 4 arguments */
1094 if ((numArgs > 4) && (numArgs % 4)) {
Bill Buzbee270c1d62009-08-13 16:58:07 -07001095 storeMultiple(cUnit, r7, regMask);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001096 }
1097}
1098
Ben Cheng38329f52009-07-07 14:19:20 -07001099/*
1100 * Generate code to setup the call stack then jump to the chaining cell if it
1101 * is not a native method.
1102 */
1103static void genInvokeSingletonCommon(CompilationUnit *cUnit, MIR *mir,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001104 BasicBlock *bb, ArmLIR *labelList,
1105 ArmLIR *pcrLabel,
Ben Cheng38329f52009-07-07 14:19:20 -07001106 const Method *calleeMethod)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001107{
Bill Buzbee1465db52009-09-23 17:17:35 -07001108 /*
1109 * Note: all Dalvik register state should be flushed to
1110 * memory by the point, so register usage restrictions no
1111 * longer apply. All temp & preserved registers may be used.
1112 */
Bill Buzbeec6f10662010-02-09 11:16:15 -08001113 dvmCompilerLockAllTemps(cUnit);
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001114 ArmLIR *retChainingCell = &labelList[bb->fallThrough->id];
Ben Chengba4fc8b2009-06-01 13:00:29 -07001115
1116 /* r1 = &retChainingCell */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001117 ArmLIR *addrRetChain = opRegRegImm(cUnit, kOpAdd, r1, r15pc, 0);
Ben Chengc8293e72010-10-12 11:50:10 -07001118
Ben Chengba4fc8b2009-06-01 13:00:29 -07001119 /* r4PC = dalvikCallsite */
1120 loadConstant(cUnit, r4PC,
1121 (int) (cUnit->method->insns + mir->offset));
1122 addrRetChain->generic.target = (LIR *) retChainingCell;
Ben Chengc8293e72010-10-12 11:50:10 -07001123
1124 /* r7 = calleeMethod->registersSize */
1125 loadConstant(cUnit, r7, calleeMethod->registersSize);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001126 /*
Ben Cheng38329f52009-07-07 14:19:20 -07001127 * r0 = calleeMethod (loaded upon calling genInvokeSingletonCommon)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001128 * r1 = &ChainingCell
Ben Chengc8293e72010-10-12 11:50:10 -07001129 * r2 = calleeMethod->outsSize (to be loaded later for Java callees)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001130 * r4PC = callsiteDPC
Ben Chengc8293e72010-10-12 11:50:10 -07001131 * r7 = calleeMethod->registersSize
Ben Chengba4fc8b2009-06-01 13:00:29 -07001132 */
1133 if (dvmIsNativeMethod(calleeMethod)) {
buzbee18fba342011-01-19 15:31:15 -08001134 genDispatchToHandler(cUnit, gDvmJit.methodTraceSupport ?
1135 TEMPLATE_INVOKE_METHOD_NATIVE_PROF :
1136 TEMPLATE_INVOKE_METHOD_NATIVE);
Ben Cheng978738d2010-05-13 13:45:57 -07001137#if defined(WITH_JIT_TUNING)
Ben Cheng38329f52009-07-07 14:19:20 -07001138 gDvmJit.invokeNative++;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001139#endif
1140 } else {
Ben Chengc8293e72010-10-12 11:50:10 -07001141 /* For Java callees, set up r2 to be calleeMethod->outsSize */
1142 loadConstant(cUnit, r2, calleeMethod->outsSize);
buzbee18fba342011-01-19 15:31:15 -08001143 genDispatchToHandler(cUnit, gDvmJit.methodTraceSupport ?
1144 TEMPLATE_INVOKE_METHOD_CHAIN_PROF :
1145 TEMPLATE_INVOKE_METHOD_CHAIN);
Ben Cheng978738d2010-05-13 13:45:57 -07001146#if defined(WITH_JIT_TUNING)
Ben Cheng86717f72010-03-05 15:27:21 -08001147 gDvmJit.invokeMonomorphic++;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001148#endif
Ben Cheng38329f52009-07-07 14:19:20 -07001149 /* Branch to the chaining cell */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001150 genUnconditionalBranch(cUnit, &labelList[bb->taken->id]);
1151 }
1152 /* Handle exceptions using the interpreter */
1153 genTrap(cUnit, mir->offset, pcrLabel);
1154}
1155
Ben Cheng38329f52009-07-07 14:19:20 -07001156/*
1157 * Generate code to check the validity of a predicted chain and take actions
1158 * based on the result.
1159 *
1160 * 0x426a99aa : ldr r4, [pc, #72] --> r4 <- dalvikPC of this invoke
1161 * 0x426a99ac : add r1, pc, #32 --> r1 <- &retChainingCell
1162 * 0x426a99ae : add r2, pc, #40 --> r2 <- &predictedChainingCell
1163 * 0x426a99b0 : blx_1 0x426a918c --+ TEMPLATE_INVOKE_METHOD_PREDICTED_CHAIN
1164 * 0x426a99b2 : blx_2 see above --+
1165 * 0x426a99b4 : b 0x426a99d8 --> off to the predicted chain
1166 * 0x426a99b6 : b 0x426a99c8 --> punt to the interpreter
1167 * 0x426a99b8 : ldr r0, [r7, #44] --> r0 <- this->class->vtable[methodIdx]
1168 * 0x426a99ba : cmp r1, #0 --> compare r1 (rechain count) against 0
1169 * 0x426a99bc : bgt 0x426a99c2 --> >=0? don't rechain
Ben Chengaf5aa1f2011-01-04 15:37:04 -08001170 * 0x426a99be : ldr r7, [pc, #off]--+ dvmJitToPatchPredictedChain
Ben Cheng38329f52009-07-07 14:19:20 -07001171 * 0x426a99c0 : blx r7 --+
1172 * 0x426a99c2 : add r1, pc, #12 --> r1 <- &retChainingCell
1173 * 0x426a99c4 : blx_1 0x426a9098 --+ TEMPLATE_INVOKE_METHOD_NO_OPT
1174 * 0x426a99c6 : blx_2 see above --+
1175 */
1176static void genInvokeVirtualCommon(CompilationUnit *cUnit, MIR *mir,
1177 int methodIndex,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001178 ArmLIR *retChainingCell,
1179 ArmLIR *predChainingCell,
1180 ArmLIR *pcrLabel)
Ben Cheng38329f52009-07-07 14:19:20 -07001181{
Bill Buzbee1465db52009-09-23 17:17:35 -07001182 /*
1183 * Note: all Dalvik register state should be flushed to
1184 * memory by the point, so register usage restrictions no
1185 * longer apply. Lock temps to prevent them from being
1186 * allocated by utility routines.
1187 */
Bill Buzbeec6f10662010-02-09 11:16:15 -08001188 dvmCompilerLockAllTemps(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07001189
Ben Cheng04517042011-03-14 11:16:21 -07001190 /*
1191 * For verbose printing, store the method pointer in operands[1] first as
1192 * operands[0] will be clobbered in dvmCompilerMIR2LIR.
1193 */
1194 predChainingCell->operands[1] = (int) mir->meta.callsiteInfo->method;
1195
Ben Cheng38329f52009-07-07 14:19:20 -07001196 /* "this" is already left in r0 by genProcessArgs* */
1197
1198 /* r4PC = dalvikCallsite */
1199 loadConstant(cUnit, r4PC,
1200 (int) (cUnit->method->insns + mir->offset));
1201
1202 /* r1 = &retChainingCell */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001203 ArmLIR *addrRetChain = opRegRegImm(cUnit, kOpAdd, r1, r15pc, 0);
Ben Cheng38329f52009-07-07 14:19:20 -07001204 addrRetChain->generic.target = (LIR *) retChainingCell;
1205
1206 /* r2 = &predictedChainingCell */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001207 ArmLIR *predictedChainingCell = opRegRegImm(cUnit, kOpAdd, r2, r15pc, 0);
Ben Cheng38329f52009-07-07 14:19:20 -07001208 predictedChainingCell->generic.target = (LIR *) predChainingCell;
1209
buzbee18fba342011-01-19 15:31:15 -08001210 genDispatchToHandler(cUnit, gDvmJit.methodTraceSupport ?
1211 TEMPLATE_INVOKE_METHOD_PREDICTED_CHAIN_PROF :
1212 TEMPLATE_INVOKE_METHOD_PREDICTED_CHAIN);
Ben Cheng38329f52009-07-07 14:19:20 -07001213
1214 /* return through lr - jump to the chaining cell */
1215 genUnconditionalBranch(cUnit, predChainingCell);
1216
1217 /*
1218 * null-check on "this" may have been eliminated, but we still need a PC-
1219 * reconstruction label for stack overflow bailout.
1220 */
1221 if (pcrLabel == NULL) {
1222 int dPC = (int) (cUnit->method->insns + mir->offset);
Carl Shapirofc75f3e2010-12-07 11:43:38 -08001223 pcrLabel = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001224 pcrLabel->opcode = kArmPseudoPCReconstructionCell;
Ben Cheng38329f52009-07-07 14:19:20 -07001225 pcrLabel->operands[0] = dPC;
1226 pcrLabel->operands[1] = mir->offset;
1227 /* Insert the place holder to the growable list */
Ben Cheng00603072010-10-28 11:13:58 -07001228 dvmInsertGrowableList(&cUnit->pcReconstructionList,
1229 (intptr_t) pcrLabel);
Ben Cheng38329f52009-07-07 14:19:20 -07001230 }
1231
1232 /* return through lr+2 - punt to the interpreter */
1233 genUnconditionalBranch(cUnit, pcrLabel);
1234
1235 /*
1236 * return through lr+4 - fully resolve the callee method.
1237 * r1 <- count
1238 * r2 <- &predictedChainCell
1239 * r3 <- this->class
1240 * r4 <- dPC
1241 * r7 <- this->class->vtable
1242 */
1243
1244 /* r0 <- calleeMethod */
Bill Buzbee270c1d62009-08-13 16:58:07 -07001245 loadWordDisp(cUnit, r7, methodIndex * 4, r0);
Ben Cheng38329f52009-07-07 14:19:20 -07001246
1247 /* Check if rechain limit is reached */
buzbee8f8109a2010-08-31 10:16:35 -07001248 ArmLIR *bypassRechaining = genCmpImmBranch(cUnit, kArmCondGt, r1, 0);
Ben Cheng38329f52009-07-07 14:19:20 -07001249
Ben Chengaf5aa1f2011-01-04 15:37:04 -08001250 LOAD_FUNC_ADDR(cUnit, r7, (int) dvmJitToPatchPredictedChain);
Ben Cheng38329f52009-07-07 14:19:20 -07001251
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001252 genRegCopy(cUnit, r1, r6SELF);
Ben Chengb88ec3c2010-05-17 12:50:33 -07001253
Ben Cheng38329f52009-07-07 14:19:20 -07001254 /*
1255 * r0 = calleeMethod
1256 * r2 = &predictedChainingCell
1257 * r3 = class
1258 *
1259 * &returnChainingCell has been loaded into r1 but is not needed
1260 * when patching the chaining cell and will be clobbered upon
1261 * returning so it will be reconstructed again.
1262 */
Bill Buzbee1465db52009-09-23 17:17:35 -07001263 opReg(cUnit, kOpBlx, r7);
Ben Cheng38329f52009-07-07 14:19:20 -07001264
1265 /* r1 = &retChainingCell */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001266 addrRetChain = opRegRegImm(cUnit, kOpAdd, r1, r15pc, 0);
Ben Cheng38329f52009-07-07 14:19:20 -07001267 addrRetChain->generic.target = (LIR *) retChainingCell;
1268
1269 bypassRechaining->generic.target = (LIR *) addrRetChain;
1270 /*
1271 * r0 = calleeMethod,
1272 * r1 = &ChainingCell,
1273 * r4PC = callsiteDPC,
1274 */
buzbee18fba342011-01-19 15:31:15 -08001275 genDispatchToHandler(cUnit, gDvmJit.methodTraceSupport ?
1276 TEMPLATE_INVOKE_METHOD_NO_OPT_PROF :
1277 TEMPLATE_INVOKE_METHOD_NO_OPT);
Ben Cheng978738d2010-05-13 13:45:57 -07001278#if defined(WITH_JIT_TUNING)
Ben Cheng86717f72010-03-05 15:27:21 -08001279 gDvmJit.invokePolymorphic++;
Ben Cheng38329f52009-07-07 14:19:20 -07001280#endif
1281 /* Handle exceptions using the interpreter */
1282 genTrap(cUnit, mir->offset, pcrLabel);
1283}
1284
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001285/* "this" pointer is already in r0 */
1286static void genInvokeVirtualWholeMethod(CompilationUnit *cUnit,
1287 MIR *mir,
1288 void *calleeAddr,
1289 ArmLIR *retChainingCell)
1290{
1291 CallsiteInfo *callsiteInfo = mir->meta.callsiteInfo;
1292 dvmCompilerLockAllTemps(cUnit);
1293
Ben Cheng385828e2011-03-04 16:48:33 -08001294 loadClassPointer(cUnit, r1, (int) callsiteInfo);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001295
1296 loadWordDisp(cUnit, r0, offsetof(Object, clazz), r2);
1297 /* Branch to the slow path if classes are not equal */
1298 opRegReg(cUnit, kOpCmp, r1, r2);
1299 /*
1300 * Set the misPredBranchOver target so that it will be generated when the
1301 * code for the non-optimized invoke is generated.
1302 */
1303 ArmLIR *classCheck = opCondBranch(cUnit, kArmCondNe);
1304
1305 /* r0 = the Dalvik PC of the callsite */
1306 loadConstant(cUnit, r0, (int) (cUnit->method->insns + mir->offset));
1307
1308 newLIR2(cUnit, kThumbBl1, (int) calleeAddr, (int) calleeAddr);
1309 newLIR2(cUnit, kThumbBl2, (int) calleeAddr, (int) calleeAddr);
1310 genUnconditionalBranch(cUnit, retChainingCell);
1311
1312 /* Target of slow path */
1313 ArmLIR *slowPathLabel = newLIR0(cUnit, kArmPseudoTargetLabel);
1314
1315 slowPathLabel->defMask = ENCODE_ALL;
1316 classCheck->generic.target = (LIR *) slowPathLabel;
1317
1318 // FIXME
1319 cUnit->printMe = true;
1320}
1321
1322static void genInvokeSingletonWholeMethod(CompilationUnit *cUnit,
1323 MIR *mir,
1324 void *calleeAddr,
1325 ArmLIR *retChainingCell)
1326{
1327 /* r0 = the Dalvik PC of the callsite */
1328 loadConstant(cUnit, r0, (int) (cUnit->method->insns + mir->offset));
1329
1330 newLIR2(cUnit, kThumbBl1, (int) calleeAddr, (int) calleeAddr);
1331 newLIR2(cUnit, kThumbBl2, (int) calleeAddr, (int) calleeAddr);
1332 genUnconditionalBranch(cUnit, retChainingCell);
1333
1334 // FIXME
1335 cUnit->printMe = true;
1336}
1337
Ben Chengba4fc8b2009-06-01 13:00:29 -07001338/* Geneate a branch to go back to the interpreter */
1339static void genPuntToInterp(CompilationUnit *cUnit, unsigned int offset)
1340{
1341 /* r0 = dalvik pc */
Bill Buzbeec6f10662010-02-09 11:16:15 -08001342 dvmCompilerFlushAllRegs(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001343 loadConstant(cUnit, r0, (int) (cUnit->method->insns + offset));
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001344 loadWordDisp(cUnit, r6SELF, offsetof(Thread,
Bill Buzbee270c1d62009-08-13 16:58:07 -07001345 jitToInterpEntries.dvmJitToInterpPunt), r1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001346 opReg(cUnit, kOpBlx, r1);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001347}
1348
1349/*
1350 * Attempt to single step one instruction using the interpreter and return
1351 * to the compiled code for the next Dalvik instruction
1352 */
1353static void genInterpSingleStep(CompilationUnit *cUnit, MIR *mir)
1354{
Dan Bornsteine4852762010-12-02 12:45:00 -08001355 int flags = dexGetFlagsFromOpcode(mir->dalvikInsn.opcode);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001356 int flagsToCheck = kInstrCanBranch | kInstrCanSwitch | kInstrCanReturn |
1357 kInstrCanThrow;
Bill Buzbee1465db52009-09-23 17:17:35 -07001358
Bill Buzbee45273872010-03-11 11:12:15 -08001359 //If already optimized out, just ignore
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001360 if (mir->dalvikInsn.opcode == OP_NOP)
Bill Buzbee45273872010-03-11 11:12:15 -08001361 return;
1362
Bill Buzbee1465db52009-09-23 17:17:35 -07001363 //Ugly, but necessary. Flush all Dalvik regs so Interp can find them
Bill Buzbeec6f10662010-02-09 11:16:15 -08001364 dvmCompilerFlushAllRegs(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07001365
Ben Chengba4fc8b2009-06-01 13:00:29 -07001366 if ((mir->next == NULL) || (flags & flagsToCheck)) {
1367 genPuntToInterp(cUnit, mir->offset);
1368 return;
1369 }
buzbee9f601a92011-02-11 17:48:20 -08001370 int entryAddr = offsetof(Thread,
Ben Chengba4fc8b2009-06-01 13:00:29 -07001371 jitToInterpEntries.dvmJitToInterpSingleStep);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001372 loadWordDisp(cUnit, r6SELF, entryAddr, r2);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001373 /* r0 = dalvik pc */
1374 loadConstant(cUnit, r0, (int) (cUnit->method->insns + mir->offset));
1375 /* r1 = dalvik pc of following instruction */
1376 loadConstant(cUnit, r1, (int) (cUnit->method->insns + mir->next->offset));
Bill Buzbee1465db52009-09-23 17:17:35 -07001377 opReg(cUnit, kOpBlx, r2);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001378}
1379
Carl Shapiro01605d22011-02-01 11:32:44 -08001380#if defined(_ARMV5TE) || defined(_ARMV5TE_VFP)
Bill Buzbeec1d9ed42010-02-02 11:04:33 -08001381/*
1382 * To prevent a thread in a monitor wait from blocking the Jit from
1383 * resetting the code cache, heavyweight monitor lock will not
1384 * be allowed to return to an existing translation. Instead, we will
1385 * handle them by branching to a handler, which will in turn call the
1386 * runtime lock routine and then branch directly back to the
1387 * interpreter main loop. Given the high cost of the heavyweight
1388 * lock operation, this additional cost should be slight (especially when
1389 * considering that we expect the vast majority of lock operations to
1390 * use the fast-path thin lock bypass).
1391 */
Ben Cheng5d90c202009-11-22 23:31:11 -08001392static void genMonitorPortable(CompilationUnit *cUnit, MIR *mir)
Bill Buzbee270c1d62009-08-13 16:58:07 -07001393{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001394 bool isEnter = (mir->dalvikInsn.opcode == OP_MONITOR_ENTER);
Bill Buzbee1465db52009-09-23 17:17:35 -07001395 genExportPC(cUnit, mir);
Bill Buzbeec6f10662010-02-09 11:16:15 -08001396 dvmCompilerFlushAllRegs(cUnit); /* Send everything to home location */
1397 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001398 loadValueDirectFixed(cUnit, rlSrc, r1);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001399 genRegCopy(cUnit, r0, r6SELF);
Bill Buzbeec1d9ed42010-02-02 11:04:33 -08001400 genNullCheck(cUnit, rlSrc.sRegLow, r1, mir->offset, NULL);
Bill Buzbeeefbd3c52009-11-04 22:18:40 -08001401 if (isEnter) {
Bill Buzbeec1d9ed42010-02-02 11:04:33 -08001402 /* Get dPC of next insn */
1403 loadConstant(cUnit, r4PC, (int)(cUnit->method->insns + mir->offset +
Dan Bornsteine4852762010-12-02 12:45:00 -08001404 dexGetWidthFromOpcode(OP_MONITOR_ENTER)));
Bill Buzbeec1d9ed42010-02-02 11:04:33 -08001405 genDispatchToHandler(cUnit, TEMPLATE_MONITOR_ENTER);
Bill Buzbee1465db52009-09-23 17:17:35 -07001406 } else {
Ben Chengbd1326d2010-04-02 15:04:53 -07001407 LOAD_FUNC_ADDR(cUnit, r2, (int)dvmUnlockObject);
Bill Buzbeec1d9ed42010-02-02 11:04:33 -08001408 /* Do the call */
1409 opReg(cUnit, kOpBlx, r2);
buzbee8f8109a2010-08-31 10:16:35 -07001410 /* Did we throw? */
1411 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondNe, r0, 0);
Bill Buzbee6bbdd6b2010-02-16 14:40:01 -08001412 loadConstant(cUnit, r0,
1413 (int) (cUnit->method->insns + mir->offset +
Dan Bornsteine4852762010-12-02 12:45:00 -08001414 dexGetWidthFromOpcode(OP_MONITOR_EXIT)));
Bill Buzbee6bbdd6b2010-02-16 14:40:01 -08001415 genDispatchToHandler(cUnit, TEMPLATE_THROW_EXCEPTION_COMMON);
1416 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
1417 target->defMask = ENCODE_ALL;
1418 branchOver->generic.target = (LIR *) target;
Elliott Hughes6a555132010-02-25 15:41:42 -08001419 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07001420 }
Bill Buzbee270c1d62009-08-13 16:58:07 -07001421}
Ben Chengfc075c22010-05-28 15:20:08 -07001422#endif
Bill Buzbee270c1d62009-08-13 16:58:07 -07001423
Ben Chengba4fc8b2009-06-01 13:00:29 -07001424/*
buzbee9a3147c2011-03-02 15:43:48 -08001425 * Fetch *self->info.breakFlags. If the breakFlags are non-zero,
Ben Cheng7ab74e12011-02-03 14:02:06 -08001426 * punt to the interpreter.
1427 */
1428static void genSuspendPoll(CompilationUnit *cUnit, MIR *mir)
1429{
1430 int rTemp = dvmCompilerAllocTemp(cUnit);
1431 ArmLIR *ld;
buzbee9a3147c2011-03-02 15:43:48 -08001432 ld = loadBaseDisp(cUnit, NULL, r6SELF,
1433 offsetof(Thread, interpBreak.ctl.breakFlags),
1434 rTemp, kUnsignedByte, INVALID_SREG);
Ben Cheng7ab74e12011-02-03 14:02:06 -08001435 setMemRefType(ld, true /* isLoad */, kMustNotAlias);
Ben Cheng7ab74e12011-02-03 14:02:06 -08001436 genRegImmCheck(cUnit, kArmCondNe, rTemp, 0, mir->offset, NULL);
1437}
1438
1439/*
Ben Chengba4fc8b2009-06-01 13:00:29 -07001440 * The following are the first-level codegen routines that analyze the format
1441 * of each bytecode then either dispatch special purpose codegen routines
1442 * or produce corresponding Thumb instructions directly.
1443 */
1444
1445static bool handleFmt10t_Fmt20t_Fmt30t(CompilationUnit *cUnit, MIR *mir,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001446 BasicBlock *bb, ArmLIR *labelList)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001447{
Ben Cheng7ab74e12011-02-03 14:02:06 -08001448 /* backward branch? */
1449 bool backwardBranch = (bb->taken->startOffset <= mir->offset);
1450
1451 if (backwardBranch && gDvmJit.genSuspendPoll) {
1452 genSuspendPoll(cUnit, mir);
1453 }
1454
1455 int numPredecessors = dvmCountSetBits(bb->taken->predecessors);
1456 /*
1457 * Things could be hoisted out of the taken block into the predecessor, so
1458 * make sure it is dominated by the predecessor.
1459 */
1460 if (numPredecessors == 1 && bb->taken->visited == false &&
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001461 bb->taken->blockType == kDalvikByteCode) {
Ben Cheng7ab74e12011-02-03 14:02:06 -08001462 cUnit->nextCodegenBlock = bb->taken;
1463 } else {
1464 /* For OP_GOTO, OP_GOTO_16, and OP_GOTO_32 */
1465 genUnconditionalBranch(cUnit, &labelList[bb->taken->id]);
1466 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001467 return false;
1468}
1469
1470static bool handleFmt10x(CompilationUnit *cUnit, MIR *mir)
1471{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001472 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
1473 if ((dalvikOpcode >= OP_UNUSED_3E) && (dalvikOpcode <= OP_UNUSED_43)) {
1474 LOGE("Codegen: got unused opcode 0x%x\n",dalvikOpcode);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001475 return true;
1476 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001477 switch (dalvikOpcode) {
Andy McFadden291758c2010-09-10 08:04:52 -07001478 case OP_RETURN_VOID_BARRIER:
buzbee2ce33c92010-11-01 15:53:27 -07001479 dvmCompilerGenMemBarrier(cUnit, kST);
1480 // Intentional fallthrough
1481 case OP_RETURN_VOID:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001482 genReturnCommon(cUnit,mir);
1483 break;
1484 case OP_UNUSED_73:
1485 case OP_UNUSED_79:
1486 case OP_UNUSED_7A:
Dan Bornstein90f15432010-12-02 16:46:25 -08001487 case OP_DISPATCH_FF:
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001488 LOGE("Codegen: got unused opcode 0x%x\n",dalvikOpcode);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001489 return true;
1490 case OP_NOP:
1491 break;
1492 default:
1493 return true;
1494 }
1495 return false;
1496}
1497
1498static bool handleFmt11n_Fmt31i(CompilationUnit *cUnit, MIR *mir)
1499{
Bill Buzbee1465db52009-09-23 17:17:35 -07001500 RegLocation rlDest;
1501 RegLocation rlResult;
1502 if (mir->ssaRep->numDefs == 2) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001503 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001504 } else {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001505 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001506 }
Ben Chenge9695e52009-06-16 16:11:47 -07001507
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001508 switch (mir->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001509 case OP_CONST:
Ben Chenge9695e52009-06-16 16:11:47 -07001510 case OP_CONST_4: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001511 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kAnyReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -07001512 loadConstantNoClobber(cUnit, rlResult.lowReg, mir->dalvikInsn.vB);
Bill Buzbee1465db52009-09-23 17:17:35 -07001513 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001514 break;
Ben Chenge9695e52009-06-16 16:11:47 -07001515 }
1516 case OP_CONST_WIDE_32: {
Bill Buzbee1465db52009-09-23 17:17:35 -07001517 //TUNING: single routine to load constant pair for support doubles
Bill Buzbee964a7b02010-01-28 12:54:19 -08001518 //TUNING: load 0/-1 separately to avoid load dependency
Bill Buzbeec6f10662010-02-09 11:16:15 -08001519 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -07001520 loadConstantNoClobber(cUnit, rlResult.lowReg, mir->dalvikInsn.vB);
Bill Buzbee1465db52009-09-23 17:17:35 -07001521 opRegRegImm(cUnit, kOpAsr, rlResult.highReg,
1522 rlResult.lowReg, 31);
1523 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001524 break;
Ben Chenge9695e52009-06-16 16:11:47 -07001525 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001526 default:
1527 return true;
1528 }
1529 return false;
1530}
1531
1532static bool handleFmt21h(CompilationUnit *cUnit, MIR *mir)
1533{
Bill Buzbee1465db52009-09-23 17:17:35 -07001534 RegLocation rlDest;
1535 RegLocation rlResult;
1536 if (mir->ssaRep->numDefs == 2) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001537 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001538 } else {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001539 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001540 }
Bill Buzbeec6f10662010-02-09 11:16:15 -08001541 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kAnyReg, true);
Ben Chenge9695e52009-06-16 16:11:47 -07001542
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001543 switch (mir->dalvikInsn.opcode) {
Ben Chenge9695e52009-06-16 16:11:47 -07001544 case OP_CONST_HIGH16: {
Ben Chengbd1326d2010-04-02 15:04:53 -07001545 loadConstantNoClobber(cUnit, rlResult.lowReg,
1546 mir->dalvikInsn.vB << 16);
Bill Buzbee1465db52009-09-23 17:17:35 -07001547 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001548 break;
Ben Chenge9695e52009-06-16 16:11:47 -07001549 }
1550 case OP_CONST_WIDE_HIGH16: {
Bill Buzbee1465db52009-09-23 17:17:35 -07001551 loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg,
1552 0, mir->dalvikInsn.vB << 16);
1553 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001554 break;
Ben Chenge9695e52009-06-16 16:11:47 -07001555 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001556 default:
1557 return true;
1558 }
1559 return false;
1560}
1561
jeffhao71eee1f2011-01-04 14:18:54 -08001562static bool handleFmt20bc_Fmt40sc(CompilationUnit *cUnit, MIR *mir)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001563{
jeffhao71eee1f2011-01-04 14:18:54 -08001564 /* For OP_THROW_VERIFICATION_ERROR & OP_THROW_VERIFICATION_ERROR_JUMBO */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001565 genInterpSingleStep(cUnit, mir);
1566 return false;
1567}
1568
jeffhao71eee1f2011-01-04 14:18:54 -08001569static bool handleFmt21c_Fmt31c_Fmt41c(CompilationUnit *cUnit, MIR *mir)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001570{
Bill Buzbee1465db52009-09-23 17:17:35 -07001571 RegLocation rlResult;
1572 RegLocation rlDest;
1573 RegLocation rlSrc;
Ben Chenge9695e52009-06-16 16:11:47 -07001574
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001575 switch (mir->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001576 case OP_CONST_STRING_JUMBO:
1577 case OP_CONST_STRING: {
1578 void *strPtr = (void*)
1579 (cUnit->method->clazz->pDvmDex->pResStrings[mir->dalvikInsn.vB]);
Ben Chengdd6e8702010-05-07 13:05:47 -07001580
1581 if (strPtr == NULL) {
1582 LOGE("Unexpected null string");
1583 dvmAbort();
1584 }
1585
Bill Buzbeec6f10662010-02-09 11:16:15 -08001586 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
1587 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -07001588 loadConstantNoClobber(cUnit, rlResult.lowReg, (int) strPtr );
Bill Buzbee1465db52009-09-23 17:17:35 -07001589 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001590 break;
1591 }
jeffhao71eee1f2011-01-04 14:18:54 -08001592 case OP_CONST_CLASS:
1593 case OP_CONST_CLASS_JUMBO: {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001594 void *classPtr = (void*)
1595 (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vB]);
Ben Chengdd6e8702010-05-07 13:05:47 -07001596
1597 if (classPtr == NULL) {
1598 LOGE("Unexpected null class");
1599 dvmAbort();
1600 }
1601
Bill Buzbeec6f10662010-02-09 11:16:15 -08001602 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
1603 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -07001604 loadConstantNoClobber(cUnit, rlResult.lowReg, (int) classPtr );
Bill Buzbee1465db52009-09-23 17:17:35 -07001605 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001606 break;
1607 }
jeffhao71eee1f2011-01-04 14:18:54 -08001608 case OP_SGET:
buzbeeecf8f6e2010-07-20 14:53:42 -07001609 case OP_SGET_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07001610 case OP_SGET_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08001611 case OP_SGET_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001612 case OP_SGET_OBJECT:
jeffhao71eee1f2011-01-04 14:18:54 -08001613 case OP_SGET_OBJECT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07001614 case OP_SGET_OBJECT_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08001615 case OP_SGET_OBJECT_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001616 case OP_SGET_BOOLEAN:
jeffhao71eee1f2011-01-04 14:18:54 -08001617 case OP_SGET_BOOLEAN_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001618 case OP_SGET_CHAR:
jeffhao71eee1f2011-01-04 14:18:54 -08001619 case OP_SGET_CHAR_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001620 case OP_SGET_BYTE:
jeffhao71eee1f2011-01-04 14:18:54 -08001621 case OP_SGET_BYTE_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001622 case OP_SGET_SHORT:
jeffhao71eee1f2011-01-04 14:18:54 -08001623 case OP_SGET_SHORT_JUMBO: {
Bill Buzbee50a6bf22009-07-08 13:08:04 -07001624 int valOffset = offsetof(StaticField, value);
Bill Buzbeec6f10662010-02-09 11:16:15 -08001625 int tReg = dvmCompilerAllocTemp(cUnit);
buzbeeecf8f6e2010-07-20 14:53:42 -07001626 bool isVolatile;
Ben Cheng7a2697d2010-06-07 13:44:23 -07001627 const Method *method = (mir->OptimizationFlags & MIR_CALLEE) ?
1628 mir->meta.calleeMethod : cUnit->method;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001629 void *fieldPtr = (void*)
Ben Cheng7a2697d2010-06-07 13:44:23 -07001630 (method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vB]);
buzbeebd7865b2011-03-31 10:55:04 -07001631 Opcode opcode = mir->dalvikInsn.opcode;
Ben Chengdd6e8702010-05-07 13:05:47 -07001632
1633 if (fieldPtr == NULL) {
1634 LOGE("Unexpected null static field");
1635 dvmAbort();
1636 }
1637
buzbeebd7865b2011-03-31 10:55:04 -07001638 isVolatile = (opcode == OP_SGET_VOLATILE) ||
1639 (opcode == OP_SGET_VOLATILE_VOLATILE) ||
1640 (opcode == OP_SGET_OBJECT_VOLATILE) ||
1641 (opcode == OP_SGET_OBJECT_VOLATILE_JUMBO) ||
Carl Shapirofc75f3e2010-12-07 11:43:38 -08001642 dvmIsVolatileField((Field *) fieldPtr);
buzbeeecf8f6e2010-07-20 14:53:42 -07001643
Bill Buzbeec6f10662010-02-09 11:16:15 -08001644 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
1645 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kAnyReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07001646 loadConstant(cUnit, tReg, (int) fieldPtr + valOffset);
Ben Cheng11d8f142010-03-24 15:24:19 -07001647
buzbeeecf8f6e2010-07-20 14:53:42 -07001648 if (isVolatile) {
buzbee2ce33c92010-11-01 15:53:27 -07001649 dvmCompilerGenMemBarrier(cUnit, kSY);
buzbeeecf8f6e2010-07-20 14:53:42 -07001650 }
Ben Cheng11d8f142010-03-24 15:24:19 -07001651 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -07001652 loadWordDisp(cUnit, tReg, 0, rlResult.lowReg);
Ben Cheng11d8f142010-03-24 15:24:19 -07001653 HEAP_ACCESS_SHADOW(false);
1654
Bill Buzbee1465db52009-09-23 17:17:35 -07001655 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001656 break;
1657 }
jeffhao71eee1f2011-01-04 14:18:54 -08001658 case OP_SGET_WIDE:
1659 case OP_SGET_WIDE_JUMBO: {
Bill Buzbee50a6bf22009-07-08 13:08:04 -07001660 int valOffset = offsetof(StaticField, value);
Ben Cheng7a2697d2010-06-07 13:44:23 -07001661 const Method *method = (mir->OptimizationFlags & MIR_CALLEE) ?
1662 mir->meta.calleeMethod : cUnit->method;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001663 void *fieldPtr = (void*)
Ben Cheng7a2697d2010-06-07 13:44:23 -07001664 (method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vB]);
Ben Chengdd6e8702010-05-07 13:05:47 -07001665
1666 if (fieldPtr == NULL) {
1667 LOGE("Unexpected null static field");
1668 dvmAbort();
1669 }
1670
Bill Buzbeec6f10662010-02-09 11:16:15 -08001671 int tReg = dvmCompilerAllocTemp(cUnit);
Bill Buzbeec6f10662010-02-09 11:16:15 -08001672 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
1673 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kAnyReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07001674 loadConstant(cUnit, tReg, (int) fieldPtr + valOffset);
Ben Cheng11d8f142010-03-24 15:24:19 -07001675
1676 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -07001677 loadPair(cUnit, tReg, rlResult.lowReg, rlResult.highReg);
Ben Cheng11d8f142010-03-24 15:24:19 -07001678 HEAP_ACCESS_SHADOW(false);
1679
Bill Buzbee1465db52009-09-23 17:17:35 -07001680 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001681 break;
1682 }
jeffhao71eee1f2011-01-04 14:18:54 -08001683 case OP_SPUT:
1684 case OP_SPUT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07001685 case OP_SPUT_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08001686 case OP_SPUT_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001687 case OP_SPUT_OBJECT:
buzbeeddc7d292010-09-02 17:16:24 -07001688 case OP_SPUT_OBJECT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07001689 case OP_SPUT_OBJECT_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08001690 case OP_SPUT_OBJECT_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001691 case OP_SPUT_BOOLEAN:
jeffhao71eee1f2011-01-04 14:18:54 -08001692 case OP_SPUT_BOOLEAN_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001693 case OP_SPUT_CHAR:
jeffhao71eee1f2011-01-04 14:18:54 -08001694 case OP_SPUT_CHAR_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001695 case OP_SPUT_BYTE:
jeffhao71eee1f2011-01-04 14:18:54 -08001696 case OP_SPUT_BYTE_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001697 case OP_SPUT_SHORT:
jeffhao71eee1f2011-01-04 14:18:54 -08001698 case OP_SPUT_SHORT_JUMBO: {
Bill Buzbee50a6bf22009-07-08 13:08:04 -07001699 int valOffset = offsetof(StaticField, value);
Bill Buzbeec6f10662010-02-09 11:16:15 -08001700 int tReg = dvmCompilerAllocTemp(cUnit);
buzbeed3b0a4b2010-09-27 11:30:22 -07001701 int objHead;
buzbeeecf8f6e2010-07-20 14:53:42 -07001702 bool isVolatile;
buzbeed3b0a4b2010-09-27 11:30:22 -07001703 bool isSputObject;
Ben Cheng7a2697d2010-06-07 13:44:23 -07001704 const Method *method = (mir->OptimizationFlags & MIR_CALLEE) ?
1705 mir->meta.calleeMethod : cUnit->method;
1706 void *fieldPtr = (void*)
1707 (method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vB]);
buzbeebd7865b2011-03-31 10:55:04 -07001708 Opcode opcode = mir->dalvikInsn.opcode;
Ben Chenge9695e52009-06-16 16:11:47 -07001709
buzbeebd7865b2011-03-31 10:55:04 -07001710 isVolatile = (opcode == OP_SPUT_VOLATILE) ||
1711 (opcode == OP_SPUT_VOLATILE_JUMBO) ||
1712 (opcode == OP_SPUT_OBJECT_VOLATILE) ||
1713 (opcode == OP_SPUT_OBJECT_VOLATILE_JUMBO) ||
Carl Shapirofc75f3e2010-12-07 11:43:38 -08001714 dvmIsVolatileField((Field *) fieldPtr);
buzbeeecf8f6e2010-07-20 14:53:42 -07001715
buzbeebd7865b2011-03-31 10:55:04 -07001716 isSputObject = (opcode == OP_SPUT_OBJECT) ||
1717 (opcode == OP_SPUT_OBJECT_JUMBO) ||
1718 (opcode == OP_SPUT_OBJECT_VOLATILE) ||
1719 (opcode == OP_SPUT_OBJECT_VOLATILE_JUMBO);
buzbeed3b0a4b2010-09-27 11:30:22 -07001720
Ben Chengdd6e8702010-05-07 13:05:47 -07001721 if (fieldPtr == NULL) {
1722 LOGE("Unexpected null static field");
1723 dvmAbort();
1724 }
1725
Bill Buzbeec6f10662010-02-09 11:16:15 -08001726 rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001727 rlSrc = loadValue(cUnit, rlSrc, kAnyReg);
buzbeeb78c76f2010-09-30 19:08:20 -07001728 loadConstant(cUnit, tReg, (int) fieldPtr);
buzbeed3b0a4b2010-09-27 11:30:22 -07001729 if (isSputObject) {
1730 objHead = dvmCompilerAllocTemp(cUnit);
buzbeeb78c76f2010-09-30 19:08:20 -07001731 loadWordDisp(cUnit, tReg, offsetof(Field, clazz), objHead);
buzbeed3b0a4b2010-09-27 11:30:22 -07001732 }
Ben Cheng11d8f142010-03-24 15:24:19 -07001733 HEAP_ACCESS_SHADOW(true);
buzbeeb78c76f2010-09-30 19:08:20 -07001734 storeWordDisp(cUnit, tReg, valOffset ,rlSrc.lowReg);
buzbeed3b0a4b2010-09-27 11:30:22 -07001735 dvmCompilerFreeTemp(cUnit, tReg);
Ben Cheng11d8f142010-03-24 15:24:19 -07001736 HEAP_ACCESS_SHADOW(false);
buzbeeecf8f6e2010-07-20 14:53:42 -07001737 if (isVolatile) {
buzbee2ce33c92010-11-01 15:53:27 -07001738 dvmCompilerGenMemBarrier(cUnit, kSY);
buzbeeecf8f6e2010-07-20 14:53:42 -07001739 }
buzbeed3b0a4b2010-09-27 11:30:22 -07001740 if (isSputObject) {
buzbeeb78c76f2010-09-30 19:08:20 -07001741 /* NOTE: marking card based sfield->clazz */
buzbeed3b0a4b2010-09-27 11:30:22 -07001742 markCard(cUnit, rlSrc.lowReg, objHead);
1743 dvmCompilerFreeTemp(cUnit, objHead);
buzbee919eb062010-07-12 12:59:22 -07001744 }
Ben Cheng11d8f142010-03-24 15:24:19 -07001745
Ben Chengba4fc8b2009-06-01 13:00:29 -07001746 break;
1747 }
jeffhao71eee1f2011-01-04 14:18:54 -08001748 case OP_SPUT_WIDE:
1749 case OP_SPUT_WIDE_JUMBO: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001750 int tReg = dvmCompilerAllocTemp(cUnit);
Bill Buzbee50a6bf22009-07-08 13:08:04 -07001751 int valOffset = offsetof(StaticField, value);
Ben Cheng7a2697d2010-06-07 13:44:23 -07001752 const Method *method = (mir->OptimizationFlags & MIR_CALLEE) ?
1753 mir->meta.calleeMethod : cUnit->method;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001754 void *fieldPtr = (void*)
Ben Cheng7a2697d2010-06-07 13:44:23 -07001755 (method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vB]);
Ben Chenge9695e52009-06-16 16:11:47 -07001756
Ben Chengdd6e8702010-05-07 13:05:47 -07001757 if (fieldPtr == NULL) {
1758 LOGE("Unexpected null static field");
1759 dvmAbort();
1760 }
1761
Bill Buzbeec6f10662010-02-09 11:16:15 -08001762 rlSrc = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001763 rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg);
1764 loadConstant(cUnit, tReg, (int) fieldPtr + valOffset);
Ben Cheng11d8f142010-03-24 15:24:19 -07001765
1766 HEAP_ACCESS_SHADOW(true);
Bill Buzbee1465db52009-09-23 17:17:35 -07001767 storePair(cUnit, tReg, rlSrc.lowReg, rlSrc.highReg);
Ben Cheng11d8f142010-03-24 15:24:19 -07001768 HEAP_ACCESS_SHADOW(false);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001769 break;
1770 }
jeffhao71eee1f2011-01-04 14:18:54 -08001771 case OP_NEW_INSTANCE:
1772 case OP_NEW_INSTANCE_JUMBO: {
Ben Chenge9695e52009-06-16 16:11:47 -07001773 /*
1774 * Obey the calling convention and don't mess with the register
1775 * usage.
1776 */
Carl Shapirofc75f3e2010-12-07 11:43:38 -08001777 ClassObject *classPtr = (ClassObject *)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001778 (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vB]);
Ben Chengdd6e8702010-05-07 13:05:47 -07001779
1780 if (classPtr == NULL) {
1781 LOGE("Unexpected null class");
1782 dvmAbort();
1783 }
1784
Ben Cheng79d173c2009-09-29 16:12:51 -07001785 /*
1786 * If it is going to throw, it should not make to the trace to begin
Bill Buzbee1465db52009-09-23 17:17:35 -07001787 * with. However, Alloc might throw, so we need to genExportPC()
Ben Cheng79d173c2009-09-29 16:12:51 -07001788 */
1789 assert((classPtr->accessFlags & (ACC_INTERFACE|ACC_ABSTRACT)) == 0);
Bill Buzbeec6f10662010-02-09 11:16:15 -08001790 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -07001791 genExportPC(cUnit, mir);
Ben Chengbd1326d2010-04-02 15:04:53 -07001792 LOAD_FUNC_ADDR(cUnit, r2, (int)dvmAllocObject);
Ben Chenge9695e52009-06-16 16:11:47 -07001793 loadConstant(cUnit, r0, (int) classPtr);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001794 loadConstant(cUnit, r1, ALLOC_DONT_TRACK);
Bill Buzbee1465db52009-09-23 17:17:35 -07001795 opReg(cUnit, kOpBlx, r2);
Elliott Hughes6a555132010-02-25 15:41:42 -08001796 dvmCompilerClobberCallRegs(cUnit);
Ben Cheng4f489172009-09-27 17:08:35 -07001797 /* generate a branch over if allocation is successful */
buzbee8f8109a2010-08-31 10:16:35 -07001798 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondNe, r0, 0);
Ben Cheng4f489172009-09-27 17:08:35 -07001799 /*
1800 * OOM exception needs to be thrown here and cannot re-execute
1801 */
1802 loadConstant(cUnit, r0,
1803 (int) (cUnit->method->insns + mir->offset));
1804 genDispatchToHandler(cUnit, TEMPLATE_THROW_EXCEPTION_COMMON);
1805 /* noreturn */
1806
Bill Buzbee1465db52009-09-23 17:17:35 -07001807 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
Ben Cheng4f489172009-09-27 17:08:35 -07001808 target->defMask = ENCODE_ALL;
1809 branchOver->generic.target = (LIR *) target;
Bill Buzbeec6f10662010-02-09 11:16:15 -08001810 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
1811 rlResult = dvmCompilerGetReturn(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07001812 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001813 break;
1814 }
jeffhao71eee1f2011-01-04 14:18:54 -08001815 case OP_CHECK_CAST:
1816 case OP_CHECK_CAST_JUMBO: {
Ben Chenge9695e52009-06-16 16:11:47 -07001817 /*
1818 * Obey the calling convention and don't mess with the register
1819 * usage.
1820 */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001821 ClassObject *classPtr =
1822 (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vB]);
Bill Buzbee4df41a52009-11-12 17:07:16 -08001823 /*
1824 * Note: It is possible that classPtr is NULL at this point,
1825 * even though this instruction has been successfully interpreted.
1826 * If the previous interpretation had a null source, the
1827 * interpreter would not have bothered to resolve the clazz.
1828 * Bail out to the interpreter in this case, and log it
1829 * so that we can tell if it happens frequently.
1830 */
1831 if (classPtr == NULL) {
Ben Cheng11d8f142010-03-24 15:24:19 -07001832 LOGVV("null clazz in OP_CHECK_CAST, single-stepping");
Bill Buzbee4df41a52009-11-12 17:07:16 -08001833 genInterpSingleStep(cUnit, mir);
1834 return false;
1835 }
Bill Buzbeec6f10662010-02-09 11:16:15 -08001836 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001837 loadConstant(cUnit, r1, (int) classPtr );
Bill Buzbeec6f10662010-02-09 11:16:15 -08001838 rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001839 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
buzbee8f8109a2010-08-31 10:16:35 -07001840 /* Null? */
1841 ArmLIR *branch1 = genCmpImmBranch(cUnit, kArmCondEq,
1842 rlSrc.lowReg, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001843 /*
1844 * rlSrc.lowReg now contains object->clazz. Note that
1845 * it could have been allocated r0, but we're okay so long
1846 * as we don't do anything desctructive until r0 is loaded
1847 * with clazz.
1848 */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001849 /* r0 now contains object->clazz */
Bill Buzbee1465db52009-09-23 17:17:35 -07001850 loadWordDisp(cUnit, rlSrc.lowReg, offsetof(Object, clazz), r0);
Ben Chengbd1326d2010-04-02 15:04:53 -07001851 LOAD_FUNC_ADDR(cUnit, r2, (int)dvmInstanceofNonTrivial);
Bill Buzbee1465db52009-09-23 17:17:35 -07001852 opRegReg(cUnit, kOpCmp, r0, r1);
1853 ArmLIR *branch2 = opCondBranch(cUnit, kArmCondEq);
1854 opReg(cUnit, kOpBlx, r2);
Elliott Hughes6a555132010-02-25 15:41:42 -08001855 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07001856 /*
1857 * If null, check cast failed - punt to the interpreter. Because
1858 * interpreter will be the one throwing, we don't need to
1859 * genExportPC() here.
1860 */
Bill Buzbee270c1d62009-08-13 16:58:07 -07001861 genZeroCheck(cUnit, r0, mir->offset, NULL);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001862 /* check cast passed - branch target here */
Bill Buzbee1465db52009-09-23 17:17:35 -07001863 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
Ben Chengd7d426a2009-09-22 11:23:36 -07001864 target->defMask = ENCODE_ALL;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001865 branch1->generic.target = (LIR *)target;
1866 branch2->generic.target = (LIR *)target;
1867 break;
1868 }
buzbee4d92e682010-07-29 15:24:14 -07001869 case OP_SGET_WIDE_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07001870 case OP_SGET_WIDE_VOLATILE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07001871 case OP_SPUT_WIDE_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07001872 case OP_SPUT_WIDE_VOLATILE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07001873 genInterpSingleStep(cUnit, mir);
1874 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001875 default:
1876 return true;
1877 }
1878 return false;
1879}
1880
Ben Cheng7a2697d2010-06-07 13:44:23 -07001881/*
1882 * A typical example of inlined getter/setter from a monomorphic callsite:
1883 *
1884 * D/dalvikvm( 289): -------- dalvik offset: 0x0000 @ invoke-static (I)
1885 * D/dalvikvm( 289): -------- dalvik offset: 0x0000 @ sget-object (C) v0, ...
1886 * D/dalvikvm( 289): 0x4427fc22 (0002): ldr r0, [pc, #56]
1887 * D/dalvikvm( 289): 0x4427fc24 (0004): ldr r1, [r0, #0]
1888 * D/dalvikvm( 289): 0x4427fc26 (0006): str r1, [r5, #0]
1889 * D/dalvikvm( 289): 0x4427fc28 (0008): .align4
1890 * D/dalvikvm( 289): L0x0003:
1891 * D/dalvikvm( 289): -------- dalvik offset: 0x0003 @ move-result-object (I) v0
1892 *
1893 * Note the invoke-static and move-result-object with the (I) notation are
1894 * turned into no-op.
1895 */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001896static bool handleFmt11x(CompilationUnit *cUnit, MIR *mir)
1897{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001898 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
Bill Buzbee1465db52009-09-23 17:17:35 -07001899 RegLocation rlResult;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001900 switch (dalvikOpcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001901 case OP_MOVE_EXCEPTION: {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001902 int exOffset = offsetof(Thread, exception);
Bill Buzbeec6f10662010-02-09 11:16:15 -08001903 int resetReg = dvmCompilerAllocTemp(cUnit);
1904 RegLocation rlDest = dvmCompilerGetDest(cUnit, mir, 0);
1905 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001906 loadWordDisp(cUnit, r6SELF, exOffset, rlResult.lowReg);
Bill Buzbeef9f33282009-11-22 12:45:30 -08001907 loadConstant(cUnit, resetReg, 0);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001908 storeWordDisp(cUnit, r6SELF, exOffset, resetReg);
Bill Buzbee1465db52009-09-23 17:17:35 -07001909 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001910 break;
1911 }
1912 case OP_MOVE_RESULT:
1913 case OP_MOVE_RESULT_OBJECT: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07001914 /* An inlined move result is effectively no-op */
1915 if (mir->OptimizationFlags & MIR_INLINED)
1916 break;
Bill Buzbeec6f10662010-02-09 11:16:15 -08001917 RegLocation rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001918 RegLocation rlSrc = LOC_DALVIK_RETURN_VAL;
1919 rlSrc.fp = rlDest.fp;
1920 storeValue(cUnit, rlDest, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001921 break;
1922 }
1923 case OP_MOVE_RESULT_WIDE: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07001924 /* An inlined move result is effectively no-op */
1925 if (mir->OptimizationFlags & MIR_INLINED)
1926 break;
Bill Buzbeec6f10662010-02-09 11:16:15 -08001927 RegLocation rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001928 RegLocation rlSrc = LOC_DALVIK_RETURN_VAL_WIDE;
1929 rlSrc.fp = rlDest.fp;
1930 storeValueWide(cUnit, rlDest, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001931 break;
1932 }
1933 case OP_RETURN_WIDE: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001934 RegLocation rlSrc = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001935 RegLocation rlDest = LOC_DALVIK_RETURN_VAL_WIDE;
1936 rlDest.fp = rlSrc.fp;
1937 storeValueWide(cUnit, rlDest, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001938 genReturnCommon(cUnit,mir);
1939 break;
1940 }
1941 case OP_RETURN:
1942 case OP_RETURN_OBJECT: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08001943 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001944 RegLocation rlDest = LOC_DALVIK_RETURN_VAL;
1945 rlDest.fp = rlSrc.fp;
1946 storeValue(cUnit, rlDest, rlSrc);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001947 genReturnCommon(cUnit, mir);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001948 break;
1949 }
Bill Buzbee1465db52009-09-23 17:17:35 -07001950 case OP_MONITOR_EXIT:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001951 case OP_MONITOR_ENTER:
Ben Cheng5d90c202009-11-22 23:31:11 -08001952 genMonitor(cUnit, mir);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001953 break;
Ben Cheng20d7e6c2011-02-18 17:12:42 -08001954 case OP_THROW:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001955 genInterpSingleStep(cUnit, mir);
1956 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001957 default:
1958 return true;
1959 }
1960 return false;
1961}
1962
Bill Buzbeed45ba372009-06-15 17:00:57 -07001963static bool handleFmt12x(CompilationUnit *cUnit, MIR *mir)
1964{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001965 Opcode opcode = mir->dalvikInsn.opcode;
Bill Buzbee1465db52009-09-23 17:17:35 -07001966 RegLocation rlDest;
1967 RegLocation rlSrc;
1968 RegLocation rlResult;
Bill Buzbeed45ba372009-06-15 17:00:57 -07001969
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001970 if ( (opcode >= OP_ADD_INT_2ADDR) && (opcode <= OP_REM_DOUBLE_2ADDR)) {
Ben Cheng5d90c202009-11-22 23:31:11 -08001971 return genArithOp( cUnit, mir );
Ben Chengba4fc8b2009-06-01 13:00:29 -07001972 }
1973
Bill Buzbee1465db52009-09-23 17:17:35 -07001974 if (mir->ssaRep->numUses == 2)
Bill Buzbeec6f10662010-02-09 11:16:15 -08001975 rlSrc = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001976 else
Bill Buzbeec6f10662010-02-09 11:16:15 -08001977 rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07001978 if (mir->ssaRep->numDefs == 2)
Bill Buzbeec6f10662010-02-09 11:16:15 -08001979 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07001980 else
Bill Buzbeec6f10662010-02-09 11:16:15 -08001981 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Ben Chenge9695e52009-06-16 16:11:47 -07001982
Dan Bornstein9a1f8162010-12-01 17:02:26 -08001983 switch (opcode) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001984 case OP_DOUBLE_TO_INT:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001985 case OP_INT_TO_FLOAT:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001986 case OP_FLOAT_TO_INT:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001987 case OP_DOUBLE_TO_FLOAT:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001988 case OP_FLOAT_TO_DOUBLE:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001989 case OP_INT_TO_DOUBLE:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001990 case OP_FLOAT_TO_LONG:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001991 case OP_LONG_TO_FLOAT:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001992 case OP_DOUBLE_TO_LONG:
Ben Chengba4fc8b2009-06-01 13:00:29 -07001993 case OP_LONG_TO_DOUBLE:
Ben Cheng5d90c202009-11-22 23:31:11 -08001994 return genConversion(cUnit, mir);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001995 case OP_NEG_INT:
1996 case OP_NOT_INT:
Ben Cheng5d90c202009-11-22 23:31:11 -08001997 return genArithOpInt(cUnit, mir, rlDest, rlSrc, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001998 case OP_NEG_LONG:
1999 case OP_NOT_LONG:
Ben Cheng5d90c202009-11-22 23:31:11 -08002000 return genArithOpLong(cUnit, mir, rlDest, rlSrc, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002001 case OP_NEG_FLOAT:
Ben Cheng5d90c202009-11-22 23:31:11 -08002002 return genArithOpFloat(cUnit, mir, rlDest, rlSrc, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002003 case OP_NEG_DOUBLE:
Ben Cheng5d90c202009-11-22 23:31:11 -08002004 return genArithOpDouble(cUnit, mir, rlDest, rlSrc, rlSrc);
Bill Buzbee1465db52009-09-23 17:17:35 -07002005 case OP_MOVE_WIDE:
2006 storeValueWide(cUnit, rlDest, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002007 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07002008 case OP_INT_TO_LONG:
Bill Buzbeec6f10662010-02-09 11:16:15 -08002009 rlSrc = dvmCompilerUpdateLoc(cUnit, rlSrc);
2010 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee964a7b02010-01-28 12:54:19 -08002011 //TUNING: shouldn't loadValueDirect already check for phys reg?
Bill Buzbee1465db52009-09-23 17:17:35 -07002012 if (rlSrc.location == kLocPhysReg) {
2013 genRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg);
2014 } else {
2015 loadValueDirect(cUnit, rlSrc, rlResult.lowReg);
2016 }
2017 opRegRegImm(cUnit, kOpAsr, rlResult.highReg,
2018 rlResult.lowReg, 31);
2019 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002020 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07002021 case OP_LONG_TO_INT:
Bill Buzbeec6f10662010-02-09 11:16:15 -08002022 rlSrc = dvmCompilerUpdateLocWide(cUnit, rlSrc);
2023 rlSrc = dvmCompilerWideToNarrow(cUnit, rlSrc);
Bill Buzbee1465db52009-09-23 17:17:35 -07002024 // Intentional fallthrough
Ben Chengba4fc8b2009-06-01 13:00:29 -07002025 case OP_MOVE:
2026 case OP_MOVE_OBJECT:
Bill Buzbee1465db52009-09-23 17:17:35 -07002027 storeValue(cUnit, rlDest, rlSrc);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002028 break;
2029 case OP_INT_TO_BYTE:
Bill Buzbee1465db52009-09-23 17:17:35 -07002030 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002031 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07002032 opRegReg(cUnit, kOp2Byte, rlResult.lowReg, rlSrc.lowReg);
2033 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002034 break;
2035 case OP_INT_TO_SHORT:
Bill Buzbee1465db52009-09-23 17:17:35 -07002036 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002037 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07002038 opRegReg(cUnit, kOp2Short, rlResult.lowReg, rlSrc.lowReg);
2039 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002040 break;
2041 case OP_INT_TO_CHAR:
Bill Buzbee1465db52009-09-23 17:17:35 -07002042 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002043 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07002044 opRegReg(cUnit, kOp2Char, rlResult.lowReg, rlSrc.lowReg);
2045 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002046 break;
2047 case OP_ARRAY_LENGTH: {
2048 int lenOffset = offsetof(ArrayObject, length);
Bill Buzbee1465db52009-09-23 17:17:35 -07002049 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
2050 genNullCheck(cUnit, rlSrc.sRegLow, rlSrc.lowReg,
2051 mir->offset, NULL);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002052 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07002053 loadWordDisp(cUnit, rlSrc.lowReg, lenOffset,
2054 rlResult.lowReg);
2055 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002056 break;
2057 }
2058 default:
2059 return true;
2060 }
2061 return false;
2062}
2063
2064static bool handleFmt21s(CompilationUnit *cUnit, MIR *mir)
2065{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002066 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
Bill Buzbee1465db52009-09-23 17:17:35 -07002067 RegLocation rlDest;
2068 RegLocation rlResult;
2069 int BBBB = mir->dalvikInsn.vB;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002070 if (dalvikOpcode == OP_CONST_WIDE_16) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002071 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
2072 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -07002073 loadConstantNoClobber(cUnit, rlResult.lowReg, BBBB);
Bill Buzbee964a7b02010-01-28 12:54:19 -08002074 //TUNING: do high separately to avoid load dependency
Bill Buzbee1465db52009-09-23 17:17:35 -07002075 opRegRegImm(cUnit, kOpAsr, rlResult.highReg, rlResult.lowReg, 31);
2076 storeValueWide(cUnit, rlDest, rlResult);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002077 } else if (dalvikOpcode == OP_CONST_16) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002078 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
2079 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kAnyReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -07002080 loadConstantNoClobber(cUnit, rlResult.lowReg, BBBB);
Bill Buzbee1465db52009-09-23 17:17:35 -07002081 storeValue(cUnit, rlDest, rlResult);
2082 } else
Ben Chengba4fc8b2009-06-01 13:00:29 -07002083 return true;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002084 return false;
2085}
2086
2087/* Compare agaist zero */
2088static bool handleFmt21t(CompilationUnit *cUnit, MIR *mir, BasicBlock *bb,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07002089 ArmLIR *labelList)
Ben Chengba4fc8b2009-06-01 13:00:29 -07002090{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002091 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07002092 ArmConditionCode cond;
Ben Cheng7ab74e12011-02-03 14:02:06 -08002093 /* backward branch? */
2094 bool backwardBranch = (bb->taken->startOffset <= mir->offset);
2095
2096 if (backwardBranch && gDvmJit.genSuspendPoll) {
2097 genSuspendPoll(cUnit, mir);
2098 }
2099
Bill Buzbeec6f10662010-02-09 11:16:15 -08002100 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07002101 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Ben Cheng7ab74e12011-02-03 14:02:06 -08002102
Bill Buzbee1465db52009-09-23 17:17:35 -07002103 opRegImm(cUnit, kOpCmp, rlSrc.lowReg, 0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002104
Bill Buzbee270c1d62009-08-13 16:58:07 -07002105//TUNING: break this out to allow use of Thumb2 CB[N]Z
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002106 switch (dalvikOpcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07002107 case OP_IF_EQZ:
Bill Buzbee1465db52009-09-23 17:17:35 -07002108 cond = kArmCondEq;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002109 break;
2110 case OP_IF_NEZ:
Bill Buzbee1465db52009-09-23 17:17:35 -07002111 cond = kArmCondNe;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002112 break;
2113 case OP_IF_LTZ:
Bill Buzbee1465db52009-09-23 17:17:35 -07002114 cond = kArmCondLt;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002115 break;
2116 case OP_IF_GEZ:
Bill Buzbee1465db52009-09-23 17:17:35 -07002117 cond = kArmCondGe;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002118 break;
2119 case OP_IF_GTZ:
Bill Buzbee1465db52009-09-23 17:17:35 -07002120 cond = kArmCondGt;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002121 break;
2122 case OP_IF_LEZ:
Bill Buzbee1465db52009-09-23 17:17:35 -07002123 cond = kArmCondLe;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002124 break;
2125 default:
2126 cond = 0;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002127 LOGE("Unexpected opcode (%d) for Fmt21t\n", dalvikOpcode);
Bill Buzbeefc519dc2010-03-06 23:30:57 -08002128 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002129 }
2130 genConditionalBranch(cUnit, cond, &labelList[bb->taken->id]);
2131 /* This mostly likely will be optimized away in a later phase */
2132 genUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]);
2133 return false;
2134}
2135
Elliott Hughesb4c05972010-02-24 16:36:18 -08002136static bool isPowerOfTwo(int x)
2137{
2138 return (x & (x - 1)) == 0;
2139}
2140
2141// Returns true if no more than two bits are set in 'x'.
2142static bool isPopCountLE2(unsigned int x)
2143{
2144 x &= x - 1;
2145 return (x & (x - 1)) == 0;
2146}
2147
2148// Returns the index of the lowest set bit in 'x'.
2149static int lowestSetBit(unsigned int x) {
2150 int bit_posn = 0;
2151 while ((x & 0xf) == 0) {
2152 bit_posn += 4;
2153 x >>= 4;
Bill Buzbee78cb0e22010-02-11 14:04:53 -08002154 }
Elliott Hughesb4c05972010-02-24 16:36:18 -08002155 while ((x & 1) == 0) {
2156 bit_posn++;
2157 x >>= 1;
2158 }
2159 return bit_posn;
2160}
2161
Elliott Hughes672511b2010-04-26 17:40:13 -07002162// Returns true if it added instructions to 'cUnit' to divide 'rlSrc' by 'lit'
2163// and store the result in 'rlDest'.
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002164static bool handleEasyDivide(CompilationUnit *cUnit, Opcode dalvikOpcode,
Elliott Hughes672511b2010-04-26 17:40:13 -07002165 RegLocation rlSrc, RegLocation rlDest, int lit)
2166{
2167 if (lit < 2 || !isPowerOfTwo(lit)) {
2168 return false;
2169 }
2170 int k = lowestSetBit(lit);
2171 if (k >= 30) {
2172 // Avoid special cases.
2173 return false;
2174 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002175 bool div = (dalvikOpcode == OP_DIV_INT_LIT8 || dalvikOpcode == OP_DIV_INT_LIT16);
Elliott Hughes672511b2010-04-26 17:40:13 -07002176 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
2177 RegLocation rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Elliott Hughes9c457022010-04-28 16:15:38 -07002178 if (div) {
2179 int tReg = dvmCompilerAllocTemp(cUnit);
2180 if (lit == 2) {
2181 // Division by 2 is by far the most common division by constant.
2182 opRegRegImm(cUnit, kOpLsr, tReg, rlSrc.lowReg, 32 - k);
2183 opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg);
2184 opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k);
2185 } else {
2186 opRegRegImm(cUnit, kOpAsr, tReg, rlSrc.lowReg, 31);
2187 opRegRegImm(cUnit, kOpLsr, tReg, tReg, 32 - k);
2188 opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg);
2189 opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k);
2190 }
Elliott Hughes672511b2010-04-26 17:40:13 -07002191 } else {
Elliott Hughes9c457022010-04-28 16:15:38 -07002192 int cReg = dvmCompilerAllocTemp(cUnit);
2193 loadConstant(cUnit, cReg, lit - 1);
2194 int tReg1 = dvmCompilerAllocTemp(cUnit);
2195 int tReg2 = dvmCompilerAllocTemp(cUnit);
2196 if (lit == 2) {
2197 opRegRegImm(cUnit, kOpLsr, tReg1, rlSrc.lowReg, 32 - k);
2198 opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg);
2199 opRegRegReg(cUnit, kOpAnd, tReg2, tReg2, cReg);
2200 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1);
2201 } else {
2202 opRegRegImm(cUnit, kOpAsr, tReg1, rlSrc.lowReg, 31);
2203 opRegRegImm(cUnit, kOpLsr, tReg1, tReg1, 32 - k);
2204 opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg);
2205 opRegRegReg(cUnit, kOpAnd, tReg2, tReg2, cReg);
2206 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1);
2207 }
Elliott Hughes672511b2010-04-26 17:40:13 -07002208 }
2209 storeValue(cUnit, rlDest, rlResult);
2210 return true;
2211}
2212
Elliott Hughesb4c05972010-02-24 16:36:18 -08002213// Returns true if it added instructions to 'cUnit' to multiply 'rlSrc' by 'lit'
2214// and store the result in 'rlDest'.
2215static bool handleEasyMultiply(CompilationUnit *cUnit,
2216 RegLocation rlSrc, RegLocation rlDest, int lit)
2217{
2218 // Can we simplify this multiplication?
2219 bool powerOfTwo = false;
2220 bool popCountLE2 = false;
2221 bool powerOfTwoMinusOne = false;
2222 if (lit < 2) {
2223 // Avoid special cases.
2224 return false;
2225 } else if (isPowerOfTwo(lit)) {
2226 powerOfTwo = true;
2227 } else if (isPopCountLE2(lit)) {
2228 popCountLE2 = true;
2229 } else if (isPowerOfTwo(lit + 1)) {
2230 powerOfTwoMinusOne = true;
2231 } else {
2232 return false;
2233 }
2234 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
2235 RegLocation rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
2236 if (powerOfTwo) {
2237 // Shift.
2238 opRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlSrc.lowReg,
2239 lowestSetBit(lit));
2240 } else if (popCountLE2) {
2241 // Shift and add and shift.
2242 int firstBit = lowestSetBit(lit);
2243 int secondBit = lowestSetBit(lit ^ (1 << firstBit));
2244 genMultiplyByTwoBitMultiplier(cUnit, rlSrc, rlResult, lit,
2245 firstBit, secondBit);
2246 } else {
2247 // Reverse subtract: (src << (shift + 1)) - src.
2248 assert(powerOfTwoMinusOne);
2249 // TODO: rsb dst, src, src lsl#lowestSetBit(lit + 1)
2250 int tReg = dvmCompilerAllocTemp(cUnit);
2251 opRegRegImm(cUnit, kOpLsl, tReg, rlSrc.lowReg, lowestSetBit(lit + 1));
2252 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg, rlSrc.lowReg);
2253 }
2254 storeValue(cUnit, rlDest, rlResult);
2255 return true;
Bill Buzbee78cb0e22010-02-11 14:04:53 -08002256}
2257
Ben Chengba4fc8b2009-06-01 13:00:29 -07002258static bool handleFmt22b_Fmt22s(CompilationUnit *cUnit, MIR *mir)
2259{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002260 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
Bill Buzbeec6f10662010-02-09 11:16:15 -08002261 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
2262 RegLocation rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07002263 RegLocation rlResult;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002264 int lit = mir->dalvikInsn.vC;
Ben Cheng4f489172009-09-27 17:08:35 -07002265 OpKind op = 0; /* Make gcc happy */
Bill Buzbee1465db52009-09-23 17:17:35 -07002266 int shiftOp = false;
2267 bool isDiv = false;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002268
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002269 switch (dalvikOpcode) {
Bill Buzbee1465db52009-09-23 17:17:35 -07002270 case OP_RSUB_INT_LIT8:
2271 case OP_RSUB_INT: {
2272 int tReg;
2273 //TUNING: add support for use of Arm rsub op
2274 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002275 tReg = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07002276 loadConstant(cUnit, tReg, lit);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002277 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07002278 opRegRegReg(cUnit, kOpSub, rlResult.lowReg,
2279 tReg, rlSrc.lowReg);
2280 storeValue(cUnit, rlDest, rlResult);
2281 return false;
2282 break;
2283 }
2284
Ben Chengba4fc8b2009-06-01 13:00:29 -07002285 case OP_ADD_INT_LIT8:
2286 case OP_ADD_INT_LIT16:
Bill Buzbee1465db52009-09-23 17:17:35 -07002287 op = kOpAdd;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002288 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002289 case OP_MUL_INT_LIT8:
Bill Buzbee78cb0e22010-02-11 14:04:53 -08002290 case OP_MUL_INT_LIT16: {
Elliott Hughesb4c05972010-02-24 16:36:18 -08002291 if (handleEasyMultiply(cUnit, rlSrc, rlDest, lit)) {
2292 return false;
Bill Buzbee78cb0e22010-02-11 14:04:53 -08002293 }
Elliott Hughesb4c05972010-02-24 16:36:18 -08002294 op = kOpMul;
Bill Buzbee1465db52009-09-23 17:17:35 -07002295 break;
Bill Buzbee78cb0e22010-02-11 14:04:53 -08002296 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07002297 case OP_AND_INT_LIT8:
2298 case OP_AND_INT_LIT16:
Bill Buzbee1465db52009-09-23 17:17:35 -07002299 op = kOpAnd;
2300 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002301 case OP_OR_INT_LIT8:
2302 case OP_OR_INT_LIT16:
Bill Buzbee1465db52009-09-23 17:17:35 -07002303 op = kOpOr;
2304 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002305 case OP_XOR_INT_LIT8:
2306 case OP_XOR_INT_LIT16:
Bill Buzbee1465db52009-09-23 17:17:35 -07002307 op = kOpXor;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002308 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002309 case OP_SHL_INT_LIT8:
Bill Buzbee0e605272009-12-01 14:28:05 -08002310 lit &= 31;
Bill Buzbee1465db52009-09-23 17:17:35 -07002311 shiftOp = true;
2312 op = kOpLsl;
2313 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002314 case OP_SHR_INT_LIT8:
Bill Buzbee0e605272009-12-01 14:28:05 -08002315 lit &= 31;
Bill Buzbee1465db52009-09-23 17:17:35 -07002316 shiftOp = true;
2317 op = kOpAsr;
2318 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002319 case OP_USHR_INT_LIT8:
Bill Buzbee0e605272009-12-01 14:28:05 -08002320 lit &= 31;
Bill Buzbee1465db52009-09-23 17:17:35 -07002321 shiftOp = true;
2322 op = kOpLsr;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002323 break;
2324
2325 case OP_DIV_INT_LIT8:
2326 case OP_DIV_INT_LIT16:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002327 case OP_REM_INT_LIT8:
2328 case OP_REM_INT_LIT16:
2329 if (lit == 0) {
2330 /* Let the interpreter deal with div by 0 */
2331 genInterpSingleStep(cUnit, mir);
2332 return false;
2333 }
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002334 if (handleEasyDivide(cUnit, dalvikOpcode, rlSrc, rlDest, lit)) {
Elliott Hughes672511b2010-04-26 17:40:13 -07002335 return false;
2336 }
Bill Buzbeec6f10662010-02-09 11:16:15 -08002337 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -07002338 loadValueDirectFixed(cUnit, rlSrc, r0);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002339 dvmCompilerClobber(cUnit, r0);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002340 if ((dalvikOpcode == OP_DIV_INT_LIT8) ||
2341 (dalvikOpcode == OP_DIV_INT_LIT16)) {
Ben Chengbd1326d2010-04-02 15:04:53 -07002342 LOAD_FUNC_ADDR(cUnit, r2, (int)__aeabi_idiv);
Bill Buzbee1465db52009-09-23 17:17:35 -07002343 isDiv = true;
2344 } else {
Ben Chengbd1326d2010-04-02 15:04:53 -07002345 LOAD_FUNC_ADDR(cUnit, r2, (int)__aeabi_idivmod);
Bill Buzbee1465db52009-09-23 17:17:35 -07002346 isDiv = false;
2347 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07002348 loadConstant(cUnit, r1, lit);
Bill Buzbee1465db52009-09-23 17:17:35 -07002349 opReg(cUnit, kOpBlx, r2);
Elliott Hughes6a555132010-02-25 15:41:42 -08002350 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07002351 if (isDiv)
Bill Buzbeec6f10662010-02-09 11:16:15 -08002352 rlResult = dvmCompilerGetReturn(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07002353 else
Bill Buzbeec6f10662010-02-09 11:16:15 -08002354 rlResult = dvmCompilerGetReturnAlt(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07002355 storeValue(cUnit, rlDest, rlResult);
2356 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002357 break;
2358 default:
2359 return true;
2360 }
Bill Buzbee1465db52009-09-23 17:17:35 -07002361 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002362 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Bill Buzbee1465db52009-09-23 17:17:35 -07002363 // Avoid shifts by literal 0 - no support in Thumb. Change to copy
2364 if (shiftOp && (lit == 0)) {
2365 genRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg);
2366 } else {
2367 opRegRegImm(cUnit, op, rlResult.lowReg, rlSrc.lowReg, lit);
2368 }
2369 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002370 return false;
2371}
2372
jeffhao71eee1f2011-01-04 14:18:54 -08002373static bool handleFmt22c_Fmt52c(CompilationUnit *cUnit, MIR *mir)
Ben Chengba4fc8b2009-06-01 13:00:29 -07002374{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002375 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
buzbee4d92e682010-07-29 15:24:14 -07002376 int fieldOffset = -1;
buzbeeecf8f6e2010-07-20 14:53:42 -07002377 bool isVolatile = false;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002378 switch (dalvikOpcode) {
buzbee4d92e682010-07-29 15:24:14 -07002379 /*
2380 * Wide volatiles currently handled via single step.
2381 * Add them here if generating in-line code.
2382 * case OP_IGET_WIDE_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002383 * case OP_IGET_WIDE_VOLATILE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002384 * case OP_IPUT_WIDE_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002385 * case OP_IPUT_WIDE_VOLATILE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002386 */
2387 case OP_IGET:
2388 case OP_IGET_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002389 case OP_IGET_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08002390 case OP_IGET_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002391 case OP_IGET_WIDE:
jeffhao71eee1f2011-01-04 14:18:54 -08002392 case OP_IGET_WIDE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002393 case OP_IGET_OBJECT:
2394 case OP_IGET_OBJECT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002395 case OP_IGET_OBJECT_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08002396 case OP_IGET_OBJECT_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002397 case OP_IGET_BOOLEAN:
jeffhao71eee1f2011-01-04 14:18:54 -08002398 case OP_IGET_BOOLEAN_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002399 case OP_IGET_BYTE:
jeffhao71eee1f2011-01-04 14:18:54 -08002400 case OP_IGET_BYTE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002401 case OP_IGET_CHAR:
jeffhao71eee1f2011-01-04 14:18:54 -08002402 case OP_IGET_CHAR_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002403 case OP_IGET_SHORT:
jeffhao71eee1f2011-01-04 14:18:54 -08002404 case OP_IGET_SHORT_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002405 case OP_IPUT:
2406 case OP_IPUT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002407 case OP_IPUT_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08002408 case OP_IPUT_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002409 case OP_IPUT_WIDE:
jeffhao71eee1f2011-01-04 14:18:54 -08002410 case OP_IPUT_WIDE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002411 case OP_IPUT_OBJECT:
2412 case OP_IPUT_OBJECT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002413 case OP_IPUT_OBJECT_VOLATILE_JUMBO:
jeffhao71eee1f2011-01-04 14:18:54 -08002414 case OP_IPUT_OBJECT_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002415 case OP_IPUT_BOOLEAN:
jeffhao71eee1f2011-01-04 14:18:54 -08002416 case OP_IPUT_BOOLEAN_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002417 case OP_IPUT_BYTE:
jeffhao71eee1f2011-01-04 14:18:54 -08002418 case OP_IPUT_BYTE_JUMBO:
buzbee4d92e682010-07-29 15:24:14 -07002419 case OP_IPUT_CHAR:
jeffhao71eee1f2011-01-04 14:18:54 -08002420 case OP_IPUT_CHAR_JUMBO:
2421 case OP_IPUT_SHORT:
2422 case OP_IPUT_SHORT_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07002423 const Method *method = (mir->OptimizationFlags & MIR_CALLEE) ?
2424 mir->meta.calleeMethod : cUnit->method;
buzbee4d92e682010-07-29 15:24:14 -07002425 Field *fieldPtr =
Ben Cheng7a2697d2010-06-07 13:44:23 -07002426 method->clazz->pDvmDex->pResFields[mir->dalvikInsn.vC];
Ben Chengba4fc8b2009-06-01 13:00:29 -07002427
buzbee4d92e682010-07-29 15:24:14 -07002428 if (fieldPtr == NULL) {
2429 LOGE("Unexpected null instance field");
2430 dvmAbort();
2431 }
2432 isVolatile = dvmIsVolatileField(fieldPtr);
2433 fieldOffset = ((InstField *)fieldPtr)->byteOffset;
2434 break;
Ben Chengdd6e8702010-05-07 13:05:47 -07002435 }
buzbee4d92e682010-07-29 15:24:14 -07002436 default:
2437 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002438 }
buzbee4d92e682010-07-29 15:24:14 -07002439
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002440 switch (dalvikOpcode) {
jeffhao71eee1f2011-01-04 14:18:54 -08002441 case OP_NEW_ARRAY:
2442 case OP_NEW_ARRAY_JUMBO: {
Bill Buzbee1465db52009-09-23 17:17:35 -07002443 // Generates a call - use explicit registers
Bill Buzbeec6f10662010-02-09 11:16:15 -08002444 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
2445 RegLocation rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07002446 RegLocation rlResult;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002447 void *classPtr = (void*)
2448 (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vC]);
Ben Chengdd6e8702010-05-07 13:05:47 -07002449
2450 if (classPtr == NULL) {
2451 LOGE("Unexpected null class");
2452 dvmAbort();
2453 }
2454
Bill Buzbeec6f10662010-02-09 11:16:15 -08002455 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -07002456 genExportPC(cUnit, mir);
2457 loadValueDirectFixed(cUnit, rlSrc, r1); /* Len */
Ben Chengba4fc8b2009-06-01 13:00:29 -07002458 loadConstant(cUnit, r0, (int) classPtr );
Ben Chengbd1326d2010-04-02 15:04:53 -07002459 LOAD_FUNC_ADDR(cUnit, r3, (int)dvmAllocArrayByClass);
Ben Cheng4f489172009-09-27 17:08:35 -07002460 /*
2461 * "len < 0": bail to the interpreter to re-execute the
2462 * instruction
2463 */
Carl Shapiroe3c01da2010-05-20 22:54:18 -07002464 genRegImmCheck(cUnit, kArmCondMi, r1, 0, mir->offset, NULL);
Bill Buzbee270c1d62009-08-13 16:58:07 -07002465 loadConstant(cUnit, r2, ALLOC_DONT_TRACK);
Bill Buzbee1465db52009-09-23 17:17:35 -07002466 opReg(cUnit, kOpBlx, r3);
Elliott Hughes6a555132010-02-25 15:41:42 -08002467 dvmCompilerClobberCallRegs(cUnit);
Ben Cheng4f489172009-09-27 17:08:35 -07002468 /* generate a branch over if allocation is successful */
buzbee8f8109a2010-08-31 10:16:35 -07002469 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondNe, r0, 0);
Ben Cheng4f489172009-09-27 17:08:35 -07002470 /*
2471 * OOM exception needs to be thrown here and cannot re-execute
2472 */
2473 loadConstant(cUnit, r0,
2474 (int) (cUnit->method->insns + mir->offset));
2475 genDispatchToHandler(cUnit, TEMPLATE_THROW_EXCEPTION_COMMON);
2476 /* noreturn */
2477
Bill Buzbee1465db52009-09-23 17:17:35 -07002478 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
Ben Cheng4f489172009-09-27 17:08:35 -07002479 target->defMask = ENCODE_ALL;
2480 branchOver->generic.target = (LIR *) target;
Bill Buzbeec6f10662010-02-09 11:16:15 -08002481 rlResult = dvmCompilerGetReturn(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07002482 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002483 break;
2484 }
jeffhao71eee1f2011-01-04 14:18:54 -08002485 case OP_INSTANCE_OF:
2486 case OP_INSTANCE_OF_JUMBO: {
Bill Buzbee1465db52009-09-23 17:17:35 -07002487 // May generate a call - use explicit registers
Bill Buzbeec6f10662010-02-09 11:16:15 -08002488 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
2489 RegLocation rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07002490 RegLocation rlResult;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002491 ClassObject *classPtr =
2492 (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vC]);
Bill Buzbee480e6782010-01-27 15:43:08 -08002493 /*
2494 * Note: It is possible that classPtr is NULL at this point,
2495 * even though this instruction has been successfully interpreted.
2496 * If the previous interpretation had a null source, the
2497 * interpreter would not have bothered to resolve the clazz.
2498 * Bail out to the interpreter in this case, and log it
2499 * so that we can tell if it happens frequently.
2500 */
2501 if (classPtr == NULL) {
2502 LOGD("null clazz in OP_INSTANCE_OF, single-stepping");
2503 genInterpSingleStep(cUnit, mir);
2504 break;
2505 }
Bill Buzbeec6f10662010-02-09 11:16:15 -08002506 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -07002507 loadValueDirectFixed(cUnit, rlSrc, r0); /* Ref */
Ben Chengba4fc8b2009-06-01 13:00:29 -07002508 loadConstant(cUnit, r2, (int) classPtr );
Ben Cheng752c7942009-06-22 10:50:07 -07002509 /* When taken r0 has NULL which can be used for store directly */
buzbee8f8109a2010-08-31 10:16:35 -07002510 ArmLIR *branch1 = genCmpImmBranch(cUnit, kArmCondEq, r0, 0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002511 /* r1 now contains object->clazz */
Bill Buzbee270c1d62009-08-13 16:58:07 -07002512 loadWordDisp(cUnit, r0, offsetof(Object, clazz), r1);
Bill Buzbee1465db52009-09-23 17:17:35 -07002513 /* r1 now contains object->clazz */
Ben Chengbd1326d2010-04-02 15:04:53 -07002514 LOAD_FUNC_ADDR(cUnit, r3, (int)dvmInstanceofNonTrivial);
Ben Cheng752c7942009-06-22 10:50:07 -07002515 loadConstant(cUnit, r0, 1); /* Assume true */
Bill Buzbee1465db52009-09-23 17:17:35 -07002516 opRegReg(cUnit, kOpCmp, r1, r2);
2517 ArmLIR *branch2 = opCondBranch(cUnit, kArmCondEq);
2518 genRegCopy(cUnit, r0, r1);
2519 genRegCopy(cUnit, r1, r2);
2520 opReg(cUnit, kOpBlx, r3);
Elliott Hughes6a555132010-02-25 15:41:42 -08002521 dvmCompilerClobberCallRegs(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002522 /* branch target here */
Bill Buzbee1465db52009-09-23 17:17:35 -07002523 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
Ben Chengd7d426a2009-09-22 11:23:36 -07002524 target->defMask = ENCODE_ALL;
Bill Buzbeec6f10662010-02-09 11:16:15 -08002525 rlResult = dvmCompilerGetReturn(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07002526 storeValue(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002527 branch1->generic.target = (LIR *)target;
2528 branch2->generic.target = (LIR *)target;
2529 break;
2530 }
2531 case OP_IGET_WIDE:
jeffhao71eee1f2011-01-04 14:18:54 -08002532 case OP_IGET_WIDE_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002533 genIGetWide(cUnit, mir, fieldOffset);
2534 break;
buzbeeecf8f6e2010-07-20 14:53:42 -07002535 case OP_IGET_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002536 case OP_IGET_VOLATILE_JUMBO:
buzbeeecf8f6e2010-07-20 14:53:42 -07002537 case OP_IGET_OBJECT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002538 case OP_IGET_OBJECT_VOLATILE_JUMBO:
buzbeeecf8f6e2010-07-20 14:53:42 -07002539 isVolatile = true;
2540 // NOTE: intentional fallthrough
Ben Chengba4fc8b2009-06-01 13:00:29 -07002541 case OP_IGET:
jeffhao71eee1f2011-01-04 14:18:54 -08002542 case OP_IGET_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002543 case OP_IGET_OBJECT:
jeffhao71eee1f2011-01-04 14:18:54 -08002544 case OP_IGET_OBJECT_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002545 case OP_IGET_BOOLEAN:
jeffhao71eee1f2011-01-04 14:18:54 -08002546 case OP_IGET_BOOLEAN_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002547 case OP_IGET_BYTE:
jeffhao71eee1f2011-01-04 14:18:54 -08002548 case OP_IGET_BYTE_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002549 case OP_IGET_CHAR:
jeffhao71eee1f2011-01-04 14:18:54 -08002550 case OP_IGET_CHAR_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002551 case OP_IGET_SHORT:
jeffhao71eee1f2011-01-04 14:18:54 -08002552 case OP_IGET_SHORT_JUMBO:
buzbee3272e2f2010-09-09 14:07:01 -07002553 genIGet(cUnit, mir, kWord, fieldOffset, isVolatile);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002554 break;
2555 case OP_IPUT_WIDE:
jeffhao71eee1f2011-01-04 14:18:54 -08002556 case OP_IPUT_WIDE_JUMBO:
Ben Chengba4fc8b2009-06-01 13:00:29 -07002557 genIPutWide(cUnit, mir, fieldOffset);
2558 break;
2559 case OP_IPUT:
jeffhao71eee1f2011-01-04 14:18:54 -08002560 case OP_IPUT_JUMBO:
buzbee3272e2f2010-09-09 14:07:01 -07002561 case OP_IPUT_BOOLEAN:
jeffhao71eee1f2011-01-04 14:18:54 -08002562 case OP_IPUT_BOOLEAN_JUMBO:
2563 case OP_IPUT_BYTE:
2564 case OP_IPUT_BYTE_JUMBO:
2565 case OP_IPUT_CHAR:
2566 case OP_IPUT_CHAR_JUMBO:
2567 case OP_IPUT_SHORT:
2568 case OP_IPUT_SHORT_JUMBO:
buzbeeecf8f6e2010-07-20 14:53:42 -07002569 genIPut(cUnit, mir, kWord, fieldOffset, false, isVolatile);
buzbee919eb062010-07-12 12:59:22 -07002570 break;
buzbee4d92e682010-07-29 15:24:14 -07002571 case OP_IPUT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002572 case OP_IPUT_VOLATILE_JUMBO:
buzbeeecf8f6e2010-07-20 14:53:42 -07002573 case OP_IPUT_OBJECT_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002574 case OP_IPUT_OBJECT_VOLATILE_JUMBO:
buzbeeecf8f6e2010-07-20 14:53:42 -07002575 isVolatile = true;
2576 // NOTE: intentional fallthrough
Ben Chengba4fc8b2009-06-01 13:00:29 -07002577 case OP_IPUT_OBJECT:
jeffhao71eee1f2011-01-04 14:18:54 -08002578 case OP_IPUT_OBJECT_JUMBO:
buzbeeecf8f6e2010-07-20 14:53:42 -07002579 genIPut(cUnit, mir, kWord, fieldOffset, true, isVolatile);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002580 break;
Bill Buzbeeb16344a2010-03-15 17:19:12 -07002581 case OP_IGET_WIDE_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002582 case OP_IGET_WIDE_VOLATILE_JUMBO:
Bill Buzbeeb16344a2010-03-15 17:19:12 -07002583 case OP_IPUT_WIDE_VOLATILE:
buzbeebd7865b2011-03-31 10:55:04 -07002584 case OP_IPUT_WIDE_VOLATILE_JUMBO:
Bill Buzbeeb16344a2010-03-15 17:19:12 -07002585 genInterpSingleStep(cUnit, mir);
2586 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002587 default:
2588 return true;
2589 }
2590 return false;
2591}
2592
2593static bool handleFmt22cs(CompilationUnit *cUnit, MIR *mir)
2594{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002595 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002596 int fieldOffset = mir->dalvikInsn.vC;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002597 switch (dalvikOpcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07002598 case OP_IGET_QUICK:
2599 case OP_IGET_OBJECT_QUICK:
buzbeeecf8f6e2010-07-20 14:53:42 -07002600 genIGet(cUnit, mir, kWord, fieldOffset, false);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002601 break;
2602 case OP_IPUT_QUICK:
buzbeeecf8f6e2010-07-20 14:53:42 -07002603 genIPut(cUnit, mir, kWord, fieldOffset, false, false);
buzbee919eb062010-07-12 12:59:22 -07002604 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002605 case OP_IPUT_OBJECT_QUICK:
buzbeeecf8f6e2010-07-20 14:53:42 -07002606 genIPut(cUnit, mir, kWord, fieldOffset, true, false);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002607 break;
2608 case OP_IGET_WIDE_QUICK:
2609 genIGetWide(cUnit, mir, fieldOffset);
2610 break;
2611 case OP_IPUT_WIDE_QUICK:
2612 genIPutWide(cUnit, mir, fieldOffset);
2613 break;
2614 default:
2615 return true;
2616 }
2617 return false;
2618
2619}
2620
2621/* Compare agaist zero */
2622static bool handleFmt22t(CompilationUnit *cUnit, MIR *mir, BasicBlock *bb,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07002623 ArmLIR *labelList)
Ben Chengba4fc8b2009-06-01 13:00:29 -07002624{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002625 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07002626 ArmConditionCode cond;
Ben Cheng7ab74e12011-02-03 14:02:06 -08002627 /* backward branch? */
2628 bool backwardBranch = (bb->taken->startOffset <= mir->offset);
2629
2630 if (backwardBranch && gDvmJit.genSuspendPoll) {
2631 genSuspendPoll(cUnit, mir);
2632 }
2633
Bill Buzbeec6f10662010-02-09 11:16:15 -08002634 RegLocation rlSrc1 = dvmCompilerGetSrc(cUnit, mir, 0);
2635 RegLocation rlSrc2 = dvmCompilerGetSrc(cUnit, mir, 1);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002636
Bill Buzbee1465db52009-09-23 17:17:35 -07002637 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
2638 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
Ben Cheng7ab74e12011-02-03 14:02:06 -08002639
Bill Buzbee1465db52009-09-23 17:17:35 -07002640 opRegReg(cUnit, kOpCmp, rlSrc1.lowReg, rlSrc2.lowReg);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002641
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002642 switch (dalvikOpcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07002643 case OP_IF_EQ:
Bill Buzbee1465db52009-09-23 17:17:35 -07002644 cond = kArmCondEq;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002645 break;
2646 case OP_IF_NE:
Bill Buzbee1465db52009-09-23 17:17:35 -07002647 cond = kArmCondNe;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002648 break;
2649 case OP_IF_LT:
Bill Buzbee1465db52009-09-23 17:17:35 -07002650 cond = kArmCondLt;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002651 break;
2652 case OP_IF_GE:
Bill Buzbee1465db52009-09-23 17:17:35 -07002653 cond = kArmCondGe;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002654 break;
2655 case OP_IF_GT:
Bill Buzbee1465db52009-09-23 17:17:35 -07002656 cond = kArmCondGt;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002657 break;
2658 case OP_IF_LE:
Bill Buzbee1465db52009-09-23 17:17:35 -07002659 cond = kArmCondLe;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002660 break;
2661 default:
2662 cond = 0;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002663 LOGE("Unexpected opcode (%d) for Fmt22t\n", dalvikOpcode);
Bill Buzbeefc519dc2010-03-06 23:30:57 -08002664 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002665 }
2666 genConditionalBranch(cUnit, cond, &labelList[bb->taken->id]);
2667 /* This mostly likely will be optimized away in a later phase */
2668 genUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]);
2669 return false;
2670}
2671
2672static bool handleFmt22x_Fmt32x(CompilationUnit *cUnit, MIR *mir)
2673{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002674 Opcode opcode = mir->dalvikInsn.opcode;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002675
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002676 switch (opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07002677 case OP_MOVE_16:
2678 case OP_MOVE_OBJECT_16:
2679 case OP_MOVE_FROM16:
Ben Chenge9695e52009-06-16 16:11:47 -07002680 case OP_MOVE_OBJECT_FROM16: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002681 storeValue(cUnit, dvmCompilerGetDest(cUnit, mir, 0),
2682 dvmCompilerGetSrc(cUnit, mir, 0));
Ben Chengba4fc8b2009-06-01 13:00:29 -07002683 break;
Ben Chenge9695e52009-06-16 16:11:47 -07002684 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07002685 case OP_MOVE_WIDE_16:
Ben Chenge9695e52009-06-16 16:11:47 -07002686 case OP_MOVE_WIDE_FROM16: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002687 storeValueWide(cUnit, dvmCompilerGetDestWide(cUnit, mir, 0, 1),
2688 dvmCompilerGetSrcWide(cUnit, mir, 0, 1));
Ben Chengba4fc8b2009-06-01 13:00:29 -07002689 break;
Ben Chenge9695e52009-06-16 16:11:47 -07002690 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07002691 default:
2692 return true;
2693 }
2694 return false;
2695}
2696
2697static bool handleFmt23x(CompilationUnit *cUnit, MIR *mir)
2698{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002699 Opcode opcode = mir->dalvikInsn.opcode;
Bill Buzbee1465db52009-09-23 17:17:35 -07002700 RegLocation rlSrc1;
2701 RegLocation rlSrc2;
2702 RegLocation rlDest;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002703
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002704 if ( (opcode >= OP_ADD_INT) && (opcode <= OP_REM_DOUBLE)) {
Ben Cheng5d90c202009-11-22 23:31:11 -08002705 return genArithOp( cUnit, mir );
Ben Chengba4fc8b2009-06-01 13:00:29 -07002706 }
2707
Bill Buzbee1465db52009-09-23 17:17:35 -07002708 /* APUTs have 3 sources and no targets */
2709 if (mir->ssaRep->numDefs == 0) {
2710 if (mir->ssaRep->numUses == 3) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002711 rlDest = dvmCompilerGetSrc(cUnit, mir, 0);
2712 rlSrc1 = dvmCompilerGetSrc(cUnit, mir, 1);
2713 rlSrc2 = dvmCompilerGetSrc(cUnit, mir, 2);
Bill Buzbee1465db52009-09-23 17:17:35 -07002714 } else {
2715 assert(mir->ssaRep->numUses == 4);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002716 rlDest = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
2717 rlSrc1 = dvmCompilerGetSrc(cUnit, mir, 2);
2718 rlSrc2 = dvmCompilerGetSrc(cUnit, mir, 3);
Bill Buzbee1465db52009-09-23 17:17:35 -07002719 }
2720 } else {
2721 /* Two sources and 1 dest. Deduce the operand sizes */
2722 if (mir->ssaRep->numUses == 4) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002723 rlSrc1 = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
2724 rlSrc2 = dvmCompilerGetSrcWide(cUnit, mir, 2, 3);
Bill Buzbee1465db52009-09-23 17:17:35 -07002725 } else {
2726 assert(mir->ssaRep->numUses == 2);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002727 rlSrc1 = dvmCompilerGetSrc(cUnit, mir, 0);
2728 rlSrc2 = dvmCompilerGetSrc(cUnit, mir, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07002729 }
2730 if (mir->ssaRep->numDefs == 2) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002731 rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
Bill Buzbee1465db52009-09-23 17:17:35 -07002732 } else {
2733 assert(mir->ssaRep->numDefs == 1);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002734 rlDest = dvmCompilerGetDest(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07002735 }
2736 }
2737
2738
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002739 switch (opcode) {
Bill Buzbeed45ba372009-06-15 17:00:57 -07002740 case OP_CMPL_FLOAT:
2741 case OP_CMPG_FLOAT:
2742 case OP_CMPL_DOUBLE:
2743 case OP_CMPG_DOUBLE:
Ben Cheng5d90c202009-11-22 23:31:11 -08002744 return genCmpFP(cUnit, mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002745 case OP_CMP_LONG:
Bill Buzbee1465db52009-09-23 17:17:35 -07002746 genCmpLong(cUnit, mir, rlDest, rlSrc1, rlSrc2);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002747 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002748 case OP_AGET_WIDE:
Bill Buzbee1465db52009-09-23 17:17:35 -07002749 genArrayGet(cUnit, mir, kLong, rlSrc1, rlSrc2, rlDest, 3);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002750 break;
2751 case OP_AGET:
2752 case OP_AGET_OBJECT:
Bill Buzbee1465db52009-09-23 17:17:35 -07002753 genArrayGet(cUnit, mir, kWord, rlSrc1, rlSrc2, rlDest, 2);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002754 break;
2755 case OP_AGET_BOOLEAN:
Bill Buzbee1465db52009-09-23 17:17:35 -07002756 genArrayGet(cUnit, mir, kUnsignedByte, rlSrc1, rlSrc2, rlDest, 0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002757 break;
2758 case OP_AGET_BYTE:
Bill Buzbee1465db52009-09-23 17:17:35 -07002759 genArrayGet(cUnit, mir, kSignedByte, rlSrc1, rlSrc2, rlDest, 0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002760 break;
2761 case OP_AGET_CHAR:
Bill Buzbee1465db52009-09-23 17:17:35 -07002762 genArrayGet(cUnit, mir, kUnsignedHalf, rlSrc1, rlSrc2, rlDest, 1);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002763 break;
2764 case OP_AGET_SHORT:
Bill Buzbee1465db52009-09-23 17:17:35 -07002765 genArrayGet(cUnit, mir, kSignedHalf, rlSrc1, rlSrc2, rlDest, 1);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002766 break;
2767 case OP_APUT_WIDE:
Bill Buzbee1465db52009-09-23 17:17:35 -07002768 genArrayPut(cUnit, mir, kLong, rlSrc1, rlSrc2, rlDest, 3);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002769 break;
2770 case OP_APUT:
Bill Buzbee1465db52009-09-23 17:17:35 -07002771 genArrayPut(cUnit, mir, kWord, rlSrc1, rlSrc2, rlDest, 2);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002772 break;
Bill Buzbeebe6534f2010-03-12 16:01:35 -08002773 case OP_APUT_OBJECT:
2774 genArrayObjectPut(cUnit, mir, rlSrc1, rlSrc2, rlDest, 2);
2775 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002776 case OP_APUT_SHORT:
2777 case OP_APUT_CHAR:
Bill Buzbee1465db52009-09-23 17:17:35 -07002778 genArrayPut(cUnit, mir, kUnsignedHalf, rlSrc1, rlSrc2, rlDest, 1);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002779 break;
2780 case OP_APUT_BYTE:
2781 case OP_APUT_BOOLEAN:
Bill Buzbee1465db52009-09-23 17:17:35 -07002782 genArrayPut(cUnit, mir, kUnsignedByte, rlSrc1, rlSrc2, rlDest, 0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002783 break;
2784 default:
2785 return true;
2786 }
2787 return false;
2788}
2789
Ben Cheng6c10a972009-10-29 14:39:18 -07002790/*
2791 * Find the matching case.
2792 *
2793 * return values:
2794 * r0 (low 32-bit): pc of the chaining cell corresponding to the resolved case,
2795 * including default which is placed at MIN(size, MAX_CHAINED_SWITCH_CASES).
2796 * r1 (high 32-bit): the branch offset of the matching case (only for indexes
2797 * above MAX_CHAINED_SWITCH_CASES).
2798 *
2799 * Instructions around the call are:
2800 *
2801 * mov r2, pc
2802 * blx &findPackedSwitchIndex
2803 * mov pc, r0
2804 * .align4
Bill Buzbeebd047242010-05-13 13:02:53 -07002805 * chaining cell for case 0 [12 bytes]
2806 * chaining cell for case 1 [12 bytes]
Ben Cheng6c10a972009-10-29 14:39:18 -07002807 * :
Bill Buzbeebd047242010-05-13 13:02:53 -07002808 * chaining cell for case MIN(size, MAX_CHAINED_SWITCH_CASES)-1 [12 bytes]
Ben Cheng6c10a972009-10-29 14:39:18 -07002809 * chaining cell for case default [8 bytes]
2810 * noChain exit
2811 */
Ben Chengbd1326d2010-04-02 15:04:53 -07002812static s8 findPackedSwitchIndex(const u2* switchData, int testVal, int pc)
Ben Cheng6c10a972009-10-29 14:39:18 -07002813{
2814 int size;
2815 int firstKey;
2816 const int *entries;
2817 int index;
2818 int jumpIndex;
2819 int caseDPCOffset = 0;
2820 /* In Thumb mode pc is 4 ahead of the "mov r2, pc" instruction */
2821 int chainingPC = (pc + 4) & ~3;
2822
2823 /*
2824 * Packed switch data format:
2825 * ushort ident = 0x0100 magic value
2826 * ushort size number of entries in the table
2827 * int first_key first (and lowest) switch case value
2828 * int targets[size] branch targets, relative to switch opcode
2829 *
2830 * Total size is (4+size*2) 16-bit code units.
2831 */
2832 size = switchData[1];
2833 assert(size > 0);
2834
2835 firstKey = switchData[2];
2836 firstKey |= switchData[3] << 16;
2837
2838
2839 /* The entries are guaranteed to be aligned on a 32-bit boundary;
2840 * we can treat them as a native int array.
2841 */
2842 entries = (const int*) &switchData[4];
2843 assert(((u4)entries & 0x3) == 0);
2844
2845 index = testVal - firstKey;
2846
2847 /* Jump to the default cell */
2848 if (index < 0 || index >= size) {
2849 jumpIndex = MIN(size, MAX_CHAINED_SWITCH_CASES);
2850 /* Jump to the non-chaining exit point */
2851 } else if (index >= MAX_CHAINED_SWITCH_CASES) {
2852 jumpIndex = MAX_CHAINED_SWITCH_CASES + 1;
2853 caseDPCOffset = entries[index];
2854 /* Jump to the inline chaining cell */
2855 } else {
2856 jumpIndex = index;
2857 }
2858
Bill Buzbeebd047242010-05-13 13:02:53 -07002859 chainingPC += jumpIndex * CHAIN_CELL_NORMAL_SIZE;
Ben Cheng6c10a972009-10-29 14:39:18 -07002860 return (((s8) caseDPCOffset) << 32) | (u8) chainingPC;
2861}
2862
2863/* See comments for findPackedSwitchIndex */
Ben Chengbd1326d2010-04-02 15:04:53 -07002864static s8 findSparseSwitchIndex(const u2* switchData, int testVal, int pc)
Ben Cheng6c10a972009-10-29 14:39:18 -07002865{
2866 int size;
2867 const int *keys;
2868 const int *entries;
2869 int chainingPC = (pc + 4) & ~3;
2870 int i;
2871
2872 /*
2873 * Sparse switch data format:
2874 * ushort ident = 0x0200 magic value
2875 * ushort size number of entries in the table; > 0
2876 * int keys[size] keys, sorted low-to-high; 32-bit aligned
2877 * int targets[size] branch targets, relative to switch opcode
2878 *
2879 * Total size is (2+size*4) 16-bit code units.
2880 */
2881
2882 size = switchData[1];
2883 assert(size > 0);
2884
2885 /* The keys are guaranteed to be aligned on a 32-bit boundary;
2886 * we can treat them as a native int array.
2887 */
2888 keys = (const int*) &switchData[2];
2889 assert(((u4)keys & 0x3) == 0);
2890
2891 /* The entries are guaranteed to be aligned on a 32-bit boundary;
2892 * we can treat them as a native int array.
2893 */
2894 entries = keys + size;
2895 assert(((u4)entries & 0x3) == 0);
2896
2897 /*
2898 * Run through the list of keys, which are guaranteed to
2899 * be sorted low-to-high.
2900 *
2901 * Most tables have 3-4 entries. Few have more than 10. A binary
2902 * search here is probably not useful.
2903 */
2904 for (i = 0; i < size; i++) {
2905 int k = keys[i];
2906 if (k == testVal) {
2907 /* MAX_CHAINED_SWITCH_CASES + 1 is the start of the overflow case */
2908 int jumpIndex = (i < MAX_CHAINED_SWITCH_CASES) ?
2909 i : MAX_CHAINED_SWITCH_CASES + 1;
Bill Buzbeebd047242010-05-13 13:02:53 -07002910 chainingPC += jumpIndex * CHAIN_CELL_NORMAL_SIZE;
Ben Cheng6c10a972009-10-29 14:39:18 -07002911 return (((s8) entries[i]) << 32) | (u8) chainingPC;
2912 } else if (k > testVal) {
2913 break;
2914 }
2915 }
Bill Buzbeebd047242010-05-13 13:02:53 -07002916 return chainingPC + MIN(size, MAX_CHAINED_SWITCH_CASES) *
2917 CHAIN_CELL_NORMAL_SIZE;
Ben Cheng6c10a972009-10-29 14:39:18 -07002918}
2919
Ben Chengba4fc8b2009-06-01 13:00:29 -07002920static bool handleFmt31t(CompilationUnit *cUnit, MIR *mir)
2921{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002922 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
2923 switch (dalvikOpcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07002924 case OP_FILL_ARRAY_DATA: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002925 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
Bill Buzbee1465db52009-09-23 17:17:35 -07002926 // Making a call - use explicit registers
Bill Buzbeec6f10662010-02-09 11:16:15 -08002927 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -07002928 genExportPC(cUnit, mir);
2929 loadValueDirectFixed(cUnit, rlSrc, r0);
Ben Chengbd1326d2010-04-02 15:04:53 -07002930 LOAD_FUNC_ADDR(cUnit, r2, (int)dvmInterpHandleFillArrayData);
Ben Cheng6c10a972009-10-29 14:39:18 -07002931 loadConstant(cUnit, r1,
2932 (int) (cUnit->method->insns + mir->offset + mir->dalvikInsn.vB));
Bill Buzbee1465db52009-09-23 17:17:35 -07002933 opReg(cUnit, kOpBlx, r2);
Elliott Hughes6a555132010-02-25 15:41:42 -08002934 dvmCompilerClobberCallRegs(cUnit);
Bill Buzbeefd023aa2009-11-02 09:23:49 -08002935 /* generate a branch over if successful */
buzbee8f8109a2010-08-31 10:16:35 -07002936 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondNe, r0, 0);
Bill Buzbeefd023aa2009-11-02 09:23:49 -08002937 loadConstant(cUnit, r0,
2938 (int) (cUnit->method->insns + mir->offset));
2939 genDispatchToHandler(cUnit, TEMPLATE_THROW_EXCEPTION_COMMON);
2940 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
2941 target->defMask = ENCODE_ALL;
2942 branchOver->generic.target = (LIR *) target;
Ben Chengba4fc8b2009-06-01 13:00:29 -07002943 break;
2944 }
2945 /*
Ben Cheng6c10a972009-10-29 14:39:18 -07002946 * Compute the goto target of up to
2947 * MIN(switchSize, MAX_CHAINED_SWITCH_CASES) + 1 chaining cells.
2948 * See the comment before findPackedSwitchIndex for the code layout.
Ben Chengba4fc8b2009-06-01 13:00:29 -07002949 */
2950 case OP_PACKED_SWITCH:
2951 case OP_SPARSE_SWITCH: {
Bill Buzbeec6f10662010-02-09 11:16:15 -08002952 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
2953 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbee1465db52009-09-23 17:17:35 -07002954 loadValueDirectFixed(cUnit, rlSrc, r1);
Bill Buzbeec6f10662010-02-09 11:16:15 -08002955 dvmCompilerLockAllTemps(cUnit);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08002956 if (dalvikOpcode == OP_PACKED_SWITCH) {
Ben Chengbd1326d2010-04-02 15:04:53 -07002957 LOAD_FUNC_ADDR(cUnit, r4PC, (int)findPackedSwitchIndex);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002958 } else {
Ben Chengbd1326d2010-04-02 15:04:53 -07002959 LOAD_FUNC_ADDR(cUnit, r4PC, (int)findSparseSwitchIndex);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002960 }
Ben Cheng6c10a972009-10-29 14:39:18 -07002961 /* r0 <- Addr of the switch data */
2962 loadConstant(cUnit, r0,
2963 (int) (cUnit->method->insns + mir->offset + mir->dalvikInsn.vB));
2964 /* r2 <- pc of the instruction following the blx */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08002965 opRegReg(cUnit, kOpMov, r2, r15pc);
Bill Buzbee1465db52009-09-23 17:17:35 -07002966 opReg(cUnit, kOpBlx, r4PC);
Elliott Hughes6a555132010-02-25 15:41:42 -08002967 dvmCompilerClobberCallRegs(cUnit);
Ben Cheng6c10a972009-10-29 14:39:18 -07002968 /* pc <- computed goto target */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08002969 opRegReg(cUnit, kOpMov, r15pc, r0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07002970 break;
2971 }
2972 default:
2973 return true;
2974 }
2975 return false;
2976}
2977
Ben Cheng7a2697d2010-06-07 13:44:23 -07002978/*
2979 * See the example of predicted inlining listed before the
2980 * genValidationForPredictedInline function. The function here takes care the
2981 * branch over at 0x4858de78 and the misprediction target at 0x4858de7a.
2982 */
2983static void genLandingPadForMispredictedCallee(CompilationUnit *cUnit, MIR *mir,
2984 BasicBlock *bb,
2985 ArmLIR *labelList)
2986{
2987 BasicBlock *fallThrough = bb->fallThrough;
2988
2989 /* Bypass the move-result block if there is one */
2990 if (fallThrough->firstMIRInsn) {
2991 assert(fallThrough->firstMIRInsn->OptimizationFlags & MIR_INLINED_PRED);
2992 fallThrough = fallThrough->fallThrough;
2993 }
2994 /* Generate a branch over if the predicted inlining is correct */
2995 genUnconditionalBranch(cUnit, &labelList[fallThrough->id]);
2996
2997 /* Reset the register state */
2998 dvmCompilerResetRegPool(cUnit);
2999 dvmCompilerClobberAllRegs(cUnit);
3000 dvmCompilerResetNullCheck(cUnit);
3001
3002 /* Target for the slow invoke path */
3003 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
3004 target->defMask = ENCODE_ALL;
3005 /* Hook up the target to the verification branch */
3006 mir->meta.callsiteInfo->misPredBranchOver->target = (LIR *) target;
3007}
3008
jeffhao71eee1f2011-01-04 14:18:54 -08003009static bool handleFmt35c_3rc_5rc(CompilationUnit *cUnit, MIR *mir,
3010 BasicBlock *bb, ArmLIR *labelList)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003011{
Bill Buzbee9bc3df32009-07-30 10:52:29 -07003012 ArmLIR *retChainingCell = NULL;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003013 ArmLIR *pcrLabel = NULL;
Ben Chengba4fc8b2009-06-01 13:00:29 -07003014
Ben Cheng7a2697d2010-06-07 13:44:23 -07003015 /* An invoke with the MIR_INLINED is effectively a no-op */
3016 if (mir->OptimizationFlags & MIR_INLINED)
3017 return false;
3018
Bill Buzbeef4ce16f2009-07-28 13:28:25 -07003019 if (bb->fallThrough != NULL)
3020 retChainingCell = &labelList[bb->fallThrough->id];
3021
Ben Chengba4fc8b2009-06-01 13:00:29 -07003022 DecodedInstruction *dInsn = &mir->dalvikInsn;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003023 switch (mir->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07003024 /*
3025 * calleeMethod = this->clazz->vtable[
3026 * method->clazz->pDvmDex->pResMethods[BBBB]->methodIndex
3027 * ]
3028 */
3029 case OP_INVOKE_VIRTUAL:
jeffhao71eee1f2011-01-04 14:18:54 -08003030 case OP_INVOKE_VIRTUAL_RANGE:
3031 case OP_INVOKE_VIRTUAL_JUMBO: {
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003032 ArmLIR *predChainingCell = &labelList[bb->taken->id];
Ben Chengba4fc8b2009-06-01 13:00:29 -07003033 int methodIndex =
3034 cUnit->method->clazz->pDvmDex->pResMethods[dInsn->vB]->
3035 methodIndex;
3036
Ben Cheng7a2697d2010-06-07 13:44:23 -07003037 /*
3038 * If the invoke has non-null misPredBranchOver, we need to generate
3039 * the non-inlined version of the invoke here to handle the
3040 * mispredicted case.
3041 */
3042 if (mir->meta.callsiteInfo->misPredBranchOver) {
3043 genLandingPadForMispredictedCallee(cUnit, mir, bb, labelList);
3044 }
3045
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003046 if (mir->dalvikInsn.opcode == OP_INVOKE_VIRTUAL)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003047 genProcessArgsNoRange(cUnit, mir, dInsn, &pcrLabel);
3048 else
3049 genProcessArgsRange(cUnit, mir, dInsn, &pcrLabel);
3050
Ben Cheng38329f52009-07-07 14:19:20 -07003051 genInvokeVirtualCommon(cUnit, mir, methodIndex,
3052 retChainingCell,
3053 predChainingCell,
3054 pcrLabel);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003055 break;
3056 }
3057 /*
3058 * calleeMethod = method->clazz->super->vtable[method->clazz->pDvmDex
3059 * ->pResMethods[BBBB]->methodIndex]
3060 */
Ben Chengba4fc8b2009-06-01 13:00:29 -07003061 case OP_INVOKE_SUPER:
jeffhao71eee1f2011-01-04 14:18:54 -08003062 case OP_INVOKE_SUPER_RANGE:
3063 case OP_INVOKE_SUPER_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07003064 /* Grab the method ptr directly from what the interpreter sees */
3065 const Method *calleeMethod = mir->meta.callsiteInfo->method;
3066 assert(calleeMethod == cUnit->method->clazz->super->vtable[
3067 cUnit->method->clazz->pDvmDex->
3068 pResMethods[dInsn->vB]->methodIndex]);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003069
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003070 if (mir->dalvikInsn.opcode == OP_INVOKE_SUPER)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003071 genProcessArgsNoRange(cUnit, mir, dInsn, &pcrLabel);
3072 else
3073 genProcessArgsRange(cUnit, mir, dInsn, &pcrLabel);
3074
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003075 if (mir->OptimizationFlags & MIR_INVOKE_METHOD_JIT) {
3076 const Method *calleeMethod = mir->meta.callsiteInfo->method;
3077 void *calleeAddr = dvmJitGetMethodAddr(calleeMethod->insns);
3078 assert(calleeAddr);
3079 genInvokeSingletonWholeMethod(cUnit, mir, calleeAddr,
3080 retChainingCell);
3081 } else {
3082 /* r0 = calleeMethod */
3083 loadConstant(cUnit, r0, (int) calleeMethod);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003084
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003085 genInvokeSingletonCommon(cUnit, mir, bb, labelList, pcrLabel,
3086 calleeMethod);
3087 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07003088 break;
3089 }
3090 /* calleeMethod = method->clazz->pDvmDex->pResMethods[BBBB] */
3091 case OP_INVOKE_DIRECT:
jeffhao71eee1f2011-01-04 14:18:54 -08003092 case OP_INVOKE_DIRECT_RANGE:
3093 case OP_INVOKE_DIRECT_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07003094 /* Grab the method ptr directly from what the interpreter sees */
3095 const Method *calleeMethod = mir->meta.callsiteInfo->method;
3096 assert(calleeMethod ==
3097 cUnit->method->clazz->pDvmDex->pResMethods[dInsn->vB]);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003098
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003099 if (mir->dalvikInsn.opcode == OP_INVOKE_DIRECT)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003100 genProcessArgsNoRange(cUnit, mir, dInsn, &pcrLabel);
3101 else
3102 genProcessArgsRange(cUnit, mir, dInsn, &pcrLabel);
3103
3104 /* r0 = calleeMethod */
3105 loadConstant(cUnit, r0, (int) calleeMethod);
3106
Ben Cheng38329f52009-07-07 14:19:20 -07003107 genInvokeSingletonCommon(cUnit, mir, bb, labelList, pcrLabel,
3108 calleeMethod);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003109 break;
3110 }
3111 /* calleeMethod = method->clazz->pDvmDex->pResMethods[BBBB] */
3112 case OP_INVOKE_STATIC:
jeffhao71eee1f2011-01-04 14:18:54 -08003113 case OP_INVOKE_STATIC_RANGE:
3114 case OP_INVOKE_STATIC_JUMBO: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07003115 /* Grab the method ptr directly from what the interpreter sees */
3116 const Method *calleeMethod = mir->meta.callsiteInfo->method;
3117 assert(calleeMethod ==
3118 cUnit->method->clazz->pDvmDex->pResMethods[dInsn->vB]);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003119
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003120 if (mir->dalvikInsn.opcode == OP_INVOKE_STATIC)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003121 genProcessArgsNoRange(cUnit, mir, dInsn,
3122 NULL /* no null check */);
3123 else
3124 genProcessArgsRange(cUnit, mir, dInsn,
3125 NULL /* no null check */);
3126
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003127 if (mir->OptimizationFlags & MIR_INVOKE_METHOD_JIT) {
3128 const Method *calleeMethod = mir->meta.callsiteInfo->method;
3129 void *calleeAddr = dvmJitGetMethodAddr(calleeMethod->insns);
3130 assert(calleeAddr);
3131 genInvokeSingletonWholeMethod(cUnit, mir, calleeAddr,
3132 retChainingCell);
3133 } else {
3134 /* r0 = calleeMethod */
3135 loadConstant(cUnit, r0, (int) calleeMethod);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003136
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003137 genInvokeSingletonCommon(cUnit, mir, bb, labelList, pcrLabel,
3138 calleeMethod);
3139 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07003140 break;
3141 }
Ben Cheng09e50c92010-05-02 10:45:32 -07003142 /*
Ben Chengba4fc8b2009-06-01 13:00:29 -07003143 * calleeMethod = dvmFindInterfaceMethodInCache(this->clazz,
3144 * BBBB, method, method->clazz->pDvmDex)
Ben Cheng38329f52009-07-07 14:19:20 -07003145 *
Ben Cheng09e50c92010-05-02 10:45:32 -07003146 * The following is an example of generated code for
3147 * "invoke-interface v0"
Ben Cheng38329f52009-07-07 14:19:20 -07003148 *
Ben Cheng09e50c92010-05-02 10:45:32 -07003149 * -------- dalvik offset: 0x0008 @ invoke-interface v0
3150 * 0x47357e36 : ldr r0, [r5, #0] --+
3151 * 0x47357e38 : sub r7,r5,#24 |
3152 * 0x47357e3c : cmp r0, #0 | genProcessArgsNoRange
3153 * 0x47357e3e : beq 0x47357e82 |
3154 * 0x47357e40 : stmia r7, <r0> --+
3155 * 0x47357e42 : ldr r4, [pc, #120] --> r4 <- dalvikPC of this invoke
3156 * 0x47357e44 : add r1, pc, #64 --> r1 <- &retChainingCell
3157 * 0x47357e46 : add r2, pc, #72 --> r2 <- &predictedChainingCell
3158 * 0x47357e48 : blx_1 0x47348190 --+ TEMPLATE_INVOKE_METHOD_
3159 * 0x47357e4a : blx_2 see above --+ PREDICTED_CHAIN
3160 * 0x47357e4c : b 0x47357e90 --> off to the predicted chain
3161 * 0x47357e4e : b 0x47357e82 --> punt to the interpreter
3162 * 0x47357e50 : mov r8, r1 --+
3163 * 0x47357e52 : mov r9, r2 |
3164 * 0x47357e54 : ldr r2, [pc, #96] |
3165 * 0x47357e56 : mov r10, r3 |
3166 * 0x47357e58 : movs r0, r3 | dvmFindInterfaceMethodInCache
3167 * 0x47357e5a : ldr r3, [pc, #88] |
3168 * 0x47357e5c : ldr r7, [pc, #80] |
3169 * 0x47357e5e : mov r1, #1452 |
3170 * 0x47357e62 : blx r7 --+
3171 * 0x47357e64 : cmp r0, #0 --> calleeMethod == NULL?
3172 * 0x47357e66 : bne 0x47357e6e --> branch over the throw if !r0
3173 * 0x47357e68 : ldr r0, [pc, #80] --> load Dalvik PC of the invoke
3174 * 0x47357e6a : blx_1 0x47348494 --+ TEMPLATE_THROW_EXCEPTION_
3175 * 0x47357e6c : blx_2 see above --+ COMMON
3176 * 0x47357e6e : mov r1, r8 --> r1 <- &retChainingCell
3177 * 0x47357e70 : cmp r1, #0 --> compare against 0
3178 * 0x47357e72 : bgt 0x47357e7c --> >=0? don't rechain
Ben Chengaf5aa1f2011-01-04 15:37:04 -08003179 * 0x47357e74 : ldr r7, [pc, #off] --+
Ben Cheng09e50c92010-05-02 10:45:32 -07003180 * 0x47357e76 : mov r2, r9 | dvmJitToPatchPredictedChain
3181 * 0x47357e78 : mov r3, r10 |
3182 * 0x47357e7a : blx r7 --+
3183 * 0x47357e7c : add r1, pc, #8 --> r1 <- &retChainingCell
3184 * 0x47357e7e : blx_1 0x4734809c --+ TEMPLATE_INVOKE_METHOD_NO_OPT
3185 * 0x47357e80 : blx_2 see above --+
3186 * -------- reconstruct dalvik PC : 0x425719dc @ +0x0008
3187 * 0x47357e82 : ldr r0, [pc, #56]
Ben Cheng38329f52009-07-07 14:19:20 -07003188 * Exception_Handling:
Ben Cheng09e50c92010-05-02 10:45:32 -07003189 * 0x47357e84 : ldr r1, [r6, #92]
3190 * 0x47357e86 : blx r1
3191 * 0x47357e88 : .align4
3192 * -------- chaining cell (hot): 0x000b
3193 * 0x47357e88 : ldr r0, [r6, #104]
3194 * 0x47357e8a : blx r0
3195 * 0x47357e8c : data 0x19e2(6626)
3196 * 0x47357e8e : data 0x4257(16983)
3197 * 0x47357e90 : .align4
Ben Cheng38329f52009-07-07 14:19:20 -07003198 * -------- chaining cell (predicted)
Ben Cheng09e50c92010-05-02 10:45:32 -07003199 * 0x47357e90 : data 0xe7fe(59390) --> will be patched into bx
3200 * 0x47357e92 : data 0x0000(0)
3201 * 0x47357e94 : data 0x0000(0) --> class
3202 * 0x47357e96 : data 0x0000(0)
3203 * 0x47357e98 : data 0x0000(0) --> method
3204 * 0x47357e9a : data 0x0000(0)
3205 * 0x47357e9c : data 0x0000(0) --> rechain count
3206 * 0x47357e9e : data 0x0000(0)
3207 * -------- end of chaining cells (0x006c)
3208 * 0x47357eb0 : .word (0xad03e369)
3209 * 0x47357eb4 : .word (0x28a90)
3210 * 0x47357eb8 : .word (0x41a63394)
3211 * 0x47357ebc : .word (0x425719dc)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003212 */
3213 case OP_INVOKE_INTERFACE:
jeffhao71eee1f2011-01-04 14:18:54 -08003214 case OP_INVOKE_INTERFACE_RANGE:
3215 case OP_INVOKE_INTERFACE_JUMBO: {
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003216 ArmLIR *predChainingCell = &labelList[bb->taken->id];
Ben Chengba4fc8b2009-06-01 13:00:29 -07003217
Ben Cheng7a2697d2010-06-07 13:44:23 -07003218 /*
3219 * If the invoke has non-null misPredBranchOver, we need to generate
3220 * the non-inlined version of the invoke here to handle the
3221 * mispredicted case.
3222 */
3223 if (mir->meta.callsiteInfo->misPredBranchOver) {
3224 genLandingPadForMispredictedCallee(cUnit, mir, bb, labelList);
3225 }
Bill Buzbee1465db52009-09-23 17:17:35 -07003226
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003227 if (mir->dalvikInsn.opcode == OP_INVOKE_INTERFACE)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003228 genProcessArgsNoRange(cUnit, mir, dInsn, &pcrLabel);
3229 else
3230 genProcessArgsRange(cUnit, mir, dInsn, &pcrLabel);
3231
Ben Cheng38329f52009-07-07 14:19:20 -07003232 /* "this" is already left in r0 by genProcessArgs* */
3233
3234 /* r4PC = dalvikCallsite */
3235 loadConstant(cUnit, r4PC,
3236 (int) (cUnit->method->insns + mir->offset));
3237
3238 /* r1 = &retChainingCell */
Bill Buzbee270c1d62009-08-13 16:58:07 -07003239 ArmLIR *addrRetChain =
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003240 opRegRegImm(cUnit, kOpAdd, r1, r15pc, 0);
Ben Cheng38329f52009-07-07 14:19:20 -07003241 addrRetChain->generic.target = (LIR *) retChainingCell;
3242
3243 /* r2 = &predictedChainingCell */
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003244 ArmLIR *predictedChainingCell =
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003245 opRegRegImm(cUnit, kOpAdd, r2, r15pc, 0);
Ben Cheng38329f52009-07-07 14:19:20 -07003246 predictedChainingCell->generic.target = (LIR *) predChainingCell;
3247
buzbee18fba342011-01-19 15:31:15 -08003248 genDispatchToHandler(cUnit, gDvmJit.methodTraceSupport ?
3249 TEMPLATE_INVOKE_METHOD_PREDICTED_CHAIN_PROF :
3250 TEMPLATE_INVOKE_METHOD_PREDICTED_CHAIN);
Ben Cheng38329f52009-07-07 14:19:20 -07003251
3252 /* return through lr - jump to the chaining cell */
3253 genUnconditionalBranch(cUnit, predChainingCell);
3254
3255 /*
3256 * null-check on "this" may have been eliminated, but we still need
3257 * a PC-reconstruction label for stack overflow bailout.
3258 */
3259 if (pcrLabel == NULL) {
3260 int dPC = (int) (cUnit->method->insns + mir->offset);
Carl Shapirofc75f3e2010-12-07 11:43:38 -08003261 pcrLabel = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003262 pcrLabel->opcode = kArmPseudoPCReconstructionCell;
Ben Cheng38329f52009-07-07 14:19:20 -07003263 pcrLabel->operands[0] = dPC;
3264 pcrLabel->operands[1] = mir->offset;
3265 /* Insert the place holder to the growable list */
Ben Cheng00603072010-10-28 11:13:58 -07003266 dvmInsertGrowableList(&cUnit->pcReconstructionList,
3267 (intptr_t) pcrLabel);
Ben Cheng38329f52009-07-07 14:19:20 -07003268 }
3269
3270 /* return through lr+2 - punt to the interpreter */
3271 genUnconditionalBranch(cUnit, pcrLabel);
3272
3273 /*
3274 * return through lr+4 - fully resolve the callee method.
3275 * r1 <- count
3276 * r2 <- &predictedChainCell
3277 * r3 <- this->class
3278 * r4 <- dPC
3279 * r7 <- this->class->vtable
3280 */
3281
3282 /* Save count, &predictedChainCell, and class to high regs first */
Bill Buzbee1465db52009-09-23 17:17:35 -07003283 genRegCopy(cUnit, r8, r1);
3284 genRegCopy(cUnit, r9, r2);
3285 genRegCopy(cUnit, r10, r3);
Ben Cheng38329f52009-07-07 14:19:20 -07003286
Ben Chengba4fc8b2009-06-01 13:00:29 -07003287 /* r0 now contains this->clazz */
Bill Buzbee1465db52009-09-23 17:17:35 -07003288 genRegCopy(cUnit, r0, r3);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003289
3290 /* r1 = BBBB */
3291 loadConstant(cUnit, r1, dInsn->vB);
3292
3293 /* r2 = method (caller) */
3294 loadConstant(cUnit, r2, (int) cUnit->method);
3295
3296 /* r3 = pDvmDex */
3297 loadConstant(cUnit, r3, (int) cUnit->method->clazz->pDvmDex);
3298
Ben Chengbd1326d2010-04-02 15:04:53 -07003299 LOAD_FUNC_ADDR(cUnit, r7,
3300 (intptr_t) dvmFindInterfaceMethodInCache);
Bill Buzbee1465db52009-09-23 17:17:35 -07003301 opReg(cUnit, kOpBlx, r7);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003302 /* r0 = calleeMethod (returned from dvmFindInterfaceMethodInCache */
3303
Ben Cheng09e50c92010-05-02 10:45:32 -07003304 dvmCompilerClobberCallRegs(cUnit);
3305 /* generate a branch over if the interface method is resolved */
buzbee8f8109a2010-08-31 10:16:35 -07003306 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondNe, r0, 0);
Ben Cheng09e50c92010-05-02 10:45:32 -07003307 /*
3308 * calleeMethod == NULL -> throw
3309 */
3310 loadConstant(cUnit, r0,
3311 (int) (cUnit->method->insns + mir->offset));
3312 genDispatchToHandler(cUnit, TEMPLATE_THROW_EXCEPTION_COMMON);
3313 /* noreturn */
3314
3315 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
3316 target->defMask = ENCODE_ALL;
3317 branchOver->generic.target = (LIR *) target;
3318
Bill Buzbee1465db52009-09-23 17:17:35 -07003319 genRegCopy(cUnit, r1, r8);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003320
Ben Cheng38329f52009-07-07 14:19:20 -07003321 /* Check if rechain limit is reached */
buzbee8f8109a2010-08-31 10:16:35 -07003322 ArmLIR *bypassRechaining = genCmpImmBranch(cUnit, kArmCondGt,
3323 r1, 0);
Ben Cheng38329f52009-07-07 14:19:20 -07003324
Ben Chengaf5aa1f2011-01-04 15:37:04 -08003325 LOAD_FUNC_ADDR(cUnit, r7, (int) dvmJitToPatchPredictedChain);
Ben Cheng38329f52009-07-07 14:19:20 -07003326
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003327 genRegCopy(cUnit, r1, r6SELF);
Bill Buzbee1465db52009-09-23 17:17:35 -07003328 genRegCopy(cUnit, r2, r9);
3329 genRegCopy(cUnit, r3, r10);
Ben Cheng38329f52009-07-07 14:19:20 -07003330
3331 /*
3332 * r0 = calleeMethod
3333 * r2 = &predictedChainingCell
3334 * r3 = class
3335 *
3336 * &returnChainingCell has been loaded into r1 but is not needed
3337 * when patching the chaining cell and will be clobbered upon
3338 * returning so it will be reconstructed again.
3339 */
Bill Buzbee1465db52009-09-23 17:17:35 -07003340 opReg(cUnit, kOpBlx, r7);
Ben Cheng38329f52009-07-07 14:19:20 -07003341
3342 /* r1 = &retChainingCell */
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003343 addrRetChain = opRegRegImm(cUnit, kOpAdd, r1, r15pc, 0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003344 addrRetChain->generic.target = (LIR *) retChainingCell;
Ben Cheng38329f52009-07-07 14:19:20 -07003345
3346 bypassRechaining->generic.target = (LIR *) addrRetChain;
3347
Ben Chengba4fc8b2009-06-01 13:00:29 -07003348 /*
3349 * r0 = this, r1 = calleeMethod,
3350 * r1 = &ChainingCell,
3351 * r4PC = callsiteDPC,
3352 */
buzbee18fba342011-01-19 15:31:15 -08003353 genDispatchToHandler(cUnit, gDvmJit.methodTraceSupport ?
3354 TEMPLATE_INVOKE_METHOD_NO_OPT_PROF :
3355 TEMPLATE_INVOKE_METHOD_NO_OPT);
Ben Cheng978738d2010-05-13 13:45:57 -07003356#if defined(WITH_JIT_TUNING)
Ben Cheng86717f72010-03-05 15:27:21 -08003357 gDvmJit.invokePolymorphic++;
Ben Chengba4fc8b2009-06-01 13:00:29 -07003358#endif
3359 /* Handle exceptions using the interpreter */
3360 genTrap(cUnit, mir->offset, pcrLabel);
3361 break;
3362 }
buzbeebd7865b2011-03-31 10:55:04 -07003363 case OP_INVOKE_OBJECT_INIT_JUMBO:
3364 case OP_INVOKE_OBJECT_INIT_RANGE:
Ben Chengba4fc8b2009-06-01 13:00:29 -07003365 case OP_FILLED_NEW_ARRAY:
jeffhao71eee1f2011-01-04 14:18:54 -08003366 case OP_FILLED_NEW_ARRAY_RANGE:
3367 case OP_FILLED_NEW_ARRAY_JUMBO: {
Ben Chengba4fc8b2009-06-01 13:00:29 -07003368 /* Just let the interpreter deal with these */
3369 genInterpSingleStep(cUnit, mir);
3370 break;
3371 }
3372 default:
3373 return true;
3374 }
3375 return false;
3376}
3377
3378static bool handleFmt35ms_3rms(CompilationUnit *cUnit, MIR *mir,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003379 BasicBlock *bb, ArmLIR *labelList)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003380{
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003381 ArmLIR *pcrLabel = NULL;
Ben Chengba4fc8b2009-06-01 13:00:29 -07003382
Ben Cheng7a2697d2010-06-07 13:44:23 -07003383 /* An invoke with the MIR_INLINED is effectively a no-op */
3384 if (mir->OptimizationFlags & MIR_INLINED)
3385 return false;
3386
Ben Chengba4fc8b2009-06-01 13:00:29 -07003387 DecodedInstruction *dInsn = &mir->dalvikInsn;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003388 switch (mir->dalvikInsn.opcode) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07003389 /* calleeMethod = this->clazz->vtable[BBBB] */
3390 case OP_INVOKE_VIRTUAL_QUICK_RANGE:
3391 case OP_INVOKE_VIRTUAL_QUICK: {
3392 int methodIndex = dInsn->vB;
Bill Buzbeea8589332010-12-27 09:31:21 -08003393 ArmLIR *retChainingCell = &labelList[bb->fallThrough->id];
3394 ArmLIR *predChainingCell = &labelList[bb->taken->id];
Ben Cheng7a2697d2010-06-07 13:44:23 -07003395
3396 /*
3397 * If the invoke has non-null misPredBranchOver, we need to generate
3398 * the non-inlined version of the invoke here to handle the
3399 * mispredicted case.
3400 */
3401 if (mir->meta.callsiteInfo->misPredBranchOver) {
3402 genLandingPadForMispredictedCallee(cUnit, mir, bb, labelList);
3403 }
3404
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003405 if (mir->dalvikInsn.opcode == OP_INVOKE_VIRTUAL_QUICK)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003406 genProcessArgsNoRange(cUnit, mir, dInsn, &pcrLabel);
3407 else
3408 genProcessArgsRange(cUnit, mir, dInsn, &pcrLabel);
3409
Ben Chengcfdeca32011-01-14 11:36:46 -08003410
3411 if (mir->OptimizationFlags & MIR_INVOKE_METHOD_JIT) {
3412 const Method *calleeMethod = mir->meta.callsiteInfo->method;
3413 void *calleeAddr = dvmJitGetMethodAddr(calleeMethod->insns);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003414 assert(calleeAddr);
3415 genInvokeVirtualWholeMethod(cUnit, mir, calleeAddr,
3416 retChainingCell);
Ben Chengcfdeca32011-01-14 11:36:46 -08003417 }
3418
Ben Cheng38329f52009-07-07 14:19:20 -07003419 genInvokeVirtualCommon(cUnit, mir, methodIndex,
3420 retChainingCell,
3421 predChainingCell,
3422 pcrLabel);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003423 break;
3424 }
3425 /* calleeMethod = method->clazz->super->vtable[BBBB] */
3426 case OP_INVOKE_SUPER_QUICK:
3427 case OP_INVOKE_SUPER_QUICK_RANGE: {
Ben Cheng7a2697d2010-06-07 13:44:23 -07003428 /* Grab the method ptr directly from what the interpreter sees */
3429 const Method *calleeMethod = mir->meta.callsiteInfo->method;
3430 assert(calleeMethod ==
3431 cUnit->method->clazz->super->vtable[dInsn->vB]);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003432
Dan Bornstein9a1f8162010-12-01 17:02:26 -08003433 if (mir->dalvikInsn.opcode == OP_INVOKE_SUPER_QUICK)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003434 genProcessArgsNoRange(cUnit, mir, dInsn, &pcrLabel);
3435 else
3436 genProcessArgsRange(cUnit, mir, dInsn, &pcrLabel);
3437
3438 /* r0 = calleeMethod */
3439 loadConstant(cUnit, r0, (int) calleeMethod);
3440
Ben Cheng38329f52009-07-07 14:19:20 -07003441 genInvokeSingletonCommon(cUnit, mir, bb, labelList, pcrLabel,
3442 calleeMethod);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003443 break;
3444 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07003445 default:
3446 return true;
3447 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07003448 return false;
3449}
3450
3451/*
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003452 * This operation is complex enough that we'll do it partly inline
3453 * and partly with a handler. NOTE: the handler uses hardcoded
3454 * values for string object offsets and must be revisitied if the
3455 * layout changes.
3456 */
3457static bool genInlinedCompareTo(CompilationUnit *cUnit, MIR *mir)
3458{
3459#if defined(USE_GLOBAL_STRING_DEFS)
Elliott Hughes7e914f12011-01-19 18:18:42 -08003460 return handleExecuteInlineC(cUnit, mir);
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003461#else
3462 ArmLIR *rollback;
Bill Buzbeec6f10662010-02-09 11:16:15 -08003463 RegLocation rlThis = dvmCompilerGetSrc(cUnit, mir, 0);
3464 RegLocation rlComp = dvmCompilerGetSrc(cUnit, mir, 1);
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003465
3466 loadValueDirectFixed(cUnit, rlThis, r0);
3467 loadValueDirectFixed(cUnit, rlComp, r1);
3468 /* Test objects for NULL */
3469 rollback = genNullCheck(cUnit, rlThis.sRegLow, r0, mir->offset, NULL);
3470 genNullCheck(cUnit, rlComp.sRegLow, r1, mir->offset, rollback);
3471 /*
3472 * TUNING: we could check for object pointer equality before invoking
3473 * handler. Unclear whether the gain would be worth the added code size
3474 * expansion.
3475 */
3476 genDispatchToHandler(cUnit, TEMPLATE_STRING_COMPARETO);
Bill Buzbeec6f10662010-02-09 11:16:15 -08003477 storeValue(cUnit, inlinedTarget(cUnit, mir, false),
3478 dvmCompilerGetReturn(cUnit));
Elliott Hughes7e914f12011-01-19 18:18:42 -08003479 return false;
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003480#endif
3481}
3482
Elliott Hughes2bdbcb62010-04-12 14:29:37 -07003483static bool genInlinedFastIndexOf(CompilationUnit *cUnit, MIR *mir)
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003484{
3485#if defined(USE_GLOBAL_STRING_DEFS)
Elliott Hughes7e914f12011-01-19 18:18:42 -08003486 return handleExecuteInlineC(cUnit, mir);
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003487#else
Bill Buzbeec6f10662010-02-09 11:16:15 -08003488 RegLocation rlThis = dvmCompilerGetSrc(cUnit, mir, 0);
3489 RegLocation rlChar = dvmCompilerGetSrc(cUnit, mir, 1);
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003490
3491 loadValueDirectFixed(cUnit, rlThis, r0);
3492 loadValueDirectFixed(cUnit, rlChar, r1);
Elliott Hughes2bdbcb62010-04-12 14:29:37 -07003493 RegLocation rlStart = dvmCompilerGetSrc(cUnit, mir, 2);
3494 loadValueDirectFixed(cUnit, rlStart, r2);
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003495 /* Test objects for NULL */
3496 genNullCheck(cUnit, rlThis.sRegLow, r0, mir->offset, NULL);
3497 genDispatchToHandler(cUnit, TEMPLATE_STRING_INDEXOF);
Bill Buzbeec6f10662010-02-09 11:16:15 -08003498 storeValue(cUnit, inlinedTarget(cUnit, mir, false),
3499 dvmCompilerGetReturn(cUnit));
Elliott Hughes7e914f12011-01-19 18:18:42 -08003500 return false;
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003501#endif
3502}
3503
Elliott Hughesee34f592010-04-05 18:13:52 -07003504// Generates an inlined String.isEmpty or String.length.
3505static bool genInlinedStringIsEmptyOrLength(CompilationUnit *cUnit, MIR *mir,
3506 bool isEmpty)
Bill Buzbee1f748632010-03-02 16:14:41 -08003507{
Elliott Hughesee34f592010-04-05 18:13:52 -07003508 // dst = src.length();
Bill Buzbee1f748632010-03-02 16:14:41 -08003509 RegLocation rlObj = dvmCompilerGetSrc(cUnit, mir, 0);
3510 RegLocation rlDest = inlinedTarget(cUnit, mir, false);
3511 rlObj = loadValue(cUnit, rlObj, kCoreReg);
3512 RegLocation rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
3513 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir->offset, NULL);
3514 loadWordDisp(cUnit, rlObj.lowReg, gDvm.offJavaLangString_count,
3515 rlResult.lowReg);
Elliott Hughesee34f592010-04-05 18:13:52 -07003516 if (isEmpty) {
3517 // dst = (dst == 0);
3518 int tReg = dvmCompilerAllocTemp(cUnit);
3519 opRegReg(cUnit, kOpNeg, tReg, rlResult.lowReg);
3520 opRegRegReg(cUnit, kOpAdc, rlResult.lowReg, rlResult.lowReg, tReg);
3521 }
Bill Buzbee1f748632010-03-02 16:14:41 -08003522 storeValue(cUnit, rlDest, rlResult);
3523 return false;
3524}
3525
Elliott Hughesee34f592010-04-05 18:13:52 -07003526static bool genInlinedStringLength(CompilationUnit *cUnit, MIR *mir)
3527{
3528 return genInlinedStringIsEmptyOrLength(cUnit, mir, false);
3529}
3530
3531static bool genInlinedStringIsEmpty(CompilationUnit *cUnit, MIR *mir)
3532{
3533 return genInlinedStringIsEmptyOrLength(cUnit, mir, true);
3534}
3535
Bill Buzbee1f748632010-03-02 16:14:41 -08003536static bool genInlinedStringCharAt(CompilationUnit *cUnit, MIR *mir)
3537{
3538 int contents = offsetof(ArrayObject, contents);
3539 RegLocation rlObj = dvmCompilerGetSrc(cUnit, mir, 0);
3540 RegLocation rlIdx = dvmCompilerGetSrc(cUnit, mir, 1);
3541 RegLocation rlDest = inlinedTarget(cUnit, mir, false);
3542 RegLocation rlResult;
3543 rlObj = loadValue(cUnit, rlObj, kCoreReg);
3544 rlIdx = loadValue(cUnit, rlIdx, kCoreReg);
3545 int regMax = dvmCompilerAllocTemp(cUnit);
3546 int regOff = dvmCompilerAllocTemp(cUnit);
3547 int regPtr = dvmCompilerAllocTemp(cUnit);
3548 ArmLIR *pcrLabel = genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg,
3549 mir->offset, NULL);
3550 loadWordDisp(cUnit, rlObj.lowReg, gDvm.offJavaLangString_count, regMax);
3551 loadWordDisp(cUnit, rlObj.lowReg, gDvm.offJavaLangString_offset, regOff);
3552 loadWordDisp(cUnit, rlObj.lowReg, gDvm.offJavaLangString_value, regPtr);
3553 genBoundsCheck(cUnit, rlIdx.lowReg, regMax, mir->offset, pcrLabel);
3554 dvmCompilerFreeTemp(cUnit, regMax);
3555 opRegImm(cUnit, kOpAdd, regPtr, contents);
3556 opRegReg(cUnit, kOpAdd, regOff, rlIdx.lowReg);
3557 rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
3558 loadBaseIndexed(cUnit, regPtr, regOff, rlResult.lowReg, 1, kUnsignedHalf);
3559 storeValue(cUnit, rlDest, rlResult);
3560 return false;
3561}
3562
3563static bool genInlinedAbsInt(CompilationUnit *cUnit, MIR *mir)
3564{
3565 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
3566 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Elliott Hughese22bd842010-08-20 18:47:36 -07003567 RegLocation rlDest = inlinedTarget(cUnit, mir, false);
Bill Buzbee1f748632010-03-02 16:14:41 -08003568 RegLocation rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
3569 int signReg = dvmCompilerAllocTemp(cUnit);
3570 /*
3571 * abs(x) = y<=x>>31, (x+y)^y.
3572 * Thumb2's IT block also yields 3 instructions, but imposes
3573 * scheduling constraints.
3574 */
3575 opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.lowReg, 31);
3576 opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg);
3577 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
3578 storeValue(cUnit, rlDest, rlResult);
3579 return false;
3580}
3581
3582static bool genInlinedAbsLong(CompilationUnit *cUnit, MIR *mir)
3583{
3584 RegLocation rlSrc = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
3585 RegLocation rlDest = inlinedTargetWide(cUnit, mir, false);
3586 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
3587 RegLocation rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
3588 int signReg = dvmCompilerAllocTemp(cUnit);
3589 /*
3590 * abs(x) = y<=x>>31, (x+y)^y.
3591 * Thumb2 IT block allows slightly shorter sequence,
3592 * but introduces a scheduling barrier. Stick with this
3593 * mechanism for now.
3594 */
3595 opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.highReg, 31);
3596 opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg);
3597 opRegRegReg(cUnit, kOpAdc, rlResult.highReg, rlSrc.highReg, signReg);
3598 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
3599 opRegReg(cUnit, kOpXor, rlResult.highReg, signReg);
3600 storeValueWide(cUnit, rlDest, rlResult);
3601 return false;
3602}
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003603
Elliott Hughese22bd842010-08-20 18:47:36 -07003604static bool genInlinedIntFloatConversion(CompilationUnit *cUnit, MIR *mir)
3605{
3606 // Just move from source to destination...
3607 RegLocation rlSrc = dvmCompilerGetSrc(cUnit, mir, 0);
3608 RegLocation rlDest = inlinedTarget(cUnit, mir, false);
3609 storeValue(cUnit, rlDest, rlSrc);
3610 return false;
3611}
3612
3613static bool genInlinedLongDoubleConversion(CompilationUnit *cUnit, MIR *mir)
3614{
3615 // Just move from source to destination...
3616 RegLocation rlSrc = dvmCompilerGetSrcWide(cUnit, mir, 0, 1);
3617 RegLocation rlDest = inlinedTargetWide(cUnit, mir, false);
3618 storeValueWide(cUnit, rlDest, rlSrc);
3619 return false;
3620}
3621
Bill Buzbeefd023aa2009-11-02 09:23:49 -08003622/*
Elliott Hughes7e914f12011-01-19 18:18:42 -08003623 * JITs a call to a C function.
3624 * TODO: use this for faster native method invocation for simple native
3625 * methods (http://b/3069458).
3626 */
3627static bool handleExecuteInlineC(CompilationUnit *cUnit, MIR *mir)
3628{
3629 DecodedInstruction *dInsn = &mir->dalvikInsn;
3630 int operation = dInsn->vB;
3631 unsigned int i;
3632 const InlineOperation* inLineTable = dvmGetInlineOpsTable();
3633 uintptr_t fn = (int) inLineTable[operation].func;
3634 if (fn == 0) {
3635 dvmCompilerAbort(cUnit);
3636 }
3637 dvmCompilerFlushAllRegs(cUnit); /* Everything to home location */
3638 dvmCompilerClobberCallRegs(cUnit);
3639 dvmCompilerClobber(cUnit, r4PC);
3640 dvmCompilerClobber(cUnit, r7);
buzbee9f601a92011-02-11 17:48:20 -08003641 int offset = offsetof(Thread, retval);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003642 opRegRegImm(cUnit, kOpAdd, r4PC, r6SELF, offset);
Elliott Hughes7e914f12011-01-19 18:18:42 -08003643 opImm(cUnit, kOpPush, (1<<r4PC) | (1<<r7));
3644 LOAD_FUNC_ADDR(cUnit, r4PC, fn);
3645 genExportPC(cUnit, mir);
3646 for (i=0; i < dInsn->vA; i++) {
3647 loadValueDirect(cUnit, dvmCompilerGetSrc(cUnit, mir, i), i);
3648 }
3649 opReg(cUnit, kOpBlx, r4PC);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003650 opRegImm(cUnit, kOpAdd, r13sp, 8);
Elliott Hughes7e914f12011-01-19 18:18:42 -08003651 /* NULL? */
3652 ArmLIR *branchOver = genCmpImmBranch(cUnit, kArmCondNe, r0, 0);
3653 loadConstant(cUnit, r0, (int) (cUnit->method->insns + mir->offset));
3654 genDispatchToHandler(cUnit, TEMPLATE_THROW_EXCEPTION_COMMON);
3655 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
3656 target->defMask = ENCODE_ALL;
3657 branchOver->generic.target = (LIR *) target;
3658 return false;
3659}
3660
3661/*
Bill Buzbeece46c942009-11-20 15:41:34 -08003662 * NOTE: Handles both range and non-range versions (arguments
3663 * have already been normalized by this point).
Ben Chengba4fc8b2009-06-01 13:00:29 -07003664 */
Bill Buzbeece46c942009-11-20 15:41:34 -08003665static bool handleExecuteInline(CompilationUnit *cUnit, MIR *mir)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003666{
3667 DecodedInstruction *dInsn = &mir->dalvikInsn;
Elliott Hughes7e914f12011-01-19 18:18:42 -08003668 assert(dInsn->opcode == OP_EXECUTE_INLINE_RANGE ||
3669 dInsn->opcode == OP_EXECUTE_INLINE);
3670 switch (dInsn->vB) {
3671 case INLINE_EMPTYINLINEMETHOD:
3672 return false; /* Nop */
3673
3674 /* These ones we potentially JIT inline. */
3675 case INLINE_STRING_LENGTH:
3676 return genInlinedStringLength(cUnit, mir);
3677 case INLINE_STRING_IS_EMPTY:
3678 return genInlinedStringIsEmpty(cUnit, mir);
3679 case INLINE_MATH_ABS_INT:
3680 return genInlinedAbsInt(cUnit, mir);
3681 case INLINE_MATH_ABS_LONG:
3682 return genInlinedAbsLong(cUnit, mir);
3683 case INLINE_MATH_MIN_INT:
3684 return genInlinedMinMaxInt(cUnit, mir, true);
3685 case INLINE_MATH_MAX_INT:
3686 return genInlinedMinMaxInt(cUnit, mir, false);
3687 case INLINE_STRING_CHARAT:
3688 return genInlinedStringCharAt(cUnit, mir);
3689 case INLINE_MATH_SQRT:
3690 return genInlineSqrt(cUnit, mir);
3691 case INLINE_MATH_ABS_FLOAT:
3692 return genInlinedAbsFloat(cUnit, mir);
3693 case INLINE_MATH_ABS_DOUBLE:
3694 return genInlinedAbsDouble(cUnit, mir);
3695 case INLINE_STRING_COMPARETO:
3696 return genInlinedCompareTo(cUnit, mir);
3697 case INLINE_STRING_FASTINDEXOF_II:
3698 return genInlinedFastIndexOf(cUnit, mir);
3699 case INLINE_FLOAT_TO_RAW_INT_BITS:
3700 case INLINE_INT_BITS_TO_FLOAT:
3701 return genInlinedIntFloatConversion(cUnit, mir);
3702 case INLINE_DOUBLE_TO_RAW_LONG_BITS:
3703 case INLINE_LONG_BITS_TO_DOUBLE:
3704 return genInlinedLongDoubleConversion(cUnit, mir);
3705
3706 /*
3707 * These ones we just JIT a call to a C function for.
3708 * TODO: special-case these in the other "invoke" call paths.
3709 */
3710 case INLINE_STRING_EQUALS:
3711 case INLINE_MATH_COS:
3712 case INLINE_MATH_SIN:
3713 case INLINE_FLOAT_TO_INT_BITS:
3714 case INLINE_DOUBLE_TO_LONG_BITS:
3715 return handleExecuteInlineC(cUnit, mir);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003716 }
Elliott Hughes7e914f12011-01-19 18:18:42 -08003717 dvmCompilerAbort(cUnit);
3718 return false; // Not reachable; keeps compiler happy.
Ben Chengba4fc8b2009-06-01 13:00:29 -07003719}
3720
3721static bool handleFmt51l(CompilationUnit *cUnit, MIR *mir)
3722{
Bill Buzbee1465db52009-09-23 17:17:35 -07003723 //TUNING: We're using core regs here - not optimal when target is a double
Bill Buzbeec6f10662010-02-09 11:16:15 -08003724 RegLocation rlDest = dvmCompilerGetDestWide(cUnit, mir, 0, 1);
3725 RegLocation rlResult = dvmCompilerEvalLoc(cUnit, rlDest, kCoreReg, true);
Ben Chengbd1326d2010-04-02 15:04:53 -07003726 loadConstantNoClobber(cUnit, rlResult.lowReg,
3727 mir->dalvikInsn.vB_wide & 0xFFFFFFFFUL);
3728 loadConstantNoClobber(cUnit, rlResult.highReg,
3729 (mir->dalvikInsn.vB_wide>>32) & 0xFFFFFFFFUL);
Bill Buzbee1465db52009-09-23 17:17:35 -07003730 storeValueWide(cUnit, rlDest, rlResult);
Ben Chengba4fc8b2009-06-01 13:00:29 -07003731 return false;
3732}
3733
Ben Chengba4fc8b2009-06-01 13:00:29 -07003734/*
3735 * The following are special processing routines that handle transfer of
3736 * controls between compiled code and the interpreter. Certain VM states like
3737 * Dalvik PC and special-purpose registers are reconstructed here.
3738 */
3739
Bill Buzbeebd047242010-05-13 13:02:53 -07003740/*
3741 * Insert a
3742 * b .+4
3743 * nop
3744 * pair at the beginning of a chaining cell. This serves as the
3745 * switch branch that selects between reverting to the interpreter or
3746 * not. Once the cell is chained to a translation, the cell will
3747 * contain a 32-bit branch. Subsequent chain/unchain operations will
3748 * then only alter that first 16-bits - the "b .+4" for unchaining,
3749 * and the restoration of the first half of the 32-bit branch for
3750 * rechaining.
3751 */
3752static void insertChainingSwitch(CompilationUnit *cUnit)
3753{
3754 ArmLIR *branch = newLIR0(cUnit, kThumbBUncond);
3755 newLIR2(cUnit, kThumbOrr, r0, r0);
3756 ArmLIR *target = newLIR0(cUnit, kArmPseudoTargetLabel);
3757 target->defMask = ENCODE_ALL;
3758 branch->generic.target = (LIR *) target;
3759}
3760
Ben Cheng1efc9c52009-06-08 18:25:27 -07003761/* Chaining cell for code that may need warmup. */
3762static void handleNormalChainingCell(CompilationUnit *cUnit,
3763 unsigned int offset)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003764{
Ben Cheng11d8f142010-03-24 15:24:19 -07003765 /*
3766 * Use raw instruction constructors to guarantee that the generated
3767 * instructions fit the predefined cell size.
3768 */
Bill Buzbeebd047242010-05-13 13:02:53 -07003769 insertChainingSwitch(cUnit);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003770 newLIR3(cUnit, kThumbLdrRRI5, r0, r6SELF,
buzbee9f601a92011-02-11 17:48:20 -08003771 offsetof(Thread,
Ben Cheng11d8f142010-03-24 15:24:19 -07003772 jitToInterpEntries.dvmJitToInterpNormal) >> 2);
3773 newLIR1(cUnit, kThumbBlxR, r0);
Ben Cheng385828e2011-03-04 16:48:33 -08003774 addWordData(cUnit, NULL, (int) (cUnit->method->insns + offset));
Ben Chengba4fc8b2009-06-01 13:00:29 -07003775}
3776
3777/*
Ben Cheng1efc9c52009-06-08 18:25:27 -07003778 * Chaining cell for instructions that immediately following already translated
3779 * code.
Ben Chengba4fc8b2009-06-01 13:00:29 -07003780 */
Ben Cheng1efc9c52009-06-08 18:25:27 -07003781static void handleHotChainingCell(CompilationUnit *cUnit,
3782 unsigned int offset)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003783{
Ben Cheng11d8f142010-03-24 15:24:19 -07003784 /*
3785 * Use raw instruction constructors to guarantee that the generated
3786 * instructions fit the predefined cell size.
3787 */
Bill Buzbeebd047242010-05-13 13:02:53 -07003788 insertChainingSwitch(cUnit);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003789 newLIR3(cUnit, kThumbLdrRRI5, r0, r6SELF,
buzbee9f601a92011-02-11 17:48:20 -08003790 offsetof(Thread,
Ben Cheng11d8f142010-03-24 15:24:19 -07003791 jitToInterpEntries.dvmJitToInterpTraceSelect) >> 2);
3792 newLIR1(cUnit, kThumbBlxR, r0);
Ben Cheng385828e2011-03-04 16:48:33 -08003793 addWordData(cUnit, NULL, (int) (cUnit->method->insns + offset));
Ben Chengba4fc8b2009-06-01 13:00:29 -07003794}
3795
Jeff Hao97319a82009-08-12 16:57:15 -07003796/* Chaining cell for branches that branch back into the same basic block */
3797static void handleBackwardBranchChainingCell(CompilationUnit *cUnit,
3798 unsigned int offset)
3799{
Ben Cheng11d8f142010-03-24 15:24:19 -07003800 /*
3801 * Use raw instruction constructors to guarantee that the generated
3802 * instructions fit the predefined cell size.
3803 */
Bill Buzbeebd047242010-05-13 13:02:53 -07003804 insertChainingSwitch(cUnit);
Bill Buzbee9c4b7c82009-09-10 10:10:38 -07003805#if defined(WITH_SELF_VERIFICATION)
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003806 newLIR3(cUnit, kThumbLdrRRI5, r0, r6SELF,
buzbee9f601a92011-02-11 17:48:20 -08003807 offsetof(Thread,
Ben Cheng40094c12010-02-24 20:58:44 -08003808 jitToInterpEntries.dvmJitToInterpBackwardBranch) >> 2);
Bill Buzbee9c4b7c82009-09-10 10:10:38 -07003809#else
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003810 newLIR3(cUnit, kThumbLdrRRI5, r0, r6SELF,
buzbee9f601a92011-02-11 17:48:20 -08003811 offsetof(Thread, jitToInterpEntries.dvmJitToInterpNormal) >> 2);
Bill Buzbee9c4b7c82009-09-10 10:10:38 -07003812#endif
Bill Buzbee1465db52009-09-23 17:17:35 -07003813 newLIR1(cUnit, kThumbBlxR, r0);
Ben Cheng385828e2011-03-04 16:48:33 -08003814 addWordData(cUnit, NULL, (int) (cUnit->method->insns + offset));
Jeff Hao97319a82009-08-12 16:57:15 -07003815}
3816
Ben Chengba4fc8b2009-06-01 13:00:29 -07003817/* Chaining cell for monomorphic method invocations. */
Ben Cheng38329f52009-07-07 14:19:20 -07003818static void handleInvokeSingletonChainingCell(CompilationUnit *cUnit,
3819 const Method *callee)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003820{
Ben Cheng11d8f142010-03-24 15:24:19 -07003821 /*
3822 * Use raw instruction constructors to guarantee that the generated
3823 * instructions fit the predefined cell size.
3824 */
Bill Buzbeebd047242010-05-13 13:02:53 -07003825 insertChainingSwitch(cUnit);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08003826 newLIR3(cUnit, kThumbLdrRRI5, r0, r6SELF,
buzbee9f601a92011-02-11 17:48:20 -08003827 offsetof(Thread,
Ben Cheng11d8f142010-03-24 15:24:19 -07003828 jitToInterpEntries.dvmJitToInterpTraceSelect) >> 2);
3829 newLIR1(cUnit, kThumbBlxR, r0);
Ben Cheng385828e2011-03-04 16:48:33 -08003830 addWordData(cUnit, NULL, (int) (callee->insns));
Ben Chengba4fc8b2009-06-01 13:00:29 -07003831}
3832
Ben Cheng38329f52009-07-07 14:19:20 -07003833/* Chaining cell for monomorphic method invocations. */
3834static void handleInvokePredictedChainingCell(CompilationUnit *cUnit)
3835{
3836
3837 /* Should not be executed in the initial state */
Ben Cheng385828e2011-03-04 16:48:33 -08003838 addWordData(cUnit, NULL, PREDICTED_CHAIN_BX_PAIR_INIT);
Ben Cheng38329f52009-07-07 14:19:20 -07003839 /* To be filled: class */
Ben Cheng385828e2011-03-04 16:48:33 -08003840 addWordData(cUnit, NULL, PREDICTED_CHAIN_CLAZZ_INIT);
Ben Cheng38329f52009-07-07 14:19:20 -07003841 /* To be filled: method */
Ben Cheng385828e2011-03-04 16:48:33 -08003842 addWordData(cUnit, NULL, PREDICTED_CHAIN_METHOD_INIT);
Ben Cheng38329f52009-07-07 14:19:20 -07003843 /*
3844 * Rechain count. The initial value of 0 here will trigger chaining upon
3845 * the first invocation of this callsite.
3846 */
Ben Cheng385828e2011-03-04 16:48:33 -08003847 addWordData(cUnit, NULL, PREDICTED_CHAIN_COUNTER_INIT);
Ben Cheng38329f52009-07-07 14:19:20 -07003848}
3849
Ben Chengba4fc8b2009-06-01 13:00:29 -07003850/* Load the Dalvik PC into r0 and jump to the specified target */
3851static void handlePCReconstruction(CompilationUnit *cUnit,
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003852 ArmLIR *targetLabel)
Ben Chengba4fc8b2009-06-01 13:00:29 -07003853{
Bill Buzbee89efc3d2009-07-28 11:22:22 -07003854 ArmLIR **pcrLabel =
3855 (ArmLIR **) cUnit->pcReconstructionList.elemList;
Ben Chengba4fc8b2009-06-01 13:00:29 -07003856 int numElems = cUnit->pcReconstructionList.numUsed;
3857 int i;
3858 for (i = 0; i < numElems; i++) {
3859 dvmCompilerAppendLIR(cUnit, (LIR *) pcrLabel[i]);
3860 /* r0 = dalvik PC */
3861 loadConstant(cUnit, r0, pcrLabel[i]->operands[0]);
3862 genUnconditionalBranch(cUnit, targetLabel);
3863 }
3864}
3865
Bill Buzbee1465db52009-09-23 17:17:35 -07003866static char *extendedMIROpNames[kMirOpLast - kMirOpFirst] = {
3867 "kMirOpPhi",
3868 "kMirOpNullNRangeUpCheck",
3869 "kMirOpNullNRangeDownCheck",
3870 "kMirOpLowerBound",
3871 "kMirOpPunt",
Ben Cheng7a2697d2010-06-07 13:44:23 -07003872 "kMirOpCheckInlinePrediction",
Ben Cheng4238ec22009-08-24 16:32:22 -07003873};
3874
3875/*
3876 * vA = arrayReg;
3877 * vB = idxReg;
3878 * vC = endConditionReg;
3879 * arg[0] = maxC
3880 * arg[1] = minC
3881 * arg[2] = loopBranchConditionCode
3882 */
3883static void genHoistedChecksForCountUpLoop(CompilationUnit *cUnit, MIR *mir)
3884{
Bill Buzbee1465db52009-09-23 17:17:35 -07003885 /*
3886 * NOTE: these synthesized blocks don't have ssa names assigned
3887 * for Dalvik registers. However, because they dominate the following
3888 * blocks we can simply use the Dalvik name w/ subscript 0 as the
3889 * ssa name.
3890 */
Ben Cheng4238ec22009-08-24 16:32:22 -07003891 DecodedInstruction *dInsn = &mir->dalvikInsn;
3892 const int lenOffset = offsetof(ArrayObject, length);
Ben Cheng4238ec22009-08-24 16:32:22 -07003893 const int maxC = dInsn->arg[0];
Bill Buzbee1465db52009-09-23 17:17:35 -07003894 int regLength;
3895 RegLocation rlArray = cUnit->regLocation[mir->dalvikInsn.vA];
3896 RegLocation rlIdxEnd = cUnit->regLocation[mir->dalvikInsn.vC];
Ben Cheng4238ec22009-08-24 16:32:22 -07003897
3898 /* regArray <- arrayRef */
Bill Buzbee1465db52009-09-23 17:17:35 -07003899 rlArray = loadValue(cUnit, rlArray, kCoreReg);
3900 rlIdxEnd = loadValue(cUnit, rlIdxEnd, kCoreReg);
3901 genRegImmCheck(cUnit, kArmCondEq, rlArray.lowReg, 0, 0,
Ben Cheng4238ec22009-08-24 16:32:22 -07003902 (ArmLIR *) cUnit->loopAnalysis->branchToPCR);
3903
3904 /* regLength <- len(arrayRef) */
Bill Buzbeec6f10662010-02-09 11:16:15 -08003905 regLength = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07003906 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLength);
Ben Cheng4238ec22009-08-24 16:32:22 -07003907
3908 int delta = maxC;
3909 /*
3910 * If the loop end condition is ">=" instead of ">", then the largest value
3911 * of the index is "endCondition - 1".
3912 */
3913 if (dInsn->arg[2] == OP_IF_GE) {
3914 delta--;
3915 }
3916
3917 if (delta) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08003918 int tReg = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07003919 opRegRegImm(cUnit, kOpAdd, tReg, rlIdxEnd.lowReg, delta);
3920 rlIdxEnd.lowReg = tReg;
Bill Buzbeec6f10662010-02-09 11:16:15 -08003921 dvmCompilerFreeTemp(cUnit, tReg);
Ben Cheng4238ec22009-08-24 16:32:22 -07003922 }
3923 /* Punt if "regIdxEnd < len(Array)" is false */
Bill Buzbee1465db52009-09-23 17:17:35 -07003924 genRegRegCheck(cUnit, kArmCondGe, rlIdxEnd.lowReg, regLength, 0,
Ben Cheng0fd31e42009-09-03 14:40:16 -07003925 (ArmLIR *) cUnit->loopAnalysis->branchToPCR);
Ben Cheng4238ec22009-08-24 16:32:22 -07003926}
3927
3928/*
3929 * vA = arrayReg;
3930 * vB = idxReg;
3931 * vC = endConditionReg;
3932 * arg[0] = maxC
3933 * arg[1] = minC
3934 * arg[2] = loopBranchConditionCode
3935 */
3936static void genHoistedChecksForCountDownLoop(CompilationUnit *cUnit, MIR *mir)
3937{
3938 DecodedInstruction *dInsn = &mir->dalvikInsn;
3939 const int lenOffset = offsetof(ArrayObject, length);
Bill Buzbeec6f10662010-02-09 11:16:15 -08003940 const int regLength = dvmCompilerAllocTemp(cUnit);
Ben Cheng4238ec22009-08-24 16:32:22 -07003941 const int maxC = dInsn->arg[0];
Bill Buzbee1465db52009-09-23 17:17:35 -07003942 RegLocation rlArray = cUnit->regLocation[mir->dalvikInsn.vA];
3943 RegLocation rlIdxInit = cUnit->regLocation[mir->dalvikInsn.vB];
Ben Cheng4238ec22009-08-24 16:32:22 -07003944
3945 /* regArray <- arrayRef */
Bill Buzbee1465db52009-09-23 17:17:35 -07003946 rlArray = loadValue(cUnit, rlArray, kCoreReg);
3947 rlIdxInit = loadValue(cUnit, rlIdxInit, kCoreReg);
3948 genRegImmCheck(cUnit, kArmCondEq, rlArray.lowReg, 0, 0,
Ben Cheng4238ec22009-08-24 16:32:22 -07003949 (ArmLIR *) cUnit->loopAnalysis->branchToPCR);
3950
3951 /* regLength <- len(arrayRef) */
Bill Buzbee1465db52009-09-23 17:17:35 -07003952 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLength);
Ben Cheng4238ec22009-08-24 16:32:22 -07003953
3954 if (maxC) {
Bill Buzbeec6f10662010-02-09 11:16:15 -08003955 int tReg = dvmCompilerAllocTemp(cUnit);
Bill Buzbee1465db52009-09-23 17:17:35 -07003956 opRegRegImm(cUnit, kOpAdd, tReg, rlIdxInit.lowReg, maxC);
3957 rlIdxInit.lowReg = tReg;
Bill Buzbeec6f10662010-02-09 11:16:15 -08003958 dvmCompilerFreeTemp(cUnit, tReg);
Ben Cheng4238ec22009-08-24 16:32:22 -07003959 }
3960
3961 /* Punt if "regIdxInit < len(Array)" is false */
Bill Buzbee1465db52009-09-23 17:17:35 -07003962 genRegRegCheck(cUnit, kArmCondGe, rlIdxInit.lowReg, regLength, 0,
Ben Cheng0fd31e42009-09-03 14:40:16 -07003963 (ArmLIR *) cUnit->loopAnalysis->branchToPCR);
Ben Cheng4238ec22009-08-24 16:32:22 -07003964}
3965
3966/*
3967 * vA = idxReg;
3968 * vB = minC;
3969 */
3970static void genHoistedLowerBoundCheck(CompilationUnit *cUnit, MIR *mir)
3971{
3972 DecodedInstruction *dInsn = &mir->dalvikInsn;
Ben Cheng4238ec22009-08-24 16:32:22 -07003973 const int minC = dInsn->vB;
Bill Buzbee1465db52009-09-23 17:17:35 -07003974 RegLocation rlIdx = cUnit->regLocation[mir->dalvikInsn.vA];
Ben Cheng4238ec22009-08-24 16:32:22 -07003975
3976 /* regIdx <- initial index value */
Bill Buzbee1465db52009-09-23 17:17:35 -07003977 rlIdx = loadValue(cUnit, rlIdx, kCoreReg);
Ben Cheng4238ec22009-08-24 16:32:22 -07003978
3979 /* Punt if "regIdxInit + minC >= 0" is false */
Bill Buzbee1465db52009-09-23 17:17:35 -07003980 genRegImmCheck(cUnit, kArmCondLt, rlIdx.lowReg, -minC, 0,
Ben Cheng4238ec22009-08-24 16:32:22 -07003981 (ArmLIR *) cUnit->loopAnalysis->branchToPCR);
3982}
3983
Ben Cheng7a2697d2010-06-07 13:44:23 -07003984/*
3985 * vC = this
3986 *
3987 * A predicted inlining target looks like the following, where instructions
3988 * between 0x4858de66 and 0x4858de72 are checking if the predicted class
3989 * matches "this", and the verificaion code is generated by this routine.
3990 *
3991 * (C) means the instruction is inlined from the callee, and (PI) means the
3992 * instruction is the predicted inlined invoke, whose corresponding
3993 * instructions are still generated to handle the mispredicted case.
3994 *
3995 * D/dalvikvm( 86): -------- kMirOpCheckInlinePrediction
3996 * D/dalvikvm( 86): 0x4858de66 (0002): ldr r0, [r5, #68]
3997 * D/dalvikvm( 86): 0x4858de68 (0004): ldr r1, [pc, #140]
3998 * D/dalvikvm( 86): 0x4858de6a (0006): cmp r0, #0
3999 * D/dalvikvm( 86): 0x4858de6c (0008): beq 0x4858deb2
4000 * D/dalvikvm( 86): 0x4858de6e (000a): ldr r2, [r0, #0]
4001 * D/dalvikvm( 86): 0x4858de70 (000c): cmp r1, r2
4002 * D/dalvikvm( 86): 0x4858de72 (000e): bne 0x4858de7a
4003 * D/dalvikvm( 86): -------- dalvik offset: 0x004c @ +iget-object-quick (C)
4004 * v4, v17, (#8)
4005 * D/dalvikvm( 86): 0x4858de74 (0010): ldr r3, [r0, #8]
4006 * D/dalvikvm( 86): 0x4858de76 (0012): str r3, [r5, #16]
4007 * D/dalvikvm( 86): -------- dalvik offset: 0x004c @
4008 * +invoke-virtual-quick/range (PI) v17..v17
4009 * D/dalvikvm( 86): 0x4858de78 (0014): b 0x4858debc
4010 * D/dalvikvm( 86): 0x4858de7a (0016): add r4,r5,#68
4011 * D/dalvikvm( 86): -------- BARRIER
4012 * D/dalvikvm( 86): 0x4858de7e (001a): ldmia r4, <r0>
4013 * D/dalvikvm( 86): -------- BARRIER
4014 * D/dalvikvm( 86): 0x4858de80 (001c): sub r7,r5,#24
4015 * D/dalvikvm( 86): 0x4858de84 (0020): cmp r0, #0
4016 * D/dalvikvm( 86): 0x4858de86 (0022): beq 0x4858deb6
4017 * D/dalvikvm( 86): -------- BARRIER
4018 * D/dalvikvm( 86): 0x4858de88 (0024): stmia r7, <r0>
4019 * D/dalvikvm( 86): -------- BARRIER
4020 * D/dalvikvm( 86): 0x4858de8a (0026): ldr r4, [pc, #104]
4021 * D/dalvikvm( 86): 0x4858de8c (0028): add r1, pc, #28
4022 * D/dalvikvm( 86): 0x4858de8e (002a): add r2, pc, #56
4023 * D/dalvikvm( 86): 0x4858de90 (002c): blx_1 0x48589198
4024 * D/dalvikvm( 86): 0x4858de92 (002e): blx_2 see above
4025 * D/dalvikvm( 86): 0x4858de94 (0030): b 0x4858dec8
4026 * D/dalvikvm( 86): 0x4858de96 (0032): b 0x4858deb6
4027 * D/dalvikvm( 86): 0x4858de98 (0034): ldr r0, [r7, #72]
4028 * D/dalvikvm( 86): 0x4858de9a (0036): cmp r1, #0
4029 * D/dalvikvm( 86): 0x4858de9c (0038): bgt 0x4858dea4
4030 * D/dalvikvm( 86): 0x4858de9e (003a): ldr r7, [r6, #116]
4031 * D/dalvikvm( 86): 0x4858dea0 (003c): movs r1, r6
4032 * D/dalvikvm( 86): 0x4858dea2 (003e): blx r7
4033 * D/dalvikvm( 86): 0x4858dea4 (0040): add r1, pc, #4
4034 * D/dalvikvm( 86): 0x4858dea6 (0042): blx_1 0x485890a0
4035 * D/dalvikvm( 86): 0x4858dea8 (0044): blx_2 see above
4036 * D/dalvikvm( 86): 0x4858deaa (0046): b 0x4858deb6
4037 * D/dalvikvm( 86): 0x4858deac (0048): .align4
4038 * D/dalvikvm( 86): L0x004f:
4039 * D/dalvikvm( 86): -------- dalvik offset: 0x004f @ move-result-object (PI)
4040 * v4, (#0), (#0)
4041 * D/dalvikvm( 86): 0x4858deac (0048): ldr r4, [r6, #8]
4042 * D/dalvikvm( 86): 0x4858deae (004a): str r4, [r5, #16]
4043 * D/dalvikvm( 86): 0x4858deb0 (004c): b 0x4858debc
4044 * D/dalvikvm( 86): -------- reconstruct dalvik PC : 0x42beefcc @ +0x004c
4045 * D/dalvikvm( 86): 0x4858deb2 (004e): ldr r0, [pc, #64]
4046 * D/dalvikvm( 86): 0x4858deb4 (0050): b 0x4858deb8
4047 * D/dalvikvm( 86): -------- reconstruct dalvik PC : 0x42beefcc @ +0x004c
4048 * D/dalvikvm( 86): 0x4858deb6 (0052): ldr r0, [pc, #60]
4049 * D/dalvikvm( 86): Exception_Handling:
4050 * D/dalvikvm( 86): 0x4858deb8 (0054): ldr r1, [r6, #100]
4051 * D/dalvikvm( 86): 0x4858deba (0056): blx r1
4052 * D/dalvikvm( 86): 0x4858debc (0058): .align4
4053 * D/dalvikvm( 86): -------- chaining cell (hot): 0x0050
4054 * D/dalvikvm( 86): 0x4858debc (0058): b 0x4858dec0
4055 * D/dalvikvm( 86): 0x4858debe (005a): orrs r0, r0
4056 * D/dalvikvm( 86): 0x4858dec0 (005c): ldr r0, [r6, #112]
4057 * D/dalvikvm( 86): 0x4858dec2 (005e): blx r0
4058 * D/dalvikvm( 86): 0x4858dec4 (0060): data 0xefd4(61396)
4059 * D/dalvikvm( 86): 0x4858dec6 (0062): data 0x42be(17086)
4060 * D/dalvikvm( 86): 0x4858dec8 (0064): .align4
4061 * D/dalvikvm( 86): -------- chaining cell (predicted)
4062 * D/dalvikvm( 86): 0x4858dec8 (0064): data 0xe7fe(59390)
4063 * D/dalvikvm( 86): 0x4858deca (0066): data 0x0000(0)
4064 * D/dalvikvm( 86): 0x4858decc (0068): data 0x0000(0)
4065 * D/dalvikvm( 86): 0x4858dece (006a): data 0x0000(0)
4066 * :
4067 */
4068static void genValidationForPredictedInline(CompilationUnit *cUnit, MIR *mir)
4069{
4070 CallsiteInfo *callsiteInfo = mir->meta.callsiteInfo;
4071 RegLocation rlThis = cUnit->regLocation[mir->dalvikInsn.vC];
4072
4073 rlThis = loadValue(cUnit, rlThis, kCoreReg);
4074 int regPredictedClass = dvmCompilerAllocTemp(cUnit);
Ben Cheng385828e2011-03-04 16:48:33 -08004075 loadClassPointer(cUnit, regPredictedClass, (int) callsiteInfo);
Ben Cheng7a2697d2010-06-07 13:44:23 -07004076 genNullCheck(cUnit, rlThis.sRegLow, rlThis.lowReg, mir->offset,
4077 NULL);/* null object? */
4078 int regActualClass = dvmCompilerAllocTemp(cUnit);
4079 loadWordDisp(cUnit, rlThis.lowReg, offsetof(Object, clazz), regActualClass);
4080 opRegReg(cUnit, kOpCmp, regPredictedClass, regActualClass);
4081 /*
4082 * Set the misPredBranchOver target so that it will be generated when the
4083 * code for the non-optimized invoke is generated.
4084 */
4085 callsiteInfo->misPredBranchOver = (LIR *) opCondBranch(cUnit, kArmCondNe);
4086}
4087
Ben Cheng4238ec22009-08-24 16:32:22 -07004088/* Extended MIR instructions like PHI */
4089static void handleExtendedMIR(CompilationUnit *cUnit, MIR *mir)
4090{
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004091 int opOffset = mir->dalvikInsn.opcode - kMirOpFirst;
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004092 char *msg = (char *)dvmCompilerNew(strlen(extendedMIROpNames[opOffset]) + 1,
4093 false);
Ben Cheng4238ec22009-08-24 16:32:22 -07004094 strcpy(msg, extendedMIROpNames[opOffset]);
Bill Buzbee1465db52009-09-23 17:17:35 -07004095 newLIR1(cUnit, kArmPseudoExtended, (int) msg);
Ben Cheng4238ec22009-08-24 16:32:22 -07004096
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004097 switch (mir->dalvikInsn.opcode) {
Bill Buzbee1465db52009-09-23 17:17:35 -07004098 case kMirOpPhi: {
Ben Cheng4238ec22009-08-24 16:32:22 -07004099 char *ssaString = dvmCompilerGetSSAString(cUnit, mir->ssaRep);
Bill Buzbee1465db52009-09-23 17:17:35 -07004100 newLIR1(cUnit, kArmPseudoSSARep, (int) ssaString);
Ben Cheng4238ec22009-08-24 16:32:22 -07004101 break;
4102 }
Bill Buzbee1465db52009-09-23 17:17:35 -07004103 case kMirOpNullNRangeUpCheck: {
Ben Cheng4238ec22009-08-24 16:32:22 -07004104 genHoistedChecksForCountUpLoop(cUnit, mir);
4105 break;
4106 }
Bill Buzbee1465db52009-09-23 17:17:35 -07004107 case kMirOpNullNRangeDownCheck: {
Ben Cheng4238ec22009-08-24 16:32:22 -07004108 genHoistedChecksForCountDownLoop(cUnit, mir);
4109 break;
4110 }
Bill Buzbee1465db52009-09-23 17:17:35 -07004111 case kMirOpLowerBound: {
Ben Cheng4238ec22009-08-24 16:32:22 -07004112 genHoistedLowerBoundCheck(cUnit, mir);
4113 break;
4114 }
Bill Buzbee1465db52009-09-23 17:17:35 -07004115 case kMirOpPunt: {
Ben Cheng4238ec22009-08-24 16:32:22 -07004116 genUnconditionalBranch(cUnit,
4117 (ArmLIR *) cUnit->loopAnalysis->branchToPCR);
4118 break;
4119 }
Ben Cheng7a2697d2010-06-07 13:44:23 -07004120 case kMirOpCheckInlinePrediction: {
4121 genValidationForPredictedInline(cUnit, mir);
4122 break;
4123 }
Ben Cheng4238ec22009-08-24 16:32:22 -07004124 default:
4125 break;
4126 }
4127}
4128
4129/*
4130 * Create a PC-reconstruction cell for the starting offset of this trace.
4131 * Since the PCR cell is placed near the end of the compiled code which is
4132 * usually out of range for a conditional branch, we put two branches (one
4133 * branch over to the loop body and one layover branch to the actual PCR) at the
4134 * end of the entry block.
4135 */
4136static void setupLoopEntryBlock(CompilationUnit *cUnit, BasicBlock *entry,
4137 ArmLIR *bodyLabel)
4138{
4139 /* Set up the place holder to reconstruct this Dalvik PC */
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004140 ArmLIR *pcrLabel = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004141 pcrLabel->opcode = kArmPseudoPCReconstructionCell;
Ben Cheng4238ec22009-08-24 16:32:22 -07004142 pcrLabel->operands[0] =
4143 (int) (cUnit->method->insns + entry->startOffset);
4144 pcrLabel->operands[1] = entry->startOffset;
4145 /* Insert the place holder to the growable list */
Ben Cheng00603072010-10-28 11:13:58 -07004146 dvmInsertGrowableList(&cUnit->pcReconstructionList, (intptr_t) pcrLabel);
Ben Cheng4238ec22009-08-24 16:32:22 -07004147
4148 /*
4149 * Next, create two branches - one branch over to the loop body and the
4150 * other branch to the PCR cell to punt.
4151 */
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004152 ArmLIR *branchToBody = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004153 branchToBody->opcode = kThumbBUncond;
Ben Cheng4238ec22009-08-24 16:32:22 -07004154 branchToBody->generic.target = (LIR *) bodyLabel;
Ben Chengdcf3e5d2009-09-11 13:42:05 -07004155 setupResourceMasks(branchToBody);
Ben Cheng4238ec22009-08-24 16:32:22 -07004156 cUnit->loopAnalysis->branchToBody = (LIR *) branchToBody;
4157
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004158 ArmLIR *branchToPCR = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true);
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004159 branchToPCR->opcode = kThumbBUncond;
Ben Cheng4238ec22009-08-24 16:32:22 -07004160 branchToPCR->generic.target = (LIR *) pcrLabel;
Ben Chengdcf3e5d2009-09-11 13:42:05 -07004161 setupResourceMasks(branchToPCR);
Ben Cheng4238ec22009-08-24 16:32:22 -07004162 cUnit->loopAnalysis->branchToPCR = (LIR *) branchToPCR;
4163}
4164
Ben Chengd5adae12010-03-26 17:45:28 -07004165#if defined(WITH_SELF_VERIFICATION)
4166static bool selfVerificationPuntOps(MIR *mir)
4167{
4168 DecodedInstruction *decInsn = &mir->dalvikInsn;
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004169 Opcode op = decInsn->opcode;
Ben Cheng7a2697d2010-06-07 13:44:23 -07004170
Ben Chengd5adae12010-03-26 17:45:28 -07004171 /*
4172 * All opcodes that can throw exceptions and use the
4173 * TEMPLATE_THROW_EXCEPTION_COMMON template should be excluded in the trace
4174 * under self-verification mode.
4175 */
4176 return (op == OP_MONITOR_ENTER || op == OP_MONITOR_EXIT ||
4177 op == OP_NEW_INSTANCE || op == OP_NEW_ARRAY ||
4178 op == OP_CHECK_CAST || op == OP_MOVE_EXCEPTION ||
4179 op == OP_FILL_ARRAY_DATA || op == OP_EXECUTE_INLINE ||
Ben Cheng7a2697d2010-06-07 13:44:23 -07004180 op == OP_EXECUTE_INLINE_RANGE);
Ben Chengd5adae12010-03-26 17:45:28 -07004181}
4182#endif
4183
Ben Chengba4fc8b2009-06-01 13:00:29 -07004184void dvmCompilerMIR2LIR(CompilationUnit *cUnit)
4185{
4186 /* Used to hold the labels of each block */
Bill Buzbee89efc3d2009-07-28 11:22:22 -07004187 ArmLIR *labelList =
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004188 (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR) * cUnit->numBlocks, true);
Ben Chengcec26f62010-01-15 15:29:33 -08004189 GrowableList chainingListByType[kChainingCellGap];
Ben Chengba4fc8b2009-06-01 13:00:29 -07004190 int i;
4191
4192 /*
Ben Cheng38329f52009-07-07 14:19:20 -07004193 * Initialize various types chaining lists.
Ben Chengba4fc8b2009-06-01 13:00:29 -07004194 */
Ben Chengcec26f62010-01-15 15:29:33 -08004195 for (i = 0; i < kChainingCellGap; i++) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004196 dvmInitGrowableList(&chainingListByType[i], 2);
4197 }
4198
Ben Cheng7ab74e12011-02-03 14:02:06 -08004199 /* Clear the visited flag for each block */
4200 dvmCompilerDataFlowAnalysisDispatcher(cUnit, dvmCompilerClearVisitedFlag,
4201 kAllNodes, false /* isIterative */);
4202
Ben Cheng00603072010-10-28 11:13:58 -07004203 GrowableListIterator iterator;
4204 dvmGrowableListIteratorInit(&cUnit->blockList, &iterator);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004205
buzbee2e152ba2010-12-15 16:32:35 -08004206 /* Traces start with a profiling entry point. Generate it here */
4207 cUnit->profileCodeSize = genTraceProfileEntry(cUnit);
Ben Cheng1efc9c52009-06-08 18:25:27 -07004208
Ben Chengba4fc8b2009-06-01 13:00:29 -07004209 /* Handle the content in each basic block */
Ben Cheng00603072010-10-28 11:13:58 -07004210 for (i = 0; ; i++) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004211 MIR *mir;
Ben Cheng00603072010-10-28 11:13:58 -07004212 BasicBlock *bb = (BasicBlock *) dvmGrowableListIteratorNext(&iterator);
4213 if (bb == NULL) break;
Ben Cheng7ab74e12011-02-03 14:02:06 -08004214 if (bb->visited == true) continue;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004215
Ben Cheng00603072010-10-28 11:13:58 -07004216 labelList[i].operands[0] = bb->startOffset;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004217
Ben Cheng00603072010-10-28 11:13:58 -07004218 if (bb->blockType >= kChainingCellGap) {
4219 if (bb->isFallThroughFromInvoke == true) {
Ben Chengd44faf52010-06-02 15:33:51 -07004220 /* Align this block first since it is a return chaining cell */
4221 newLIR0(cUnit, kArmPseudoPseudoAlign4);
4222 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07004223 /*
4224 * Append the label pseudo LIR first. Chaining cells will be handled
4225 * separately afterwards.
4226 */
4227 dvmCompilerAppendLIR(cUnit, (LIR *) &labelList[i]);
4228 }
4229
Ben Cheng00603072010-10-28 11:13:58 -07004230 if (bb->blockType == kTraceEntryBlock) {
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004231 labelList[i].opcode = kArmPseudoEntryBlock;
Ben Cheng00603072010-10-28 11:13:58 -07004232 if (bb->firstMIRInsn == NULL) {
Ben Cheng4238ec22009-08-24 16:32:22 -07004233 continue;
4234 } else {
Ben Cheng00603072010-10-28 11:13:58 -07004235 setupLoopEntryBlock(cUnit, bb,
4236 &labelList[bb->fallThrough->id]);
Ben Cheng4238ec22009-08-24 16:32:22 -07004237 }
Ben Cheng00603072010-10-28 11:13:58 -07004238 } else if (bb->blockType == kTraceExitBlock) {
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004239 labelList[i].opcode = kArmPseudoExitBlock;
Ben Cheng4238ec22009-08-24 16:32:22 -07004240 goto gen_fallthrough;
Ben Cheng00603072010-10-28 11:13:58 -07004241 } else if (bb->blockType == kDalvikByteCode) {
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004242 labelList[i].opcode = kArmPseudoNormalBlockLabel;
Ben Chenge9695e52009-06-16 16:11:47 -07004243 /* Reset the register state */
Bill Buzbeec6f10662010-02-09 11:16:15 -08004244 dvmCompilerResetRegPool(cUnit);
4245 dvmCompilerClobberAllRegs(cUnit);
4246 dvmCompilerResetNullCheck(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004247 } else {
Ben Cheng00603072010-10-28 11:13:58 -07004248 switch (bb->blockType) {
Bill Buzbee1465db52009-09-23 17:17:35 -07004249 case kChainingCellNormal:
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004250 labelList[i].opcode = kArmPseudoChainingCellNormal;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004251 /* handle the codegen later */
4252 dvmInsertGrowableList(
Ben Cheng00603072010-10-28 11:13:58 -07004253 &chainingListByType[kChainingCellNormal], i);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004254 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004255 case kChainingCellInvokeSingleton:
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004256 labelList[i].opcode =
Ben Chenga4973592010-03-31 11:59:18 -07004257 kArmPseudoChainingCellInvokeSingleton;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004258 labelList[i].operands[0] =
Ben Cheng00603072010-10-28 11:13:58 -07004259 (int) bb->containingMethod;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004260 /* handle the codegen later */
4261 dvmInsertGrowableList(
Ben Cheng00603072010-10-28 11:13:58 -07004262 &chainingListByType[kChainingCellInvokeSingleton], i);
Ben Cheng38329f52009-07-07 14:19:20 -07004263 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004264 case kChainingCellInvokePredicted:
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004265 labelList[i].opcode =
Ben Chenga4973592010-03-31 11:59:18 -07004266 kArmPseudoChainingCellInvokePredicted;
Ben Cheng04517042011-03-14 11:16:21 -07004267 /*
4268 * Move the cached method pointer from operand 1 to 0.
4269 * Operand 0 was clobbered earlier in this routine to store
4270 * the block starting offset, which is not applicable to
4271 * predicted chaining cell.
4272 */
4273 labelList[i].operands[0] = labelList[i].operands[1];
Ben Cheng38329f52009-07-07 14:19:20 -07004274 /* handle the codegen later */
4275 dvmInsertGrowableList(
Ben Cheng00603072010-10-28 11:13:58 -07004276 &chainingListByType[kChainingCellInvokePredicted], i);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004277 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004278 case kChainingCellHot:
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004279 labelList[i].opcode =
Ben Chenga4973592010-03-31 11:59:18 -07004280 kArmPseudoChainingCellHot;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004281 /* handle the codegen later */
4282 dvmInsertGrowableList(
Ben Cheng00603072010-10-28 11:13:58 -07004283 &chainingListByType[kChainingCellHot], i);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004284 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004285 case kPCReconstruction:
Ben Chengba4fc8b2009-06-01 13:00:29 -07004286 /* Make sure exception handling block is next */
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004287 labelList[i].opcode =
Ben Chenga4973592010-03-31 11:59:18 -07004288 kArmPseudoPCReconstructionBlockLabel;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004289 assert (i == cUnit->numBlocks - 2);
4290 handlePCReconstruction(cUnit, &labelList[i+1]);
4291 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004292 case kExceptionHandling:
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004293 labelList[i].opcode = kArmPseudoEHBlockLabel;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004294 if (cUnit->pcReconstructionList.numUsed) {
Ben Cheng20d7e6c2011-02-18 17:12:42 -08004295 loadWordDisp(cUnit, r6SELF, offsetof(Thread,
Bill Buzbee270c1d62009-08-13 16:58:07 -07004296 jitToInterpEntries.dvmJitToInterpPunt),
4297 r1);
Bill Buzbee1465db52009-09-23 17:17:35 -07004298 opReg(cUnit, kOpBlx, r1);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004299 }
4300 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004301 case kChainingCellBackwardBranch:
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004302 labelList[i].opcode =
Ben Chenga4973592010-03-31 11:59:18 -07004303 kArmPseudoChainingCellBackwardBranch;
Jeff Hao97319a82009-08-12 16:57:15 -07004304 /* handle the codegen later */
4305 dvmInsertGrowableList(
Bill Buzbee1465db52009-09-23 17:17:35 -07004306 &chainingListByType[kChainingCellBackwardBranch],
Ben Cheng00603072010-10-28 11:13:58 -07004307 i);
Jeff Hao97319a82009-08-12 16:57:15 -07004308 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004309 default:
4310 break;
4311 }
4312 continue;
4313 }
Ben Chenge9695e52009-06-16 16:11:47 -07004314
Bill Buzbee89efc3d2009-07-28 11:22:22 -07004315 ArmLIR *headLIR = NULL;
Ben Cheng7ab74e12011-02-03 14:02:06 -08004316 BasicBlock *nextBB = bb;
Ben Chenge9695e52009-06-16 16:11:47 -07004317
Ben Cheng7ab74e12011-02-03 14:02:06 -08004318 /*
4319 * Try to build a longer optimization unit. Currently if the previous
4320 * block ends with a goto, we continue adding instructions and don't
4321 * reset the register allocation pool.
4322 */
4323 for (; nextBB != NULL; nextBB = cUnit->nextCodegenBlock) {
4324 bb = nextBB;
4325 bb->visited = true;
4326 cUnit->nextCodegenBlock = NULL;
Bill Buzbee1465db52009-09-23 17:17:35 -07004327
Ben Cheng7ab74e12011-02-03 14:02:06 -08004328 for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
Bill Buzbee1465db52009-09-23 17:17:35 -07004329
Ben Cheng7ab74e12011-02-03 14:02:06 -08004330 dvmCompilerResetRegPool(cUnit);
4331 if (gDvmJit.disableOpt & (1 << kTrackLiveTemps)) {
4332 dvmCompilerClobberAllRegs(cUnit);
Ben Cheng80211d22011-01-14 10:23:37 -08004333 }
Ben Cheng4238ec22009-08-24 16:32:22 -07004334
Ben Cheng7ab74e12011-02-03 14:02:06 -08004335 if (gDvmJit.disableOpt & (1 << kSuppressLoads)) {
4336 dvmCompilerResetDefTracking(cUnit);
4337 }
Ben Cheng4238ec22009-08-24 16:32:22 -07004338
Ben Cheng7ab74e12011-02-03 14:02:06 -08004339 if (mir->dalvikInsn.opcode >= kMirOpFirst) {
4340 handleExtendedMIR(cUnit, mir);
4341 continue;
4342 }
4343
4344
4345 Opcode dalvikOpcode = mir->dalvikInsn.opcode;
4346 InstructionFormat dalvikFormat =
4347 dexGetFormatFromOpcode(dalvikOpcode);
4348 char *note;
4349 if (mir->OptimizationFlags & MIR_INLINED) {
4350 note = " (I)";
4351 } else if (mir->OptimizationFlags & MIR_INLINED_PRED) {
4352 note = " (PI)";
4353 } else if (mir->OptimizationFlags & MIR_CALLEE) {
4354 note = " (C)";
4355 } else {
4356 note = NULL;
4357 }
4358
4359 ArmLIR *boundaryLIR;
4360
4361 /*
4362 * Don't generate the boundary LIR unless we are debugging this
4363 * trace or we need a scheduling barrier.
4364 */
4365 if (headLIR == NULL || cUnit->printMe == true) {
4366 boundaryLIR =
4367 newLIR2(cUnit, kArmPseudoDalvikByteCodeBoundary,
4368 mir->offset,
4369 (int) dvmCompilerGetDalvikDisassembly(
4370 &mir->dalvikInsn, note));
4371 /* Remember the first LIR for this block */
4372 if (headLIR == NULL) {
4373 headLIR = boundaryLIR;
4374 /* Set the first boundaryLIR as a scheduling barrier */
4375 headLIR->defMask = ENCODE_ALL;
4376 }
4377 }
4378
4379 /*
4380 * Don't generate the SSA annotation unless verbose mode is on
4381 */
4382 if (cUnit->printMe && mir->ssaRep) {
4383 char *ssaString = dvmCompilerGetSSAString(cUnit,
4384 mir->ssaRep);
4385 newLIR1(cUnit, kArmPseudoSSARep, (int) ssaString);
4386 }
4387
4388 bool notHandled;
4389 /*
4390 * Debugging: screen the opcode first to see if it is in the
4391 * do[-not]-compile list
4392 */
4393 bool singleStepMe = SINGLE_STEP_OP(dalvikOpcode);
Ben Chengd5adae12010-03-26 17:45:28 -07004394#if defined(WITH_SELF_VERIFICATION)
Ben Cheng7ab74e12011-02-03 14:02:06 -08004395 if (singleStepMe == false) {
4396 singleStepMe = selfVerificationPuntOps(mir);
4397 }
Ben Chengd5adae12010-03-26 17:45:28 -07004398#endif
Ben Cheng7ab74e12011-02-03 14:02:06 -08004399 if (singleStepMe || cUnit->allSingleStep) {
4400 notHandled = false;
4401 genInterpSingleStep(cUnit, mir);
4402 } else {
4403 opcodeCoverage[dalvikOpcode]++;
4404 switch (dalvikFormat) {
4405 case kFmt10t:
4406 case kFmt20t:
4407 case kFmt30t:
4408 notHandled = handleFmt10t_Fmt20t_Fmt30t(cUnit,
4409 mir, bb, labelList);
4410 break;
4411 case kFmt10x:
4412 notHandled = handleFmt10x(cUnit, mir);
4413 break;
4414 case kFmt11n:
4415 case kFmt31i:
4416 notHandled = handleFmt11n_Fmt31i(cUnit, mir);
4417 break;
4418 case kFmt11x:
4419 notHandled = handleFmt11x(cUnit, mir);
4420 break;
4421 case kFmt12x:
4422 notHandled = handleFmt12x(cUnit, mir);
4423 break;
4424 case kFmt20bc:
4425 case kFmt40sc:
4426 notHandled = handleFmt20bc_Fmt40sc(cUnit, mir);
4427 break;
4428 case kFmt21c:
4429 case kFmt31c:
4430 case kFmt41c:
4431 notHandled = handleFmt21c_Fmt31c_Fmt41c(cUnit, mir);
4432 break;
4433 case kFmt21h:
4434 notHandled = handleFmt21h(cUnit, mir);
4435 break;
4436 case kFmt21s:
4437 notHandled = handleFmt21s(cUnit, mir);
4438 break;
4439 case kFmt21t:
4440 notHandled = handleFmt21t(cUnit, mir, bb,
Ben Chengba4fc8b2009-06-01 13:00:29 -07004441 labelList);
Ben Cheng7ab74e12011-02-03 14:02:06 -08004442 break;
4443 case kFmt22b:
4444 case kFmt22s:
4445 notHandled = handleFmt22b_Fmt22s(cUnit, mir);
4446 break;
4447 case kFmt22c:
4448 case kFmt52c:
4449 notHandled = handleFmt22c_Fmt52c(cUnit, mir);
4450 break;
4451 case kFmt22cs:
4452 notHandled = handleFmt22cs(cUnit, mir);
4453 break;
4454 case kFmt22t:
4455 notHandled = handleFmt22t(cUnit, mir, bb,
4456 labelList);
4457 break;
4458 case kFmt22x:
4459 case kFmt32x:
4460 notHandled = handleFmt22x_Fmt32x(cUnit, mir);
4461 break;
4462 case kFmt23x:
4463 notHandled = handleFmt23x(cUnit, mir);
4464 break;
4465 case kFmt31t:
4466 notHandled = handleFmt31t(cUnit, mir);
4467 break;
4468 case kFmt3rc:
4469 case kFmt35c:
4470 case kFmt5rc:
4471 notHandled = handleFmt35c_3rc_5rc(cUnit, mir, bb,
4472 labelList);
4473 break;
4474 case kFmt3rms:
4475 case kFmt35ms:
4476 notHandled = handleFmt35ms_3rms(cUnit, mir, bb,
4477 labelList);
4478 break;
4479 case kFmt35mi:
4480 case kFmt3rmi:
4481 notHandled = handleExecuteInline(cUnit, mir);
4482 break;
4483 case kFmt51l:
4484 notHandled = handleFmt51l(cUnit, mir);
4485 break;
4486 default:
4487 notHandled = true;
4488 break;
4489 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07004490 }
Ben Cheng7ab74e12011-02-03 14:02:06 -08004491 if (notHandled) {
4492 LOGE("%#06x: Opcode 0x%x (%s) / Fmt %d not handled\n",
4493 mir->offset,
4494 dalvikOpcode, dexGetOpcodeName(dalvikOpcode),
4495 dalvikFormat);
4496 dvmCompilerAbort(cUnit);
4497 break;
4498 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07004499 }
4500 }
Ben Cheng4238ec22009-08-24 16:32:22 -07004501
Ben Cheng00603072010-10-28 11:13:58 -07004502 if (bb->blockType == kTraceEntryBlock) {
Ben Cheng4238ec22009-08-24 16:32:22 -07004503 dvmCompilerAppendLIR(cUnit,
4504 (LIR *) cUnit->loopAnalysis->branchToBody);
4505 dvmCompilerAppendLIR(cUnit,
4506 (LIR *) cUnit->loopAnalysis->branchToPCR);
4507 }
4508
4509 if (headLIR) {
4510 /*
4511 * Eliminate redundant loads/stores and delay stores into later
4512 * slots
4513 */
4514 dvmCompilerApplyLocalOptimizations(cUnit, (LIR *) headLIR,
4515 cUnit->lastLIRInsn);
4516 }
4517
4518gen_fallthrough:
Ben Cheng1efc9c52009-06-08 18:25:27 -07004519 /*
4520 * Check if the block is terminated due to trace length constraint -
4521 * insert an unconditional branch to the chaining cell.
4522 */
Ben Cheng00603072010-10-28 11:13:58 -07004523 if (bb->needFallThroughBranch) {
Ben Cheng7ab74e12011-02-03 14:02:06 -08004524 genUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]);
Ben Cheng1efc9c52009-06-08 18:25:27 -07004525 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07004526 }
4527
Ben Chenge9695e52009-06-16 16:11:47 -07004528 /* Handle the chaining cells in predefined order */
Ben Chengcec26f62010-01-15 15:29:33 -08004529 for (i = 0; i < kChainingCellGap; i++) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004530 size_t j;
4531 int *blockIdList = (int *) chainingListByType[i].elemList;
4532
4533 cUnit->numChainingCells[i] = chainingListByType[i].numUsed;
4534
4535 /* No chaining cells of this type */
4536 if (cUnit->numChainingCells[i] == 0)
4537 continue;
4538
4539 /* Record the first LIR for a new type of chaining cell */
4540 cUnit->firstChainingLIR[i] = (LIR *) &labelList[blockIdList[0]];
4541
4542 for (j = 0; j < chainingListByType[i].numUsed; j++) {
4543 int blockId = blockIdList[j];
Ben Cheng00603072010-10-28 11:13:58 -07004544 BasicBlock *chainingBlock =
4545 (BasicBlock *) dvmGrowableListGetElement(&cUnit->blockList,
4546 blockId);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004547
4548 /* Align this chaining cell first */
Bill Buzbee1465db52009-09-23 17:17:35 -07004549 newLIR0(cUnit, kArmPseudoPseudoAlign4);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004550
4551 /* Insert the pseudo chaining instruction */
4552 dvmCompilerAppendLIR(cUnit, (LIR *) &labelList[blockId]);
4553
4554
Ben Cheng00603072010-10-28 11:13:58 -07004555 switch (chainingBlock->blockType) {
Bill Buzbee1465db52009-09-23 17:17:35 -07004556 case kChainingCellNormal:
Ben Cheng00603072010-10-28 11:13:58 -07004557 handleNormalChainingCell(cUnit, chainingBlock->startOffset);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004558 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004559 case kChainingCellInvokeSingleton:
Ben Cheng38329f52009-07-07 14:19:20 -07004560 handleInvokeSingletonChainingCell(cUnit,
Ben Cheng00603072010-10-28 11:13:58 -07004561 chainingBlock->containingMethod);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004562 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004563 case kChainingCellInvokePredicted:
Ben Cheng38329f52009-07-07 14:19:20 -07004564 handleInvokePredictedChainingCell(cUnit);
4565 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004566 case kChainingCellHot:
Ben Cheng00603072010-10-28 11:13:58 -07004567 handleHotChainingCell(cUnit, chainingBlock->startOffset);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004568 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07004569 case kChainingCellBackwardBranch:
Jeff Hao97319a82009-08-12 16:57:15 -07004570 handleBackwardBranchChainingCell(cUnit,
Ben Cheng00603072010-10-28 11:13:58 -07004571 chainingBlock->startOffset);
Jeff Hao97319a82009-08-12 16:57:15 -07004572 break;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004573 default:
Ben Cheng00603072010-10-28 11:13:58 -07004574 LOGE("Bad blocktype %d", chainingBlock->blockType);
Bill Buzbeefc519dc2010-03-06 23:30:57 -08004575 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004576 }
4577 }
4578 }
Ben Chenge9695e52009-06-16 16:11:47 -07004579
Ben Chengcec26f62010-01-15 15:29:33 -08004580 /* Mark the bottom of chaining cells */
4581 cUnit->chainingCellBottom = (LIR *) newLIR0(cUnit, kArmChainingCellBottom);
4582
Ben Cheng6c10a972009-10-29 14:39:18 -07004583 /*
4584 * Generate the branch to the dvmJitToInterpNoChain entry point at the end
4585 * of all chaining cells for the overflow cases.
4586 */
4587 if (cUnit->switchOverflowPad) {
4588 loadConstant(cUnit, r0, (int) cUnit->switchOverflowPad);
Ben Cheng20d7e6c2011-02-18 17:12:42 -08004589 loadWordDisp(cUnit, r6SELF, offsetof(Thread,
Ben Cheng6c10a972009-10-29 14:39:18 -07004590 jitToInterpEntries.dvmJitToInterpNoChain), r2);
4591 opRegReg(cUnit, kOpAdd, r1, r1);
4592 opRegRegReg(cUnit, kOpAdd, r4PC, r0, r1);
Ben Cheng978738d2010-05-13 13:45:57 -07004593#if defined(WITH_JIT_TUNING)
Ben Cheng6c10a972009-10-29 14:39:18 -07004594 loadConstant(cUnit, r0, kSwitchOverflow);
4595#endif
4596 opReg(cUnit, kOpBlx, r2);
4597 }
4598
Ben Chenge9695e52009-06-16 16:11:47 -07004599 dvmCompilerApplyGlobalOptimizations(cUnit);
jeffhao9e45c0b2010-02-03 10:24:05 -08004600
4601#if defined(WITH_SELF_VERIFICATION)
4602 selfVerificationBranchInsertPass(cUnit);
4603#endif
Ben Chengba4fc8b2009-06-01 13:00:29 -07004604}
4605
buzbee2e152ba2010-12-15 16:32:35 -08004606/*
4607 * Accept the work and start compiling. Returns true if compilation
4608 * is attempted.
4609 */
Bill Buzbee716f1202009-07-23 13:22:09 -07004610bool dvmCompilerDoWork(CompilerWorkOrder *work)
Ben Chengba4fc8b2009-06-01 13:00:29 -07004611{
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004612 JitTraceDescription *desc;
buzbee2e152ba2010-12-15 16:32:35 -08004613 bool isCompile;
4614 bool success = true;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004615
Ben Cheng6999d842010-01-26 16:46:15 -08004616 if (gDvmJit.codeCacheFull) {
Ben Chengccd6c012009-10-15 14:52:45 -07004617 return false;
4618 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07004619
Ben Chengccd6c012009-10-15 14:52:45 -07004620 switch (work->kind) {
Ben Chengccd6c012009-10-15 14:52:45 -07004621 case kWorkOrderTrace:
buzbee2e152ba2010-12-15 16:32:35 -08004622 isCompile = true;
Ben Chengccd6c012009-10-15 14:52:45 -07004623 /* Start compilation with maximally allowed trace length */
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004624 desc = (JitTraceDescription *)work->info;
buzbee2e152ba2010-12-15 16:32:35 -08004625 success = dvmCompileTrace(desc, JIT_MAX_TRACE_LEN, &work->result,
4626 work->bailPtr, 0 /* no hints */);
Ben Chengccd6c012009-10-15 14:52:45 -07004627 break;
4628 case kWorkOrderTraceDebug: {
4629 bool oldPrintMe = gDvmJit.printMe;
4630 gDvmJit.printMe = true;
buzbee2e152ba2010-12-15 16:32:35 -08004631 isCompile = true;
Ben Chengccd6c012009-10-15 14:52:45 -07004632 /* Start compilation with maximally allowed trace length */
Carl Shapirofc75f3e2010-12-07 11:43:38 -08004633 desc = (JitTraceDescription *)work->info;
buzbee2e152ba2010-12-15 16:32:35 -08004634 success = dvmCompileTrace(desc, JIT_MAX_TRACE_LEN, &work->result,
4635 work->bailPtr, 0 /* no hints */);
Elliott Hughes672511b2010-04-26 17:40:13 -07004636 gDvmJit.printMe = oldPrintMe;
Ben Chengccd6c012009-10-15 14:52:45 -07004637 break;
4638 }
buzbee2e152ba2010-12-15 16:32:35 -08004639 case kWorkOrderProfileMode:
4640 dvmJitChangeProfileMode((TraceProfilingModes)work->info);
4641 isCompile = false;
4642 break;
Ben Chengccd6c012009-10-15 14:52:45 -07004643 default:
buzbee2e152ba2010-12-15 16:32:35 -08004644 isCompile = false;
Bill Buzbeefc519dc2010-03-06 23:30:57 -08004645 LOGE("Jit: unknown work order type");
Elliott Hughes672511b2010-04-26 17:40:13 -07004646 assert(0); // Bail if debug build, discard otherwise
Ben Chengccd6c012009-10-15 14:52:45 -07004647 }
buzbee2e152ba2010-12-15 16:32:35 -08004648 if (!success)
4649 work->result.codeAddress = NULL;
4650 return isCompile;
Ben Chengba4fc8b2009-06-01 13:00:29 -07004651}
4652
Ben Chengba4fc8b2009-06-01 13:00:29 -07004653/* Architectural-specific debugging helpers go here */
4654void dvmCompilerArchDump(void)
4655{
4656 /* Print compiled opcode in this VM instance */
4657 int i, start, streak;
4658 char buf[1024];
4659
4660 streak = i = 0;
4661 buf[0] = 0;
Dan Bornsteinccaab182010-12-03 15:32:40 -08004662 while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004663 i++;
4664 }
Dan Bornsteinccaab182010-12-03 15:32:40 -08004665 if (i == kNumPackedOpcodes) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004666 return;
4667 }
Dan Bornsteinccaab182010-12-03 15:32:40 -08004668 for (start = i++, streak = 1; i < kNumPackedOpcodes; i++) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004669 if (opcodeCoverage[i]) {
4670 streak++;
4671 } else {
4672 if (streak == 1) {
4673 sprintf(buf+strlen(buf), "%x,", start);
4674 } else {
4675 sprintf(buf+strlen(buf), "%x-%x,", start, start + streak - 1);
4676 }
4677 streak = 0;
Dan Bornsteinccaab182010-12-03 15:32:40 -08004678 while (opcodeCoverage[i] == 0 && i < kNumPackedOpcodes) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004679 i++;
4680 }
Dan Bornsteinccaab182010-12-03 15:32:40 -08004681 if (i < kNumPackedOpcodes) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07004682 streak = 1;
4683 start = i;
4684 }
4685 }
4686 }
4687 if (streak) {
4688 if (streak == 1) {
4689 sprintf(buf+strlen(buf), "%x", start);
4690 } else {
4691 sprintf(buf+strlen(buf), "%x-%x", start, start + streak - 1);
4692 }
4693 }
4694 if (strlen(buf)) {
Ben Cheng8b258bf2009-06-24 17:27:07 -07004695 LOGD("dalvik.vm.jit.op = %s", buf);
Ben Chengba4fc8b2009-06-01 13:00:29 -07004696 }
4697}
Ben Chengd7d426a2009-09-22 11:23:36 -07004698
4699/* Common initialization routine for an architecture family */
4700bool dvmCompilerArchInit()
4701{
4702 int i;
4703
Bill Buzbee1465db52009-09-23 17:17:35 -07004704 for (i = 0; i < kArmLast; i++) {
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004705 if (EncodingMap[i].opcode != i) {
Ben Chengd7d426a2009-09-22 11:23:36 -07004706 LOGE("Encoding order for %s is wrong: expecting %d, seeing %d",
Dan Bornstein9a1f8162010-12-01 17:02:26 -08004707 EncodingMap[i].name, i, EncodingMap[i].opcode);
Bill Buzbeefc519dc2010-03-06 23:30:57 -08004708 dvmAbort(); // OK to dvmAbort - build error
Ben Chengd7d426a2009-09-22 11:23:36 -07004709 }
4710 }
4711
Ben Cheng5d90c202009-11-22 23:31:11 -08004712 return dvmCompilerArchVariantInit();
4713}
4714
4715void *dvmCompilerGetInterpretTemplate()
4716{
4717 return (void*) ((int)gDvmJit.codeCache +
4718 templateEntryOffsets[TEMPLATE_INTERPRET]);
4719}
4720
Bill Buzbee1b3da592011-02-03 07:38:22 -08004721JitInstructionSetType dvmCompilerGetInterpretTemplateSet()
4722{
4723 return DALVIK_JIT_ARM;
4724}
4725
buzbeebff121a2010-08-04 15:25:06 -07004726/* Needed by the Assembler */
4727void dvmCompilerSetupResourceMasks(ArmLIR *lir)
4728{
4729 setupResourceMasks(lir);
4730}
4731
Ben Cheng5d90c202009-11-22 23:31:11 -08004732/* Needed by the ld/st optmizatons */
4733ArmLIR* dvmCompilerRegCopyNoInsert(CompilationUnit *cUnit, int rDest, int rSrc)
4734{
4735 return genRegCopyNoInsert(cUnit, rDest, rSrc);
4736}
4737
4738/* Needed by the register allocator */
4739ArmLIR* dvmCompilerRegCopy(CompilationUnit *cUnit, int rDest, int rSrc)
4740{
4741 return genRegCopy(cUnit, rDest, rSrc);
4742}
4743
4744/* Needed by the register allocator */
4745void dvmCompilerRegCopyWide(CompilationUnit *cUnit, int destLo, int destHi,
4746 int srcLo, int srcHi)
4747{
4748 genRegCopyWide(cUnit, destLo, destHi, srcLo, srcHi);
4749}
4750
4751void dvmCompilerFlushRegImpl(CompilationUnit *cUnit, int rBase,
4752 int displacement, int rSrc, OpSize size)
4753{
4754 storeBaseDisp(cUnit, rBase, displacement, rSrc, size);
4755}
4756
4757void dvmCompilerFlushRegWideImpl(CompilationUnit *cUnit, int rBase,
4758 int displacement, int rSrcLo, int rSrcHi)
4759{
4760 storeBaseDispWide(cUnit, rBase, displacement, rSrcLo, rSrcHi);
Ben Chengd7d426a2009-09-22 11:23:36 -07004761}