blob: 0208a4afc5d569f304258e81b24a4eb22bfbb25c [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"
18
buzbee31a4a6f2012-02-28 15:36:15 -080019namespace art {
20
21/*
22 * This source files contains "gen" codegen routines that should
23 * be applicable to most targets. Only mid-level support utilities
24 * and "op" calls may be used here.
25 */
26
buzbee3b3dbdd2012-06-13 13:39:34 -070027typedef int (*NextCallInsn)(CompilationUnit*, CallInfo*, int, uint32_t dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -070028 uint32_t methodIdx, uintptr_t directCode,
Brian Carlstromf5822582012-03-19 22:34:31 -070029 uintptr_t directMethod, InvokeType type);
buzbeefc9e6fa2012-03-23 15:14:29 -070030LIR* opCondBranch(CompilationUnit* cUnit, ConditionCode cc, LIR* target);
31
buzbee31a4a6f2012-02-28 15:36:15 -080032/*
33 * If there are any ins passed in registers that have not been promoted
34 * to a callee-save register, flush them to the frame. Perform intial
35 * assignment of promoted arguments.
buzbeead8f15e2012-06-18 14:49:45 -070036 *
37 * argLocs is an array of location records describing the incoming arguments
38 * with one location record per word of argument.
buzbee31a4a6f2012-02-28 15:36:15 -080039 */
buzbeead8f15e2012-06-18 14:49:45 -070040void flushIns(CompilationUnit* cUnit, RegLocation* argLocs, RegLocation rlMethod)
buzbee31a4a6f2012-02-28 15:36:15 -080041{
Bill Buzbeea114add2012-05-03 15:00:40 -070042 /*
43 * Dummy up a RegLocation for the incoming Method*
44 * It will attempt to keep rARG0 live (or copy it to home location
45 * if promoted).
46 */
buzbeead8f15e2012-06-18 14:49:45 -070047 RegLocation rlSrc = rlMethod;
Bill Buzbeea114add2012-05-03 15:00:40 -070048 rlSrc.location = kLocPhysReg;
49 rlSrc.lowReg = rARG0;
50 rlSrc.home = false;
51 oatMarkLive(cUnit, rlSrc.lowReg, rlSrc.sRegLow);
52 storeValue(cUnit, rlMethod, rlSrc);
53 // If Method* has been promoted, explicitly flush
54 if (rlMethod.location == kLocPhysReg) {
55 storeWordDisp(cUnit, rSP, 0, rARG0);
56 }
buzbee9c044ce2012-03-18 13:24:07 -070057
Bill Buzbeea114add2012-05-03 15:00:40 -070058 if (cUnit->numIns == 0)
59 return;
60 const int numArgRegs = 3;
61 static int argRegs[] = {rARG1, rARG2, rARG3};
62 int startVReg = cUnit->numDalvikRegisters - cUnit->numIns;
63 /*
64 * Copy incoming arguments to their proper home locations.
65 * NOTE: an older version of dx had an issue in which
66 * it would reuse static method argument registers.
67 * This could result in the same Dalvik virtual register
68 * being promoted to both core and fp regs. To account for this,
69 * we only copy to the corresponding promoted physical register
70 * if it matches the type of the SSA name for the incoming
71 * argument. It is also possible that long and double arguments
72 * end up half-promoted. In those cases, we must flush the promoted
73 * half to memory as well.
74 */
75 for (int i = 0; i < cUnit->numIns; i++) {
76 PromotionMap* vMap = &cUnit->promotionMap[startVReg + i];
77 if (i < numArgRegs) {
78 // If arriving in register
79 bool needFlush = true;
buzbeead8f15e2012-06-18 14:49:45 -070080 RegLocation* tLoc = &argLocs[i];
Bill Buzbeea114add2012-05-03 15:00:40 -070081 if ((vMap->coreLocation == kLocPhysReg) && !tLoc->fp) {
82 opRegCopy(cUnit, vMap->coreReg, argRegs[i]);
83 needFlush = false;
84 } else if ((vMap->fpLocation == kLocPhysReg) && tLoc->fp) {
85 opRegCopy(cUnit, vMap->fpReg, argRegs[i]);
86 needFlush = false;
87 } else {
88 needFlush = true;
89 }
buzbee86a4bce2012-03-06 18:15:00 -080090
Bill Buzbeea114add2012-05-03 15:00:40 -070091 // For wide args, force flush if only half is promoted
92 if (tLoc->wide) {
93 PromotionMap* pMap = vMap + (tLoc->highWord ? -1 : +1);
94 needFlush |= (pMap->coreLocation != vMap->coreLocation) ||
95 (pMap->fpLocation != vMap->fpLocation);
96 }
97 if (needFlush) {
98 storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
99 argRegs[i], kWord);
100 }
101 } else {
102 // If arriving in frame & promoted
103 if (vMap->coreLocation == kLocPhysReg) {
104 loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
105 vMap->coreReg);
106 }
107 if (vMap->fpLocation == kLocPhysReg) {
108 loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
109 vMap->fpReg);
110 }
buzbee31a4a6f2012-02-28 15:36:15 -0800111 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700112 }
buzbee31a4a6f2012-02-28 15:36:15 -0800113}
114
Ian Rogers3fa13792012-03-18 15:53:45 -0700115void scanMethodLiteralPool(CompilationUnit* cUnit, LIR** methodTarget, LIR** codeTarget, const DexFile* dexFile, uint32_t dexMethodIdx)
116{
Bill Buzbeea114add2012-05-03 15:00:40 -0700117 LIR* curTarget = cUnit->methodLiteralList;
118 LIR* nextTarget = curTarget != NULL ? curTarget->next : NULL;
119 while (curTarget != NULL && nextTarget != NULL) {
120 if (curTarget->operands[0] == (int)dexFile &&
121 nextTarget->operands[0] == (int)dexMethodIdx) {
122 *codeTarget = curTarget;
123 *methodTarget = nextTarget;
124 DCHECK((*codeTarget)->next == *methodTarget);
125 DCHECK_EQ((*codeTarget)->operands[0], (int)dexFile);
126 DCHECK_EQ((*methodTarget)->operands[0], (int)dexMethodIdx);
127 break;
Ian Rogers3fa13792012-03-18 15:53:45 -0700128 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700129 curTarget = nextTarget->next;
130 nextTarget = curTarget != NULL ? curTarget->next : NULL;
131 }
Ian Rogers3fa13792012-03-18 15:53:45 -0700132}
133
buzbee31a4a6f2012-02-28 15:36:15 -0800134/*
Elliott Hughesbdf6c3d2012-03-20 13:43:53 -0700135 * Bit of a hack here - in the absence of a real scheduling pass,
buzbee31a4a6f2012-02-28 15:36:15 -0800136 * emit the next instruction in static & direct invoke sequences.
137 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700138int nextSDCallInsn(CompilationUnit* cUnit, CallInfo* info,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700139 int state, uint32_t dexIdx, uint32_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700140 uintptr_t directCode, uintptr_t directMethod,
141 InvokeType type)
buzbee31a4a6f2012-02-28 15:36:15 -0800142{
Brian Carlstromf5822582012-03-19 22:34:31 -0700143#if !defined(TARGET_ARM)
Bill Buzbeea114add2012-05-03 15:00:40 -0700144 directCode = 0;
145 directMethod = 0;
Brian Carlstromf5822582012-03-19 22:34:31 -0700146#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700147 if (directCode != 0 && directMethod != 0) {
148 switch (state) {
149 case 0: // Get the current Method* [sets rARG0]
150 if (directCode != (uintptr_t)-1) {
151 loadConstant(cUnit, rINVOKE_TGT, directCode);
152 } else {
153 LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0);
154 if (dataTarget == NULL) {
155 dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx);
156 dataTarget->operands[1] = type;
Ian Rogers2ed3b952012-03-17 11:49:39 -0700157 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700158#if defined(TARGET_ARM)
159 LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset,
160 kThumb2LdrPcRel12, rINVOKE_TGT, 0, 0, 0, 0,
161 dataTarget);
162 oatAppendLIR(cUnit, loadPcRel);
163#else
164 UNIMPLEMENTED(FATAL) << (void*)dataTarget;
165#endif
166 }
167 if (directMethod != (uintptr_t)-1) {
168 loadConstant(cUnit, rARG0, directMethod);
169 } else {
170 LIR* dataTarget = scanLiteralPool(cUnit->methodLiteralList, dexIdx, 0);
171 if (dataTarget == NULL) {
172 dataTarget = addWordData(cUnit, &cUnit->methodLiteralList, dexIdx);
173 dataTarget->operands[1] = type;
174 }
175#if defined(TARGET_ARM)
176 LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset,
177 kThumb2LdrPcRel12, rARG0, 0, 0, 0, 0,
178 dataTarget);
179 oatAppendLIR(cUnit, loadPcRel);
180#else
181 UNIMPLEMENTED(FATAL) << (void*)dataTarget;
182#endif
183 }
184 break;
185 default:
186 return -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800187 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700188 } else {
189 switch (state) {
190 case 0: // Get the current Method* [sets rARG0]
Ian Rogers137e88f2012-10-08 17:46:47 -0700191 // TUNING: we can save a reg copy if Method* has been promoted.
Bill Buzbeea114add2012-05-03 15:00:40 -0700192 loadCurrMethodDirect(cUnit, rARG0);
193 break;
194 case 1: // Get method->dex_cache_resolved_methods_
195 loadWordDisp(cUnit, rARG0,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700196 AbstractMethod::DexCacheResolvedMethodsOffset().Int32Value(),
Bill Buzbeea114add2012-05-03 15:00:40 -0700197 rARG0);
198 // Set up direct code if known.
199 if (directCode != 0) {
200 if (directCode != (uintptr_t)-1) {
201 loadConstant(cUnit, rINVOKE_TGT, directCode);
202 } else {
203 LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0);
204 if (dataTarget == NULL) {
205 dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx);
206 dataTarget->operands[1] = type;
207 }
208#if defined(TARGET_ARM)
209 LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset,
210 kThumb2LdrPcRel12, rINVOKE_TGT, 0, 0, 0, 0,
211 dataTarget);
212 oatAppendLIR(cUnit, loadPcRel);
213#else
214 UNIMPLEMENTED(FATAL) << (void*)dataTarget;
215#endif
216 }
217 }
218 break;
219 case 2: // Grab target method*
220 loadWordDisp(cUnit, rARG0,
221 Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4,
222 rARG0);
223 break;
224#if !defined(TARGET_X86)
225 case 3: // Grab the code from the method*
226 if (directCode == 0) {
Mathieu Chartier66f19252012-09-18 08:57:04 -0700227 loadWordDisp(cUnit, rARG0, AbstractMethod::GetCodeOffset().Int32Value(),
Bill Buzbeea114add2012-05-03 15:00:40 -0700228 rINVOKE_TGT);
229 }
230 break;
231#endif
232 default:
233 return -1;
234 }
235 }
236 return state + 1;
buzbee31a4a6f2012-02-28 15:36:15 -0800237}
238
239/*
Elliott Hughesbdf6c3d2012-03-20 13:43:53 -0700240 * Bit of a hack here - in the absence of a real scheduling pass,
buzbee31a4a6f2012-02-28 15:36:15 -0800241 * emit the next instruction in a virtual invoke sequence.
242 * We can use rLR as a temp prior to target address loading
243 * Note also that we'll load the first argument ("this") into
244 * rARG1 here rather than the standard loadArgRegs.
245 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700246int nextVCallInsn(CompilationUnit* cUnit, CallInfo* info,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700247 int state, uint32_t dexIdx, uint32_t methodIdx,
Brian Carlstromf5822582012-03-19 22:34:31 -0700248 uintptr_t unused, uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800249{
Bill Buzbeea114add2012-05-03 15:00:40 -0700250 /*
251 * This is the fast path in which the target virtual method is
252 * fully resolved at compile time.
253 */
254 switch (state) {
Ian Rogers137e88f2012-10-08 17:46:47 -0700255 case 0: { // Get "this" [set rARG1]
256 RegLocation rlArg = info->args[0];
Bill Buzbeea114add2012-05-03 15:00:40 -0700257 loadValueDirectFixed(cUnit, rlArg, rARG1);
258 break;
Ian Rogers137e88f2012-10-08 17:46:47 -0700259 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700260 case 1: // Is "this" null? [use rARG1]
buzbee15bf9802012-06-12 17:49:27 -0700261 genNullCheck(cUnit, info->args[0].sRegLow, rARG1, info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700262 // get this->klass_ [use rARG1, set rINVOKE_TGT]
263 loadWordDisp(cUnit, rARG1, Object::ClassOffset().Int32Value(),
264 rINVOKE_TGT);
265 break;
266 case 2: // Get this->klass_->vtable [usr rINVOKE_TGT, set rINVOKE_TGT]
267 loadWordDisp(cUnit, rINVOKE_TGT, Class::VTableOffset().Int32Value(),
268 rINVOKE_TGT);
269 break;
270 case 3: // Get target method [use rINVOKE_TGT, set rARG0]
271 loadWordDisp(cUnit, rINVOKE_TGT, (methodIdx * 4) +
272 Array::DataOffset(sizeof(Object*)).Int32Value(), rARG0);
273 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700274#if !defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700275 case 4: // Get the compiled code address [uses rARG0, sets rINVOKE_TGT]
Mathieu Chartier66f19252012-09-18 08:57:04 -0700276 loadWordDisp(cUnit, rARG0, AbstractMethod::GetCodeOffset().Int32Value(),
Bill Buzbeea114add2012-05-03 15:00:40 -0700277 rINVOKE_TGT);
278 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700279#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700280 default:
281 return -1;
282 }
283 return state + 1;
buzbee31a4a6f2012-02-28 15:36:15 -0800284}
285
Ian Rogers137e88f2012-10-08 17:46:47 -0700286/*
287 * All invoke-interface calls bounce off of art_invoke_interface_trampoline,
288 * which will locate the target and continue on via a tail call.
289 */
290int nextInterfaceCallInsn(CompilationUnit* cUnit, CallInfo* info, int state,
291 uint32_t dexIdx, uint32_t unused, uintptr_t unused2,
292 uintptr_t directMethod, InvokeType unused4)
293{
294#if !defined(TARGET_ARM)
295 directMethod = 0;
296#endif
297#if !defined(TARGET_X86)
298 int trampoline = ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline);
299#endif
300
301 if (directMethod != 0) {
302 switch (state) {
303 case 0: // Load the trampoline target [sets rINVOKE_TGT].
304#if !defined(TARGET_X86)
305 loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT);
306#endif
307 // Get the interface Method* [sets rARG0]
308 if (directMethod != (uintptr_t)-1) {
309 loadConstant(cUnit, rARG0, directMethod);
310 } else {
311 LIR* dataTarget = scanLiteralPool(cUnit->methodLiteralList, dexIdx, 0);
312 if (dataTarget == NULL) {
313 dataTarget = addWordData(cUnit, &cUnit->methodLiteralList, dexIdx);
314 dataTarget->operands[1] = kInterface;
315 }
316#if defined(TARGET_ARM)
317 LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset,
318 kThumb2LdrPcRel12, rARG0, 0, 0, 0, 0,
319 dataTarget);
320 oatAppendLIR(cUnit, loadPcRel);
321#else
322 UNIMPLEMENTED(FATAL) << (void*)dataTarget;
323#endif
324 }
325 break;
326 default:
327 return -1;
328 }
329 } else {
330 switch (state) {
331 case 0:
332 // Get the current Method* [sets rARG0] - TUNING: remove copy of method if it is promoted.
333 loadCurrMethodDirect(cUnit, rARG0);
334 // Load the trampoline target [sets rINVOKE_TGT].
335#if !defined(TARGET_X86)
336 loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT);
337#endif
338 break;
339 case 1: // Get method->dex_cache_resolved_methods_ [set/use rARG0]
340 loadWordDisp(cUnit, rARG0,
341 AbstractMethod::DexCacheResolvedMethodsOffset().Int32Value(),
342 rARG0);
343 break;
344 case 2: // Grab target method* [set/use rARG0]
345 loadWordDisp(cUnit, rARG0,
346 Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4,
347 rARG0);
348 break;
349 default:
350 return -1;
351 }
352 }
353 return state + 1;
354}
355
buzbee3b3dbdd2012-06-13 13:39:34 -0700356int nextInvokeInsnSP(CompilationUnit* cUnit, CallInfo* info, int trampoline,
buzbee31a4a6f2012-02-28 15:36:15 -0800357 int state, uint32_t dexIdx, uint32_t methodIdx)
358{
Bill Buzbeea114add2012-05-03 15:00:40 -0700359 /*
360 * This handles the case in which the base method is not fully
361 * resolved at compile time, we bail to a runtime helper.
362 */
363 if (state == 0) {
Ian Rogers7caad772012-03-30 01:07:54 -0700364#if !defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700365 // Load trampoline target
366 loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT);
Ian Rogers7caad772012-03-30 01:07:54 -0700367#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700368 // Load rARG0 with method index
369 loadConstant(cUnit, rARG0, dexIdx);
370 return 1;
371 }
372 return -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800373}
374
buzbee3b3dbdd2012-06-13 13:39:34 -0700375int nextStaticCallInsnSP(CompilationUnit* cUnit, CallInfo* info,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700376 int state, uint32_t dexIdx, uint32_t methodIdx,
Brian Carlstromf5822582012-03-19 22:34:31 -0700377 uintptr_t unused, uintptr_t unused2,
378 InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800379{
Ian Rogers57b86d42012-03-27 16:05:41 -0700380 int trampoline = ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700381 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800382}
383
buzbee3b3dbdd2012-06-13 13:39:34 -0700384int nextDirectCallInsnSP(CompilationUnit* cUnit, CallInfo* info, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700385 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700386 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800387{
Ian Rogers57b86d42012-03-27 16:05:41 -0700388 int trampoline = ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700389 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800390}
391
buzbee3b3dbdd2012-06-13 13:39:34 -0700392int nextSuperCallInsnSP(CompilationUnit* cUnit, CallInfo* info, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700393 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700394 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800395{
Ian Rogers57b86d42012-03-27 16:05:41 -0700396 int trampoline = ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700397 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800398}
399
buzbee3b3dbdd2012-06-13 13:39:34 -0700400int nextVCallInsnSP(CompilationUnit* cUnit, CallInfo* info, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700401 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700402 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800403{
Ian Rogers57b86d42012-03-27 16:05:41 -0700404 int trampoline = ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700405 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800406}
407
buzbee15bf9802012-06-12 17:49:27 -0700408int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit,
buzbee3b3dbdd2012-06-13 13:39:34 -0700409 CallInfo* info, int state,
buzbee15bf9802012-06-12 17:49:27 -0700410 uint32_t dexIdx, uint32_t unused,
411 uintptr_t unused2, uintptr_t unused3,
412 InvokeType unused4)
buzbee31a4a6f2012-02-28 15:36:15 -0800413{
Ian Rogers57b86d42012-03-27 16:05:41 -0700414 int trampoline = ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
buzbee15bf9802012-06-12 17:49:27 -0700415 return nextInvokeInsnSP(cUnit, info, trampoline, state, dexIdx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800416}
417
buzbee3b3dbdd2012-06-13 13:39:34 -0700418int loadArgRegs(CompilationUnit* cUnit, CallInfo* info, int callState,
buzbee15bf9802012-06-12 17:49:27 -0700419 NextCallInsn nextCallInsn, uint32_t dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700420 uint32_t methodIdx, uintptr_t directCode,
Brian Carlstromf5822582012-03-19 22:34:31 -0700421 uintptr_t directMethod, InvokeType type, bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800422{
Bill Buzbeea114add2012-05-03 15:00:40 -0700423 int lastArgReg = rARG3;
424 int nextReg = rARG1;
425 int nextArg = 0;
426 if (skipThis) {
427 nextReg++;
428 nextArg++;
429 }
buzbee15bf9802012-06-12 17:49:27 -0700430 for (; (nextReg <= lastArgReg) && (nextArg < info->numArgWords); nextReg++) {
431 RegLocation rlArg = info->args[nextArg++];
Bill Buzbeea114add2012-05-03 15:00:40 -0700432 rlArg = oatUpdateRawLoc(cUnit, rlArg);
433 if (rlArg.wide && (nextReg <= rARG2)) {
434 loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1);
435 nextReg++;
436 nextArg++;
437 } else {
438 rlArg.wide = false;
439 loadValueDirectFixed(cUnit, rlArg, nextReg);
buzbee31a4a6f2012-02-28 15:36:15 -0800440 }
buzbee15bf9802012-06-12 17:49:27 -0700441 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700442 directCode, directMethod, type);
443 }
444 return callState;
buzbee31a4a6f2012-02-28 15:36:15 -0800445}
446
447/*
448 * Load up to 5 arguments, the first three of which will be in
449 * rARG1 .. rARG3. On entry rARG0 contains the current method pointer,
450 * and as part of the load sequence, it must be replaced with
451 * the target method pointer. Note, this may also be called
452 * for "range" variants if the number of arguments is 5 or fewer.
453 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700454int genDalvikArgsNoRange(CompilationUnit* cUnit, CallInfo* info,
buzbee15bf9802012-06-12 17:49:27 -0700455 int callState,
buzbee31a4a6f2012-02-28 15:36:15 -0800456 LIR** pcrLabel, NextCallInsn nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700457 uint32_t dexIdx, uint32_t methodIdx,
458 uintptr_t directCode, uintptr_t directMethod,
Brian Carlstromf5822582012-03-19 22:34:31 -0700459 InvokeType type, bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800460{
Bill Buzbeea114add2012-05-03 15:00:40 -0700461 RegLocation rlArg;
buzbee31a4a6f2012-02-28 15:36:15 -0800462
Bill Buzbeea114add2012-05-03 15:00:40 -0700463 /* If no arguments, just return */
buzbee15bf9802012-06-12 17:49:27 -0700464 if (info->numArgWords == 0)
buzbee31a4a6f2012-02-28 15:36:15 -0800465 return callState;
Bill Buzbeea114add2012-05-03 15:00:40 -0700466
buzbee15bf9802012-06-12 17:49:27 -0700467 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700468 directCode, directMethod, type);
469
buzbee15bf9802012-06-12 17:49:27 -0700470 DCHECK_LE(info->numArgWords, 5);
471 if (info->numArgWords > 3) {
472 int32_t nextUse = 3;
Bill Buzbeea114add2012-05-03 15:00:40 -0700473 //Detect special case of wide arg spanning arg3/arg4
buzbee15bf9802012-06-12 17:49:27 -0700474 RegLocation rlUse0 = info->args[0];
475 RegLocation rlUse1 = info->args[1];
476 RegLocation rlUse2 = info->args[2];
Bill Buzbeea114add2012-05-03 15:00:40 -0700477 if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) &&
478 rlUse2.wide) {
479 int reg = -1;
480 // Wide spans, we need the 2nd half of uses[2].
481 rlArg = oatUpdateLocWide(cUnit, rlUse2);
482 if (rlArg.location == kLocPhysReg) {
483 reg = rlArg.highReg;
484 } else {
485 // rARG2 & rARG3 can safely be used here
486 reg = rARG3;
487 loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg);
buzbee15bf9802012-06-12 17:49:27 -0700488 callState = nextCallInsn(cUnit, info, callState, dexIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700489 methodIdx, directCode, directMethod, type);
490 }
491 storeBaseDisp(cUnit, rSP, (nextUse + 1) * 4, reg, kWord);
492 storeBaseDisp(cUnit, rSP, 16 /* (3+1)*4 */, reg, kWord);
buzbee15bf9802012-06-12 17:49:27 -0700493 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700494 directCode, directMethod, type);
495 nextUse++;
496 }
497 // Loop through the rest
buzbee15bf9802012-06-12 17:49:27 -0700498 while (nextUse < info->numArgWords) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700499 int lowReg;
500 int highReg = -1;
buzbee15bf9802012-06-12 17:49:27 -0700501 rlArg = info->args[nextUse];
Bill Buzbeea114add2012-05-03 15:00:40 -0700502 rlArg = oatUpdateRawLoc(cUnit, rlArg);
503 if (rlArg.location == kLocPhysReg) {
504 lowReg = rlArg.lowReg;
505 highReg = rlArg.highReg;
506 } else {
507 lowReg = rARG2;
508 if (rlArg.wide) {
509 highReg = rARG3;
510 loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg);
511 } else {
512 loadValueDirectFixed(cUnit, rlArg, lowReg);
513 }
buzbee15bf9802012-06-12 17:49:27 -0700514 callState = nextCallInsn(cUnit, info, callState, dexIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700515 methodIdx, directCode, directMethod, type);
516 }
517 int outsOffset = (nextUse + 1) * 4;
518 if (rlArg.wide) {
519 storeBaseDispWide(cUnit, rSP, outsOffset, lowReg, highReg);
520 nextUse += 2;
521 } else {
522 storeWordDisp(cUnit, rSP, outsOffset, lowReg);
523 nextUse++;
524 }
buzbee15bf9802012-06-12 17:49:27 -0700525 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700526 directCode, directMethod, type);
527 }
528 }
529
buzbee15bf9802012-06-12 17:49:27 -0700530 callState = loadArgRegs(cUnit, info, callState, nextCallInsn,
Bill Buzbeea114add2012-05-03 15:00:40 -0700531 dexIdx, methodIdx, directCode, directMethod,
532 type, skipThis);
533
534 if (pcrLabel) {
buzbee15bf9802012-06-12 17:49:27 -0700535 *pcrLabel = genNullCheck(cUnit, info->args[0].sRegLow, rARG1,
536 info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700537 }
538 return callState;
buzbee31a4a6f2012-02-28 15:36:15 -0800539}
540
541/*
542 * May have 0+ arguments (also used for jumbo). Note that
543 * source virtual registers may be in physical registers, so may
544 * need to be flushed to home location before copying. This
545 * applies to arg3 and above (see below).
546 *
547 * Two general strategies:
548 * If < 20 arguments
549 * Pass args 3-18 using vldm/vstm block copy
550 * Pass arg0, arg1 & arg2 in rARG1-rARG3
551 * If 20+ arguments
552 * Pass args arg19+ using memcpy block copy
553 * Pass arg0, arg1 & arg2 in rARG1-rARG3
554 *
555 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700556int genDalvikArgsRange(CompilationUnit* cUnit, CallInfo* info, int callState,
buzbee31a4a6f2012-02-28 15:36:15 -0800557 LIR** pcrLabel, NextCallInsn nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700558 uint32_t dexIdx, uint32_t methodIdx,
559 uintptr_t directCode, uintptr_t directMethod,
Brian Carlstromf5822582012-03-19 22:34:31 -0700560 InvokeType type, bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800561{
buzbee31a4a6f2012-02-28 15:36:15 -0800562
Bill Buzbeea114add2012-05-03 15:00:40 -0700563 // If we can treat it as non-range (Jumbo ops will use range form)
buzbee15bf9802012-06-12 17:49:27 -0700564 if (info->numArgWords <= 5)
565 return genDalvikArgsNoRange(cUnit, info, callState, pcrLabel,
Bill Buzbeea114add2012-05-03 15:00:40 -0700566 nextCallInsn, dexIdx, methodIdx,
567 directCode, directMethod, type, skipThis);
568 /*
Bill Buzbeea114add2012-05-03 15:00:40 -0700569 * First load the non-register arguments. Both forms expect all
570 * of the source arguments to be in their home frame location, so
571 * scan the sReg names and flush any that have been promoted to
572 * frame backing storage.
573 */
574 // Scan the rest of the args - if in physReg flush to memory
buzbee15bf9802012-06-12 17:49:27 -0700575 for (int nextArg = 0; nextArg < info->numArgWords;) {
576 RegLocation loc = info->args[nextArg];
Bill Buzbeea114add2012-05-03 15:00:40 -0700577 if (loc.wide) {
578 loc = oatUpdateLocWide(cUnit, loc);
579 if ((nextArg >= 2) && (loc.location == kLocPhysReg)) {
580 storeBaseDispWide(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow),
581 loc.lowReg, loc.highReg);
582 }
583 nextArg += 2;
584 } else {
585 loc = oatUpdateLoc(cUnit, loc);
586 if ((nextArg >= 3) && (loc.location == kLocPhysReg)) {
587 storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow),
588 loc.lowReg, kWord);
589 }
590 nextArg++;
buzbee31a4a6f2012-02-28 15:36:15 -0800591 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700592 }
buzbee31a4a6f2012-02-28 15:36:15 -0800593
buzbee15bf9802012-06-12 17:49:27 -0700594 int startOffset = oatSRegOffset(cUnit, info->args[3].sRegLow);
Bill Buzbeea114add2012-05-03 15:00:40 -0700595 int outsOffset = 4 /* Method* */ + (3 * 4);
Ian Rogersab2b55d2012-03-18 00:06:11 -0700596#if defined(TARGET_MIPS) || defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700597 // Generate memcpy
598 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
599 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
600 callRuntimeHelperRegRegImm(cUnit, ENTRYPOINT_OFFSET(pMemcpy),
buzbee8320f382012-09-11 16:29:42 -0700601 rARG0, rARG1, (info->numArgWords - 3) * 4, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700602#else
buzbee15bf9802012-06-12 17:49:27 -0700603 if (info->numArgWords >= 20) {
buzbee31a4a6f2012-02-28 15:36:15 -0800604 // Generate memcpy
605 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
606 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
Ian Rogers57b86d42012-03-27 16:05:41 -0700607 callRuntimeHelperRegRegImm(cUnit, ENTRYPOINT_OFFSET(pMemcpy),
buzbee8320f382012-09-11 16:29:42 -0700608 rARG0, rARG1, (info->numArgWords - 3) * 4, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700609 } else {
610 // Use vldm/vstm pair using rARG3 as a temp
buzbee15bf9802012-06-12 17:49:27 -0700611 int regsLeft = std::min(info->numArgWords - 3, 16);
612 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Brian Carlstromf5822582012-03-19 22:34:31 -0700613 directCode, directMethod, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700614 opRegRegImm(cUnit, kOpAdd, rARG3, rSP, startOffset);
615 LIR* ld = newLIR3(cUnit, kThumb2Vldms, rARG3, fr0, regsLeft);
616 //TUNING: loosen barrier
617 ld->defMask = ENCODE_ALL;
618 setMemRefType(ld, true /* isLoad */, kDalvikReg);
buzbee15bf9802012-06-12 17:49:27 -0700619 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700620 directCode, directMethod, type);
621 opRegRegImm(cUnit, kOpAdd, rARG3, rSP, 4 /* Method* */ + (3 * 4));
buzbee15bf9802012-06-12 17:49:27 -0700622 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700623 directCode, directMethod, type);
624 LIR* st = newLIR3(cUnit, kThumb2Vstms, rARG3, fr0, regsLeft);
625 setMemRefType(st, false /* isLoad */, kDalvikReg);
626 st->defMask = ENCODE_ALL;
buzbee15bf9802012-06-12 17:49:27 -0700627 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700628 directCode, directMethod, type);
629
630 }
631#endif
632
buzbee15bf9802012-06-12 17:49:27 -0700633 callState = loadArgRegs(cUnit, info, callState, nextCallInsn,
Bill Buzbeea114add2012-05-03 15:00:40 -0700634 dexIdx, methodIdx, directCode, directMethod,
635 type, skipThis);
636
buzbee15bf9802012-06-12 17:49:27 -0700637 callState = nextCallInsn(cUnit, info, callState, dexIdx, methodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700638 directCode, directMethod, type);
639 if (pcrLabel) {
buzbee15bf9802012-06-12 17:49:27 -0700640 *pcrLabel = genNullCheck(cUnit, info->args[0].sRegLow, rARG1,
641 info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700642 }
643 return callState;
buzbee31a4a6f2012-02-28 15:36:15 -0800644}
645
buzbee3b3dbdd2012-06-13 13:39:34 -0700646RegLocation inlineTarget(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700647{
Bill Buzbeea114add2012-05-03 15:00:40 -0700648 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700649 if (info->result.location == kLocInvalid) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700650 res = oatGetReturn(cUnit, false);
651 } else {
buzbee15bf9802012-06-12 17:49:27 -0700652 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700653 }
654 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700655}
656
buzbee3b3dbdd2012-06-13 13:39:34 -0700657RegLocation inlineTargetWide(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700658{
Bill Buzbeea114add2012-05-03 15:00:40 -0700659 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700660 if (info->result.location == kLocInvalid) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700661 res = oatGetReturnWide(cUnit, false);
662 } else {
buzbee15bf9802012-06-12 17:49:27 -0700663 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700664 }
665 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700666}
667
buzbee3b3dbdd2012-06-13 13:39:34 -0700668bool genInlinedCharAt(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700669{
jeffhao634ea282012-08-10 13:04:01 -0700670#if defined(TARGET_ARM) || defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700671 // Location of reference to data array
672 int valueOffset = String::ValueOffset().Int32Value();
673 // Location of count
674 int countOffset = String::CountOffset().Int32Value();
675 // Starting offset within data array
676 int offsetOffset = String::OffsetOffset().Int32Value();
677 // Start of char data with array_
678 int dataOffset = Array::DataOffset(sizeof(uint16_t)).Int32Value();
buzbeefc9e6fa2012-03-23 15:14:29 -0700679
buzbee15bf9802012-06-12 17:49:27 -0700680 RegLocation rlObj = info->args[0];
681 RegLocation rlIdx = info->args[1];
Bill Buzbeea114add2012-05-03 15:00:40 -0700682 rlObj = loadValue(cUnit, rlObj, kCoreReg);
683 rlIdx = loadValue(cUnit, rlIdx, kCoreReg);
684 int regMax;
buzbee15bf9802012-06-12 17:49:27 -0700685 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, info->optFlags);
686 bool rangeCheck = (!(info->optFlags & MIR_IGNORE_RANGE_CHECK));
jeffhao634ea282012-08-10 13:04:01 -0700687 LIR* launchPad = NULL;
688#if !defined(TARGET_X86)
689 int regOff = oatAllocTemp(cUnit);
690 int regPtr = oatAllocTemp(cUnit);
Bill Buzbeea114add2012-05-03 15:00:40 -0700691 if (rangeCheck) {
692 regMax = oatAllocTemp(cUnit);
693 loadWordDisp(cUnit, rlObj.lowReg, countOffset, regMax);
694 }
695 loadWordDisp(cUnit, rlObj.lowReg, offsetOffset, regOff);
696 loadWordDisp(cUnit, rlObj.lowReg, valueOffset, regPtr);
Bill Buzbeea114add2012-05-03 15:00:40 -0700697 if (rangeCheck) {
698 // Set up a launch pad to allow retry in case of bounds violation */
buzbee15bf9802012-06-12 17:49:27 -0700699 launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, (uintptr_t)info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700700 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads,
701 (intptr_t)launchPad);
702 opRegReg(cUnit, kOpCmp, rlIdx.lowReg, regMax);
703 oatFreeTemp(cUnit, regMax);
704 opCondBranch(cUnit, kCondCs, launchPad);
705 }
jeffhao634ea282012-08-10 13:04:01 -0700706#else
707 if (rangeCheck) {
708 regMax = oatAllocTemp(cUnit);
709 loadWordDisp(cUnit, rlObj.lowReg, countOffset, regMax);
710 // Set up a launch pad to allow retry in case of bounds violation */
711 launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, (uintptr_t)info);
712 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads,
713 (intptr_t)launchPad);
714 opRegReg(cUnit, kOpCmp, rlIdx.lowReg, regMax);
715 oatFreeTemp(cUnit, regMax);
716 opCondBranch(cUnit, kCondCc, launchPad);
717 }
718 int regOff = oatAllocTemp(cUnit);
719 int regPtr = oatAllocTemp(cUnit);
720 loadWordDisp(cUnit, rlObj.lowReg, offsetOffset, regOff);
721 loadWordDisp(cUnit, rlObj.lowReg, valueOffset, regPtr);
722#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700723 opRegImm(cUnit, kOpAdd, regPtr, dataOffset);
724 opRegReg(cUnit, kOpAdd, regOff, rlIdx.lowReg);
jeffhao634ea282012-08-10 13:04:01 -0700725 oatFreeTemp(cUnit, rlObj.lowReg);
726 oatFreeTemp(cUnit, rlIdx.lowReg);
buzbee15bf9802012-06-12 17:49:27 -0700727 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700728 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
729 loadBaseIndexed(cUnit, regPtr, regOff, rlResult.lowReg, 1, kUnsignedHalf);
730 oatFreeTemp(cUnit, regOff);
731 oatFreeTemp(cUnit, regPtr);
732 storeValue(cUnit, rlDest, rlResult);
733 if (rangeCheck) {
Elliott Hughes60234562012-06-01 12:25:59 -0700734 launchPad->operands[2] = 0; // no resumption
Bill Buzbeea114add2012-05-03 15:00:40 -0700735 }
736 // Record that we've already inlined & null checked
buzbee15bf9802012-06-12 17:49:27 -0700737 info->optFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
Bill Buzbeea114add2012-05-03 15:00:40 -0700738 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700739#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700740 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700741#endif
742}
743
buzbee3b3dbdd2012-06-13 13:39:34 -0700744bool genInlinedMinMaxInt(CompilationUnit *cUnit, CallInfo* info, bool isMin)
buzbeefc9e6fa2012-03-23 15:14:29 -0700745{
jeffhao77ae36b2012-08-07 14:18:16 -0700746#if defined(TARGET_ARM) || defined(TARGET_X86)
buzbee15bf9802012-06-12 17:49:27 -0700747 RegLocation rlSrc1 = info->args[0];
748 RegLocation rlSrc2 = info->args[1];
Bill Buzbeea114add2012-05-03 15:00:40 -0700749 rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg);
750 rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg);
buzbee15bf9802012-06-12 17:49:27 -0700751 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700752 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
753 opRegReg(cUnit, kOpCmp, rlSrc1.lowReg, rlSrc2.lowReg);
jeffhao77ae36b2012-08-07 14:18:16 -0700754#if defined(TARGET_ARM)
Bill Buzbeea114add2012-05-03 15:00:40 -0700755 opIT(cUnit, (isMin) ? kArmCondGt : kArmCondLt, "E");
756 opRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc2.lowReg);
757 opRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc1.lowReg);
758 genBarrier(cUnit);
jeffhao77ae36b2012-08-07 14:18:16 -0700759#elif defined(TARGET_X86)
760 LIR* branch = newLIR2(cUnit, kX86Jcc8, 0, isMin ? kX86CondG : kX86CondL);
761 opRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc1.lowReg);
762 LIR* branch2 = newLIR1(cUnit, kX86Jmp8, 0);
763 branch->target = newLIR0(cUnit, kPseudoTargetLabel);
764 opRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc2.lowReg);
765 branch2->target = newLIR0(cUnit, kPseudoTargetLabel);
766#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700767 storeValue(cUnit, rlDest, rlResult);
768 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700769#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700770 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700771#endif
772}
773
774// Generates an inlined String.isEmpty or String.length.
buzbee3b3dbdd2012-06-13 13:39:34 -0700775bool genInlinedStringIsEmptyOrLength(CompilationUnit* cUnit, CallInfo* info,
buzbee15bf9802012-06-12 17:49:27 -0700776 bool isEmpty)
buzbeefc9e6fa2012-03-23 15:14:29 -0700777{
jeffhao77ae36b2012-08-07 14:18:16 -0700778#if defined(TARGET_ARM) || defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700779 // dst = src.length();
buzbee15bf9802012-06-12 17:49:27 -0700780 RegLocation rlObj = info->args[0];
Bill Buzbeea114add2012-05-03 15:00:40 -0700781 rlObj = loadValue(cUnit, rlObj, kCoreReg);
buzbee15bf9802012-06-12 17:49:27 -0700782 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700783 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
buzbee15bf9802012-06-12 17:49:27 -0700784 genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700785 loadWordDisp(cUnit, rlObj.lowReg, String::CountOffset().Int32Value(),
786 rlResult.lowReg);
787 if (isEmpty) {
788 // dst = (dst == 0);
jeffhao77ae36b2012-08-07 14:18:16 -0700789#if defined(TARGET_ARM)
Bill Buzbeea114add2012-05-03 15:00:40 -0700790 int tReg = oatAllocTemp(cUnit);
791 opRegReg(cUnit, kOpNeg, tReg, rlResult.lowReg);
792 opRegRegReg(cUnit, kOpAdc, rlResult.lowReg, rlResult.lowReg, tReg);
jeffhao77ae36b2012-08-07 14:18:16 -0700793#elif defined(TARGET_X86)
794 opRegImm(cUnit, kOpSub, rlResult.lowReg, 1);
795 opRegImm(cUnit, kOpLsr, rlResult.lowReg, 31);
796#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700797 }
798 storeValue(cUnit, rlDest, rlResult);
799 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700800#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700801 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700802#endif
803}
804
buzbee3b3dbdd2012-06-13 13:39:34 -0700805bool genInlinedAbsInt(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700806{
jeffhao77ae36b2012-08-07 14:18:16 -0700807#if defined(TARGET_ARM) || defined(TARGET_X86)
buzbee15bf9802012-06-12 17:49:27 -0700808 RegLocation rlSrc = info->args[0];
Bill Buzbeea114add2012-05-03 15:00:40 -0700809 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
buzbee15bf9802012-06-12 17:49:27 -0700810 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700811 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
812 int signReg = oatAllocTemp(cUnit);
813 // abs(x) = y<=x>>31, (x+y)^y.
814 opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.lowReg, 31);
815 opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg);
816 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
817 storeValue(cUnit, rlDest, rlResult);
818 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700819#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700820 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700821#endif
822}
823
buzbee3b3dbdd2012-06-13 13:39:34 -0700824bool genInlinedAbsLong(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700825{
826#if defined(TARGET_ARM)
buzbee15bf9802012-06-12 17:49:27 -0700827 RegLocation rlSrc = info->args[0];
Bill Buzbeea114add2012-05-03 15:00:40 -0700828 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
buzbee15bf9802012-06-12 17:49:27 -0700829 RegLocation rlDest = inlineTargetWide(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700830 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
831 int signReg = oatAllocTemp(cUnit);
832 // abs(x) = y<=x>>31, (x+y)^y.
833 opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.highReg, 31);
834 opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg);
835 opRegRegReg(cUnit, kOpAdc, rlResult.highReg, rlSrc.highReg, signReg);
836 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
837 opRegReg(cUnit, kOpXor, rlResult.highReg, signReg);
838 storeValueWide(cUnit, rlDest, rlResult);
839 return true;
jeffhao77ae36b2012-08-07 14:18:16 -0700840#elif defined(TARGET_X86)
841 // Reuse source registers to avoid running out of temps
842 RegLocation rlSrc = info->args[0];
843 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
844 RegLocation rlDest = inlineTargetWide(cUnit, info);
845 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
846 opRegCopyWide(cUnit, rlResult.lowReg, rlResult.highReg, rlSrc.lowReg, rlSrc.highReg);
847 oatFreeTemp(cUnit, rlSrc.lowReg);
848 oatFreeTemp(cUnit, rlSrc.highReg);
849 int signReg = oatAllocTemp(cUnit);
850 // abs(x) = y<=x>>31, (x+y)^y.
851 opRegRegImm(cUnit, kOpAsr, signReg, rlResult.highReg, 31);
852 opRegReg(cUnit, kOpAdd, rlResult.lowReg, signReg);
853 opRegReg(cUnit, kOpAdc, rlResult.highReg, signReg);
854 opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg);
855 opRegReg(cUnit, kOpXor, rlResult.highReg, signReg);
856 storeValueWide(cUnit, rlDest, rlResult);
857 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700858#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700859 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700860#endif
861}
862
buzbee3b3dbdd2012-06-13 13:39:34 -0700863bool genInlinedFloatCvt(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700864{
jeffhaobabda952012-08-02 15:55:30 -0700865#if defined(TARGET_ARM) || defined(TARGET_X86)
buzbee15bf9802012-06-12 17:49:27 -0700866 RegLocation rlSrc = info->args[0];
867 RegLocation rlDest = inlineTarget(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700868 storeValue(cUnit, rlDest, rlSrc);
869 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700870#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700871 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700872#endif
873}
874
buzbee3b3dbdd2012-06-13 13:39:34 -0700875bool genInlinedDoubleCvt(CompilationUnit *cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700876{
jeffhaobabda952012-08-02 15:55:30 -0700877#if defined(TARGET_ARM) || defined(TARGET_X86)
buzbee15bf9802012-06-12 17:49:27 -0700878 RegLocation rlSrc = info->args[0];
879 RegLocation rlDest = inlineTargetWide(cUnit, info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700880 storeValueWide(cUnit, rlDest, rlSrc);
881 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700882#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700883 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700884#endif
885}
886
887/*
888 * Fast string.indexOf(I) & (II). Tests for simple case of char <= 0xffff,
889 * otherwise bails to standard library code.
890 */
buzbee3b3dbdd2012-06-13 13:39:34 -0700891bool genInlinedIndexOf(CompilationUnit* cUnit, CallInfo* info,
buzbee15bf9802012-06-12 17:49:27 -0700892 bool zeroBased)
buzbeefc9e6fa2012-03-23 15:14:29 -0700893{
jeffhao86e46712012-08-08 17:30:59 -0700894#if defined(TARGET_ARM) || defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700895 oatClobberCalleeSave(cUnit);
896 oatLockCallTemps(cUnit); // Using fixed registers
897 int regPtr = rARG0;
898 int regChar = rARG1;
899 int regStart = rARG2;
buzbeefc9e6fa2012-03-23 15:14:29 -0700900
buzbee15bf9802012-06-12 17:49:27 -0700901 RegLocation rlObj = info->args[0];
902 RegLocation rlChar = info->args[1];
903 RegLocation rlStart = info->args[2];
Bill Buzbeea114add2012-05-03 15:00:40 -0700904 loadValueDirectFixed(cUnit, rlObj, regPtr);
905 loadValueDirectFixed(cUnit, rlChar, regChar);
906 if (zeroBased) {
907 loadConstant(cUnit, regStart, 0);
908 } else {
909 loadValueDirectFixed(cUnit, rlStart, regStart);
910 }
jeffhao86e46712012-08-08 17:30:59 -0700911#if !defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700912 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pIndexOf));
jeffhao86e46712012-08-08 17:30:59 -0700913#endif
buzbee15bf9802012-06-12 17:49:27 -0700914 genNullCheck(cUnit, rlObj.sRegLow, regPtr, info->optFlags);
915 LIR* launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, (uintptr_t)info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700916 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads,
917 (intptr_t)launchPad);
918 opCmpImmBranch(cUnit, kCondGt, regChar, 0xFFFF, launchPad);
buzbee8320f382012-09-11 16:29:42 -0700919 // NOTE: not a safepoint
jeffhao86e46712012-08-08 17:30:59 -0700920#if !defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700921 opReg(cUnit, kOpBlx, rTgt);
jeffhao86e46712012-08-08 17:30:59 -0700922#else
923 opThreadMem(cUnit, kOpBlx, ENTRYPOINT_OFFSET(pIndexOf));
924#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700925 LIR* resumeTgt = newLIR0(cUnit, kPseudoTargetLabel);
926 launchPad->operands[2] = (uintptr_t)resumeTgt;
Bill Buzbeea114add2012-05-03 15:00:40 -0700927 // Record that we've already inlined & null checked
buzbee15bf9802012-06-12 17:49:27 -0700928 info->optFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
929 RegLocation rlReturn = oatGetReturn(cUnit, false);
930 RegLocation rlDest = inlineTarget(cUnit, info);
931 storeValue(cUnit, rlDest, rlReturn);
Bill Buzbeea114add2012-05-03 15:00:40 -0700932 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700933#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700934 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700935#endif
936}
937
938/* Fast string.compareTo(Ljava/lang/string;)I. */
buzbee3b3dbdd2012-06-13 13:39:34 -0700939bool genInlinedStringCompareTo(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700940{
jeffhao86e46712012-08-08 17:30:59 -0700941#if defined(TARGET_ARM) || defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700942 oatClobberCalleeSave(cUnit);
943 oatLockCallTemps(cUnit); // Using fixed registers
944 int regThis = rARG0;
945 int regCmp = rARG1;
buzbeefc9e6fa2012-03-23 15:14:29 -0700946
buzbee15bf9802012-06-12 17:49:27 -0700947 RegLocation rlThis = info->args[0];
948 RegLocation rlCmp = info->args[1];
Bill Buzbeea114add2012-05-03 15:00:40 -0700949 loadValueDirectFixed(cUnit, rlThis, regThis);
950 loadValueDirectFixed(cUnit, rlCmp, regCmp);
jeffhao86e46712012-08-08 17:30:59 -0700951#if !defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700952 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pStringCompareTo));
jeffhao86e46712012-08-08 17:30:59 -0700953#endif
buzbee15bf9802012-06-12 17:49:27 -0700954 genNullCheck(cUnit, rlThis.sRegLow, regThis, info->optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700955 //TUNING: check if rlCmp.sRegLow is already null checked
buzbee15bf9802012-06-12 17:49:27 -0700956 LIR* launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, (uintptr_t)info);
Bill Buzbeea114add2012-05-03 15:00:40 -0700957 oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads,
Elliott Hughes60234562012-06-01 12:25:59 -0700958 (intptr_t)launchPad);
Bill Buzbeea114add2012-05-03 15:00:40 -0700959 opCmpImmBranch(cUnit, kCondEq, regCmp, 0, launchPad);
buzbee8320f382012-09-11 16:29:42 -0700960 // NOTE: not a safepoint
jeffhao86e46712012-08-08 17:30:59 -0700961#if !defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700962 opReg(cUnit, kOpBlx, rTgt);
jeffhao86e46712012-08-08 17:30:59 -0700963#else
964 opThreadMem(cUnit, kOpBlx, ENTRYPOINT_OFFSET(pStringCompareTo));
965#endif
Elliott Hughes60234562012-06-01 12:25:59 -0700966 launchPad->operands[2] = 0; // No return possible
Bill Buzbeea114add2012-05-03 15:00:40 -0700967 // Record that we've already inlined & null checked
buzbee15bf9802012-06-12 17:49:27 -0700968 info->optFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
969 RegLocation rlReturn = oatGetReturn(cUnit, false);
970 RegLocation rlDest = inlineTarget(cUnit, info);
971 storeValue(cUnit, rlDest, rlReturn);
Bill Buzbeea114add2012-05-03 15:00:40 -0700972 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700973#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700974 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -0700975#endif
976}
977
Ian Rogerse13eafa2012-09-07 11:24:27 -0700978bool genInlinedCas32(CompilationUnit* cUnit, CallInfo* info, bool need_write_barrier) {
979#if defined(TARGET_ARM)
980 // Unused - RegLocation rlSrcUnsafe = info->args[0];
981 RegLocation rlSrcObj= info->args[1]; // Object - known non-null
982 RegLocation rlSrcOffset= info->args[2]; // long low
983 rlSrcOffset.wide = 0; // ignore high half in info->args[3]
984 RegLocation rlSrcExpected= info->args[4]; // int or Object
985 RegLocation rlSrcNewValue= info->args[5]; // int or Object
986 RegLocation rlDest = inlineTarget(cUnit, info); // boolean place for result
987
988
989 // Release store semantics, get the barrier out of the way.
990 oatGenMemBarrier(cUnit, kSY);
991
992 RegLocation rlObject = loadValue(cUnit, rlSrcObj, kCoreReg);
993 RegLocation rlNewValue = loadValue(cUnit, rlSrcNewValue, kCoreReg);
994
995 if (need_write_barrier) {
996 // Mark card for object assuming new value is stored.
997 markGCCard(cUnit, rlNewValue.lowReg, rlObject.lowReg);
998 }
999
1000 RegLocation rlOffset = loadValue(cUnit, rlSrcOffset, kCoreReg);
1001
1002 int rPtr = oatAllocTemp(cUnit);
1003 opRegRegReg(cUnit, kOpAdd, rPtr, rlObject.lowReg, rlOffset.lowReg);
1004
1005 // Free now unneeded rlObject and rlOffset to give more temps.
1006 oatClobberSReg(cUnit, rlObject.sRegLow);
1007 oatFreeTemp(cUnit, rlObject.lowReg);
1008 oatClobberSReg(cUnit, rlOffset.sRegLow);
1009 oatFreeTemp(cUnit, rlOffset.lowReg);
1010
1011 int rOldValue = oatAllocTemp(cUnit);
1012 newLIR3(cUnit, kThumb2Ldrex, rOldValue, rPtr, 0); // rOldValue := [rPtr]
1013
1014 RegLocation rlExpected = loadValue(cUnit, rlSrcExpected, kCoreReg);
1015
1016 // if (rOldValue == rExpected) {
1017 // [rPtr] <- rNewValue && rResult := success ? 0 : 1
1018 // rResult ^= 1
1019 // } else {
1020 // rResult := 0
1021 // }
1022 opRegReg(cUnit, kOpCmp, rOldValue, rlExpected.lowReg);
1023 oatFreeTemp(cUnit, rOldValue); // Now unneeded.
1024 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
1025 opIT(cUnit, kArmCondEq, "TE");
1026 newLIR4(cUnit, kThumb2Strex, rlResult.lowReg, rlNewValue.lowReg, rPtr, 0);
1027 oatFreeTemp(cUnit, rPtr); // Now unneeded.
1028 opRegImm(cUnit, kOpXor, rlResult.lowReg, 1);
1029 opRegReg(cUnit, kOpXor, rlResult.lowReg, rlResult.lowReg);
1030
1031 storeValue(cUnit, rlDest, rlResult);
1032
1033 return true;
1034#else
1035 return false;
1036#endif
1037}
1038
Ian Rogers0183dd72012-09-17 23:06:51 -07001039bool genInlinedSqrt(CompilationUnit* cUnit, CallInfo* info) {
1040#if defined(TARGET_ARM)
1041 LIR *branch;
1042 RegLocation rlSrc = info->args[0];
1043 RegLocation rlDest = inlineTargetWide(cUnit, info); // double place for result
1044 rlSrc = loadValueWide(cUnit, rlSrc, kFPReg);
1045 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true);
1046 newLIR2(cUnit, kThumb2Vsqrtd, S2D(rlResult.lowReg, rlResult.highReg),
1047 S2D(rlSrc.lowReg, rlSrc.highReg));
1048 newLIR2(cUnit, kThumb2Vcmpd, S2D(rlResult.lowReg, rlResult.highReg),
1049 S2D(rlResult.lowReg, rlResult.highReg));
1050 newLIR0(cUnit, kThumb2Fmstat);
1051 branch = newLIR2(cUnit, kThumbBCond, 0, kArmCondEq);
1052 oatClobberCalleeSave(cUnit);
1053 oatLockCallTemps(cUnit); // Using fixed registers
1054 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pSqrt));
1055 newLIR3(cUnit, kThumb2Fmrrd, r0, r1, S2D(rlSrc.lowReg, rlSrc.highReg));
1056 newLIR1(cUnit, kThumbBlxR, rTgt);
1057 newLIR3(cUnit, kThumb2Fmdrr, S2D(rlResult.lowReg, rlResult.highReg), r0, r1);
1058 branch->target = newLIR0(cUnit, kPseudoTargetLabel);
1059 storeValueWide(cUnit, rlDest, rlResult);
1060 return true;
1061#else
1062 return false;
1063#endif
1064}
1065
buzbee3b3dbdd2012-06-13 13:39:34 -07001066bool genIntrinsic(CompilationUnit* cUnit, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001067{
Ian Rogerse13eafa2012-09-07 11:24:27 -07001068 if (info->optFlags & MIR_INLINED) {
buzbeefc9e6fa2012-03-23 15:14:29 -07001069 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07001070 }
1071 /*
1072 * TODO: move these to a target-specific structured constant array
1073 * and use a generic match function. The list of intrinsics may be
1074 * slightly different depending on target.
1075 * TODO: Fold this into a matching function that runs during
1076 * basic block building. This should be part of the action for
1077 * small method inlining and recognition of the special object init
1078 * method. By doing this during basic block construction, we can also
1079 * take advantage of/generate new useful dataflow info.
1080 */
buzbee3b3dbdd2012-06-13 13:39:34 -07001081 std::string tgtMethod(PrettyMethod(info->index, *cUnit->dex_file));
Ian Rogers0183dd72012-09-17 23:06:51 -07001082 if (tgtMethod.find(" java.lang") != std::string::npos) {
1083 if (tgtMethod == "long java.lang.Double.doubleToRawLongBits(double)") {
1084 return genInlinedDoubleCvt(cUnit, info);
1085 }
1086 if (tgtMethod == "double java.lang.Double.longBitsToDouble(long)") {
1087 return genInlinedDoubleCvt(cUnit, info);
1088 }
1089 if (tgtMethod == "int java.lang.Float.floatToRawIntBits(float)") {
1090 return genInlinedFloatCvt(cUnit, info);
1091 }
1092 if (tgtMethod == "float java.lang.Float.intBitsToFloat(int)") {
1093 return genInlinedFloatCvt(cUnit, info);
1094 }
1095 if (tgtMethod == "int java.lang.Math.abs(int)" ||
1096 tgtMethod == "int java.lang.StrictMath.abs(int)") {
1097 return genInlinedAbsInt(cUnit, info);
1098 }
1099 if (tgtMethod == "long java.lang.Math.abs(long)" ||
1100 tgtMethod == "long java.lang.StrictMath.abs(long)") {
1101 return genInlinedAbsLong(cUnit, info);
1102 }
1103 if (tgtMethod == "int java.lang.Math.max(int, int)" ||
1104 tgtMethod == "int java.lang.StrictMath.max(int, int)") {
1105 return genInlinedMinMaxInt(cUnit, info, false /* isMin */);
1106 }
1107 if (tgtMethod == "int java.lang.Math.min(int, int)" ||
1108 tgtMethod == "int java.lang.StrictMath.min(int, int)") {
1109 return genInlinedMinMaxInt(cUnit, info, true /* isMin */);
1110 }
1111 if (tgtMethod == "double java.lang.Math.sqrt(double)" ||
1112 tgtMethod == "double java.lang.StrictMath.sqrt(double)") {
1113 return genInlinedSqrt(cUnit, info);
1114 }
1115 if (tgtMethod == "char java.lang.String.charAt(int)") {
1116 return genInlinedCharAt(cUnit, info);
1117 }
1118 if (tgtMethod == "int java.lang.String.compareTo(java.lang.String)") {
1119 return genInlinedStringCompareTo(cUnit, info);
1120 }
1121 if (tgtMethod == "boolean java.lang.String.isEmpty()") {
1122 return genInlinedStringIsEmptyOrLength(cUnit, info, true /* isEmpty */);
1123 }
1124 if (tgtMethod == "int java.lang.String.indexOf(int, int)") {
1125 return genInlinedIndexOf(cUnit, info, false /* base 0 */);
1126 }
1127 if (tgtMethod == "int java.lang.String.indexOf(int)") {
1128 return genInlinedIndexOf(cUnit, info, true /* base 0 */);
1129 }
1130 if (tgtMethod == "int java.lang.String.length()") {
1131 return genInlinedStringIsEmptyOrLength(cUnit, info, false /* isEmpty */);
1132 }
1133 } else if (tgtMethod.find("boolean sun.misc.Unsafe.compareAndSwap") != std::string::npos) {
1134 if (tgtMethod == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") {
1135 return genInlinedCas32(cUnit, info, false);
1136 }
1137 if (tgtMethod == "boolean sun.misc.Unsafe.compareAndSwapObject(java.lang.Object, long, java.lang.Object, java.lang.Object)") {
1138 return genInlinedCas32(cUnit, info, true);
1139 }
Ian Rogerse13eafa2012-09-07 11:24:27 -07001140 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001141 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -07001142}
1143
1144
buzbee31a4a6f2012-02-28 15:36:15 -08001145} // namespace art