blob: 649ae827acecd1145190e45c02302a27ab7bb585 [file] [log] [blame]
buzbee31a4a6f2012-02-28 15:36:15 -08001/*
2 * Copyright (C) 2012 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
Ian Rogers57b86d42012-03-27 16:05:41 -070017#include "oat/runtime/oat_support_entrypoints.h"
buzbee1bc37c62012-11-20 13:35:41 -080018#include "../compiler_ir.h"
19#include "ralloc_util.h"
20#include "codegen_util.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070021
buzbee31a4a6f2012-02-28 15:36:15 -080022namespace art {
23
buzbeeeaf09bc2012-11-15 14:51:41 -080024//TODO: remove decl.
25void genInvoke(CompilationUnit* cUnit, CallInfo* info);
26
buzbee31a4a6f2012-02-28 15:36:15 -080027/*
28 * This source files contains "gen" codegen routines that should
29 * be applicable to most targets. Only mid-level support utilities
30 * and "op" calls may be used here.
31 */
buzbee31a4a6f2012-02-28 15:36:15 -080032
buzbee8320f382012-09-11 16:29:42 -070033void markSafepointPC(CompilationUnit* cUnit, LIR* inst)
34{
35 inst->defMask = ENCODE_ALL;
36 LIR* safepointPC = newLIR0(cUnit, kPseudoSafepointPC);
37 DCHECK_EQ(safepointPC->defMask, ENCODE_ALL);
38}
39
buzbeeb046e162012-10-30 15:48:42 -070040/*
41 * To save scheduling time, helper calls are broken into two parts: generation of
42 * the helper target address, and the actuall call to the helper. Because x86
43 * has a memory call operation, part 1 is a NOP for x86. For other targets,
44 * load arguments between the two parts.
45 */
46int callHelperSetup(CompilationUnit* cUnit, int helperOffset)
47{
48 return (cUnit->instructionSet == kX86) ? 0 : loadHelper(cUnit, helperOffset);
49}
50
51/* NOTE: if rTgt is a temp, it will be freed following use */
52LIR* callHelper(CompilationUnit* cUnit, int rTgt, int helperOffset, bool safepointPC)
53{
54 LIR* callInst;
55 if (cUnit->instructionSet == kX86) {
56 callInst = opThreadMem(cUnit, kOpBlx, helperOffset);
57 } else {
58 callInst = opReg(cUnit, kOpBlx, rTgt);
59 oatFreeTemp(cUnit, rTgt);
60 }
buzbee8320f382012-09-11 16:29:42 -070061 if (safepointPC) {
62 markSafepointPC(cUnit, callInst);
63 }
buzbeeb046e162012-10-30 15:48:42 -070064 return callInst;
65}
66
67void callRuntimeHelperImm(CompilationUnit* cUnit, int helperOffset, int arg0, bool safepointPC) {
68 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -080069 loadConstant(cUnit, targetReg(kArg0), arg0);
buzbeeb046e162012-10-30 15:48:42 -070070 oatClobberCalleeSave(cUnit);
71 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -070072}
73
buzbee8320f382012-09-11 16:29:42 -070074void callRuntimeHelperReg(CompilationUnit* cUnit, int helperOffset, int arg0, bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -070075 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -080076 opRegCopy(cUnit, targetReg(kArg0), arg0);
Bill Buzbeea114add2012-05-03 15:00:40 -070077 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -070078 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogers7caad772012-03-30 01:07:54 -070079}
80
buzbee8320f382012-09-11 16:29:42 -070081void callRuntimeHelperRegLocation(CompilationUnit* cUnit, int helperOffset, RegLocation arg0,
82 bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -070083 int rTgt = callHelperSetup(cUnit, helperOffset);
Bill Buzbeea114add2012-05-03 15:00:40 -070084 if (arg0.wide == 0) {
buzbeef0504cd2012-11-13 16:31:10 -080085 loadValueDirectFixed(cUnit, arg0, targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -070086 } else {
buzbeef0504cd2012-11-13 16:31:10 -080087 loadValueDirectWideFixed(cUnit, arg0, targetReg(kArg0), targetReg(kArg1));
Bill Buzbeea114add2012-05-03 15:00:40 -070088 }
89 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -070090 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -070091}
92
buzbee8320f382012-09-11 16:29:42 -070093void callRuntimeHelperImmImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1,
94 bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -070095 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -080096 loadConstant(cUnit, targetReg(kArg0), arg0);
97 loadConstant(cUnit, targetReg(kArg1), arg1);
Bill Buzbeea114add2012-05-03 15:00:40 -070098 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -070099 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700100}
101
buzbee8320f382012-09-11 16:29:42 -0700102void callRuntimeHelperImmRegLocation(CompilationUnit* cUnit, int helperOffset, int arg0,
103 RegLocation arg1, bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700104 int rTgt = callHelperSetup(cUnit, helperOffset);
Bill Buzbeea114add2012-05-03 15:00:40 -0700105 if (arg1.wide == 0) {
buzbeef0504cd2012-11-13 16:31:10 -0800106 loadValueDirectFixed(cUnit, arg1, targetReg(kArg1));
Bill Buzbeea114add2012-05-03 15:00:40 -0700107 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800108 loadValueDirectWideFixed(cUnit, arg1, targetReg(kArg1), targetReg(kArg2));
Bill Buzbeea114add2012-05-03 15:00:40 -0700109 }
buzbeef0504cd2012-11-13 16:31:10 -0800110 loadConstant(cUnit, targetReg(kArg0), arg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700111 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700112 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700113}
114
buzbee8320f382012-09-11 16:29:42 -0700115void callRuntimeHelperRegLocationImm(CompilationUnit* cUnit, int helperOffset, RegLocation arg0,
116 int arg1, bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700117 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -0800118 loadValueDirectFixed(cUnit, arg0, targetReg(kArg0));
119 loadConstant(cUnit, targetReg(kArg1), arg1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700120 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700121 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700122}
123
buzbee8320f382012-09-11 16:29:42 -0700124void callRuntimeHelperImmReg(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1,
125 bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700126 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -0800127 opRegCopy(cUnit, targetReg(kArg1), arg1);
128 loadConstant(cUnit, targetReg(kArg0), arg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700129 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700130 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700131}
132
buzbee8320f382012-09-11 16:29:42 -0700133void callRuntimeHelperRegImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1,
134 bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700135 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -0800136 opRegCopy(cUnit, targetReg(kArg0), arg0);
137 loadConstant(cUnit, targetReg(kArg1), arg1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700138 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700139 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700140}
141
buzbee8320f382012-09-11 16:29:42 -0700142void callRuntimeHelperImmMethod(CompilationUnit* cUnit, int helperOffset, int arg0, bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700143 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -0800144 loadCurrMethodDirect(cUnit, targetReg(kArg1));
145 loadConstant(cUnit, targetReg(kArg0), arg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700146 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700147 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700148}
149
buzbee8320f382012-09-11 16:29:42 -0700150void callRuntimeHelperRegLocationRegLocation(CompilationUnit* cUnit, int helperOffset,
151 RegLocation arg0, RegLocation arg1, bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700152 int rTgt = callHelperSetup(cUnit, helperOffset);
Bill Buzbeea114add2012-05-03 15:00:40 -0700153 if (arg0.wide == 0) {
buzbeef0504cd2012-11-13 16:31:10 -0800154 loadValueDirectFixed(cUnit, arg0, arg0.fp ? targetReg(kFArg0) : targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700155 if (arg1.wide == 0) {
buzbeeb046e162012-10-30 15:48:42 -0700156 if (cUnit->instructionSet == kMips) {
buzbeef0504cd2012-11-13 16:31:10 -0800157 loadValueDirectFixed(cUnit, arg1, arg1.fp ? targetReg(kFArg2) : targetReg(kArg1));
buzbeeb046e162012-10-30 15:48:42 -0700158 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800159 loadValueDirectFixed(cUnit, arg1, targetReg(kArg1));
buzbeeb046e162012-10-30 15:48:42 -0700160 }
Ian Rogersab2b55d2012-03-18 00:06:11 -0700161 } else {
buzbeeb046e162012-10-30 15:48:42 -0700162 if (cUnit->instructionSet == kMips) {
buzbeef0504cd2012-11-13 16:31:10 -0800163 loadValueDirectWideFixed(cUnit, arg1, arg1.fp ? targetReg(kFArg2) : targetReg(kArg1), arg1.fp ? targetReg(kFArg3) : targetReg(kArg2));
buzbeeb046e162012-10-30 15:48:42 -0700164 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800165 loadValueDirectWideFixed(cUnit, arg1, targetReg(kArg1), targetReg(kArg2));
buzbeeb046e162012-10-30 15:48:42 -0700166 }
Ian Rogersab2b55d2012-03-18 00:06:11 -0700167 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700168 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800169 loadValueDirectWideFixed(cUnit, arg0, arg0.fp ? targetReg(kFArg0) : targetReg(kArg0), arg0.fp ? targetReg(kFArg1) : targetReg(kArg1));
Bill Buzbeea114add2012-05-03 15:00:40 -0700170 if (arg1.wide == 0) {
buzbeef0504cd2012-11-13 16:31:10 -0800171 loadValueDirectFixed(cUnit, arg1, arg1.fp ? targetReg(kFArg2) : targetReg(kArg2));
Bill Buzbeea114add2012-05-03 15:00:40 -0700172 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800173 loadValueDirectWideFixed(cUnit, arg1, arg1.fp ? targetReg(kFArg2) : targetReg(kArg2), arg1.fp ? targetReg(kFArg3) : targetReg(kArg3));
Bill Buzbeea114add2012-05-03 15:00:40 -0700174 }
175 }
176 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700177 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700178}
179
buzbee8320f382012-09-11 16:29:42 -0700180void callRuntimeHelperRegReg(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1,
181 bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700182 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeecbd6d442012-11-17 14:11:25 -0800183 DCHECK_NE(targetReg(kArg0), arg1); // check copy into arg0 won't clobber arg1
buzbeef0504cd2012-11-13 16:31:10 -0800184 opRegCopy(cUnit, targetReg(kArg0), arg0);
185 opRegCopy(cUnit, targetReg(kArg1), arg1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700186 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700187 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700188}
189
buzbee8320f382012-09-11 16:29:42 -0700190void callRuntimeHelperRegRegImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1,
191 int arg2, bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700192 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeecbd6d442012-11-17 14:11:25 -0800193 DCHECK_NE(targetReg(kArg0), arg1); // check copy into arg0 won't clobber arg1
buzbeef0504cd2012-11-13 16:31:10 -0800194 opRegCopy(cUnit, targetReg(kArg0), arg0);
195 opRegCopy(cUnit, targetReg(kArg1), arg1);
196 loadConstant(cUnit, targetReg(kArg2), arg2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700197 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700198 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700199}
200
buzbee8320f382012-09-11 16:29:42 -0700201void callRuntimeHelperImmMethodRegLocation(CompilationUnit* cUnit, int helperOffset, int arg0,
202 RegLocation arg2, bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700203 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -0800204 loadValueDirectFixed(cUnit, arg2, targetReg(kArg2));
205 loadCurrMethodDirect(cUnit, targetReg(kArg1));
206 loadConstant(cUnit, targetReg(kArg0), arg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700207 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700208 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700209}
210
buzbee8320f382012-09-11 16:29:42 -0700211void callRuntimeHelperImmMethodImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg2,
212 bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700213 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -0800214 loadCurrMethodDirect(cUnit, targetReg(kArg1));
215 loadConstant(cUnit, targetReg(kArg2), arg2);
216 loadConstant(cUnit, targetReg(kArg0), arg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700217 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700218 callHelper(cUnit, rTgt, helperOffset, safepointPC);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700219}
220
buzbee8320f382012-09-11 16:29:42 -0700221void callRuntimeHelperImmRegLocationRegLocation(CompilationUnit* cUnit, int helperOffset,
222 int arg0, RegLocation arg1, RegLocation arg2,
223 bool safepointPC) {
buzbeeb046e162012-10-30 15:48:42 -0700224 int rTgt = callHelperSetup(cUnit, helperOffset);
buzbeef0504cd2012-11-13 16:31:10 -0800225 loadValueDirectFixed(cUnit, arg1, targetReg(kArg1));
Bill Buzbeea114add2012-05-03 15:00:40 -0700226 if (arg2.wide == 0) {
buzbeef0504cd2012-11-13 16:31:10 -0800227 loadValueDirectFixed(cUnit, arg2, targetReg(kArg2));
Bill Buzbeea114add2012-05-03 15:00:40 -0700228 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800229 loadValueDirectWideFixed(cUnit, arg2, targetReg(kArg2), targetReg(kArg3));
Bill Buzbeea114add2012-05-03 15:00:40 -0700230 }
buzbeef0504cd2012-11-13 16:31:10 -0800231 loadConstant(cUnit, targetReg(kArg0), arg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700232 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700233 callHelper(cUnit, rTgt, helperOffset, safepointPC);
buzbee31a4a6f2012-02-28 15:36:15 -0800234}
235
236/*
237 * Generate an kPseudoBarrier marker to indicate the boundary of special
238 * blocks.
239 */
240void genBarrier(CompilationUnit* cUnit)
241{
Bill Buzbeea114add2012-05-03 15:00:40 -0700242 LIR* barrier = newLIR0(cUnit, kPseudoBarrier);
243 /* Mark all resources as being clobbered */
244 barrier->defMask = -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800245}
246
buzbee31a4a6f2012-02-28 15:36:15 -0800247
248/* Generate unconditional branch instructions */
buzbee82488f52012-03-02 08:20:26 -0800249LIR* opUnconditionalBranch(CompilationUnit* cUnit, LIR* target)
buzbee31a4a6f2012-02-28 15:36:15 -0800250{
Bill Buzbeea114add2012-05-03 15:00:40 -0700251 LIR* branch = opBranchUnconditional(cUnit, kOpUncondBr);
buzbeecbd6d442012-11-17 14:11:25 -0800252 branch->target = target;
Bill Buzbeea114add2012-05-03 15:00:40 -0700253 return branch;
buzbee31a4a6f2012-02-28 15:36:15 -0800254}
255
buzbee5de34942012-03-01 14:51:57 -0800256// FIXME: need to do some work to split out targets with
257// condition codes and those without
buzbee408ad162012-06-06 16:45:18 -0700258LIR* genCheck(CompilationUnit* cUnit, ConditionCode cCode,
buzbee31a4a6f2012-02-28 15:36:15 -0800259 ThrowKind kind)
260{
buzbeeb046e162012-10-30 15:48:42 -0700261 DCHECK_NE(cUnit->instructionSet, kMips);
Bill Buzbeea114add2012-05-03 15:00:40 -0700262 LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind,
buzbee408ad162012-06-06 16:45:18 -0700263 cUnit->currentDalvikOffset);
Bill Buzbeea114add2012-05-03 15:00:40 -0700264 LIR* branch = opCondBranch(cUnit, cCode, tgt);
265 // Remember branch target - will process later
buzbeecbd6d442012-11-17 14:11:25 -0800266 oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, reinterpret_cast<uintptr_t>(tgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700267 return branch;
buzbee31a4a6f2012-02-28 15:36:15 -0800268}
269
270LIR* genImmedCheck(CompilationUnit* cUnit, ConditionCode cCode,
buzbee408ad162012-06-06 16:45:18 -0700271 int reg, int immVal, ThrowKind kind)
buzbee31a4a6f2012-02-28 15:36:15 -0800272{
buzbee408ad162012-06-06 16:45:18 -0700273 LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind,
274 cUnit->currentDalvikOffset);
Bill Buzbeea114add2012-05-03 15:00:40 -0700275 LIR* branch;
276 if (cCode == kCondAl) {
277 branch = opUnconditionalBranch(cUnit, tgt);
278 } else {
279 branch = opCmpImmBranch(cUnit, cCode, reg, immVal, tgt);
280 }
281 // Remember branch target - will process later
buzbeecbd6d442012-11-17 14:11:25 -0800282 oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, reinterpret_cast<uintptr_t>(tgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700283 return branch;
buzbee31a4a6f2012-02-28 15:36:15 -0800284}
285
286/* Perform null-check on a register. */
buzbee408ad162012-06-06 16:45:18 -0700287LIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, int optFlags)
buzbee31a4a6f2012-02-28 15:36:15 -0800288{
Bill Buzbeea114add2012-05-03 15:00:40 -0700289 if (!(cUnit->disableOpt & (1 << kNullCheckElimination)) &&
buzbee408ad162012-06-06 16:45:18 -0700290 optFlags & MIR_IGNORE_NULL_CHECK) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700291 return NULL;
292 }
buzbee408ad162012-06-06 16:45:18 -0700293 return genImmedCheck(cUnit, kCondEq, mReg, 0, kThrowNullPointer);
buzbee31a4a6f2012-02-28 15:36:15 -0800294}
295
296/* Perform check on two registers */
297LIR* genRegRegCheck(CompilationUnit* cUnit, ConditionCode cCode,
buzbee408ad162012-06-06 16:45:18 -0700298 int reg1, int reg2, ThrowKind kind)
buzbee31a4a6f2012-02-28 15:36:15 -0800299{
Bill Buzbeea114add2012-05-03 15:00:40 -0700300 LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind,
buzbee408ad162012-06-06 16:45:18 -0700301 cUnit->currentDalvikOffset, reg1, reg2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700302 LIR* branch = opCmpBranch(cUnit, cCode, reg1, reg2, tgt);
Bill Buzbeea114add2012-05-03 15:00:40 -0700303 // Remember branch target - will process later
buzbeecbd6d442012-11-17 14:11:25 -0800304 oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, reinterpret_cast<uintptr_t>(tgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700305 return branch;
buzbee31a4a6f2012-02-28 15:36:15 -0800306}
307
buzbee3b3dbdd2012-06-13 13:39:34 -0700308void genCompareAndBranch(CompilationUnit* cUnit, Instruction::Code opcode,
309 RegLocation rlSrc1, RegLocation rlSrc2, LIR* taken,
310 LIR* fallThrough)
buzbee31a4a6f2012-02-28 15:36:15 -0800311{
Bill Buzbeea114add2012-05-03 15:00:40 -0700312 ConditionCode cond;
313 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
314 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700315 switch (opcode) {
316 case Instruction::IF_EQ:
317 cond = kCondEq;
318 break;
319 case Instruction::IF_NE:
320 cond = kCondNe;
321 break;
322 case Instruction::IF_LT:
323 cond = kCondLt;
324 break;
325 case Instruction::IF_GE:
326 cond = kCondGe;
327 break;
328 case Instruction::IF_GT:
329 cond = kCondGt;
330 break;
331 case Instruction::IF_LE:
332 cond = kCondLe;
333 break;
334 default:
buzbeecbd6d442012-11-17 14:11:25 -0800335 cond = static_cast<ConditionCode>(0);
336 LOG(FATAL) << "Unexpected opcode " << opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700337 }
buzbee3b3dbdd2012-06-13 13:39:34 -0700338 opCmpBranch(cUnit, cond, rlSrc1.lowReg, rlSrc2.lowReg, taken);
buzbee3b3dbdd2012-06-13 13:39:34 -0700339 opUnconditionalBranch(cUnit, fallThrough);
buzbee31a4a6f2012-02-28 15:36:15 -0800340}
341
buzbee3b3dbdd2012-06-13 13:39:34 -0700342void genCompareZeroAndBranch(CompilationUnit* cUnit, Instruction::Code opcode,
343 RegLocation rlSrc, LIR* taken, LIR* fallThrough)
buzbee31a4a6f2012-02-28 15:36:15 -0800344{
Bill Buzbeea114add2012-05-03 15:00:40 -0700345 ConditionCode cond;
346 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700347 switch (opcode) {
348 case Instruction::IF_EQZ:
349 cond = kCondEq;
350 break;
351 case Instruction::IF_NEZ:
352 cond = kCondNe;
353 break;
354 case Instruction::IF_LTZ:
355 cond = kCondLt;
356 break;
357 case Instruction::IF_GEZ:
358 cond = kCondGe;
359 break;
360 case Instruction::IF_GTZ:
361 cond = kCondGt;
362 break;
363 case Instruction::IF_LEZ:
364 cond = kCondLe;
365 break;
366 default:
buzbeecbd6d442012-11-17 14:11:25 -0800367 cond = static_cast<ConditionCode>(0);
368 LOG(FATAL) << "Unexpected opcode " << opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700369 }
buzbeeb046e162012-10-30 15:48:42 -0700370 if (cUnit->instructionSet == kThumb2) {
371 opRegImm(cUnit, kOpCmp, rlSrc.lowReg, 0);
372 opCondBranch(cUnit, cond, taken);
373 } else {
374 opCmpImmBranch(cUnit, cond, rlSrc.lowReg, 0, taken);
375 }
buzbee3b3dbdd2012-06-13 13:39:34 -0700376 opUnconditionalBranch(cUnit, fallThrough);
buzbee31a4a6f2012-02-28 15:36:15 -0800377}
378
buzbee408ad162012-06-06 16:45:18 -0700379void genIntToLong(CompilationUnit* cUnit, RegLocation rlDest,
buzbee31a4a6f2012-02-28 15:36:15 -0800380 RegLocation rlSrc)
381{
Bill Buzbeea114add2012-05-03 15:00:40 -0700382 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
383 if (rlSrc.location == kLocPhysReg) {
384 opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg);
385 } else {
386 loadValueDirect(cUnit, rlSrc, rlResult.lowReg);
387 }
388 opRegRegImm(cUnit, kOpAsr, rlResult.highReg, rlResult.lowReg, 31);
389 storeValueWide(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -0800390}
391
buzbee408ad162012-06-06 16:45:18 -0700392void genIntNarrowing(CompilationUnit* cUnit, Instruction::Code opcode,
393 RegLocation rlDest, RegLocation rlSrc)
buzbee31a4a6f2012-02-28 15:36:15 -0800394{
Bill Buzbeea114add2012-05-03 15:00:40 -0700395 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
396 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
397 OpKind op = kOpInvalid;
buzbee408ad162012-06-06 16:45:18 -0700398 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700399 case Instruction::INT_TO_BYTE:
400 op = kOp2Byte;
401 break;
402 case Instruction::INT_TO_SHORT:
403 op = kOp2Short;
404 break;
405 case Instruction::INT_TO_CHAR:
406 op = kOp2Char;
407 break;
408 default:
409 LOG(ERROR) << "Bad int conversion type";
410 }
411 opRegReg(cUnit, op, rlResult.lowReg, rlSrc.lowReg);
412 storeValue(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -0800413}
414
415/*
416 * Let helper function take care of everything. Will call
417 * Array::AllocFromCode(type_idx, method, count);
418 * Note: AllocFromCode will handle checks for errNegativeArraySize.
419 */
buzbee408ad162012-06-06 16:45:18 -0700420void genNewArray(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlDest,
buzbee31a4a6f2012-02-28 15:36:15 -0800421 RegLocation rlSrc)
422{
Bill Buzbeea114add2012-05-03 15:00:40 -0700423 oatFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbeea114add2012-05-03 15:00:40 -0700424 int funcOffset;
425 if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700426 *cUnit->dex_file,
427 type_idx)) {
428 funcOffset = ENTRYPOINT_OFFSET(pAllocArrayFromCode);
429 } else {
430 funcOffset= ENTRYPOINT_OFFSET(pAllocArrayFromCodeWithAccessCheck);
431 }
buzbee8320f382012-09-11 16:29:42 -0700432 callRuntimeHelperImmMethodRegLocation(cUnit, funcOffset, type_idx, rlSrc, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700433 RegLocation rlResult = oatGetReturn(cUnit, false);
434 storeValue(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -0800435}
436
437/*
438 * Similar to genNewArray, but with post-allocation initialization.
439 * Verifier guarantees we're dealing with an array class. Current
440 * code throws runtime exception "bad Filled array req" for 'D' and 'J'.
441 * Current code also throws internal unimp if not 'L', '[' or 'I'.
442 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700443void genFilledNewArray(CompilationUnit* cUnit, CallInfo* info)
buzbee31a4a6f2012-02-28 15:36:15 -0800444{
buzbee3b3dbdd2012-06-13 13:39:34 -0700445 int elems = info->numArgWords;
446 int typeIdx = info->index;
Bill Buzbeea114add2012-05-03 15:00:40 -0700447 oatFlushAllRegs(cUnit); /* Everything to home location */
448 int funcOffset;
449 if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700450 *cUnit->dex_file,
451 typeIdx)) {
452 funcOffset = ENTRYPOINT_OFFSET(pCheckAndAllocArrayFromCode);
453 } else {
454 funcOffset = ENTRYPOINT_OFFSET(pCheckAndAllocArrayFromCodeWithAccessCheck);
455 }
buzbee8320f382012-09-11 16:29:42 -0700456 callRuntimeHelperImmMethodImm(cUnit, funcOffset, typeIdx, elems, true);
buzbeef0504cd2012-11-13 16:31:10 -0800457 oatFreeTemp(cUnit, targetReg(kArg2));
458 oatFreeTemp(cUnit, targetReg(kArg1));
Bill Buzbeea114add2012-05-03 15:00:40 -0700459 /*
460 * NOTE: the implicit target for Instruction::FILLED_NEW_ARRAY is the
461 * return region. Because AllocFromCode placed the new array
buzbeef0504cd2012-11-13 16:31:10 -0800462 * in kRet0, we'll just lock it into place. When debugger support is
Bill Buzbeea114add2012-05-03 15:00:40 -0700463 * added, it may be necessary to additionally copy all return
464 * values to a home location in thread-local storage
465 */
buzbeef0504cd2012-11-13 16:31:10 -0800466 oatLockTemp(cUnit, targetReg(kRet0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700467
468 // TODO: use the correct component size, currently all supported types
469 // share array alignment with ints (see comment at head of function)
470 size_t component_size = sizeof(int32_t);
471
472 // Having a range of 0 is legal
buzbee3b3dbdd2012-06-13 13:39:34 -0700473 if (info->isRange && (elems > 0)) {
buzbee31a4a6f2012-02-28 15:36:15 -0800474 /*
Bill Buzbeea114add2012-05-03 15:00:40 -0700475 * Bit of ugliness here. We're going generate a mem copy loop
476 * on the register range, but it is possible that some regs
477 * in the range have been promoted. This is unlikely, but
478 * before generating the copy, we'll just force a flush
479 * of any regs in the source range that have been promoted to
480 * home location.
buzbee31a4a6f2012-02-28 15:36:15 -0800481 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700482 for (int i = 0; i < elems; i++) {
483 RegLocation loc = oatUpdateLoc(cUnit, info->args[i]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700484 if (loc.location == kLocPhysReg) {
buzbeef0504cd2012-11-13 16:31:10 -0800485 storeBaseDisp(cUnit, targetReg(kSp), oatSRegOffset(cUnit, loc.sRegLow),
Bill Buzbeea114add2012-05-03 15:00:40 -0700486 loc.lowReg, kWord);
487 }
buzbee31a4a6f2012-02-28 15:36:15 -0800488 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700489 /*
490 * TUNING note: generated code here could be much improved, but
491 * this is an uncommon operation and isn't especially performance
492 * critical.
493 */
494 int rSrc = oatAllocTemp(cUnit);
495 int rDst = oatAllocTemp(cUnit);
496 int rIdx = oatAllocTemp(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700497 int rVal = INVALID_REG;
498 switch(cUnit->instructionSet) {
499 case kThumb2:
buzbeef0504cd2012-11-13 16:31:10 -0800500 rVal = targetReg(kLr);
buzbeeb046e162012-10-30 15:48:42 -0700501 break;
502 case kX86:
buzbeef0504cd2012-11-13 16:31:10 -0800503 oatFreeTemp(cUnit, targetReg(kRet0));
buzbeeb046e162012-10-30 15:48:42 -0700504 rVal = oatAllocTemp(cUnit);
505 break;
506 case kMips:
507 rVal = oatAllocTemp(cUnit);
508 break;
509 default: LOG(FATAL) << "Unexpected instruction set: " << cUnit->instructionSet;
510 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700511 // Set up source pointer
buzbee3b3dbdd2012-06-13 13:39:34 -0700512 RegLocation rlFirst = info->args[0];
buzbeef0504cd2012-11-13 16:31:10 -0800513 opRegRegImm(cUnit, kOpAdd, rSrc, targetReg(kSp),
Bill Buzbeea114add2012-05-03 15:00:40 -0700514 oatSRegOffset(cUnit, rlFirst.sRegLow));
515 // Set up the target pointer
buzbeef0504cd2012-11-13 16:31:10 -0800516 opRegRegImm(cUnit, kOpAdd, rDst, targetReg(kRet0),
Bill Buzbeea114add2012-05-03 15:00:40 -0700517 Array::DataOffset(component_size).Int32Value());
518 // Set up the loop counter (known to be > 0)
buzbee3b3dbdd2012-06-13 13:39:34 -0700519 loadConstant(cUnit, rIdx, elems - 1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700520 // Generate the copy loop. Going backwards for convenience
521 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
522 // Copy next element
523 loadBaseIndexed(cUnit, rSrc, rIdx, rVal, 2, kWord);
524 storeBaseIndexed(cUnit, rDst, rIdx, rVal, 2, kWord);
Bill Buzbeea114add2012-05-03 15:00:40 -0700525 oatFreeTemp(cUnit, rVal);
buzbeeb046e162012-10-30 15:48:42 -0700526 opDecAndBranch(cUnit, kCondGe, rIdx, target);
527 if (cUnit->instructionSet == kX86) {
528 // Restore the target pointer
buzbeef0504cd2012-11-13 16:31:10 -0800529 opRegRegImm(cUnit, kOpAdd, targetReg(kRet0), rDst, -Array::DataOffset(component_size).Int32Value());
buzbeeb046e162012-10-30 15:48:42 -0700530 }
buzbee3b3dbdd2012-06-13 13:39:34 -0700531 } else if (!info->isRange) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700532 // TUNING: interleave
buzbee3b3dbdd2012-06-13 13:39:34 -0700533 for (int i = 0; i < elems; i++) {
534 RegLocation rlArg = loadValue(cUnit, info->args[i], kCoreReg);
buzbeef0504cd2012-11-13 16:31:10 -0800535 storeBaseDisp(cUnit, targetReg(kRet0),
Bill Buzbeea114add2012-05-03 15:00:40 -0700536 Array::DataOffset(component_size).Int32Value() +
537 i * 4, rlArg.lowReg, kWord);
538 // If the loadValue caused a temp to be allocated, free it
539 if (oatIsTemp(cUnit, rlArg.lowReg)) {
540 oatFreeTemp(cUnit, rlArg.lowReg);
541 }
542 }
543 }
buzbeee5f01222012-06-14 15:19:35 -0700544 if (info->result.location != kLocInvalid) {
545 storeValue(cUnit, info->result, oatGetReturn(cUnit, false /* not fp */));
546 }
buzbee31a4a6f2012-02-28 15:36:15 -0800547}
548
buzbee408ad162012-06-06 16:45:18 -0700549void genSput(CompilationUnit* cUnit, uint32_t fieldIdx, RegLocation rlSrc,
Bill Buzbeea114add2012-05-03 15:00:40 -0700550 bool isLongOrDouble, bool isObject)
buzbee31a4a6f2012-02-28 15:36:15 -0800551{
Bill Buzbeea114add2012-05-03 15:00:40 -0700552 int fieldOffset;
553 int ssbIndex;
554 bool isVolatile;
555 bool isReferrersClass;
buzbee31a4a6f2012-02-28 15:36:15 -0800556
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700557 OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, *cUnit->dex_file,
558 cUnit->code_item, cUnit->method_idx, cUnit->access_flags);
buzbee31a4a6f2012-02-28 15:36:15 -0800559
Bill Buzbeea114add2012-05-03 15:00:40 -0700560 bool fastPath =
561 cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, &mUnit,
562 fieldOffset, ssbIndex,
563 isReferrersClass, isVolatile,
564 true);
565 if (fastPath && !SLOW_FIELD_PATH) {
566 DCHECK_GE(fieldOffset, 0);
567 int rBase;
568 if (isReferrersClass) {
569 // Fast path, static storage base is this method's class
570 RegLocation rlMethod = loadCurrMethod(cUnit);
571 rBase = oatAllocTemp(cUnit);
572 loadWordDisp(cUnit, rlMethod.lowReg,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700573 AbstractMethod::DeclaringClassOffset().Int32Value(), rBase);
Bill Buzbeea114add2012-05-03 15:00:40 -0700574 if (oatIsTemp(cUnit, rlMethod.lowReg)) {
575 oatFreeTemp(cUnit, rlMethod.lowReg);
576 }
buzbee31a4a6f2012-02-28 15:36:15 -0800577 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700578 // Medium path, static storage base in a different class which
579 // requires checks that the other class is initialized.
580 DCHECK_GE(ssbIndex, 0);
581 // May do runtime call so everything to home locations.
582 oatFlushAllRegs(cUnit);
583 // Using fixed register to sync with possible call to runtime
584 // support.
buzbeef0504cd2012-11-13 16:31:10 -0800585 int rMethod = targetReg(kArg1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700586 oatLockTemp(cUnit, rMethod);
587 loadCurrMethodDirect(cUnit, rMethod);
buzbeef0504cd2012-11-13 16:31:10 -0800588 rBase = targetReg(kArg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700589 oatLockTemp(cUnit, rBase);
590 loadWordDisp(cUnit, rMethod,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700591 AbstractMethod::DexCacheInitializedStaticStorageOffset().Int32Value(),
Bill Buzbeea114add2012-05-03 15:00:40 -0700592 rBase);
593 loadWordDisp(cUnit, rBase,
594 Array::DataOffset(sizeof(Object*)).Int32Value() +
595 sizeof(int32_t*) * ssbIndex, rBase);
596 // rBase now points at appropriate static storage base (Class*)
597 // or NULL if not initialized. Check for NULL and call helper if NULL.
598 // TUNING: fast path should fall through
599 LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rBase, 0, NULL);
buzbeef0504cd2012-11-13 16:31:10 -0800600 loadConstant(cUnit, targetReg(kArg0), ssbIndex);
buzbee8320f382012-09-11 16:29:42 -0700601 callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssbIndex, true);
buzbeeb046e162012-10-30 15:48:42 -0700602 if (cUnit->instructionSet == kMips) {
buzbeef0504cd2012-11-13 16:31:10 -0800603 // For Arm, kRet0 = kArg0 = rBase, for Mips, we need to copy
604 opRegCopy(cUnit, rBase, targetReg(kRet0));
buzbeeb046e162012-10-30 15:48:42 -0700605 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700606 LIR* skipTarget = newLIR0(cUnit, kPseudoTargetLabel);
buzbeecbd6d442012-11-17 14:11:25 -0800607 branchOver->target = skipTarget;
Bill Buzbeea114add2012-05-03 15:00:40 -0700608 oatFreeTemp(cUnit, rMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800609 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700610 // rBase now holds static storage base
611 if (isLongOrDouble) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700612 rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg);
613 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700614 rlSrc = loadValue(cUnit, rlSrc, kAnyReg);
615 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700616 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800617 oatGenMemBarrier(cUnit, kStoreStore);
Bill Buzbeea114add2012-05-03 15:00:40 -0700618 }
619 if (isLongOrDouble) {
620 storeBaseDispWide(cUnit, rBase, fieldOffset, rlSrc.lowReg,
621 rlSrc.highReg);
622 } else {
623 storeWordDisp(cUnit, rBase, fieldOffset, rlSrc.lowReg);
624 }
625 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800626 oatGenMemBarrier(cUnit, kStoreLoad);
Bill Buzbeea114add2012-05-03 15:00:40 -0700627 }
628 if (isObject) {
629 markGCCard(cUnit, rlSrc.lowReg, rBase);
630 }
631 oatFreeTemp(cUnit, rBase);
632 } else {
633 oatFlushAllRegs(cUnit); // Everything to home locations
634 int setterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pSet64Static) :
635 (isObject ? ENTRYPOINT_OFFSET(pSetObjStatic)
636 : ENTRYPOINT_OFFSET(pSet32Static));
buzbee8320f382012-09-11 16:29:42 -0700637 callRuntimeHelperImmRegLocation(cUnit, setterOffset, fieldIdx, rlSrc, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700638 }
buzbee31a4a6f2012-02-28 15:36:15 -0800639}
640
buzbee408ad162012-06-06 16:45:18 -0700641void genSget(CompilationUnit* cUnit, uint32_t fieldIdx, RegLocation rlDest,
Bill Buzbeea114add2012-05-03 15:00:40 -0700642 bool isLongOrDouble, bool isObject)
buzbee31a4a6f2012-02-28 15:36:15 -0800643{
Bill Buzbeea114add2012-05-03 15:00:40 -0700644 int fieldOffset;
645 int ssbIndex;
646 bool isVolatile;
647 bool isReferrersClass;
buzbee31a4a6f2012-02-28 15:36:15 -0800648
Bill Buzbeea114add2012-05-03 15:00:40 -0700649 OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700650 *cUnit->dex_file,
Bill Buzbeea114add2012-05-03 15:00:40 -0700651 cUnit->code_item, cUnit->method_idx,
652 cUnit->access_flags);
buzbee31a4a6f2012-02-28 15:36:15 -0800653
Bill Buzbeea114add2012-05-03 15:00:40 -0700654 bool fastPath =
655 cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, &mUnit,
656 fieldOffset, ssbIndex,
657 isReferrersClass, isVolatile,
658 false);
659 if (fastPath && !SLOW_FIELD_PATH) {
660 DCHECK_GE(fieldOffset, 0);
661 int rBase;
662 if (isReferrersClass) {
663 // Fast path, static storage base is this method's class
664 RegLocation rlMethod = loadCurrMethod(cUnit);
665 rBase = oatAllocTemp(cUnit);
666 loadWordDisp(cUnit, rlMethod.lowReg,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700667 AbstractMethod::DeclaringClassOffset().Int32Value(), rBase);
buzbee31a4a6f2012-02-28 15:36:15 -0800668 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700669 // Medium path, static storage base in a different class which
670 // requires checks that the other class is initialized
671 DCHECK_GE(ssbIndex, 0);
672 // May do runtime call so everything to home locations.
673 oatFlushAllRegs(cUnit);
674 // Using fixed register to sync with possible call to runtime
675 // support
buzbeef0504cd2012-11-13 16:31:10 -0800676 int rMethod = targetReg(kArg1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700677 oatLockTemp(cUnit, rMethod);
678 loadCurrMethodDirect(cUnit, rMethod);
buzbeef0504cd2012-11-13 16:31:10 -0800679 rBase = targetReg(kArg0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700680 oatLockTemp(cUnit, rBase);
681 loadWordDisp(cUnit, rMethod,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700682 AbstractMethod::DexCacheInitializedStaticStorageOffset().Int32Value(),
Bill Buzbeea114add2012-05-03 15:00:40 -0700683 rBase);
684 loadWordDisp(cUnit, rBase,
685 Array::DataOffset(sizeof(Object*)).Int32Value() +
686 sizeof(int32_t*) * ssbIndex, rBase);
687 // rBase now points at appropriate static storage base (Class*)
688 // or NULL if not initialized. Check for NULL and call helper if NULL.
689 // TUNING: fast path should fall through
690 LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rBase, 0, NULL);
buzbee8320f382012-09-11 16:29:42 -0700691 callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssbIndex, true);
buzbeeb046e162012-10-30 15:48:42 -0700692 if (cUnit->instructionSet == kMips) {
buzbeef0504cd2012-11-13 16:31:10 -0800693 // For Arm, kRet0 = kArg0 = rBase, for Mips, we need to copy
694 opRegCopy(cUnit, rBase, targetReg(kRet0));
buzbeeb046e162012-10-30 15:48:42 -0700695 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700696 LIR* skipTarget = newLIR0(cUnit, kPseudoTargetLabel);
buzbeecbd6d442012-11-17 14:11:25 -0800697 branchOver->target = skipTarget;
Bill Buzbeea114add2012-05-03 15:00:40 -0700698 oatFreeTemp(cUnit, rMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800699 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700700 // rBase now holds static storage base
Bill Buzbeea114add2012-05-03 15:00:40 -0700701 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
702 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800703 oatGenMemBarrier(cUnit, kLoadLoad);
Bill Buzbeea114add2012-05-03 15:00:40 -0700704 }
705 if (isLongOrDouble) {
buzbee408ad162012-06-06 16:45:18 -0700706 loadBaseDispWide(cUnit, rBase, fieldOffset, rlResult.lowReg,
Bill Buzbeea114add2012-05-03 15:00:40 -0700707 rlResult.highReg, INVALID_SREG);
708 } else {
709 loadWordDisp(cUnit, rBase, fieldOffset, rlResult.lowReg);
710 }
711 oatFreeTemp(cUnit, rBase);
712 if (isLongOrDouble) {
713 storeValueWide(cUnit, rlDest, rlResult);
714 } else {
715 storeValue(cUnit, rlDest, rlResult);
716 }
717 } else {
718 oatFlushAllRegs(cUnit); // Everything to home locations
719 int getterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pGet64Static) :
720 (isObject ? ENTRYPOINT_OFFSET(pGetObjStatic)
721 : ENTRYPOINT_OFFSET(pGet32Static));
buzbee8320f382012-09-11 16:29:42 -0700722 callRuntimeHelperImm(cUnit, getterOffset, fieldIdx, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700723 if (isLongOrDouble) {
724 RegLocation rlResult = oatGetReturnWide(cUnit, rlDest.fp);
725 storeValueWide(cUnit, rlDest, rlResult);
726 } else {
727 RegLocation rlResult = oatGetReturn(cUnit, rlDest.fp);
728 storeValue(cUnit, rlDest, rlResult);
729 }
730 }
buzbee31a4a6f2012-02-28 15:36:15 -0800731}
732
733
734// Debugging routine - if null target, branch to DebugMe
735void genShowTarget(CompilationUnit* cUnit)
736{
buzbeeb046e162012-10-30 15:48:42 -0700737 DCHECK_NE(cUnit->instructionSet, kX86) << "unimplemented genShowTarget";
buzbeef0504cd2012-11-13 16:31:10 -0800738 LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, targetReg(kInvokeTgt), 0, NULL);
739 loadWordDisp(cUnit, targetReg(kSelf), ENTRYPOINT_OFFSET(pDebugMe), targetReg(kInvokeTgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700740 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
buzbeecbd6d442012-11-17 14:11:25 -0800741 branchOver->target = target;
buzbee31a4a6f2012-02-28 15:36:15 -0800742}
743
buzbee31a4a6f2012-02-28 15:36:15 -0800744void handleSuspendLaunchpads(CompilationUnit *cUnit)
745{
buzbeecbd6d442012-11-17 14:11:25 -0800746 LIR** suspendLabel = reinterpret_cast<LIR**>(cUnit->suspendLaunchpads.elemList);
Bill Buzbeea114add2012-05-03 15:00:40 -0700747 int numElems = cUnit->suspendLaunchpads.numUsed;
buzbeeb046e162012-10-30 15:48:42 -0700748 int helperOffset = ENTRYPOINT_OFFSET(pTestSuspendFromCode);
Bill Buzbeea114add2012-05-03 15:00:40 -0700749 for (int i = 0; i < numElems; i++) {
750 oatResetRegPool(cUnit);
751 oatResetDefTracking(cUnit);
752 LIR* lab = suspendLabel[i];
buzbeecbd6d442012-11-17 14:11:25 -0800753 LIR* resumeLab = reinterpret_cast<LIR*>(lab->operands[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700754 cUnit->currentDalvikOffset = lab->operands[1];
755 oatAppendLIR(cUnit, lab);
buzbeeb046e162012-10-30 15:48:42 -0700756 int rTgt = callHelperSetup(cUnit, helperOffset);
757 callHelper(cUnit, rTgt, helperOffset, true /* markSafepointPC */);
Bill Buzbeea114add2012-05-03 15:00:40 -0700758 opUnconditionalBranch(cUnit, resumeLab);
759 }
buzbee31a4a6f2012-02-28 15:36:15 -0800760}
761
buzbeefc9e6fa2012-03-23 15:14:29 -0700762void handleIntrinsicLaunchpads(CompilationUnit *cUnit)
763{
buzbeecbd6d442012-11-17 14:11:25 -0800764 LIR** intrinsicLabel = reinterpret_cast<LIR**>(cUnit->intrinsicLaunchpads.elemList);
Bill Buzbeea114add2012-05-03 15:00:40 -0700765 int numElems = cUnit->intrinsicLaunchpads.numUsed;
766 for (int i = 0; i < numElems; i++) {
767 oatResetRegPool(cUnit);
768 oatResetDefTracking(cUnit);
769 LIR* lab = intrinsicLabel[i];
buzbeecbd6d442012-11-17 14:11:25 -0800770 CallInfo* info = reinterpret_cast<CallInfo*>(lab->operands[0]);
buzbee15bf9802012-06-12 17:49:27 -0700771 cUnit->currentDalvikOffset = info->offset;
Bill Buzbeea114add2012-05-03 15:00:40 -0700772 oatAppendLIR(cUnit, lab);
buzbee8320f382012-09-11 16:29:42 -0700773 // NOTE: genInvoke handles markSafepointPC
buzbee15bf9802012-06-12 17:49:27 -0700774 genInvoke(cUnit, info);
buzbeecbd6d442012-11-17 14:11:25 -0800775 LIR* resumeLab = reinterpret_cast<LIR*>(lab->operands[2]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700776 if (resumeLab != NULL) {
777 opUnconditionalBranch(cUnit, resumeLab);
buzbeefc9e6fa2012-03-23 15:14:29 -0700778 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700779 }
buzbeefc9e6fa2012-03-23 15:14:29 -0700780}
781
buzbee31a4a6f2012-02-28 15:36:15 -0800782void handleThrowLaunchpads(CompilationUnit *cUnit)
783{
buzbeecbd6d442012-11-17 14:11:25 -0800784 LIR** throwLabel = reinterpret_cast<LIR**>(cUnit->throwLaunchpads.elemList);
Bill Buzbeea114add2012-05-03 15:00:40 -0700785 int numElems = cUnit->throwLaunchpads.numUsed;
786 for (int i = 0; i < numElems; i++) {
787 oatResetRegPool(cUnit);
788 oatResetDefTracking(cUnit);
789 LIR* lab = throwLabel[i];
790 cUnit->currentDalvikOffset = lab->operands[1];
791 oatAppendLIR(cUnit, lab);
792 int funcOffset = 0;
793 int v1 = lab->operands[2];
794 int v2 = lab->operands[3];
buzbeeb046e162012-10-30 15:48:42 -0700795 bool targetX86 = (cUnit->instructionSet == kX86);
Bill Buzbeea114add2012-05-03 15:00:40 -0700796 switch (lab->operands[0]) {
797 case kThrowNullPointer:
798 funcOffset = ENTRYPOINT_OFFSET(pThrowNullPointerFromCode);
799 break;
800 case kThrowArrayBounds:
buzbeef0504cd2012-11-13 16:31:10 -0800801 // Move v1 (array index) to kArg0 and v2 (array length) to kArg1
802 if (v2 != targetReg(kArg0)) {
803 opRegCopy(cUnit, targetReg(kArg0), v1);
buzbeeb046e162012-10-30 15:48:42 -0700804 if (targetX86) {
805 // x86 leaves the array pointer in v2, so load the array length that the handler expects
buzbeef0504cd2012-11-13 16:31:10 -0800806 opRegMem(cUnit, kOpMov, targetReg(kArg1), v2, Array::LengthOffset().Int32Value());
buzbeeb046e162012-10-30 15:48:42 -0700807 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800808 opRegCopy(cUnit, targetReg(kArg1), v2);
buzbeeb046e162012-10-30 15:48:42 -0700809 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700810 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800811 if (v1 == targetReg(kArg1)) {
812 // Swap v1 and v2, using kArg2 as a temp
813 opRegCopy(cUnit, targetReg(kArg2), v1);
buzbeeb046e162012-10-30 15:48:42 -0700814 if (targetX86) {
815 // x86 leaves the array pointer in v2; load the array length that the handler expects
buzbeef0504cd2012-11-13 16:31:10 -0800816 opRegMem(cUnit, kOpMov, targetReg(kArg1), v2, Array::LengthOffset().Int32Value());
buzbeeb046e162012-10-30 15:48:42 -0700817 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800818 opRegCopy(cUnit, targetReg(kArg1), v2);
buzbeeb046e162012-10-30 15:48:42 -0700819 }
buzbeef0504cd2012-11-13 16:31:10 -0800820 opRegCopy(cUnit, targetReg(kArg0), targetReg(kArg2));
Bill Buzbeea114add2012-05-03 15:00:40 -0700821 } else {
buzbeeb046e162012-10-30 15:48:42 -0700822 if (targetX86) {
823 // x86 leaves the array pointer in v2; load the array length that the handler expects
buzbeef0504cd2012-11-13 16:31:10 -0800824 opRegMem(cUnit, kOpMov, targetReg(kArg1), v2, Array::LengthOffset().Int32Value());
buzbeeb046e162012-10-30 15:48:42 -0700825 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800826 opRegCopy(cUnit, targetReg(kArg1), v2);
buzbeeb046e162012-10-30 15:48:42 -0700827 }
buzbeef0504cd2012-11-13 16:31:10 -0800828 opRegCopy(cUnit, targetReg(kArg0), v1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700829 }
buzbee31a4a6f2012-02-28 15:36:15 -0800830 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700831 funcOffset = ENTRYPOINT_OFFSET(pThrowArrayBoundsFromCode);
832 break;
833 case kThrowDivZero:
834 funcOffset = ENTRYPOINT_OFFSET(pThrowDivZeroFromCode);
835 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700836 case kThrowNoSuchMethod:
buzbeef0504cd2012-11-13 16:31:10 -0800837 opRegCopy(cUnit, targetReg(kArg0), v1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700838 funcOffset =
839 ENTRYPOINT_OFFSET(pThrowNoSuchMethodFromCode);
840 break;
841 case kThrowStackOverflow:
842 funcOffset = ENTRYPOINT_OFFSET(pThrowStackOverflowFromCode);
843 // Restore stack alignment
buzbeeb046e162012-10-30 15:48:42 -0700844 if (targetX86) {
buzbeef0504cd2012-11-13 16:31:10 -0800845 opRegImm(cUnit, kOpAdd, targetReg(kSp), cUnit->frameSize);
buzbeeb046e162012-10-30 15:48:42 -0700846 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800847 opRegImm(cUnit, kOpAdd, targetReg(kSp), (cUnit->numCoreSpills + cUnit->numFPSpills) * 4);
buzbeeb046e162012-10-30 15:48:42 -0700848 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700849 break;
850 default:
851 LOG(FATAL) << "Unexpected throw kind: " << lab->operands[0];
buzbee31a4a6f2012-02-28 15:36:15 -0800852 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700853 oatClobberCalleeSave(cUnit);
buzbeeb046e162012-10-30 15:48:42 -0700854 int rTgt = callHelperSetup(cUnit, funcOffset);
855 callHelper(cUnit, rTgt, funcOffset, true /* markSafepointPC */);
Bill Buzbeea114add2012-05-03 15:00:40 -0700856 }
buzbee31a4a6f2012-02-28 15:36:15 -0800857}
858
859/* Needed by the Assembler */
buzbeeb046e162012-10-30 15:48:42 -0700860void oatSetupResourceMasks(CompilationUnit* cUnit, LIR* lir)
buzbee31a4a6f2012-02-28 15:36:15 -0800861{
buzbeeb046e162012-10-30 15:48:42 -0700862 setupResourceMasks(cUnit, lir);
buzbee31a4a6f2012-02-28 15:36:15 -0800863}
864
buzbee16da88c2012-03-20 10:38:17 -0700865bool fastInstance(CompilationUnit* cUnit, uint32_t fieldIdx,
866 int& fieldOffset, bool& isVolatile, bool isPut)
867{
Bill Buzbeea114add2012-05-03 15:00:40 -0700868 OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700869 *cUnit->dex_file,
Bill Buzbeea114add2012-05-03 15:00:40 -0700870 cUnit->code_item, cUnit->method_idx,
871 cUnit->access_flags);
872 return cUnit->compiler->ComputeInstanceFieldInfo(fieldIdx, &mUnit,
873 fieldOffset, isVolatile, isPut);
buzbee16da88c2012-03-20 10:38:17 -0700874}
875
buzbee408ad162012-06-06 16:45:18 -0700876void genIGet(CompilationUnit* cUnit, uint32_t fieldIdx, int optFlags, OpSize size,
buzbee31a4a6f2012-02-28 15:36:15 -0800877 RegLocation rlDest, RegLocation rlObj,
Bill Buzbeea114add2012-05-03 15:00:40 -0700878 bool isLongOrDouble, bool isObject)
buzbee31a4a6f2012-02-28 15:36:15 -0800879{
Bill Buzbeea114add2012-05-03 15:00:40 -0700880 int fieldOffset;
881 bool isVolatile;
buzbee31a4a6f2012-02-28 15:36:15 -0800882
Bill Buzbeea114add2012-05-03 15:00:40 -0700883 bool fastPath = fastInstance(cUnit, fieldIdx, fieldOffset, isVolatile, false);
buzbee31a4a6f2012-02-28 15:36:15 -0800884
Bill Buzbeea114add2012-05-03 15:00:40 -0700885 if (fastPath && !SLOW_FIELD_PATH) {
886 RegLocation rlResult;
887 RegisterClass regClass = oatRegClassBySize(size);
888 DCHECK_GE(fieldOffset, 0);
889 rlObj = loadValue(cUnit, rlObj, kCoreReg);
890 if (isLongOrDouble) {
891 DCHECK(rlDest.wide);
buzbee408ad162012-06-06 16:45:18 -0700892 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags);
buzbeeb046e162012-10-30 15:48:42 -0700893 if (cUnit->instructionSet == kX86) {
894 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
895 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags);
896 loadBaseDispWide(cUnit, rlObj.lowReg, fieldOffset, rlResult.lowReg,
897 rlResult.highReg, rlObj.sRegLow);
898 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800899 oatGenMemBarrier(cUnit, kLoadLoad);
buzbeeb046e162012-10-30 15:48:42 -0700900 }
901 } else {
902 int regPtr = oatAllocTemp(cUnit);
903 opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset);
904 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
905 loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg);
906 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800907 oatGenMemBarrier(cUnit, kLoadLoad);
buzbeeb046e162012-10-30 15:48:42 -0700908 }
909 oatFreeTemp(cUnit, regPtr);
Bill Buzbeea114add2012-05-03 15:00:40 -0700910 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700911 storeValueWide(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -0800912 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700913 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
buzbee408ad162012-06-06 16:45:18 -0700914 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags);
915 loadBaseDisp(cUnit, rlObj.lowReg, fieldOffset, rlResult.lowReg,
Bill Buzbeea114add2012-05-03 15:00:40 -0700916 kWord, rlObj.sRegLow);
917 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800918 oatGenMemBarrier(cUnit, kLoadLoad);
Bill Buzbeea114add2012-05-03 15:00:40 -0700919 }
920 storeValue(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -0800921 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700922 } else {
923 int getterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pGet64Instance) :
924 (isObject ? ENTRYPOINT_OFFSET(pGetObjInstance)
925 : ENTRYPOINT_OFFSET(pGet32Instance));
buzbee8320f382012-09-11 16:29:42 -0700926 callRuntimeHelperImmRegLocation(cUnit, getterOffset, fieldIdx, rlObj, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700927 if (isLongOrDouble) {
928 RegLocation rlResult = oatGetReturnWide(cUnit, rlDest.fp);
929 storeValueWide(cUnit, rlDest, rlResult);
930 } else {
931 RegLocation rlResult = oatGetReturn(cUnit, rlDest.fp);
932 storeValue(cUnit, rlDest, rlResult);
933 }
934 }
buzbee31a4a6f2012-02-28 15:36:15 -0800935}
936
buzbee408ad162012-06-06 16:45:18 -0700937void genIPut(CompilationUnit* cUnit, uint32_t fieldIdx, int optFlags, OpSize size,
938 RegLocation rlSrc, RegLocation rlObj, bool isLongOrDouble, bool isObject)
buzbee31a4a6f2012-02-28 15:36:15 -0800939{
Bill Buzbeea114add2012-05-03 15:00:40 -0700940 int fieldOffset;
941 bool isVolatile;
buzbee31a4a6f2012-02-28 15:36:15 -0800942
Bill Buzbeea114add2012-05-03 15:00:40 -0700943 bool fastPath = fastInstance(cUnit, fieldIdx, fieldOffset, isVolatile,
944 true);
945 if (fastPath && !SLOW_FIELD_PATH) {
946 RegisterClass regClass = oatRegClassBySize(size);
947 DCHECK_GE(fieldOffset, 0);
948 rlObj = loadValue(cUnit, rlObj, kCoreReg);
949 if (isLongOrDouble) {
950 int regPtr;
951 rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg);
buzbee408ad162012-06-06 16:45:18 -0700952 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700953 regPtr = oatAllocTemp(cUnit);
954 opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset);
955 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800956 oatGenMemBarrier(cUnit, kStoreStore);
Bill Buzbeea114add2012-05-03 15:00:40 -0700957 }
jeffhao41005dd2012-05-09 17:58:52 -0700958 storeBaseDispWide(cUnit, regPtr, 0, rlSrc.lowReg, rlSrc.highReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700959 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800960 oatGenMemBarrier(cUnit, kLoadLoad);
Bill Buzbeea114add2012-05-03 15:00:40 -0700961 }
962 oatFreeTemp(cUnit, regPtr);
buzbee31a4a6f2012-02-28 15:36:15 -0800963 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700964 rlSrc = loadValue(cUnit, rlSrc, regClass);
buzbee408ad162012-06-06 16:45:18 -0700965 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700966 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800967 oatGenMemBarrier(cUnit, kStoreStore);
Bill Buzbeea114add2012-05-03 15:00:40 -0700968 }
969 storeBaseDisp(cUnit, rlObj.lowReg, fieldOffset, rlSrc.lowReg, kWord);
970 if (isVolatile) {
buzbee1bc37c62012-11-20 13:35:41 -0800971 oatGenMemBarrier(cUnit, kLoadLoad);
Bill Buzbeea114add2012-05-03 15:00:40 -0700972 }
973 if (isObject) {
974 markGCCard(cUnit, rlSrc.lowReg, rlObj.lowReg);
975 }
buzbee31a4a6f2012-02-28 15:36:15 -0800976 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700977 } else {
978 int setterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pSet64Instance) :
979 (isObject ? ENTRYPOINT_OFFSET(pSetObjInstance)
980 : ENTRYPOINT_OFFSET(pSet32Instance));
buzbee8320f382012-09-11 16:29:42 -0700981 callRuntimeHelperImmRegLocationRegLocation(cUnit, setterOffset, fieldIdx, rlObj, rlSrc, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700982 }
buzbee31a4a6f2012-02-28 15:36:15 -0800983}
984
buzbee6969d502012-06-15 16:40:31 -0700985void genConstClass(CompilationUnit* cUnit, uint32_t type_idx,
986 RegLocation rlDest)
buzbee31a4a6f2012-02-28 15:36:15 -0800987{
Bill Buzbeea114add2012-05-03 15:00:40 -0700988 RegLocation rlMethod = loadCurrMethod(cUnit);
989 int resReg = oatAllocTemp(cUnit);
990 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
991 if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700992 *cUnit->dex_file,
993 type_idx)) {
994 // Call out to helper which resolves type and verifies access.
buzbeef0504cd2012-11-13 16:31:10 -0800995 // Resolved type returned in kRet0.
buzbee8320f382012-09-11 16:29:42 -0700996 callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccessFromCode),
997 type_idx, rlMethod.lowReg, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700998 RegLocation rlResult = oatGetReturn(cUnit, false);
999 storeValue(cUnit, rlDest, rlResult);
1000 } else {
1001 // We're don't need access checks, load type from dex cache
1002 int32_t dex_cache_offset =
Mathieu Chartier66f19252012-09-18 08:57:04 -07001003 AbstractMethod::DexCacheResolvedTypesOffset().Int32Value();
Bill Buzbeea114add2012-05-03 15:00:40 -07001004 loadWordDisp(cUnit, rlMethod.lowReg, dex_cache_offset, resReg);
1005 int32_t offset_of_type =
1006 Array::DataOffset(sizeof(Class*)).Int32Value() + (sizeof(Class*)
1007 * type_idx);
1008 loadWordDisp(cUnit, resReg, offset_of_type, rlResult.lowReg);
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001009 if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(*cUnit->dex_file,
Bill Buzbeea114add2012-05-03 15:00:40 -07001010 type_idx) || SLOW_TYPE_PATH) {
1011 // Slow path, at runtime test if type is null and if so initialize
1012 oatFlushAllRegs(cUnit);
1013 LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, rlResult.lowReg, 0, NULL);
1014 // Resolved, store and hop over following code
1015 storeValue(cUnit, rlDest, rlResult);
1016 /*
1017 * Because we have stores of the target value on two paths,
1018 * clobber temp tracking for the destination using the ssa name
1019 */
1020 oatClobberSReg(cUnit, rlDest.sRegLow);
1021 LIR* branch2 = opUnconditionalBranch(cUnit,0);
1022 // TUNING: move slow path to end & remove unconditional branch
1023 LIR* target1 = newLIR0(cUnit, kPseudoTargetLabel);
buzbeef0504cd2012-11-13 16:31:10 -08001024 // Call out to helper, which will return resolved type in kArg0
buzbee8320f382012-09-11 16:29:42 -07001025 callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeFromCode), type_idx,
1026 rlMethod.lowReg, true);
Bill Buzbeea114add2012-05-03 15:00:40 -07001027 RegLocation rlResult = oatGetReturn(cUnit, false);
1028 storeValue(cUnit, rlDest, rlResult);
1029 /*
1030 * Because we have stores of the target value on two paths,
1031 * clobber temp tracking for the destination using the ssa name
1032 */
1033 oatClobberSReg(cUnit, rlDest.sRegLow);
1034 // Rejoin code paths
1035 LIR* target2 = newLIR0(cUnit, kPseudoTargetLabel);
buzbeecbd6d442012-11-17 14:11:25 -08001036 branch1->target = target1;
1037 branch2->target = target2;
buzbee31a4a6f2012-02-28 15:36:15 -08001038 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -07001039 // Fast path, we're done - just store result
1040 storeValue(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -08001041 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001042 }
buzbee31a4a6f2012-02-28 15:36:15 -08001043}
Ian Rogersab2b55d2012-03-18 00:06:11 -07001044
buzbee6969d502012-06-15 16:40:31 -07001045void genConstString(CompilationUnit* cUnit, uint32_t string_idx,
1046 RegLocation rlDest)
buzbee31a4a6f2012-02-28 15:36:15 -08001047{
Bill Buzbeea114add2012-05-03 15:00:40 -07001048 /* NOTE: Most strings should be available at compile time */
Bill Buzbeea114add2012-05-03 15:00:40 -07001049 int32_t offset_of_string = Array::DataOffset(sizeof(String*)).Int32Value() +
1050 (sizeof(String*) * string_idx);
1051 if (!cUnit->compiler->CanAssumeStringIsPresentInDexCache(
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001052 *cUnit->dex_file, string_idx) || SLOW_STRING_PATH) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001053 // slow path, resolve string if not in dex cache
1054 oatFlushAllRegs(cUnit);
1055 oatLockCallTemps(cUnit); // Using explicit registers
buzbeef0504cd2012-11-13 16:31:10 -08001056 loadCurrMethodDirect(cUnit, targetReg(kArg2));
1057 loadWordDisp(cUnit, targetReg(kArg2),
1058 AbstractMethod::DexCacheStringsOffset().Int32Value(), targetReg(kArg0));
1059 // Might call out to helper, which will return resolved string in kRet0
buzbeeb046e162012-10-30 15:48:42 -07001060 int rTgt = callHelperSetup(cUnit, ENTRYPOINT_OFFSET(pResolveStringFromCode));
buzbeef0504cd2012-11-13 16:31:10 -08001061 loadWordDisp(cUnit, targetReg(kArg0), offset_of_string, targetReg(kRet0));
1062 loadConstant(cUnit, targetReg(kArg1), string_idx);
buzbeeb046e162012-10-30 15:48:42 -07001063 if (cUnit->instructionSet == kThumb2) {
buzbeef0504cd2012-11-13 16:31:10 -08001064 opRegImm(cUnit, kOpCmp, targetReg(kRet0), 0); // Is resolved?
buzbeeb046e162012-10-30 15:48:42 -07001065 genBarrier(cUnit);
1066 // For testing, always force through helper
1067 if (!EXERCISE_SLOWEST_STRING_PATH) {
1068 opIT(cUnit, kArmCondEq, "T");
1069 }
buzbeef0504cd2012-11-13 16:31:10 -08001070 opRegCopy(cUnit, targetReg(kArg0), targetReg(kArg2)); // .eq
buzbeeb046e162012-10-30 15:48:42 -07001071 LIR* callInst = opReg(cUnit, kOpBlx, rTgt); // .eq, helper(Method*, string_idx)
1072 markSafepointPC(cUnit, callInst);
1073 oatFreeTemp(cUnit, rTgt);
1074 } else if (cUnit->instructionSet == kMips) {
buzbeef0504cd2012-11-13 16:31:10 -08001075 LIR* branch = opCmpImmBranch(cUnit, kCondNe, targetReg(kRet0), 0, NULL);
1076 opRegCopy(cUnit, targetReg(kArg0), targetReg(kArg2)); // .eq
buzbeeb046e162012-10-30 15:48:42 -07001077 LIR* callInst = opReg(cUnit, kOpBlx, rTgt);
1078 markSafepointPC(cUnit, callInst);
1079 oatFreeTemp(cUnit, rTgt);
1080 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
1081 branch->target = target;
1082 } else {
1083 DCHECK_EQ(cUnit->instructionSet, kX86);
buzbeef0504cd2012-11-13 16:31:10 -08001084 callRuntimeHelperRegReg(cUnit, ENTRYPOINT_OFFSET(pResolveStringFromCode), targetReg(kArg2), targetReg(kArg1), true);
buzbee31a4a6f2012-02-28 15:36:15 -08001085 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001086 genBarrier(cUnit);
1087 storeValue(cUnit, rlDest, oatGetReturn(cUnit, false));
1088 } else {
1089 RegLocation rlMethod = loadCurrMethod(cUnit);
1090 int resReg = oatAllocTemp(cUnit);
1091 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1092 loadWordDisp(cUnit, rlMethod.lowReg,
Mathieu Chartier66f19252012-09-18 08:57:04 -07001093 AbstractMethod::DexCacheStringsOffset().Int32Value(), resReg);
Bill Buzbeea114add2012-05-03 15:00:40 -07001094 loadWordDisp(cUnit, resReg, offset_of_string, rlResult.lowReg);
1095 storeValue(cUnit, rlDest, rlResult);
1096 }
buzbee31a4a6f2012-02-28 15:36:15 -08001097}
1098
1099/*
1100 * Let helper function take care of everything. Will
1101 * call Class::NewInstanceFromCode(type_idx, method);
1102 */
buzbee408ad162012-06-06 16:45:18 -07001103void genNewInstance(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlDest)
buzbee31a4a6f2012-02-28 15:36:15 -08001104{
Bill Buzbeea114add2012-05-03 15:00:40 -07001105 oatFlushAllRegs(cUnit); /* Everything to home location */
Bill Buzbeea114add2012-05-03 15:00:40 -07001106 // alloc will always check for resolution, do we also need to verify
1107 // access because the verifier was unable to?
1108 int funcOffset;
1109 if (cUnit->compiler->CanAccessInstantiableTypeWithoutChecks(
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001110 cUnit->method_idx, *cUnit->dex_file, type_idx)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001111 funcOffset = ENTRYPOINT_OFFSET(pAllocObjectFromCode);
1112 } else {
1113 funcOffset = ENTRYPOINT_OFFSET(pAllocObjectFromCodeWithAccessCheck);
1114 }
buzbee8320f382012-09-11 16:29:42 -07001115 callRuntimeHelperImmMethod(cUnit, funcOffset, type_idx, true);
Bill Buzbeea114add2012-05-03 15:00:40 -07001116 RegLocation rlResult = oatGetReturn(cUnit, false);
1117 storeValue(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -08001118}
1119
Ian Rogers474b6da2012-09-25 00:20:38 -07001120void genMoveException(CompilationUnit* cUnit, RegLocation rlDest)
1121{
1122 oatFlushAllRegs(cUnit); /* Everything to home location */
1123 int funcOffset = ENTRYPOINT_OFFSET(pGetAndClearException);
buzbeeb046e162012-10-30 15:48:42 -07001124 if (cUnit->instructionSet == kX86) {
1125 // Runtime helper will load argument for x86.
buzbeef0504cd2012-11-13 16:31:10 -08001126 callRuntimeHelperReg(cUnit, funcOffset, targetReg(kArg0), false);
buzbeeb046e162012-10-30 15:48:42 -07001127 } else {
buzbeef0504cd2012-11-13 16:31:10 -08001128 callRuntimeHelperReg(cUnit, funcOffset, targetReg(kSelf), false);
buzbeeb046e162012-10-30 15:48:42 -07001129 }
Ian Rogers474b6da2012-09-25 00:20:38 -07001130 RegLocation rlResult = oatGetReturn(cUnit, false);
1131 storeValue(cUnit, rlDest, rlResult);
1132}
1133
buzbee408ad162012-06-06 16:45:18 -07001134void genThrow(CompilationUnit* cUnit, RegLocation rlSrc)
Ian Rogersab2b55d2012-03-18 00:06:11 -07001135{
Bill Buzbeea114add2012-05-03 15:00:40 -07001136 oatFlushAllRegs(cUnit);
buzbee8320f382012-09-11 16:29:42 -07001137 callRuntimeHelperRegLocation(cUnit, ENTRYPOINT_OFFSET(pDeliverException), rlSrc, true);
Ian Rogersab2b55d2012-03-18 00:06:11 -07001138}
1139
buzbee408ad162012-06-06 16:45:18 -07001140void genInstanceof(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlDest,
buzbee31a4a6f2012-02-28 15:36:15 -08001141 RegLocation rlSrc)
1142{
Bill Buzbeea114add2012-05-03 15:00:40 -07001143 oatFlushAllRegs(cUnit);
1144 // May generate a call - use explicit registers
1145 oatLockCallTemps(cUnit);
buzbeef0504cd2012-11-13 16:31:10 -08001146 loadCurrMethodDirect(cUnit, targetReg(kArg1)); // kArg1 <= current Method*
1147 int classReg = targetReg(kArg2); // kArg2 will hold the Class*
Bill Buzbeea114add2012-05-03 15:00:40 -07001148 if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
Bill Buzbeea114add2012-05-03 15:00:40 -07001149 *cUnit->dex_file,
1150 type_idx)) {
1151 // Check we have access to type_idx and if not throw IllegalAccessError,
buzbeef0504cd2012-11-13 16:31:10 -08001152 // returns Class* in kArg0
buzbee8320f382012-09-11 16:29:42 -07001153 callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccessFromCode),
1154 type_idx, true);
buzbeef0504cd2012-11-13 16:31:10 -08001155 opRegCopy(cUnit, classReg, targetReg(kRet0)); // Align usage with fast path
1156 loadValueDirectFixed(cUnit, rlSrc, targetReg(kArg0)); // kArg0 <= ref
Bill Buzbeea114add2012-05-03 15:00:40 -07001157 } else {
buzbeef0504cd2012-11-13 16:31:10 -08001158 // Load dex cache entry into classReg (kArg2)
1159 loadValueDirectFixed(cUnit, rlSrc, targetReg(kArg0)); // kArg0 <= ref
1160 loadWordDisp(cUnit, targetReg(kArg1),
Mathieu Chartier66f19252012-09-18 08:57:04 -07001161 AbstractMethod::DexCacheResolvedTypesOffset().Int32Value(), classReg);
Bill Buzbeea114add2012-05-03 15:00:40 -07001162 int32_t offset_of_type =
1163 Array::DataOffset(sizeof(Class*)).Int32Value() + (sizeof(Class*)
1164 * type_idx);
1165 loadWordDisp(cUnit, classReg, offset_of_type, classReg);
1166 if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001167 *cUnit->dex_file, type_idx)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001168 // Need to test presence of type in dex cache at runtime
1169 LIR* hopBranch = opCmpImmBranch(cUnit, kCondNe, classReg, 0, NULL);
1170 // Not resolved
buzbeef0504cd2012-11-13 16:31:10 -08001171 // Call out to helper, which will return resolved type in kRet0
buzbee8320f382012-09-11 16:29:42 -07001172 callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeFromCode), type_idx, true);
buzbeef0504cd2012-11-13 16:31:10 -08001173 opRegCopy(cUnit, targetReg(kArg2), targetReg(kRet0)); // Align usage with fast path
1174 loadValueDirectFixed(cUnit, rlSrc, targetReg(kArg0)); /* reload Ref */
Bill Buzbeea114add2012-05-03 15:00:40 -07001175 // Rejoin code paths
1176 LIR* hopTarget = newLIR0(cUnit, kPseudoTargetLabel);
buzbeecbd6d442012-11-17 14:11:25 -08001177 hopBranch->target = hopTarget;
buzbee31a4a6f2012-02-28 15:36:15 -08001178 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001179 }
buzbeef0504cd2012-11-13 16:31:10 -08001180 /* kArg0 is ref, kArg2 is class. If ref==null, use directly as bool result */
jeffhao4eb68ed2012-10-17 16:41:07 -07001181 RegLocation rlResult = oatGetReturn(cUnit, false);
buzbeeb046e162012-10-30 15:48:42 -07001182 if (cUnit->instructionSet == kMips) {
1183 loadConstant(cUnit, rlResult.lowReg, 0); // store false result for if branch is taken
1184 }
buzbeef0504cd2012-11-13 16:31:10 -08001185 LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, targetReg(kArg0), 0, NULL);
Bill Buzbeea114add2012-05-03 15:00:40 -07001186 /* load object->klass_ */
1187 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
buzbeef0504cd2012-11-13 16:31:10 -08001188 loadWordDisp(cUnit, targetReg(kArg0), Object::ClassOffset().Int32Value(), targetReg(kArg1));
1189 /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class */
buzbee8320f382012-09-11 16:29:42 -07001190 LIR* callInst;
buzbeeb046e162012-10-30 15:48:42 -07001191 LIR* branchover = NULL;
1192 if (cUnit->instructionSet == kThumb2) {
1193 /* Uses conditional nullification */
1194 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pInstanceofNonTrivialFromCode));
buzbeef0504cd2012-11-13 16:31:10 -08001195 opRegReg(cUnit, kOpCmp, targetReg(kArg1), targetReg(kArg2)); // Same?
buzbeeb046e162012-10-30 15:48:42 -07001196 opIT(cUnit, kArmCondEq, "EE"); // if-convert the test
buzbeef0504cd2012-11-13 16:31:10 -08001197 loadConstant(cUnit, targetReg(kArg0), 1); // .eq case - load true
1198 opRegCopy(cUnit, targetReg(kArg0), targetReg(kArg2)); // .ne case - arg0 <= class
buzbeeb046e162012-10-30 15:48:42 -07001199 callInst = opReg(cUnit, kOpBlx, rTgt); // .ne case: helper(class, ref->class)
1200 oatFreeTemp(cUnit, rTgt);
1201 } else {
1202 /* Uses branchovers */
1203 loadConstant(cUnit, rlResult.lowReg, 1); // assume true
buzbeef0504cd2012-11-13 16:31:10 -08001204 branchover = opCmpBranch(cUnit, kCondEq, targetReg(kArg1), targetReg(kArg2), NULL);
buzbeeb046e162012-10-30 15:48:42 -07001205 if (cUnit->instructionSet != kX86) {
1206 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pInstanceofNonTrivialFromCode));
buzbeef0504cd2012-11-13 16:31:10 -08001207 opRegCopy(cUnit, targetReg(kArg0), targetReg(kArg2)); // .ne case - arg0 <= class
buzbeeb046e162012-10-30 15:48:42 -07001208 callInst = opReg(cUnit, kOpBlx, rTgt); // .ne case: helper(class, ref->class)
1209 oatFreeTemp(cUnit, rTgt);
1210 } else {
buzbeef0504cd2012-11-13 16:31:10 -08001211 opRegCopy(cUnit, targetReg(kArg0), targetReg(kArg2));
buzbeeb046e162012-10-30 15:48:42 -07001212 callInst = opThreadMem(cUnit, kOpBlx, ENTRYPOINT_OFFSET(pInstanceofNonTrivialFromCode));
1213 }
1214 }
buzbee8320f382012-09-11 16:29:42 -07001215 markSafepointPC(cUnit, callInst);
Bill Buzbeea114add2012-05-03 15:00:40 -07001216 oatClobberCalleeSave(cUnit);
1217 /* branch targets here */
1218 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
Bill Buzbeea114add2012-05-03 15:00:40 -07001219 storeValue(cUnit, rlDest, rlResult);
1220 branch1->target = target;
buzbeeb046e162012-10-30 15:48:42 -07001221 if (cUnit->instructionSet != kThumb2) {
1222 branchover->target = target;
1223 }
buzbee31a4a6f2012-02-28 15:36:15 -08001224}
1225
buzbee408ad162012-06-06 16:45:18 -07001226void genCheckCast(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlSrc)
buzbee31a4a6f2012-02-28 15:36:15 -08001227{
Bill Buzbeea114add2012-05-03 15:00:40 -07001228 oatFlushAllRegs(cUnit);
1229 // May generate a call - use explicit registers
1230 oatLockCallTemps(cUnit);
buzbeef0504cd2012-11-13 16:31:10 -08001231 loadCurrMethodDirect(cUnit, targetReg(kArg1)); // kArg1 <= current Method*
1232 int classReg = targetReg(kArg2); // kArg2 will hold the Class*
Bill Buzbeea114add2012-05-03 15:00:40 -07001233 if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx,
Bill Buzbeea114add2012-05-03 15:00:40 -07001234 *cUnit->dex_file,
1235 type_idx)) {
1236 // Check we have access to type_idx and if not throw IllegalAccessError,
buzbeef0504cd2012-11-13 16:31:10 -08001237 // returns Class* in kRet0
Bill Buzbeea114add2012-05-03 15:00:40 -07001238 // InitializeTypeAndVerifyAccess(idx, method)
buzbee8320f382012-09-11 16:29:42 -07001239 callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccessFromCode),
buzbeef0504cd2012-11-13 16:31:10 -08001240 type_idx, targetReg(kArg1), true);
1241 opRegCopy(cUnit, classReg, targetReg(kRet0)); // Align usage with fast path
Bill Buzbeea114add2012-05-03 15:00:40 -07001242 } else {
buzbeef0504cd2012-11-13 16:31:10 -08001243 // Load dex cache entry into classReg (kArg2)
1244 loadWordDisp(cUnit, targetReg(kArg1),
Mathieu Chartier66f19252012-09-18 08:57:04 -07001245 AbstractMethod::DexCacheResolvedTypesOffset().Int32Value(), classReg);
Bill Buzbeea114add2012-05-03 15:00:40 -07001246 int32_t offset_of_type =
1247 Array::DataOffset(sizeof(Class*)).Int32Value() +
1248 (sizeof(Class*) * type_idx);
1249 loadWordDisp(cUnit, classReg, offset_of_type, classReg);
1250 if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001251 *cUnit->dex_file, type_idx)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001252 // Need to test presence of type in dex cache at runtime
1253 LIR* hopBranch = opCmpImmBranch(cUnit, kCondNe, classReg, 0, NULL);
1254 // Not resolved
buzbeef0504cd2012-11-13 16:31:10 -08001255 // Call out to helper, which will return resolved type in kArg0
Bill Buzbeea114add2012-05-03 15:00:40 -07001256 // InitializeTypeFromCode(idx, method)
buzbeef0504cd2012-11-13 16:31:10 -08001257 callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeFromCode), type_idx, targetReg(kArg1),
buzbee8320f382012-09-11 16:29:42 -07001258 true);
buzbeef0504cd2012-11-13 16:31:10 -08001259 opRegCopy(cUnit, classReg, targetReg(kRet0)); // Align usage with fast path
Bill Buzbeea114add2012-05-03 15:00:40 -07001260 // Rejoin code paths
1261 LIR* hopTarget = newLIR0(cUnit, kPseudoTargetLabel);
buzbeecbd6d442012-11-17 14:11:25 -08001262 hopBranch->target = hopTarget;
buzbee31a4a6f2012-02-28 15:36:15 -08001263 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001264 }
buzbeef0504cd2012-11-13 16:31:10 -08001265 // At this point, classReg (kArg2) has class
1266 loadValueDirectFixed(cUnit, rlSrc, targetReg(kArg0)); // kArg0 <= ref
Bill Buzbeea114add2012-05-03 15:00:40 -07001267 /* Null is OK - continue */
buzbeef0504cd2012-11-13 16:31:10 -08001268 LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, targetReg(kArg0), 0, NULL);
Bill Buzbeea114add2012-05-03 15:00:40 -07001269 /* load object->klass_ */
1270 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
buzbeef0504cd2012-11-13 16:31:10 -08001271 loadWordDisp(cUnit, targetReg(kArg0), Object::ClassOffset().Int32Value(), targetReg(kArg1));
1272 /* kArg1 now contains object->klass_ */
buzbeeb046e162012-10-30 15:48:42 -07001273 LIR* branch2;
1274 if (cUnit->instructionSet == kThumb2) {
1275 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pCheckCastFromCode));
buzbeef0504cd2012-11-13 16:31:10 -08001276 opRegReg(cUnit, kOpCmp, targetReg(kArg1), classReg);
buzbeeb046e162012-10-30 15:48:42 -07001277 branch2 = opCondBranch(cUnit, kCondEq, NULL); /* If eq, trivial yes */
buzbeef0504cd2012-11-13 16:31:10 -08001278 opRegCopy(cUnit, targetReg(kArg0), targetReg(kArg1));
1279 opRegCopy(cUnit, targetReg(kArg1), targetReg(kArg2));
buzbeeb046e162012-10-30 15:48:42 -07001280 oatClobberCalleeSave(cUnit);
1281 LIR* callInst = opReg(cUnit, kOpBlx, rTgt);
1282 markSafepointPC(cUnit, callInst);
1283 oatFreeTemp(cUnit, rTgt);
1284 } else {
buzbeef0504cd2012-11-13 16:31:10 -08001285 branch2 = opCmpBranch(cUnit, kCondEq, targetReg(kArg1), classReg, NULL);
1286 callRuntimeHelperRegReg(cUnit, ENTRYPOINT_OFFSET(pCheckCastFromCode), targetReg(kArg1), targetReg(kArg2), true);
buzbeeb046e162012-10-30 15:48:42 -07001287 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001288 /* branch target here */
1289 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
1290 branch1->target = target;
1291 branch2->target = target;
buzbee31a4a6f2012-02-28 15:36:15 -08001292}
1293
buzbee31a4a6f2012-02-28 15:36:15 -08001294/*
1295 * Generate array store
1296 *
1297 */
buzbee408ad162012-06-06 16:45:18 -07001298void genArrayObjPut(CompilationUnit* cUnit, int optFlags, RegLocation rlArray,
Bill Buzbeea114add2012-05-03 15:00:40 -07001299 RegLocation rlIndex, RegLocation rlSrc, int scale)
buzbee31a4a6f2012-02-28 15:36:15 -08001300{
Bill Buzbeea114add2012-05-03 15:00:40 -07001301 int lenOffset = Array::LengthOffset().Int32Value();
1302 int dataOffset = Array::DataOffset(sizeof(Object*)).Int32Value();
buzbee31a4a6f2012-02-28 15:36:15 -08001303
Bill Buzbeea114add2012-05-03 15:00:40 -07001304 oatFlushAllRegs(cUnit); // Use explicit registers
1305 oatLockCallTemps(cUnit);
buzbee31a4a6f2012-02-28 15:36:15 -08001306
buzbeef0504cd2012-11-13 16:31:10 -08001307 int rValue = targetReg(kArg0); // Register holding value
1308 int rArrayClass = targetReg(kArg1); // Register holding array's Class
1309 int rArray = targetReg(kArg2); // Register holding array
1310 int rIndex = targetReg(kArg3); // Register holding index into array
Ian Rogersd36c52e2012-04-09 16:29:25 -07001311
Bill Buzbeea114add2012-05-03 15:00:40 -07001312 loadValueDirectFixed(cUnit, rlArray, rArray); // Grab array
1313 loadValueDirectFixed(cUnit, rlSrc, rValue); // Grab value
1314 loadValueDirectFixed(cUnit, rlIndex, rIndex); // Grab index
Ian Rogersd36c52e2012-04-09 16:29:25 -07001315
buzbee408ad162012-06-06 16:45:18 -07001316 genNullCheck(cUnit, rlArray.sRegLow, rArray, optFlags); // NPE?
Ian Rogersd36c52e2012-04-09 16:29:25 -07001317
Bill Buzbeea114add2012-05-03 15:00:40 -07001318 // Store of null?
1319 LIR* null_value_check = opCmpImmBranch(cUnit, kCondEq, rValue, 0, NULL);
Ian Rogersd36c52e2012-04-09 16:29:25 -07001320
Bill Buzbeea114add2012-05-03 15:00:40 -07001321 // Get the array's class.
1322 loadWordDisp(cUnit, rArray, Object::ClassOffset().Int32Value(), rArrayClass);
buzbee8320f382012-09-11 16:29:42 -07001323 callRuntimeHelperRegReg(cUnit, ENTRYPOINT_OFFSET(pCanPutArrayElementFromCode), rValue,
1324 rArrayClass, true);
Bill Buzbeea114add2012-05-03 15:00:40 -07001325 // Redo loadValues in case they didn't survive the call.
1326 loadValueDirectFixed(cUnit, rlArray, rArray); // Reload array
1327 loadValueDirectFixed(cUnit, rlIndex, rIndex); // Reload index
1328 loadValueDirectFixed(cUnit, rlSrc, rValue); // Reload value
1329 rArrayClass = INVALID_REG;
buzbee31a4a6f2012-02-28 15:36:15 -08001330
Bill Buzbeea114add2012-05-03 15:00:40 -07001331 // Branch here if value to be stored == null
1332 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
1333 null_value_check->target = target;
buzbee31a4a6f2012-02-28 15:36:15 -08001334
buzbeeb046e162012-10-30 15:48:42 -07001335 if (cUnit->instructionSet == kX86) {
1336 // make an extra temp available for card mark below
buzbeef0504cd2012-11-13 16:31:10 -08001337 oatFreeTemp(cUnit, targetReg(kArg1));
buzbeeb046e162012-10-30 15:48:42 -07001338 if (!(optFlags & MIR_IGNORE_RANGE_CHECK)) {
1339 /* if (rlIndex >= [rlArray + lenOffset]) goto kThrowArrayBounds */
1340 genRegMemCheck(cUnit, kCondUge, rIndex, rArray, lenOffset, kThrowArrayBounds);
1341 }
1342 storeBaseIndexedDisp(cUnit, rArray, rIndex, scale,
1343 dataOffset, rValue, INVALID_REG, kWord, INVALID_SREG);
1344 } else {
1345 bool needsRangeCheck = (!(optFlags & MIR_IGNORE_RANGE_CHECK));
1346 int regLen = INVALID_REG;
1347 if (needsRangeCheck) {
buzbeef0504cd2012-11-13 16:31:10 -08001348 regLen = targetReg(kArg1);
buzbeeb046e162012-10-30 15:48:42 -07001349 loadWordDisp(cUnit, rArray, lenOffset, regLen); // Get len
1350 }
1351 /* rPtr -> array data */
1352 int rPtr = oatAllocTemp(cUnit);
1353 opRegRegImm(cUnit, kOpAdd, rPtr, rArray, dataOffset);
1354 if (needsRangeCheck) {
1355 genRegRegCheck(cUnit, kCondCs, rIndex, regLen, kThrowArrayBounds);
1356 }
1357 storeBaseIndexed(cUnit, rPtr, rIndex, rValue, scale, kWord);
1358 oatFreeTemp(cUnit, rPtr);
Bill Buzbeea114add2012-05-03 15:00:40 -07001359 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001360 oatFreeTemp(cUnit, rIndex);
1361 markGCCard(cUnit, rValue, rArray);
buzbee31a4a6f2012-02-28 15:36:15 -08001362}
1363
1364/*
1365 * Generate array load
1366 */
buzbee408ad162012-06-06 16:45:18 -07001367void genArrayGet(CompilationUnit* cUnit, int optFlags, OpSize size,
buzbee31a4a6f2012-02-28 15:36:15 -08001368 RegLocation rlArray, RegLocation rlIndex,
1369 RegLocation rlDest, int scale)
1370{
Bill Buzbeea114add2012-05-03 15:00:40 -07001371 RegisterClass regClass = oatRegClassBySize(size);
1372 int lenOffset = Array::LengthOffset().Int32Value();
1373 int dataOffset;
1374 RegLocation rlResult;
1375 rlArray = loadValue(cUnit, rlArray, kCoreReg);
1376 rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
buzbee31a4a6f2012-02-28 15:36:15 -08001377
Bill Buzbeea114add2012-05-03 15:00:40 -07001378 if (size == kLong || size == kDouble) {
1379 dataOffset = Array::DataOffset(sizeof(int64_t)).Int32Value();
1380 } else {
1381 dataOffset = Array::DataOffset(sizeof(int32_t)).Int32Value();
1382 }
buzbee31a4a6f2012-02-28 15:36:15 -08001383
Bill Buzbeea114add2012-05-03 15:00:40 -07001384 /* null object? */
buzbee408ad162012-06-06 16:45:18 -07001385 genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, optFlags);
buzbee31a4a6f2012-02-28 15:36:15 -08001386
buzbeeb046e162012-10-30 15:48:42 -07001387 if (cUnit->instructionSet == kX86) {
1388 if (!(optFlags & MIR_IGNORE_RANGE_CHECK)) {
1389 /* if (rlIndex >= [rlArray + lenOffset]) goto kThrowArrayBounds */
1390 genRegMemCheck(cUnit, kCondUge, rlIndex.lowReg, rlArray.lowReg,
1391 lenOffset, kThrowArrayBounds);
1392 }
1393 if ((size == kLong) || (size == kDouble)) {
1394 int regAddr = oatAllocTemp(cUnit);
1395 opLea(cUnit, regAddr, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset);
1396 oatFreeTemp(cUnit, rlArray.lowReg);
1397 oatFreeTemp(cUnit, rlIndex.lowReg);
1398 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
1399 loadBaseIndexedDisp(cUnit, regAddr, INVALID_REG, 0, 0, rlResult.lowReg,
1400 rlResult.highReg, size, INVALID_SREG);
1401 storeValueWide(cUnit, rlDest, rlResult);
buzbee31a4a6f2012-02-28 15:36:15 -08001402 } else {
buzbeeb046e162012-10-30 15:48:42 -07001403 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
Bill Buzbeea114add2012-05-03 15:00:40 -07001404
buzbeeb046e162012-10-30 15:48:42 -07001405 loadBaseIndexedDisp(cUnit, rlArray.lowReg, rlIndex.lowReg, scale,
1406 dataOffset, rlResult.lowReg, INVALID_REG, size,
1407 INVALID_SREG);
Bill Buzbeea114add2012-05-03 15:00:40 -07001408
buzbeeb046e162012-10-30 15:48:42 -07001409 storeValue(cUnit, rlDest, rlResult);
1410 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001411 } else {
buzbeeb046e162012-10-30 15:48:42 -07001412 int regPtr = oatAllocTemp(cUnit);
1413 bool needsRangeCheck = (!(optFlags & MIR_IGNORE_RANGE_CHECK));
1414 int regLen = INVALID_REG;
Bill Buzbeea114add2012-05-03 15:00:40 -07001415 if (needsRangeCheck) {
buzbeeb046e162012-10-30 15:48:42 -07001416 regLen = oatAllocTemp(cUnit);
1417 /* Get len */
1418 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen);
Bill Buzbeea114add2012-05-03 15:00:40 -07001419 }
buzbeeb046e162012-10-30 15:48:42 -07001420 /* regPtr -> array data */
1421 opRegRegImm(cUnit, kOpAdd, regPtr, rlArray.lowReg, dataOffset);
1422 oatFreeTemp(cUnit, rlArray.lowReg);
1423 if ((size == kLong) || (size == kDouble)) {
1424 if (scale) {
1425 int rNewIndex = oatAllocTemp(cUnit);
1426 opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale);
1427 opRegReg(cUnit, kOpAdd, regPtr, rNewIndex);
1428 oatFreeTemp(cUnit, rNewIndex);
1429 } else {
1430 opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg);
1431 }
1432 oatFreeTemp(cUnit, rlIndex.lowReg);
1433 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
Bill Buzbeea114add2012-05-03 15:00:40 -07001434
buzbeeb046e162012-10-30 15:48:42 -07001435 if (needsRangeCheck) {
1436 // TODO: change kCondCS to a more meaningful name, is the sense of
1437 // carry-set/clear flipped?
1438 genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds);
1439 oatFreeTemp(cUnit, regLen);
1440 }
1441 loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg);
1442
1443 oatFreeTemp(cUnit, regPtr);
1444 storeValueWide(cUnit, rlDest, rlResult);
1445 } else {
1446 rlResult = oatEvalLoc(cUnit, rlDest, regClass, true);
1447
1448 if (needsRangeCheck) {
1449 // TODO: change kCondCS to a more meaningful name, is the sense of
1450 // carry-set/clear flipped?
1451 genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds);
1452 oatFreeTemp(cUnit, regLen);
1453 }
1454 loadBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlResult.lowReg, scale, size);
1455
1456 oatFreeTemp(cUnit, regPtr);
1457 storeValue(cUnit, rlDest, rlResult);
1458 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001459 }
buzbee31a4a6f2012-02-28 15:36:15 -08001460}
1461
1462/*
1463 * Generate array store
1464 *
1465 */
buzbee408ad162012-06-06 16:45:18 -07001466void genArrayPut(CompilationUnit* cUnit, int optFlags, OpSize size,
buzbee31a4a6f2012-02-28 15:36:15 -08001467 RegLocation rlArray, RegLocation rlIndex,
1468 RegLocation rlSrc, int scale)
1469{
Bill Buzbeea114add2012-05-03 15:00:40 -07001470 RegisterClass regClass = oatRegClassBySize(size);
1471 int lenOffset = Array::LengthOffset().Int32Value();
1472 int dataOffset;
buzbee31a4a6f2012-02-28 15:36:15 -08001473
Bill Buzbeea114add2012-05-03 15:00:40 -07001474 if (size == kLong || size == kDouble) {
1475 dataOffset = Array::DataOffset(sizeof(int64_t)).Int32Value();
1476 } else {
1477 dataOffset = Array::DataOffset(sizeof(int32_t)).Int32Value();
1478 }
buzbee31a4a6f2012-02-28 15:36:15 -08001479
Bill Buzbeea114add2012-05-03 15:00:40 -07001480 rlArray = loadValue(cUnit, rlArray, kCoreReg);
1481 rlIndex = loadValue(cUnit, rlIndex, kCoreReg);
buzbeeb046e162012-10-30 15:48:42 -07001482 int regPtr = INVALID_REG;
1483 if (cUnit->instructionSet != kX86) {
1484 if (oatIsTemp(cUnit, rlArray.lowReg)) {
1485 oatClobber(cUnit, rlArray.lowReg);
1486 regPtr = rlArray.lowReg;
1487 } else {
1488 regPtr = oatAllocTemp(cUnit);
1489 opRegCopy(cUnit, regPtr, rlArray.lowReg);
1490 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001491 }
buzbee31a4a6f2012-02-28 15:36:15 -08001492
Bill Buzbeea114add2012-05-03 15:00:40 -07001493 /* null object? */
buzbee408ad162012-06-06 16:45:18 -07001494 genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, optFlags);
buzbee31a4a6f2012-02-28 15:36:15 -08001495
buzbeeb046e162012-10-30 15:48:42 -07001496 if (cUnit->instructionSet == kX86) {
1497 if (!(optFlags & MIR_IGNORE_RANGE_CHECK)) {
1498 /* if (rlIndex >= [rlArray + lenOffset]) goto kThrowArrayBounds */
1499 genRegMemCheck(cUnit, kCondUge, rlIndex.lowReg, rlArray.lowReg, lenOffset, kThrowArrayBounds);
1500 }
1501 if ((size == kLong) || (size == kDouble)) {
1502 rlSrc = loadValueWide(cUnit, rlSrc, regClass);
buzbee31a4a6f2012-02-28 15:36:15 -08001503 } else {
buzbeeb046e162012-10-30 15:48:42 -07001504 rlSrc = loadValue(cUnit, rlSrc, regClass);
buzbee31a4a6f2012-02-28 15:36:15 -08001505 }
buzbeeb046e162012-10-30 15:48:42 -07001506 // If the src reg can't be byte accessed, move it to a temp first.
1507 if ((size == kSignedByte || size == kUnsignedByte) && rlSrc.lowReg >= 4) {
1508 int temp = oatAllocTemp(cUnit);
1509 opRegCopy(cUnit, temp, rlSrc.lowReg);
1510 storeBaseIndexedDisp(cUnit, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset, temp,
1511 INVALID_REG, size, INVALID_SREG);
1512 } else {
1513 storeBaseIndexedDisp(cUnit, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset, rlSrc.lowReg,
1514 rlSrc.highReg, size, INVALID_SREG);
Bill Buzbeea114add2012-05-03 15:00:40 -07001515 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001516 } else {
buzbeeb046e162012-10-30 15:48:42 -07001517 bool needsRangeCheck = (!(optFlags & MIR_IGNORE_RANGE_CHECK));
1518 int regLen = INVALID_REG;
Bill Buzbeea114add2012-05-03 15:00:40 -07001519 if (needsRangeCheck) {
buzbeeb046e162012-10-30 15:48:42 -07001520 regLen = oatAllocTemp(cUnit);
1521 //NOTE: max live temps(4) here.
1522 /* Get len */
1523 loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen);
Bill Buzbeea114add2012-05-03 15:00:40 -07001524 }
buzbeeb046e162012-10-30 15:48:42 -07001525 /* regPtr -> array data */
1526 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
1527 /* at this point, regPtr points to array, 2 live temps */
1528 if ((size == kLong) || (size == kDouble)) {
1529 //TUNING: specific wide routine that can handle fp regs
1530 if (scale) {
1531 int rNewIndex = oatAllocTemp(cUnit);
1532 opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale);
1533 opRegReg(cUnit, kOpAdd, regPtr, rNewIndex);
1534 oatFreeTemp(cUnit, rNewIndex);
1535 } else {
1536 opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg);
1537 }
1538 rlSrc = loadValueWide(cUnit, rlSrc, regClass);
1539
1540 if (needsRangeCheck) {
1541 genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds);
1542 oatFreeTemp(cUnit, regLen);
1543 }
1544
1545 storeBaseDispWide(cUnit, regPtr, 0, rlSrc.lowReg, rlSrc.highReg);
1546
1547 oatFreeTemp(cUnit, regPtr);
1548 } else {
1549 rlSrc = loadValue(cUnit, rlSrc, regClass);
1550 if (needsRangeCheck) {
1551 genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds);
1552 oatFreeTemp(cUnit, regLen);
1553 }
1554 storeBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlSrc.lowReg,
1555 scale, size);
1556 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001557 }
buzbee31a4a6f2012-02-28 15:36:15 -08001558}
1559
buzbee408ad162012-06-06 16:45:18 -07001560void genLong3Addr(CompilationUnit* cUnit, OpKind firstOp,
buzbee31a4a6f2012-02-28 15:36:15 -08001561 OpKind secondOp, RegLocation rlDest,
Bill Buzbeea114add2012-05-03 15:00:40 -07001562 RegLocation rlSrc1, RegLocation rlSrc2)
buzbee31a4a6f2012-02-28 15:36:15 -08001563{
Bill Buzbeea114add2012-05-03 15:00:40 -07001564 RegLocation rlResult;
buzbeeb046e162012-10-30 15:48:42 -07001565 if (cUnit->instructionSet == kThumb2) {
1566 /*
1567 * NOTE: This is the one place in the code in which we might have
1568 * as many as six live temporary registers. There are 5 in the normal
1569 * set for Arm. Until we have spill capabilities, temporarily add
1570 * lr to the temp set. It is safe to do this locally, but note that
1571 * lr is used explicitly elsewhere in the code generator and cannot
1572 * normally be used as a general temp register.
1573 */
buzbeef0504cd2012-11-13 16:31:10 -08001574 oatMarkTemp(cUnit, targetReg(kLr)); // Add lr to the temp pool
1575 oatFreeTemp(cUnit, targetReg(kLr)); // and make it available
buzbeeb046e162012-10-30 15:48:42 -07001576 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001577 rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg);
1578 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
1579 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1580 // The longs may overlap - use intermediate temp if so
buzbeea4a970a2012-11-08 07:54:03 -08001581 if ((rlResult.lowReg == rlSrc1.highReg) || (rlResult.lowReg == rlSrc2.highReg)){
Bill Buzbeea114add2012-05-03 15:00:40 -07001582 int tReg = oatAllocTemp(cUnit);
buzbeea4a970a2012-11-08 07:54:03 -08001583 opRegRegReg(cUnit, firstOp, tReg, rlSrc1.lowReg, rlSrc2.lowReg);
1584 opRegRegReg(cUnit, secondOp, rlResult.highReg, rlSrc1.highReg, rlSrc2.highReg);
1585 opRegCopy(cUnit, rlResult.lowReg, tReg);
Bill Buzbeea114add2012-05-03 15:00:40 -07001586 oatFreeTemp(cUnit, tReg);
1587 } else {
1588 opRegRegReg(cUnit, firstOp, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg);
1589 opRegRegReg(cUnit, secondOp, rlResult.highReg, rlSrc1.highReg,
1590 rlSrc2.highReg);
1591 }
1592 /*
1593 * NOTE: If rlDest refers to a frame variable in a large frame, the
1594 * following storeValueWide might need to allocate a temp register.
1595 * To further work around the lack of a spill capability, explicitly
1596 * free any temps from rlSrc1 & rlSrc2 that aren't still live in rlResult.
1597 * Remove when spill is functional.
1598 */
1599 freeRegLocTemps(cUnit, rlResult, rlSrc1);
1600 freeRegLocTemps(cUnit, rlResult, rlSrc2);
1601 storeValueWide(cUnit, rlDest, rlResult);
buzbeeb046e162012-10-30 15:48:42 -07001602 if (cUnit->instructionSet == kThumb2) {
buzbeef0504cd2012-11-13 16:31:10 -08001603 oatClobber(cUnit, targetReg(kLr));
1604 oatUnmarkTemp(cUnit, targetReg(kLr)); // Remove lr from the temp pool
buzbeeb046e162012-10-30 15:48:42 -07001605 }
buzbee31a4a6f2012-02-28 15:36:15 -08001606}
1607
1608
buzbee408ad162012-06-06 16:45:18 -07001609bool genShiftOpLong(CompilationUnit* cUnit, Instruction::Code opcode, RegLocation rlDest,
buzbee31a4a6f2012-02-28 15:36:15 -08001610 RegLocation rlSrc1, RegLocation rlShift)
1611{
Bill Buzbeea114add2012-05-03 15:00:40 -07001612 int funcOffset;
buzbee31a4a6f2012-02-28 15:36:15 -08001613
buzbee408ad162012-06-06 16:45:18 -07001614 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001615 case Instruction::SHL_LONG:
1616 case Instruction::SHL_LONG_2ADDR:
1617 funcOffset = ENTRYPOINT_OFFSET(pShlLong);
1618 break;
1619 case Instruction::SHR_LONG:
1620 case Instruction::SHR_LONG_2ADDR:
1621 funcOffset = ENTRYPOINT_OFFSET(pShrLong);
1622 break;
1623 case Instruction::USHR_LONG:
1624 case Instruction::USHR_LONG_2ADDR:
1625 funcOffset = ENTRYPOINT_OFFSET(pUshrLong);
1626 break;
1627 default:
1628 LOG(FATAL) << "Unexpected case";
1629 return true;
1630 }
1631 oatFlushAllRegs(cUnit); /* Send everything to home location */
buzbee8320f382012-09-11 16:29:42 -07001632 callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlShift, false);
Bill Buzbeea114add2012-05-03 15:00:40 -07001633 RegLocation rlResult = oatGetReturnWide(cUnit, false);
1634 storeValueWide(cUnit, rlDest, rlResult);
1635 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08001636}
1637
1638
buzbee408ad162012-06-06 16:45:18 -07001639bool genArithOpInt(CompilationUnit* cUnit, Instruction::Code opcode, RegLocation rlDest,
Bill Buzbeea114add2012-05-03 15:00:40 -07001640 RegLocation rlSrc1, RegLocation rlSrc2)
buzbee31a4a6f2012-02-28 15:36:15 -08001641{
Bill Buzbeea114add2012-05-03 15:00:40 -07001642 OpKind op = kOpBkpt;
jeffhao4f8f04a2012-10-02 18:10:35 -07001643 bool isDivRem = false;
Bill Buzbeea114add2012-05-03 15:00:40 -07001644 bool checkZero = false;
1645 bool unary = false;
1646 RegLocation rlResult;
1647 bool shiftOp = false;
buzbee408ad162012-06-06 16:45:18 -07001648 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001649 case Instruction::NEG_INT:
1650 op = kOpNeg;
1651 unary = true;
1652 break;
1653 case Instruction::NOT_INT:
1654 op = kOpMvn;
1655 unary = true;
1656 break;
1657 case Instruction::ADD_INT:
1658 case Instruction::ADD_INT_2ADDR:
1659 op = kOpAdd;
1660 break;
1661 case Instruction::SUB_INT:
1662 case Instruction::SUB_INT_2ADDR:
1663 op = kOpSub;
1664 break;
1665 case Instruction::MUL_INT:
1666 case Instruction::MUL_INT_2ADDR:
1667 op = kOpMul;
1668 break;
1669 case Instruction::DIV_INT:
1670 case Instruction::DIV_INT_2ADDR:
1671 checkZero = true;
1672 op = kOpDiv;
jeffhao4f8f04a2012-10-02 18:10:35 -07001673 isDivRem = true;
Bill Buzbeea114add2012-05-03 15:00:40 -07001674 break;
buzbeef0504cd2012-11-13 16:31:10 -08001675 /* NOTE: returns in kArg1 */
Bill Buzbeea114add2012-05-03 15:00:40 -07001676 case Instruction::REM_INT:
1677 case Instruction::REM_INT_2ADDR:
1678 checkZero = true;
1679 op = kOpRem;
jeffhao4f8f04a2012-10-02 18:10:35 -07001680 isDivRem = true;
Bill Buzbeea114add2012-05-03 15:00:40 -07001681 break;
1682 case Instruction::AND_INT:
1683 case Instruction::AND_INT_2ADDR:
1684 op = kOpAnd;
1685 break;
1686 case Instruction::OR_INT:
1687 case Instruction::OR_INT_2ADDR:
1688 op = kOpOr;
1689 break;
1690 case Instruction::XOR_INT:
1691 case Instruction::XOR_INT_2ADDR:
1692 op = kOpXor;
1693 break;
1694 case Instruction::SHL_INT:
1695 case Instruction::SHL_INT_2ADDR:
1696 shiftOp = true;
1697 op = kOpLsl;
1698 break;
1699 case Instruction::SHR_INT:
1700 case Instruction::SHR_INT_2ADDR:
1701 shiftOp = true;
1702 op = kOpAsr;
1703 break;
1704 case Instruction::USHR_INT:
1705 case Instruction::USHR_INT_2ADDR:
1706 shiftOp = true;
1707 op = kOpLsr;
1708 break;
1709 default:
buzbeecbd6d442012-11-17 14:11:25 -08001710 LOG(FATAL) << "Invalid word arith op: " << opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -07001711 }
jeffhao4f8f04a2012-10-02 18:10:35 -07001712 if (!isDivRem) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001713 if (unary) {
1714 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
1715 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1716 opRegReg(cUnit, op, rlResult.lowReg, rlSrc1.lowReg);
buzbee31a4a6f2012-02-28 15:36:15 -08001717 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -07001718 if (shiftOp) {
buzbeeb046e162012-10-30 15:48:42 -07001719 int tReg = INVALID_REG;
1720 if (cUnit->instructionSet == kX86) {
1721 // X86 doesn't require masking and must use ECX
buzbeef0504cd2012-11-13 16:31:10 -08001722 tReg = targetReg(kCount); // rCX
buzbeeb046e162012-10-30 15:48:42 -07001723 loadValueDirectFixed(cUnit, rlSrc2, tReg);
1724 } else {
1725 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
1726 tReg = oatAllocTemp(cUnit);
1727 opRegRegImm(cUnit, kOpAnd, tReg, rlSrc2.lowReg, 31);
1728 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001729 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
1730 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1731 opRegRegReg(cUnit, op, rlResult.lowReg, rlSrc1.lowReg, tReg);
1732 oatFreeTemp(cUnit, tReg);
1733 } else {
1734 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
1735 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
1736 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1737 opRegRegReg(cUnit, op, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg);
1738 }
buzbee31a4a6f2012-02-28 15:36:15 -08001739 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001740 storeValue(cUnit, rlDest, rlResult);
1741 } else {
buzbeeb046e162012-10-30 15:48:42 -07001742 if (cUnit->instructionSet == kMips) {
1743 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
1744 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
1745 if (checkZero) {
1746 genImmedCheck(cUnit, kCondEq, rlSrc2.lowReg, 0, kThrowDivZero);
1747 }
1748 rlResult = genDivRem(cUnit, rlDest, rlSrc1.lowReg, rlSrc2.lowReg, op == kOpDiv);
jeffhao4f8f04a2012-10-02 18:10:35 -07001749 } else {
buzbeeb046e162012-10-30 15:48:42 -07001750 int funcOffset = ENTRYPOINT_OFFSET(pIdivmod);
1751 oatFlushAllRegs(cUnit); /* Send everything to home location */
buzbeef0504cd2012-11-13 16:31:10 -08001752 loadValueDirectFixed(cUnit, rlSrc2, targetReg(kArg1));
buzbeeb046e162012-10-30 15:48:42 -07001753 int rTgt = callHelperSetup(cUnit, funcOffset);
buzbeef0504cd2012-11-13 16:31:10 -08001754 loadValueDirectFixed(cUnit, rlSrc1, targetReg(kArg0));
buzbeeb046e162012-10-30 15:48:42 -07001755 if (checkZero) {
buzbeef0504cd2012-11-13 16:31:10 -08001756 genImmedCheck(cUnit, kCondEq, targetReg(kArg1), 0, kThrowDivZero);
buzbeeb046e162012-10-30 15:48:42 -07001757 }
1758 // NOTE: callout here is not a safepoint
1759 callHelper(cUnit, rTgt, funcOffset, false /* not a safepoint */ );
1760 if (op == kOpDiv)
1761 rlResult = oatGetReturn(cUnit, false);
1762 else
1763 rlResult = oatGetReturnAlt(cUnit);
jeffhao4f8f04a2012-10-02 18:10:35 -07001764 }
jeffhao4eb68ed2012-10-17 16:41:07 -07001765 storeValue(cUnit, rlDest, rlResult);
Bill Buzbeea114add2012-05-03 15:00:40 -07001766 }
1767 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08001768}
1769
1770/*
1771 * The following are the first-level codegen routines that analyze the format
1772 * of each bytecode then either dispatch special purpose codegen routines
1773 * or produce corresponding Thumb instructions directly.
1774 */
1775
1776bool isPowerOfTwo(int x)
1777{
Bill Buzbeea114add2012-05-03 15:00:40 -07001778 return (x & (x - 1)) == 0;
buzbee31a4a6f2012-02-28 15:36:15 -08001779}
1780
1781// Returns true if no more than two bits are set in 'x'.
1782bool isPopCountLE2(unsigned int x)
1783{
Bill Buzbeea114add2012-05-03 15:00:40 -07001784 x &= x - 1;
1785 return (x & (x - 1)) == 0;
buzbee31a4a6f2012-02-28 15:36:15 -08001786}
1787
1788// Returns the index of the lowest set bit in 'x'.
1789int lowestSetBit(unsigned int x) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001790 int bit_posn = 0;
1791 while ((x & 0xf) == 0) {
1792 bit_posn += 4;
1793 x >>= 4;
1794 }
1795 while ((x & 1) == 0) {
1796 bit_posn++;
1797 x >>= 1;
1798 }
1799 return bit_posn;
buzbee31a4a6f2012-02-28 15:36:15 -08001800}
1801
1802// Returns true if it added instructions to 'cUnit' to divide 'rlSrc' by 'lit'
1803// and store the result in 'rlDest'.
Elliott Hughesadb8c672012-03-06 16:49:32 -08001804bool handleEasyDivide(CompilationUnit* cUnit, Instruction::Code dalvikOpcode,
Bill Buzbeea114add2012-05-03 15:00:40 -07001805 RegLocation rlSrc, RegLocation rlDest, int lit)
buzbee31a4a6f2012-02-28 15:36:15 -08001806{
buzbee0f79d722012-11-01 15:35:27 -07001807 if ((lit < 2) || ((cUnit->instructionSet != kThumb2) && !isPowerOfTwo(lit))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001808 return false;
buzbee0f79d722012-11-01 15:35:27 -07001809 }
buzbeeb046e162012-10-30 15:48:42 -07001810 // No divide instruction for Arm, so check for more special cases
1811 if ((cUnit->instructionSet == kThumb2) && !isPowerOfTwo(lit)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001812 return smallLiteralDivide(cUnit, dalvikOpcode, rlSrc, rlDest, lit);
1813 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001814 int k = lowestSetBit(lit);
1815 if (k >= 30) {
1816 // Avoid special cases.
1817 return false;
1818 }
1819 bool div = (dalvikOpcode == Instruction::DIV_INT_LIT8 ||
1820 dalvikOpcode == Instruction::DIV_INT_LIT16);
1821 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1822 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1823 if (div) {
1824 int tReg = oatAllocTemp(cUnit);
1825 if (lit == 2) {
1826 // Division by 2 is by far the most common division by constant.
1827 opRegRegImm(cUnit, kOpLsr, tReg, rlSrc.lowReg, 32 - k);
1828 opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg);
1829 opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k);
buzbee31a4a6f2012-02-28 15:36:15 -08001830 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -07001831 opRegRegImm(cUnit, kOpAsr, tReg, rlSrc.lowReg, 31);
1832 opRegRegImm(cUnit, kOpLsr, tReg, tReg, 32 - k);
1833 opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg);
1834 opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k);
buzbee31a4a6f2012-02-28 15:36:15 -08001835 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001836 } else {
1837 int tReg1 = oatAllocTemp(cUnit);
1838 int tReg2 = oatAllocTemp(cUnit);
1839 if (lit == 2) {
1840 opRegRegImm(cUnit, kOpLsr, tReg1, rlSrc.lowReg, 32 - k);
1841 opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg);
1842 opRegRegImm(cUnit, kOpAnd, tReg2, tReg2, lit -1);
1843 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1);
1844 } else {
1845 opRegRegImm(cUnit, kOpAsr, tReg1, rlSrc.lowReg, 31);
1846 opRegRegImm(cUnit, kOpLsr, tReg1, tReg1, 32 - k);
1847 opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg);
1848 opRegRegImm(cUnit, kOpAnd, tReg2, tReg2, lit - 1);
1849 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1);
1850 }
1851 }
1852 storeValue(cUnit, rlDest, rlResult);
1853 return true;
buzbee31a4a6f2012-02-28 15:36:15 -08001854}
1855
buzbee31a4a6f2012-02-28 15:36:15 -08001856// Returns true if it added instructions to 'cUnit' to multiply 'rlSrc' by 'lit'
1857// and store the result in 'rlDest'.
1858bool handleEasyMultiply(CompilationUnit* cUnit, RegLocation rlSrc,
1859 RegLocation rlDest, int lit)
1860{
Bill Buzbeea114add2012-05-03 15:00:40 -07001861 // Can we simplify this multiplication?
1862 bool powerOfTwo = false;
1863 bool popCountLE2 = false;
1864 bool powerOfTwoMinusOne = false;
1865 if (lit < 2) {
1866 // Avoid special cases.
1867 return false;
1868 } else if (isPowerOfTwo(lit)) {
1869 powerOfTwo = true;
1870 } else if (isPopCountLE2(lit)) {
1871 popCountLE2 = true;
1872 } else if (isPowerOfTwo(lit + 1)) {
1873 powerOfTwoMinusOne = true;
1874 } else {
1875 return false;
1876 }
1877 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1878 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1879 if (powerOfTwo) {
1880 // Shift.
1881 opRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlSrc.lowReg,
1882 lowestSetBit(lit));
1883 } else if (popCountLE2) {
1884 // Shift and add and shift.
1885 int firstBit = lowestSetBit(lit);
1886 int secondBit = lowestSetBit(lit ^ (1 << firstBit));
1887 genMultiplyByTwoBitMultiplier(cUnit, rlSrc, rlResult, lit,
1888 firstBit, secondBit);
1889 } else {
1890 // Reverse subtract: (src << (shift + 1)) - src.
1891 DCHECK(powerOfTwoMinusOne);
1892 // TUNING: rsb dst, src, src lsl#lowestSetBit(lit + 1)
1893 int tReg = oatAllocTemp(cUnit);
1894 opRegRegImm(cUnit, kOpLsl, tReg, rlSrc.lowReg, lowestSetBit(lit + 1));
1895 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg, rlSrc.lowReg);
1896 }
1897 storeValue(cUnit, rlDest, rlResult);
1898 return true;
buzbee31a4a6f2012-02-28 15:36:15 -08001899}
1900
buzbee408ad162012-06-06 16:45:18 -07001901bool genArithOpIntLit(CompilationUnit* cUnit, Instruction::Code opcode,
1902 RegLocation rlDest, RegLocation rlSrc, int lit)
buzbee31a4a6f2012-02-28 15:36:15 -08001903{
Bill Buzbeea114add2012-05-03 15:00:40 -07001904 RegLocation rlResult;
buzbeecbd6d442012-11-17 14:11:25 -08001905 OpKind op = static_cast<OpKind>(0); /* Make gcc happy */
Bill Buzbeea114add2012-05-03 15:00:40 -07001906 int shiftOp = false;
1907 bool isDiv = false;
buzbee31a4a6f2012-02-28 15:36:15 -08001908
buzbee408ad162012-06-06 16:45:18 -07001909 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001910 case Instruction::RSUB_INT_LIT8:
1911 case Instruction::RSUB_INT: {
1912 int tReg;
1913 //TUNING: add support for use of Arm rsub op
1914 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1915 tReg = oatAllocTemp(cUnit);
1916 loadConstant(cUnit, tReg, lit);
1917 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1918 opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg, rlSrc.lowReg);
1919 storeValue(cUnit, rlDest, rlResult);
1920 return false;
1921 break;
buzbee31a4a6f2012-02-28 15:36:15 -08001922 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001923
1924 case Instruction::ADD_INT_LIT8:
1925 case Instruction::ADD_INT_LIT16:
1926 op = kOpAdd;
1927 break;
1928 case Instruction::MUL_INT_LIT8:
1929 case Instruction::MUL_INT_LIT16: {
1930 if (handleEasyMultiply(cUnit, rlSrc, rlDest, lit)) {
1931 return false;
1932 }
1933 op = kOpMul;
1934 break;
buzbee31a4a6f2012-02-28 15:36:15 -08001935 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001936 case Instruction::AND_INT_LIT8:
1937 case Instruction::AND_INT_LIT16:
1938 op = kOpAnd;
1939 break;
1940 case Instruction::OR_INT_LIT8:
1941 case Instruction::OR_INT_LIT16:
1942 op = kOpOr;
1943 break;
1944 case Instruction::XOR_INT_LIT8:
1945 case Instruction::XOR_INT_LIT16:
1946 op = kOpXor;
1947 break;
1948 case Instruction::SHL_INT_LIT8:
buzbee2a83e8f2012-07-13 16:42:30 -07001949 case Instruction::SHL_INT:
Bill Buzbeea114add2012-05-03 15:00:40 -07001950 lit &= 31;
1951 shiftOp = true;
1952 op = kOpLsl;
1953 break;
1954 case Instruction::SHR_INT_LIT8:
buzbee2a83e8f2012-07-13 16:42:30 -07001955 case Instruction::SHR_INT:
Bill Buzbeea114add2012-05-03 15:00:40 -07001956 lit &= 31;
1957 shiftOp = true;
1958 op = kOpAsr;
1959 break;
1960 case Instruction::USHR_INT_LIT8:
buzbee2a83e8f2012-07-13 16:42:30 -07001961 case Instruction::USHR_INT:
Bill Buzbeea114add2012-05-03 15:00:40 -07001962 lit &= 31;
1963 shiftOp = true;
1964 op = kOpLsr;
1965 break;
1966
1967 case Instruction::DIV_INT_LIT8:
1968 case Instruction::DIV_INT_LIT16:
1969 case Instruction::REM_INT_LIT8:
jeffhao4f8f04a2012-10-02 18:10:35 -07001970 case Instruction::REM_INT_LIT16: {
Bill Buzbeea114add2012-05-03 15:00:40 -07001971 if (lit == 0) {
buzbee408ad162012-06-06 16:45:18 -07001972 genImmedCheck(cUnit, kCondAl, 0, 0, kThrowDivZero);
Bill Buzbeea114add2012-05-03 15:00:40 -07001973 return false;
1974 }
buzbee408ad162012-06-06 16:45:18 -07001975 if (handleEasyDivide(cUnit, opcode, rlSrc, rlDest, lit)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001976 return false;
1977 }
buzbee408ad162012-06-06 16:45:18 -07001978 if ((opcode == Instruction::DIV_INT_LIT8) ||
1979 (opcode == Instruction::DIV_INT_LIT16)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001980 isDiv = true;
1981 } else {
1982 isDiv = false;
1983 }
buzbeeb046e162012-10-30 15:48:42 -07001984 if (cUnit->instructionSet == kMips) {
1985 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
1986 rlResult = genDivRemLit(cUnit, rlDest, rlSrc.lowReg, lit, isDiv);
jeffhao4f8f04a2012-10-02 18:10:35 -07001987 } else {
buzbeeb046e162012-10-30 15:48:42 -07001988 oatFlushAllRegs(cUnit); /* Everything to home location */
buzbeef0504cd2012-11-13 16:31:10 -08001989 loadValueDirectFixed(cUnit, rlSrc, targetReg(kArg0));
1990 oatClobber(cUnit, targetReg(kArg0));
buzbeeb046e162012-10-30 15:48:42 -07001991 int funcOffset = ENTRYPOINT_OFFSET(pIdivmod);
buzbeef0504cd2012-11-13 16:31:10 -08001992 callRuntimeHelperRegImm(cUnit, funcOffset, targetReg(kArg0), lit, false);
buzbeeb046e162012-10-30 15:48:42 -07001993 if (isDiv)
1994 rlResult = oatGetReturn(cUnit, false);
1995 else
1996 rlResult = oatGetReturnAlt(cUnit);
jeffhao4f8f04a2012-10-02 18:10:35 -07001997 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001998 storeValue(cUnit, rlDest, rlResult);
1999 return false;
2000 break;
jeffhao4f8f04a2012-10-02 18:10:35 -07002001 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002002 default:
2003 return true;
2004 }
2005 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
2006 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
2007 // Avoid shifts by literal 0 - no support in Thumb. Change to copy
2008 if (shiftOp && (lit == 0)) {
2009 opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg);
2010 } else {
2011 opRegRegImm(cUnit, op, rlResult.lowReg, rlSrc.lowReg, lit);
2012 }
2013 storeValue(cUnit, rlDest, rlResult);
2014 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002015}
2016
buzbee408ad162012-06-06 16:45:18 -07002017bool genArithOpLong(CompilationUnit* cUnit, Instruction::Code opcode, RegLocation rlDest,
Bill Buzbeea114add2012-05-03 15:00:40 -07002018 RegLocation rlSrc1, RegLocation rlSrc2)
buzbee31a4a6f2012-02-28 15:36:15 -08002019{
Bill Buzbeea114add2012-05-03 15:00:40 -07002020 RegLocation rlResult;
2021 OpKind firstOp = kOpBkpt;
2022 OpKind secondOp = kOpBkpt;
2023 bool callOut = false;
2024 bool checkZero = false;
2025 int funcOffset;
buzbeef0504cd2012-11-13 16:31:10 -08002026 int retReg = targetReg(kRet0);
buzbee31a4a6f2012-02-28 15:36:15 -08002027
buzbee408ad162012-06-06 16:45:18 -07002028 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002029 case Instruction::NOT_LONG:
2030 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
2031 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
2032 // Check for destructive overlap
2033 if (rlResult.lowReg == rlSrc2.highReg) {
2034 int tReg = oatAllocTemp(cUnit);
2035 opRegCopy(cUnit, tReg, rlSrc2.highReg);
2036 opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg);
2037 opRegReg(cUnit, kOpMvn, rlResult.highReg, tReg);
2038 oatFreeTemp(cUnit, tReg);
2039 } else {
2040 opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg);
2041 opRegReg(cUnit, kOpMvn, rlResult.highReg, rlSrc2.highReg);
2042 }
2043 storeValueWide(cUnit, rlDest, rlResult);
2044 return false;
2045 break;
2046 case Instruction::ADD_LONG:
2047 case Instruction::ADD_LONG_2ADDR:
buzbeeb046e162012-10-30 15:48:42 -07002048 if (cUnit->instructionSet != kThumb2) {
2049 return genAddLong(cUnit, rlDest, rlSrc1, rlSrc2);
2050 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002051 firstOp = kOpAdd;
2052 secondOp = kOpAdc;
2053 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07002054 case Instruction::SUB_LONG:
2055 case Instruction::SUB_LONG_2ADDR:
buzbeeb046e162012-10-30 15:48:42 -07002056 if (cUnit->instructionSet != kThumb2) {
2057 return genSubLong(cUnit, rlDest, rlSrc1, rlSrc2);
2058 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002059 firstOp = kOpSub;
2060 secondOp = kOpSbc;
2061 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07002062 case Instruction::MUL_LONG:
2063 case Instruction::MUL_LONG_2ADDR:
2064 callOut = true;
buzbeef0504cd2012-11-13 16:31:10 -08002065 retReg = targetReg(kRet0);
Bill Buzbeea114add2012-05-03 15:00:40 -07002066 funcOffset = ENTRYPOINT_OFFSET(pLmul);
2067 break;
2068 case Instruction::DIV_LONG:
2069 case Instruction::DIV_LONG_2ADDR:
2070 callOut = true;
2071 checkZero = true;
buzbeef0504cd2012-11-13 16:31:10 -08002072 retReg = targetReg(kRet0);
jeffhao644d5312012-05-03 19:04:49 -07002073 funcOffset = ENTRYPOINT_OFFSET(pLdiv);
Bill Buzbeea114add2012-05-03 15:00:40 -07002074 break;
2075 case Instruction::REM_LONG:
2076 case Instruction::REM_LONG_2ADDR:
2077 callOut = true;
2078 checkZero = true;
jeffhao644d5312012-05-03 19:04:49 -07002079 funcOffset = ENTRYPOINT_OFFSET(pLdivmod);
buzbeef0504cd2012-11-13 16:31:10 -08002080 /* NOTE - for Arm, result is in kArg2/kArg3 instead of kRet0/kRet1 */
2081 retReg = (cUnit->instructionSet == kThumb2) ? targetReg(kArg2) : targetReg(kRet0);
Bill Buzbeea114add2012-05-03 15:00:40 -07002082 break;
2083 case Instruction::AND_LONG_2ADDR:
2084 case Instruction::AND_LONG:
buzbeeb046e162012-10-30 15:48:42 -07002085 if (cUnit->instructionSet == kX86) {
2086 return genAndLong(cUnit, rlDest, rlSrc1, rlSrc2);
2087 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002088 firstOp = kOpAnd;
2089 secondOp = kOpAnd;
2090 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07002091 case Instruction::OR_LONG:
2092 case Instruction::OR_LONG_2ADDR:
buzbeeb046e162012-10-30 15:48:42 -07002093 if (cUnit->instructionSet == kX86) {
2094 return genOrLong(cUnit, rlDest, rlSrc1, rlSrc2);
2095 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002096 firstOp = kOpOr;
2097 secondOp = kOpOr;
2098 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07002099 case Instruction::XOR_LONG:
2100 case Instruction::XOR_LONG_2ADDR:
buzbeeb046e162012-10-30 15:48:42 -07002101 if (cUnit->instructionSet == kX86) {
2102 return genXorLong(cUnit, rlDest, rlSrc1, rlSrc2);
2103 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002104 firstOp = kOpXor;
2105 secondOp = kOpXor;
2106 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07002107 case Instruction::NEG_LONG: {
buzbee408ad162012-06-06 16:45:18 -07002108 return genNegLong(cUnit, rlDest, rlSrc2);
buzbee31a4a6f2012-02-28 15:36:15 -08002109 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002110 default:
2111 LOG(FATAL) << "Invalid long arith op";
2112 }
2113 if (!callOut) {
buzbee408ad162012-06-06 16:45:18 -07002114 genLong3Addr(cUnit, firstOp, secondOp, rlDest, rlSrc1, rlSrc2);
Bill Buzbeea114add2012-05-03 15:00:40 -07002115 } else {
2116 oatFlushAllRegs(cUnit); /* Send everything to home location */
2117 if (checkZero) {
buzbeef0504cd2012-11-13 16:31:10 -08002118 loadValueDirectWideFixed(cUnit, rlSrc2, targetReg(kArg2), targetReg(kArg3));
buzbeeb046e162012-10-30 15:48:42 -07002119 int rTgt = callHelperSetup(cUnit, funcOffset);
buzbeef0504cd2012-11-13 16:31:10 -08002120 genDivZeroCheck(cUnit, targetReg(kArg2), targetReg(kArg3));
2121 loadValueDirectWideFixed(cUnit, rlSrc1, targetReg(kArg0), targetReg(kArg1));
buzbee8320f382012-09-11 16:29:42 -07002122 // NOTE: callout here is not a safepoint
buzbeeb046e162012-10-30 15:48:42 -07002123 callHelper(cUnit, rTgt, funcOffset, false /* not safepoint */);
buzbee31a4a6f2012-02-28 15:36:15 -08002124 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -07002125 callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset,
buzbee8320f382012-09-11 16:29:42 -07002126 rlSrc1, rlSrc2, false);
buzbee31a4a6f2012-02-28 15:36:15 -08002127 }
buzbeef0504cd2012-11-13 16:31:10 -08002128 // Adjust return regs in to handle case of rem returning kArg2/kArg3
2129 if (retReg == targetReg(kRet0))
Bill Buzbeea114add2012-05-03 15:00:40 -07002130 rlResult = oatGetReturnWide(cUnit, false);
2131 else
2132 rlResult = oatGetReturnWideAlt(cUnit);
2133 storeValueWide(cUnit, rlDest, rlResult);
2134 }
2135 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002136}
2137
buzbee408ad162012-06-06 16:45:18 -07002138bool genConversionCall(CompilationUnit* cUnit, int funcOffset,
2139 RegLocation rlDest, RegLocation rlSrc)
buzbee31a4a6f2012-02-28 15:36:15 -08002140{
Bill Buzbeea114add2012-05-03 15:00:40 -07002141 /*
2142 * Don't optimize the register usage since it calls out to support
2143 * functions
2144 */
Bill Buzbeea114add2012-05-03 15:00:40 -07002145 oatFlushAllRegs(cUnit); /* Send everything to home location */
buzbee408ad162012-06-06 16:45:18 -07002146 if (rlSrc.wide) {
buzbeef0504cd2012-11-13 16:31:10 -08002147 loadValueDirectWideFixed(cUnit, rlSrc, rlSrc.fp ? targetReg(kFArg0) : targetReg(kArg0),
2148 rlSrc.fp ? targetReg(kFArg1) : targetReg(kArg1));
buzbee408ad162012-06-06 16:45:18 -07002149 } else {
buzbeef0504cd2012-11-13 16:31:10 -08002150 loadValueDirectFixed(cUnit, rlSrc, rlSrc.fp ? targetReg(kFArg0) : targetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -07002151 }
buzbee8320f382012-09-11 16:29:42 -07002152 callRuntimeHelperRegLocation(cUnit, funcOffset, rlSrc, false);
buzbee408ad162012-06-06 16:45:18 -07002153 if (rlDest.wide) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002154 RegLocation rlResult;
Bill Buzbeea114add2012-05-03 15:00:40 -07002155 rlResult = oatGetReturnWide(cUnit, rlDest.fp);
2156 storeValueWide(cUnit, rlDest, rlResult);
buzbee408ad162012-06-06 16:45:18 -07002157 } else {
2158 RegLocation rlResult;
2159 rlResult = oatGetReturn(cUnit, rlDest.fp);
2160 storeValue(cUnit, rlDest, rlResult);
Bill Buzbeea114add2012-05-03 15:00:40 -07002161 }
2162 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002163}
2164
buzbee408ad162012-06-06 16:45:18 -07002165bool genArithOpFloatPortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbee31a4a6f2012-02-28 15:36:15 -08002166 RegLocation rlDest, RegLocation rlSrc1,
2167 RegLocation rlSrc2)
2168{
Bill Buzbeea114add2012-05-03 15:00:40 -07002169 RegLocation rlResult;
2170 int funcOffset;
buzbee31a4a6f2012-02-28 15:36:15 -08002171
buzbee408ad162012-06-06 16:45:18 -07002172 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002173 case Instruction::ADD_FLOAT_2ADDR:
2174 case Instruction::ADD_FLOAT:
2175 funcOffset = ENTRYPOINT_OFFSET(pFadd);
2176 break;
2177 case Instruction::SUB_FLOAT_2ADDR:
2178 case Instruction::SUB_FLOAT:
2179 funcOffset = ENTRYPOINT_OFFSET(pFsub);
2180 break;
2181 case Instruction::DIV_FLOAT_2ADDR:
2182 case Instruction::DIV_FLOAT:
2183 funcOffset = ENTRYPOINT_OFFSET(pFdiv);
2184 break;
2185 case Instruction::MUL_FLOAT_2ADDR:
2186 case Instruction::MUL_FLOAT:
2187 funcOffset = ENTRYPOINT_OFFSET(pFmul);
2188 break;
2189 case Instruction::REM_FLOAT_2ADDR:
2190 case Instruction::REM_FLOAT:
2191 funcOffset = ENTRYPOINT_OFFSET(pFmodf);
2192 break;
2193 case Instruction::NEG_FLOAT: {
2194 genNegFloat(cUnit, rlDest, rlSrc1);
2195 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002196 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002197 default:
2198 return true;
2199 }
2200 oatFlushAllRegs(cUnit); /* Send everything to home location */
buzbee8320f382012-09-11 16:29:42 -07002201 callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlSrc2, false);
Bill Buzbeea114add2012-05-03 15:00:40 -07002202 rlResult = oatGetReturn(cUnit, true);
2203 storeValue(cUnit, rlDest, rlResult);
2204 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002205}
2206
buzbee408ad162012-06-06 16:45:18 -07002207bool genArithOpDoublePortable(CompilationUnit* cUnit, Instruction::Code opcode,
buzbee31a4a6f2012-02-28 15:36:15 -08002208 RegLocation rlDest, RegLocation rlSrc1,
2209 RegLocation rlSrc2)
2210{
Bill Buzbeea114add2012-05-03 15:00:40 -07002211 RegLocation rlResult;
2212 int funcOffset;
buzbee31a4a6f2012-02-28 15:36:15 -08002213
buzbee408ad162012-06-06 16:45:18 -07002214 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002215 case Instruction::ADD_DOUBLE_2ADDR:
2216 case Instruction::ADD_DOUBLE:
2217 funcOffset = ENTRYPOINT_OFFSET(pDadd);
2218 break;
2219 case Instruction::SUB_DOUBLE_2ADDR:
2220 case Instruction::SUB_DOUBLE:
2221 funcOffset = ENTRYPOINT_OFFSET(pDsub);
2222 break;
2223 case Instruction::DIV_DOUBLE_2ADDR:
2224 case Instruction::DIV_DOUBLE:
2225 funcOffset = ENTRYPOINT_OFFSET(pDdiv);
2226 break;
2227 case Instruction::MUL_DOUBLE_2ADDR:
2228 case Instruction::MUL_DOUBLE:
2229 funcOffset = ENTRYPOINT_OFFSET(pDmul);
2230 break;
2231 case Instruction::REM_DOUBLE_2ADDR:
2232 case Instruction::REM_DOUBLE:
2233 funcOffset = ENTRYPOINT_OFFSET(pFmod);
2234 break;
2235 case Instruction::NEG_DOUBLE: {
2236 genNegDouble(cUnit, rlDest, rlSrc1);
2237 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002238 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002239 default:
2240 return true;
2241 }
2242 oatFlushAllRegs(cUnit); /* Send everything to home location */
buzbee8320f382012-09-11 16:29:42 -07002243 callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlSrc2, false);
Bill Buzbeea114add2012-05-03 15:00:40 -07002244 rlResult = oatGetReturnWide(cUnit, true);
2245 storeValueWide(cUnit, rlDest, rlResult);
2246 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002247}
2248
buzbee408ad162012-06-06 16:45:18 -07002249bool genConversionPortable(CompilationUnit* cUnit, Instruction::Code opcode,
2250 RegLocation rlDest, RegLocation rlSrc)
buzbee31a4a6f2012-02-28 15:36:15 -08002251{
buzbee31a4a6f2012-02-28 15:36:15 -08002252
Bill Buzbeea114add2012-05-03 15:00:40 -07002253 switch (opcode) {
2254 case Instruction::INT_TO_FLOAT:
buzbee408ad162012-06-06 16:45:18 -07002255 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pI2f),
2256 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002257 case Instruction::FLOAT_TO_INT:
buzbee408ad162012-06-06 16:45:18 -07002258 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pF2iz),
2259 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002260 case Instruction::DOUBLE_TO_FLOAT:
buzbee408ad162012-06-06 16:45:18 -07002261 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pD2f),
2262 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002263 case Instruction::FLOAT_TO_DOUBLE:
buzbee408ad162012-06-06 16:45:18 -07002264 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pF2d),
2265 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002266 case Instruction::INT_TO_DOUBLE:
buzbee408ad162012-06-06 16:45:18 -07002267 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pI2d),
2268 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002269 case Instruction::DOUBLE_TO_INT:
buzbee408ad162012-06-06 16:45:18 -07002270 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pD2iz),
2271 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002272 case Instruction::FLOAT_TO_LONG:
buzbee408ad162012-06-06 16:45:18 -07002273 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pF2l),
2274 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002275 case Instruction::LONG_TO_FLOAT:
buzbee408ad162012-06-06 16:45:18 -07002276 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pL2f),
2277 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002278 case Instruction::DOUBLE_TO_LONG:
buzbee408ad162012-06-06 16:45:18 -07002279 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pD2l),
2280 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002281 case Instruction::LONG_TO_DOUBLE:
buzbee408ad162012-06-06 16:45:18 -07002282 return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pL2d),
2283 rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002284 default:
2285 return true;
2286 }
2287 return false;
buzbee31a4a6f2012-02-28 15:36:15 -08002288}
2289
buzbee31a4a6f2012-02-28 15:36:15 -08002290/* Check if we need to check for pending suspend request */
buzbee408ad162012-06-06 16:45:18 -07002291void genSuspendTest(CompilationUnit* cUnit, int optFlags)
buzbee31a4a6f2012-02-28 15:36:15 -08002292{
buzbee408ad162012-06-06 16:45:18 -07002293 if (NO_SUSPEND || (optFlags & MIR_IGNORE_SUSPEND_CHECK)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002294 return;
2295 }
2296 oatFlushAllRegs(cUnit);
buzbeeb046e162012-10-30 15:48:42 -07002297 LIR* branch = opTestSuspend(cUnit, NULL);
2298 LIR* retLab = newLIR0(cUnit, kPseudoTargetLabel);
2299 LIR* target = rawLIR(cUnit, cUnit->currentDalvikOffset, kPseudoSuspendTarget,
buzbeecbd6d442012-11-17 14:11:25 -08002300 reinterpret_cast<uintptr_t>(retLab), cUnit->currentDalvikOffset);
2301 branch->target = target;
2302 oatInsertGrowableList(cUnit, &cUnit->suspendLaunchpads, reinterpret_cast<uintptr_t>(target));
buzbee31a4a6f2012-02-28 15:36:15 -08002303}
2304
buzbeefead2932012-03-30 14:02:01 -07002305/* Check if we need to check for pending suspend request */
buzbee408ad162012-06-06 16:45:18 -07002306void genSuspendTestAndBranch(CompilationUnit* cUnit, int optFlags, LIR* target)
buzbeefead2932012-03-30 14:02:01 -07002307{
buzbee408ad162012-06-06 16:45:18 -07002308 if (NO_SUSPEND || (optFlags & MIR_IGNORE_SUSPEND_CHECK)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002309 opUnconditionalBranch(cUnit, target);
2310 return;
2311 }
buzbeeb046e162012-10-30 15:48:42 -07002312 opTestSuspend(cUnit, target);
buzbeecbd6d442012-11-17 14:11:25 -08002313 LIR* launchPad =
2314 rawLIR(cUnit, cUnit->currentDalvikOffset, kPseudoSuspendTarget,
2315 reinterpret_cast<uintptr_t>(target), cUnit->currentDalvikOffset);
buzbeeb046e162012-10-30 15:48:42 -07002316 oatFlushAllRegs(cUnit);
2317 opUnconditionalBranch(cUnit, launchPad);
buzbeecbd6d442012-11-17 14:11:25 -08002318 oatInsertGrowableList(cUnit, &cUnit->suspendLaunchpads, reinterpret_cast<uintptr_t>(launchPad));
buzbeefead2932012-03-30 14:02:01 -07002319}
2320
buzbee31a4a6f2012-02-28 15:36:15 -08002321} // namespace art