blob: 401eeb6db6b78894ae0cb0e9454b617819961e43 [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
17namespace art {
18
19/*
20 * This source files contains "gen" codegen routines that should
21 * be applicable to most targets. Only mid-level support utilities
22 * and "op" calls may be used here.
23 */
24
25
buzbee31a4a6f2012-02-28 15:36:15 -080026typedef int (*NextCallInsn)(CompilationUnit*, MIR*, int, uint32_t dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -070027 uint32_t methodIdx, uintptr_t directCode,
28 uintptr_t directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -080029/*
30 * If there are any ins passed in registers that have not been promoted
31 * to a callee-save register, flush them to the frame. Perform intial
32 * assignment of promoted arguments.
33 */
34void flushIns(CompilationUnit* cUnit)
35{
36 if (cUnit->numIns == 0)
37 return;
38 int firstArgReg = rARG1;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -070039#if !defined(TARGET_X86)
buzbee31a4a6f2012-02-28 15:36:15 -080040 int lastArgReg = rARG3;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -070041#else
42 int lastArgReg = rARG2;
43#endif
buzbee31a4a6f2012-02-28 15:36:15 -080044 int startVReg = cUnit->numDalvikRegisters - cUnit->numIns;
45 /*
buzbee86a4bce2012-03-06 18:15:00 -080046 * Copy incoming arguments to their proper home locations.
47 * NOTE: an older version of dx had an issue in which
48 * it would reuse static method argument registers.
buzbee31a4a6f2012-02-28 15:36:15 -080049 * This could result in the same Dalvik virtual register
buzbee86a4bce2012-03-06 18:15:00 -080050 * being promoted to both core and fp regs. To account for this,
51 * we only copy to the corresponding promoted physical register
52 * if it matches the type of the SSA name for the incoming
53 * argument. It is also possible that long and double arguments
54 * end up half-promoted. In those cases, we must flush the promoted
55 * half to memory as well.
buzbee31a4a6f2012-02-28 15:36:15 -080056 */
57 for (int i = 0; i < cUnit->numIns; i++) {
buzbee86a4bce2012-03-06 18:15:00 -080058 PromotionMap* vMap = &cUnit->promotionMap[startVReg + i];
buzbee31a4a6f2012-02-28 15:36:15 -080059 if (i <= (lastArgReg - firstArgReg)) {
60 // If arriving in register
buzbee86a4bce2012-03-06 18:15:00 -080061 bool needFlush = true;
62 RegLocation* tLoc = &cUnit->regLocation[startVReg + i];
63 if ((vMap->coreLocation == kLocPhysReg) && !tLoc->fp) {
64 opRegCopy(cUnit, vMap->coreReg, firstArgReg + i);
65 needFlush = false;
66 } else if ((vMap->fpLocation == kLocPhysReg) && tLoc->fp) {
67 opRegCopy(cUnit, vMap->fpReg, firstArgReg + i);
68 needFlush = false;
69 } else {
70 needFlush = true;
buzbee31a4a6f2012-02-28 15:36:15 -080071 }
buzbee86a4bce2012-03-06 18:15:00 -080072
73 // For wide args, force flush if only half is promoted
74 if (tLoc->wide) {
75 PromotionMap* pMap = vMap + (tLoc->highWord ? -1 : +1);
76 needFlush |= (pMap->coreLocation != vMap->coreLocation) ||
77 (pMap->fpLocation != vMap->fpLocation);
buzbee31a4a6f2012-02-28 15:36:15 -080078 }
buzbee86a4bce2012-03-06 18:15:00 -080079 if (needFlush) {
80 storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
81 firstArgReg + i, kWord);
82 }
buzbee31a4a6f2012-02-28 15:36:15 -080083 } else {
84 // If arriving in frame & promoted
buzbee86a4bce2012-03-06 18:15:00 -080085 if (vMap->coreLocation == kLocPhysReg) {
buzbee31a4a6f2012-02-28 15:36:15 -080086 loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
buzbee86a4bce2012-03-06 18:15:00 -080087 vMap->coreReg);
buzbee31a4a6f2012-02-28 15:36:15 -080088 }
buzbee86a4bce2012-03-06 18:15:00 -080089 if (vMap->fpLocation == kLocPhysReg) {
buzbee31a4a6f2012-02-28 15:36:15 -080090 loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
buzbee86a4bce2012-03-06 18:15:00 -080091 vMap->fpReg);
buzbee31a4a6f2012-02-28 15:36:15 -080092 }
93 }
94 }
95}
96
97/*
98 * Bit of a hack here - in leiu of a real scheduling pass,
99 * emit the next instruction in static & direct invoke sequences.
100 */
101int nextSDCallInsn(CompilationUnit* cUnit, MIR* mir,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700102 int state, uint32_t dexIdx, uint32_t unused,
103 uintptr_t directCode, uintptr_t directMethod)
buzbee31a4a6f2012-02-28 15:36:15 -0800104{
Ian Rogers2ed3b952012-03-17 11:49:39 -0700105 if (directCode != 0 && directMethod != 0) {
106 switch(state) {
107 case 0: // Get the current Method* [sets rARG0]
108 loadConstant(cUnit, rINVOKE_TGT, directCode);
109 loadConstant(cUnit, rARG0, directMethod);
110 break;
111 default:
112 return -1;
113 }
114 } else {
115 switch(state) {
buzbee31a4a6f2012-02-28 15:36:15 -0800116 case 0: // Get the current Method* [sets rARG0]
117 loadCurrMethodDirect(cUnit, rARG0);
118 break;
119 case 1: // Get method->dex_cache_resolved_methods_
120 loadWordDisp(cUnit, rARG0,
121 Method::DexCacheResolvedMethodsOffset().Int32Value(),
122 rARG0);
Ian Rogers2ed3b952012-03-17 11:49:39 -0700123 // Set up direct code if known.
124 if (directCode != 0) {
125 loadConstant(cUnit, rINVOKE_TGT, directCode);
126 }
buzbee31a4a6f2012-02-28 15:36:15 -0800127 break;
128 case 2: // Grab target method*
129 loadWordDisp(cUnit, rARG0,
130 Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4,
131 rARG0);
132 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700133#if !defined(TARGET_X86)
buzbee31a4a6f2012-02-28 15:36:15 -0800134 case 3: // Grab the code from the method*
Ian Rogers2ed3b952012-03-17 11:49:39 -0700135 if (directCode == 0) {
136 loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(),
137 rINVOKE_TGT);
138 }
buzbee31a4a6f2012-02-28 15:36:15 -0800139 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700140#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800141 default:
142 return -1;
Ian Rogers2ed3b952012-03-17 11:49:39 -0700143 }
buzbee31a4a6f2012-02-28 15:36:15 -0800144 }
145 return state + 1;
146}
147
148/*
149 * Bit of a hack here - in leiu of a real scheduling pass,
150 * emit the next instruction in a virtual invoke sequence.
151 * We can use rLR as a temp prior to target address loading
152 * Note also that we'll load the first argument ("this") into
153 * rARG1 here rather than the standard loadArgRegs.
154 */
155int nextVCallInsn(CompilationUnit* cUnit, MIR* mir,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700156 int state, uint32_t dexIdx, uint32_t methodIdx,
157 uintptr_t unused, uintptr_t unused2)
buzbee31a4a6f2012-02-28 15:36:15 -0800158{
159 RegLocation rlArg;
160 /*
161 * This is the fast path in which the target virtual method is
162 * fully resolved at compile time.
163 */
164 switch(state) {
165 case 0: // Get "this" [set rARG1]
166 rlArg = oatGetSrc(cUnit, mir, 0);
167 loadValueDirectFixed(cUnit, rlArg, rARG1);
168 break;
169 case 1: // Is "this" null? [use rARG1]
170 genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir);
buzbee0398c422012-03-02 15:22:47 -0800171 // get this->klass_ [use rARG1, set rINVOKE_TGT]
buzbee31a4a6f2012-02-28 15:36:15 -0800172 loadWordDisp(cUnit, rARG1, Object::ClassOffset().Int32Value(),
buzbee0398c422012-03-02 15:22:47 -0800173 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800174 break;
buzbee0398c422012-03-02 15:22:47 -0800175 case 2: // Get this->klass_->vtable [usr rINVOKE_TGT, set rINVOKE_TGT]
176 loadWordDisp(cUnit, rINVOKE_TGT, Class::VTableOffset().Int32Value(),
177 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800178 break;
buzbee0398c422012-03-02 15:22:47 -0800179 case 3: // Get target method [use rINVOKE_TGT, set rARG0]
180 loadWordDisp(cUnit, rINVOKE_TGT, (methodIdx * 4) +
buzbee31a4a6f2012-02-28 15:36:15 -0800181 Array::DataOffset(sizeof(Object*)).Int32Value(),
182 rARG0);
183 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700184#if !defined(TARGET_X86)
buzbee0398c422012-03-02 15:22:47 -0800185 case 4: // Get the compiled code address [uses rARG0, sets rINVOKE_TGT]
buzbee31a4a6f2012-02-28 15:36:15 -0800186 loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(),
buzbee0398c422012-03-02 15:22:47 -0800187 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800188 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700189#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800190 default:
191 return -1;
192 }
193 return state + 1;
194}
195
buzbee31a4a6f2012-02-28 15:36:15 -0800196int nextInvokeInsnSP(CompilationUnit* cUnit, MIR* mir, int trampoline,
197 int state, uint32_t dexIdx, uint32_t methodIdx)
198{
199 /*
200 * This handles the case in which the base method is not fully
201 * resolved at compile time, we bail to a runtime helper.
202 */
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700203#if !defined(TARGET_X86)
buzbee31a4a6f2012-02-28 15:36:15 -0800204 if (state == 0) {
205 // Load trampoline target
buzbee0398c422012-03-02 15:22:47 -0800206 loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800207 // Load rARG0 with method index
208 loadConstant(cUnit, rARG0, dexIdx);
209 return 1;
210 }
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700211#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800212 return -1;
213}
214
215int nextStaticCallInsnSP(CompilationUnit* cUnit, MIR* mir,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700216 int state, uint32_t dexIdx, uint32_t methodIdx,
217 uintptr_t unused, uintptr_t unused2)
buzbee31a4a6f2012-02-28 15:36:15 -0800218{
219 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeStaticTrampolineWithAccessCheck);
220 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
221}
222
223int nextDirectCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700224 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
225 uintptr_t unused2)
buzbee31a4a6f2012-02-28 15:36:15 -0800226{
227 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeDirectTrampolineWithAccessCheck);
228 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
229}
230
231int nextSuperCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700232 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
233 uintptr_t unused2)
buzbee31a4a6f2012-02-28 15:36:15 -0800234{
235 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeSuperTrampolineWithAccessCheck);
236 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
237}
238
239int nextVCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700240 uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused,
241 uintptr_t unused2)
buzbee31a4a6f2012-02-28 15:36:15 -0800242{
243 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeVirtualTrampolineWithAccessCheck);
244 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
245}
246
247/*
248 * All invoke-interface calls bounce off of art_invoke_interface_trampoline,
249 * which will locate the target and continue on via a tail call.
250 */
251int nextInterfaceCallInsn(CompilationUnit* cUnit, MIR* mir, int state,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700252 uint32_t dexIdx, uint32_t unused, uintptr_t unused2,
253 uintptr_t unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800254{
255 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampoline);
256 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
257}
258
259int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit, MIR* mir,
260 int state, uint32_t dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700261 uint32_t unused, uintptr_t unused2,
262 uintptr_t unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800263{
264 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampolineWithAccessCheck);
265 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
266}
267
268int loadArgRegs(CompilationUnit* cUnit, MIR* mir, DecodedInstruction* dInsn,
269 int callState, NextCallInsn nextCallInsn, uint32_t dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700270 uint32_t methodIdx, uintptr_t directCode,
271 uintptr_t directMethod, bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800272{
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700273#if !defined(TARGET_X86)
274 int lastArgReg = rARG3;
275#else
276 int lastArgReg = rARG2;
277#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800278 int nextReg = rARG1;
279 int nextArg = 0;
280 if (skipThis) {
281 nextReg++;
282 nextArg++;
283 }
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700284 for (; (nextReg <= lastArgReg) && (nextArg < mir->ssaRep->numUses); nextReg++) {
buzbee31a4a6f2012-02-28 15:36:15 -0800285 RegLocation rlArg = oatGetRawSrc(cUnit, mir, nextArg++);
286 rlArg = oatUpdateRawLoc(cUnit, rlArg);
287 if (rlArg.wide && (nextReg <= rARG2)) {
288 loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1);
289 nextReg++;
290 nextArg++;
291 } else {
292 rlArg.wide = false;
293 loadValueDirectFixed(cUnit, rlArg, nextReg);
294 }
Ian Rogers2ed3b952012-03-17 11:49:39 -0700295 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
296 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800297 }
298 return callState;
299}
300
301/*
302 * Load up to 5 arguments, the first three of which will be in
303 * rARG1 .. rARG3. On entry rARG0 contains the current method pointer,
304 * and as part of the load sequence, it must be replaced with
305 * the target method pointer. Note, this may also be called
306 * for "range" variants if the number of arguments is 5 or fewer.
307 */
308int genDalvikArgsNoRange(CompilationUnit* cUnit, MIR* mir,
309 DecodedInstruction* dInsn, int callState,
310 LIR** pcrLabel, NextCallInsn nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700311 uint32_t dexIdx, uint32_t methodIdx,
312 uintptr_t directCode, uintptr_t directMethod,
313 bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800314{
315 RegLocation rlArg;
316
317 /* If no arguments, just return */
318 if (dInsn->vA == 0)
319 return callState;
320
Ian Rogers2ed3b952012-03-17 11:49:39 -0700321 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
322 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800323
324 DCHECK_LE(dInsn->vA, 5U);
325 if (dInsn->vA > 3) {
326 uint32_t nextUse = 3;
327 //Detect special case of wide arg spanning arg3/arg4
328 RegLocation rlUse0 = oatGetRawSrc(cUnit, mir, 0);
329 RegLocation rlUse1 = oatGetRawSrc(cUnit, mir, 1);
330 RegLocation rlUse2 = oatGetRawSrc(cUnit, mir, 2);
331 if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) &&
332 rlUse2.wide) {
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700333 int reg = -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800334 // Wide spans, we need the 2nd half of uses[2].
335 rlArg = oatUpdateLocWide(cUnit, rlUse2);
336 if (rlArg.location == kLocPhysReg) {
337 reg = rlArg.highReg;
338 } else {
339 // rARG2 & rARG3 can safely be used here
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700340#if defined(TARGET_X86)
341 UNIMPLEMENTED(FATAL);
342#else
buzbee31a4a6f2012-02-28 15:36:15 -0800343 reg = rARG3;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700344#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800345 loadWordDisp(cUnit, rSP,
346 oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg);
347 callState = nextCallInsn(cUnit, mir, callState, dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700348 methodIdx, directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800349 }
350 storeBaseDisp(cUnit, rSP, (nextUse + 1) * 4, reg, kWord);
351 storeBaseDisp(cUnit, rSP, 16 /* (3+1)*4 */, reg, kWord);
Ian Rogers2ed3b952012-03-17 11:49:39 -0700352 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
353 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800354 nextUse++;
355 }
356 // Loop through the rest
357 while (nextUse < dInsn->vA) {
358 int lowReg;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700359 int highReg = -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800360 rlArg = oatGetRawSrc(cUnit, mir, nextUse);
361 rlArg = oatUpdateRawLoc(cUnit, rlArg);
362 if (rlArg.location == kLocPhysReg) {
363 lowReg = rlArg.lowReg;
364 highReg = rlArg.highReg;
365 } else {
366 lowReg = rARG2;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700367#if defined(TARGET_X86)
368 UNIMPLEMENTED(FATAL);
369#else
buzbee31a4a6f2012-02-28 15:36:15 -0800370 highReg = rARG3;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700371#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800372 if (rlArg.wide) {
373 loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg);
374 } else {
375 loadValueDirectFixed(cUnit, rlArg, lowReg);
376 }
377 callState = nextCallInsn(cUnit, mir, callState, dexIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700378 methodIdx, directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800379 }
380 int outsOffset = (nextUse + 1) * 4;
381 if (rlArg.wide) {
382 storeBaseDispWide(cUnit, rSP, outsOffset, lowReg, highReg);
383 nextUse += 2;
384 } else {
385 storeWordDisp(cUnit, rSP, outsOffset, lowReg);
386 nextUse++;
387 }
Ian Rogers2ed3b952012-03-17 11:49:39 -0700388 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
389 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800390 }
391 }
392
393 callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700394 dexIdx, methodIdx, directCode, directMethod,
395 skipThis);
buzbee31a4a6f2012-02-28 15:36:15 -0800396
397 if (pcrLabel) {
398 *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir);
399 }
400 return callState;
401}
402
403/*
404 * May have 0+ arguments (also used for jumbo). Note that
405 * source virtual registers may be in physical registers, so may
406 * need to be flushed to home location before copying. This
407 * applies to arg3 and above (see below).
408 *
409 * Two general strategies:
410 * If < 20 arguments
411 * Pass args 3-18 using vldm/vstm block copy
412 * Pass arg0, arg1 & arg2 in rARG1-rARG3
413 * If 20+ arguments
414 * Pass args arg19+ using memcpy block copy
415 * Pass arg0, arg1 & arg2 in rARG1-rARG3
416 *
417 */
418int genDalvikArgsRange(CompilationUnit* cUnit, MIR* mir,
419 DecodedInstruction* dInsn, int callState,
420 LIR** pcrLabel, NextCallInsn nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700421 uint32_t dexIdx, uint32_t methodIdx,
422 uintptr_t directCode, uintptr_t directMethod,
423 bool skipThis)
buzbee31a4a6f2012-02-28 15:36:15 -0800424{
425 int firstArg = dInsn->vC;
426 int numArgs = dInsn->vA;
427
428 // If we can treat it as non-range (Jumbo ops will use range form)
429 if (numArgs <= 5)
430 return genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pcrLabel,
431 nextCallInsn, dexIdx, methodIdx,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700432 directCode, directMethod, skipThis);
buzbee31a4a6f2012-02-28 15:36:15 -0800433 /*
434 * Make sure range list doesn't span the break between in normal
435 * Dalvik vRegs and the ins.
436 */
437 int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow;
438 int boundaryReg = cUnit->numDalvikRegisters - cUnit->numIns;
439 if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) {
440 LOG(FATAL) << "Argument list spanned locals & args";
441 }
442
443 /*
444 * First load the non-register arguments. Both forms expect all
445 * of the source arguments to be in their home frame location, so
446 * scan the sReg names and flush any that have been promoted to
447 * frame backing storage.
448 */
449 // Scan the rest of the args - if in physReg flush to memory
450 for (int nextArg = 0; nextArg < numArgs;) {
451 RegLocation loc = oatGetRawSrc(cUnit, mir, nextArg);
452 if (loc.wide) {
453 loc = oatUpdateLocWide(cUnit, loc);
454 if ((nextArg >= 2) && (loc.location == kLocPhysReg)) {
455 storeBaseDispWide(cUnit, rSP,
456 oatSRegOffset(cUnit, loc.sRegLow),
457 loc.lowReg, loc.highReg);
458 }
459 nextArg += 2;
460 } else {
461 loc = oatUpdateLoc(cUnit, loc);
462 if ((nextArg >= 3) && (loc.location == kLocPhysReg)) {
463 storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow),
464 loc.lowReg, kWord);
465 }
466 nextArg++;
467 }
468 }
469
470 int startOffset = oatSRegOffset(cUnit,
471 cUnit->regLocation[mir->ssaRep->uses[3]].sRegLow);
472 int outsOffset = 4 /* Method* */ + (3 * 4);
473#if defined(TARGET_MIPS)
474 // Generate memcpy
475 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
476 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
477 int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy));
478 loadConstant(cUnit, rARG2, (numArgs - 3) * 4);
479 callRuntimeHelper(cUnit, rTgt);
480 // Restore Method*
481 loadCurrMethodDirect(cUnit, rARG0);
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700482#elif defined(TARGET_X86)
483 // Generate memcpy
484 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
485 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
486 loadConstant(cUnit, rARG2, (numArgs - 3) * 4);
487 callRuntimeHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy));
488 // Restore Method*
489 loadCurrMethodDirect(cUnit, rARG0);
buzbee31a4a6f2012-02-28 15:36:15 -0800490#else
491 if (numArgs >= 20) {
492 // Generate memcpy
493 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
494 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
495 int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy));
496 loadConstant(cUnit, rARG2, (numArgs - 3) * 4);
497 callRuntimeHelper(cUnit, rTgt);
498 // Restore Method*
499 loadCurrMethodDirect(cUnit, rARG0);
500 } else {
501 // Use vldm/vstm pair using rARG3 as a temp
502 int regsLeft = std::min(numArgs - 3, 16);
Ian Rogers2ed3b952012-03-17 11:49:39 -0700503 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
504 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800505 opRegRegImm(cUnit, kOpAdd, rARG3, rSP, startOffset);
506 LIR* ld = newLIR3(cUnit, kThumb2Vldms, rARG3, fr0, regsLeft);
507 //TUNING: loosen barrier
508 ld->defMask = ENCODE_ALL;
509 setMemRefType(ld, true /* isLoad */, kDalvikReg);
Ian Rogers2ed3b952012-03-17 11:49:39 -0700510 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
511 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800512 opRegRegImm(cUnit, kOpAdd, rARG3, rSP, 4 /* Method* */ + (3 * 4));
Ian Rogers2ed3b952012-03-17 11:49:39 -0700513 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
514 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800515 LIR* st = newLIR3(cUnit, kThumb2Vstms, rARG3, fr0, regsLeft);
516 setMemRefType(st, false /* isLoad */, kDalvikReg);
517 st->defMask = ENCODE_ALL;
Ian Rogers2ed3b952012-03-17 11:49:39 -0700518 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
519 directCode, directMethod);
520
buzbee31a4a6f2012-02-28 15:36:15 -0800521 }
522#endif
523
524 callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn,
Ian Rogers2ed3b952012-03-17 11:49:39 -0700525 dexIdx, methodIdx, directCode, directMethod,
526 skipThis);
buzbee31a4a6f2012-02-28 15:36:15 -0800527
Ian Rogers2ed3b952012-03-17 11:49:39 -0700528 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx,
529 directCode, directMethod);
buzbee31a4a6f2012-02-28 15:36:15 -0800530 if (pcrLabel) {
531 *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir);
532 }
533 return callState;
534}
535
buzbee31a4a6f2012-02-28 15:36:15 -0800536} // namespace art