blob: d19c1f9e100217a2fa79da59a88e62740f1b64cf [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,
27 uint32_t methodIdx);
28/*
29 * If there are any ins passed in registers that have not been promoted
30 * to a callee-save register, flush them to the frame. Perform intial
31 * assignment of promoted arguments.
32 */
33void flushIns(CompilationUnit* cUnit)
34{
35 if (cUnit->numIns == 0)
36 return;
37 int firstArgReg = rARG1;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -070038#if !defined(TARGET_X86)
buzbee31a4a6f2012-02-28 15:36:15 -080039 int lastArgReg = rARG3;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -070040#else
41 int lastArgReg = rARG2;
42#endif
buzbee31a4a6f2012-02-28 15:36:15 -080043 int startVReg = cUnit->numDalvikRegisters - cUnit->numIns;
44 /*
buzbee86a4bce2012-03-06 18:15:00 -080045 * Copy incoming arguments to their proper home locations.
46 * NOTE: an older version of dx had an issue in which
47 * it would reuse static method argument registers.
buzbee31a4a6f2012-02-28 15:36:15 -080048 * This could result in the same Dalvik virtual register
buzbee86a4bce2012-03-06 18:15:00 -080049 * being promoted to both core and fp regs. To account for this,
50 * we only copy to the corresponding promoted physical register
51 * if it matches the type of the SSA name for the incoming
52 * argument. It is also possible that long and double arguments
53 * end up half-promoted. In those cases, we must flush the promoted
54 * half to memory as well.
buzbee31a4a6f2012-02-28 15:36:15 -080055 */
56 for (int i = 0; i < cUnit->numIns; i++) {
buzbee86a4bce2012-03-06 18:15:00 -080057 PromotionMap* vMap = &cUnit->promotionMap[startVReg + i];
buzbee31a4a6f2012-02-28 15:36:15 -080058 if (i <= (lastArgReg - firstArgReg)) {
59 // If arriving in register
buzbee86a4bce2012-03-06 18:15:00 -080060 bool needFlush = true;
61 RegLocation* tLoc = &cUnit->regLocation[startVReg + i];
62 if ((vMap->coreLocation == kLocPhysReg) && !tLoc->fp) {
63 opRegCopy(cUnit, vMap->coreReg, firstArgReg + i);
64 needFlush = false;
65 } else if ((vMap->fpLocation == kLocPhysReg) && tLoc->fp) {
66 opRegCopy(cUnit, vMap->fpReg, firstArgReg + i);
67 needFlush = false;
68 } else {
69 needFlush = true;
buzbee31a4a6f2012-02-28 15:36:15 -080070 }
buzbee86a4bce2012-03-06 18:15:00 -080071
72 // For wide args, force flush if only half is promoted
73 if (tLoc->wide) {
74 PromotionMap* pMap = vMap + (tLoc->highWord ? -1 : +1);
75 needFlush |= (pMap->coreLocation != vMap->coreLocation) ||
76 (pMap->fpLocation != vMap->fpLocation);
buzbee31a4a6f2012-02-28 15:36:15 -080077 }
buzbee86a4bce2012-03-06 18:15:00 -080078 if (needFlush) {
79 storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
80 firstArgReg + i, kWord);
81 }
buzbee31a4a6f2012-02-28 15:36:15 -080082 } else {
83 // If arriving in frame & promoted
buzbee86a4bce2012-03-06 18:15:00 -080084 if (vMap->coreLocation == kLocPhysReg) {
buzbee31a4a6f2012-02-28 15:36:15 -080085 loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
buzbee86a4bce2012-03-06 18:15:00 -080086 vMap->coreReg);
buzbee31a4a6f2012-02-28 15:36:15 -080087 }
buzbee86a4bce2012-03-06 18:15:00 -080088 if (vMap->fpLocation == kLocPhysReg) {
buzbee31a4a6f2012-02-28 15:36:15 -080089 loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i),
buzbee86a4bce2012-03-06 18:15:00 -080090 vMap->fpReg);
buzbee31a4a6f2012-02-28 15:36:15 -080091 }
92 }
93 }
94}
95
96/*
97 * Bit of a hack here - in leiu of a real scheduling pass,
98 * emit the next instruction in static & direct invoke sequences.
99 */
100int nextSDCallInsn(CompilationUnit* cUnit, MIR* mir,
101 int state, uint32_t dexIdx, uint32_t unused)
102{
103 switch(state) {
104 case 0: // Get the current Method* [sets rARG0]
105 loadCurrMethodDirect(cUnit, rARG0);
106 break;
107 case 1: // Get method->dex_cache_resolved_methods_
108 loadWordDisp(cUnit, rARG0,
109 Method::DexCacheResolvedMethodsOffset().Int32Value(),
110 rARG0);
111 break;
112 case 2: // Grab target method*
113 loadWordDisp(cUnit, rARG0,
114 Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4,
115 rARG0);
116 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700117#if !defined(TARGET_X86)
buzbee31a4a6f2012-02-28 15:36:15 -0800118 case 3: // Grab the code from the method*
119 loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(),
buzbee0398c422012-03-02 15:22:47 -0800120 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800121 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700122#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800123 default:
124 return -1;
125 }
126 return state + 1;
127}
128
129/*
130 * Bit of a hack here - in leiu of a real scheduling pass,
131 * emit the next instruction in a virtual invoke sequence.
132 * We can use rLR as a temp prior to target address loading
133 * Note also that we'll load the first argument ("this") into
134 * rARG1 here rather than the standard loadArgRegs.
135 */
136int nextVCallInsn(CompilationUnit* cUnit, MIR* mir,
137 int state, uint32_t dexIdx, uint32_t methodIdx)
138{
139 RegLocation rlArg;
140 /*
141 * This is the fast path in which the target virtual method is
142 * fully resolved at compile time.
143 */
144 switch(state) {
145 case 0: // Get "this" [set rARG1]
146 rlArg = oatGetSrc(cUnit, mir, 0);
147 loadValueDirectFixed(cUnit, rlArg, rARG1);
148 break;
149 case 1: // Is "this" null? [use rARG1]
150 genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir);
buzbee0398c422012-03-02 15:22:47 -0800151 // get this->klass_ [use rARG1, set rINVOKE_TGT]
buzbee31a4a6f2012-02-28 15:36:15 -0800152 loadWordDisp(cUnit, rARG1, Object::ClassOffset().Int32Value(),
buzbee0398c422012-03-02 15:22:47 -0800153 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800154 break;
buzbee0398c422012-03-02 15:22:47 -0800155 case 2: // Get this->klass_->vtable [usr rINVOKE_TGT, set rINVOKE_TGT]
156 loadWordDisp(cUnit, rINVOKE_TGT, Class::VTableOffset().Int32Value(),
157 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800158 break;
buzbee0398c422012-03-02 15:22:47 -0800159 case 3: // Get target method [use rINVOKE_TGT, set rARG0]
160 loadWordDisp(cUnit, rINVOKE_TGT, (methodIdx * 4) +
buzbee31a4a6f2012-02-28 15:36:15 -0800161 Array::DataOffset(sizeof(Object*)).Int32Value(),
162 rARG0);
163 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700164#if !defined(TARGET_X86)
buzbee0398c422012-03-02 15:22:47 -0800165 case 4: // Get the compiled code address [uses rARG0, sets rINVOKE_TGT]
buzbee31a4a6f2012-02-28 15:36:15 -0800166 loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(),
buzbee0398c422012-03-02 15:22:47 -0800167 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800168 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700169#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800170 default:
171 return -1;
172 }
173 return state + 1;
174}
175
176/*
177 * Interleave launch code for INVOKE_SUPER. See comments
178 * for nextVCallIns.
179 */
180int nextSuperCallInsn(CompilationUnit* cUnit, MIR* mir,
181 int state, uint32_t dexIdx, uint32_t methodIdx)
182{
183 /*
184 * This is the fast path in which the target virtual method is
185 * fully resolved at compile time. Note also that this path assumes
186 * that the check to verify that the target method index falls
187 * within the size of the super's vtable has been done at compile-time.
188 */
189 RegLocation rlArg;
190 switch(state) {
191 case 0: // Get current Method* [set rARG0]
192 loadCurrMethodDirect(cUnit, rARG0);
193 // Load "this" [set rARG1]
194 rlArg = oatGetSrc(cUnit, mir, 0);
195 loadValueDirectFixed(cUnit, rlArg, rARG1);
buzbee0398c422012-03-02 15:22:47 -0800196 // Get method->declaring_class_ [use rARG0, set rINVOKE_TGT]
buzbee31a4a6f2012-02-28 15:36:15 -0800197 loadWordDisp(cUnit, rARG0,
198 Method::DeclaringClassOffset().Int32Value(),
buzbee0398c422012-03-02 15:22:47 -0800199 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800200 // Is "this" null? [use rARG1]
201 genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir);
202 break;
buzbee0398c422012-03-02 15:22:47 -0800203 case 1: // method->declaring_class_->super_class [use/set rINVOKE_TGT]
204 loadWordDisp(cUnit, rINVOKE_TGT,
205 Class::SuperClassOffset().Int32Value(), rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800206 break;
buzbee0398c422012-03-02 15:22:47 -0800207 case 2: // Get ...->super_class_->vtable [u/s rINVOKE_TGT]
208 loadWordDisp(cUnit, rINVOKE_TGT,
209 Class::VTableOffset().Int32Value(), rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800210 break;
buzbee0398c422012-03-02 15:22:47 -0800211 case 3: // Get target method [use rINVOKE_TGT, set rARG0]
212 loadWordDisp(cUnit, rINVOKE_TGT, (methodIdx * 4) +
buzbee31a4a6f2012-02-28 15:36:15 -0800213 Array::DataOffset(sizeof(Object*)).Int32Value(),
214 rARG0);
215 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700216#if !defined(TARGET_X86)
buzbee0398c422012-03-02 15:22:47 -0800217 case 4: // target compiled code address [uses rARG0, sets rINVOKE_TGT]
buzbee31a4a6f2012-02-28 15:36:15 -0800218 loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(),
buzbee0398c422012-03-02 15:22:47 -0800219 rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800220 break;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700221#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800222 default:
223 return -1;
224 }
225 return state + 1;
226}
227
228int nextInvokeInsnSP(CompilationUnit* cUnit, MIR* mir, int trampoline,
229 int state, uint32_t dexIdx, uint32_t methodIdx)
230{
231 /*
232 * This handles the case in which the base method is not fully
233 * resolved at compile time, we bail to a runtime helper.
234 */
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700235#if !defined(TARGET_X86)
buzbee31a4a6f2012-02-28 15:36:15 -0800236 if (state == 0) {
237 // Load trampoline target
buzbee0398c422012-03-02 15:22:47 -0800238 loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT);
buzbee31a4a6f2012-02-28 15:36:15 -0800239 // Load rARG0 with method index
240 loadConstant(cUnit, rARG0, dexIdx);
241 return 1;
242 }
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700243#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800244 return -1;
245}
246
247int nextStaticCallInsnSP(CompilationUnit* cUnit, MIR* mir,
248 int state, uint32_t dexIdx, uint32_t methodIdx)
249{
250 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeStaticTrampolineWithAccessCheck);
251 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
252}
253
254int nextDirectCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state,
255 uint32_t dexIdx, uint32_t methodIdx)
256{
257 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeDirectTrampolineWithAccessCheck);
258 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
259}
260
261int nextSuperCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state,
262 uint32_t dexIdx, uint32_t methodIdx)
263{
264 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeSuperTrampolineWithAccessCheck);
265 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
266}
267
268int nextVCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state,
269 uint32_t dexIdx, uint32_t methodIdx)
270{
271 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeVirtualTrampolineWithAccessCheck);
272 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
273}
274
275/*
276 * All invoke-interface calls bounce off of art_invoke_interface_trampoline,
277 * which will locate the target and continue on via a tail call.
278 */
279int nextInterfaceCallInsn(CompilationUnit* cUnit, MIR* mir, int state,
280 uint32_t dexIdx, uint32_t unused)
281{
282 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampoline);
283 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
284}
285
286int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit, MIR* mir,
287 int state, uint32_t dexIdx,
288 uint32_t unused)
289{
290 int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampolineWithAccessCheck);
291 return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0);
292}
293
294int loadArgRegs(CompilationUnit* cUnit, MIR* mir, DecodedInstruction* dInsn,
295 int callState, NextCallInsn nextCallInsn, uint32_t dexIdx,
296 uint32_t methodIdx, bool skipThis)
297{
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700298#if !defined(TARGET_X86)
299 int lastArgReg = rARG3;
300#else
301 int lastArgReg = rARG2;
302#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800303 int nextReg = rARG1;
304 int nextArg = 0;
305 if (skipThis) {
306 nextReg++;
307 nextArg++;
308 }
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700309 for (; (nextReg <= lastArgReg) && (nextArg < mir->ssaRep->numUses); nextReg++) {
buzbee31a4a6f2012-02-28 15:36:15 -0800310 RegLocation rlArg = oatGetRawSrc(cUnit, mir, nextArg++);
311 rlArg = oatUpdateRawLoc(cUnit, rlArg);
312 if (rlArg.wide && (nextReg <= rARG2)) {
313 loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1);
314 nextReg++;
315 nextArg++;
316 } else {
317 rlArg.wide = false;
318 loadValueDirectFixed(cUnit, rlArg, nextReg);
319 }
320 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
321 }
322 return callState;
323}
324
325/*
326 * Load up to 5 arguments, the first three of which will be in
327 * rARG1 .. rARG3. On entry rARG0 contains the current method pointer,
328 * and as part of the load sequence, it must be replaced with
329 * the target method pointer. Note, this may also be called
330 * for "range" variants if the number of arguments is 5 or fewer.
331 */
332int genDalvikArgsNoRange(CompilationUnit* cUnit, MIR* mir,
333 DecodedInstruction* dInsn, int callState,
334 LIR** pcrLabel, NextCallInsn nextCallInsn,
335 uint32_t dexIdx, uint32_t methodIdx, bool skipThis)
336{
337 RegLocation rlArg;
338
339 /* If no arguments, just return */
340 if (dInsn->vA == 0)
341 return callState;
342
343 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
344
345 DCHECK_LE(dInsn->vA, 5U);
346 if (dInsn->vA > 3) {
347 uint32_t nextUse = 3;
348 //Detect special case of wide arg spanning arg3/arg4
349 RegLocation rlUse0 = oatGetRawSrc(cUnit, mir, 0);
350 RegLocation rlUse1 = oatGetRawSrc(cUnit, mir, 1);
351 RegLocation rlUse2 = oatGetRawSrc(cUnit, mir, 2);
352 if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) &&
353 rlUse2.wide) {
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700354 int reg = -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800355 // Wide spans, we need the 2nd half of uses[2].
356 rlArg = oatUpdateLocWide(cUnit, rlUse2);
357 if (rlArg.location == kLocPhysReg) {
358 reg = rlArg.highReg;
359 } else {
360 // rARG2 & rARG3 can safely be used here
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700361#if defined(TARGET_X86)
362 UNIMPLEMENTED(FATAL);
363#else
buzbee31a4a6f2012-02-28 15:36:15 -0800364 reg = rARG3;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700365#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800366 loadWordDisp(cUnit, rSP,
367 oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg);
368 callState = nextCallInsn(cUnit, mir, callState, dexIdx,
369 methodIdx);
370 }
371 storeBaseDisp(cUnit, rSP, (nextUse + 1) * 4, reg, kWord);
372 storeBaseDisp(cUnit, rSP, 16 /* (3+1)*4 */, reg, kWord);
373 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
374 nextUse++;
375 }
376 // Loop through the rest
377 while (nextUse < dInsn->vA) {
378 int lowReg;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700379 int highReg = -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800380 rlArg = oatGetRawSrc(cUnit, mir, nextUse);
381 rlArg = oatUpdateRawLoc(cUnit, rlArg);
382 if (rlArg.location == kLocPhysReg) {
383 lowReg = rlArg.lowReg;
384 highReg = rlArg.highReg;
385 } else {
386 lowReg = rARG2;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700387#if defined(TARGET_X86)
388 UNIMPLEMENTED(FATAL);
389#else
buzbee31a4a6f2012-02-28 15:36:15 -0800390 highReg = rARG3;
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700391#endif
buzbee31a4a6f2012-02-28 15:36:15 -0800392 if (rlArg.wide) {
393 loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg);
394 } else {
395 loadValueDirectFixed(cUnit, rlArg, lowReg);
396 }
397 callState = nextCallInsn(cUnit, mir, callState, dexIdx,
398 methodIdx);
399 }
400 int outsOffset = (nextUse + 1) * 4;
401 if (rlArg.wide) {
402 storeBaseDispWide(cUnit, rSP, outsOffset, lowReg, highReg);
403 nextUse += 2;
404 } else {
405 storeWordDisp(cUnit, rSP, outsOffset, lowReg);
406 nextUse++;
407 }
408 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
409 }
410 }
411
412 callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn,
413 dexIdx, methodIdx, skipThis);
414
415 if (pcrLabel) {
416 *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir);
417 }
418 return callState;
419}
420
421/*
422 * May have 0+ arguments (also used for jumbo). Note that
423 * source virtual registers may be in physical registers, so may
424 * need to be flushed to home location before copying. This
425 * applies to arg3 and above (see below).
426 *
427 * Two general strategies:
428 * If < 20 arguments
429 * Pass args 3-18 using vldm/vstm block copy
430 * Pass arg0, arg1 & arg2 in rARG1-rARG3
431 * If 20+ arguments
432 * Pass args arg19+ using memcpy block copy
433 * Pass arg0, arg1 & arg2 in rARG1-rARG3
434 *
435 */
436int genDalvikArgsRange(CompilationUnit* cUnit, MIR* mir,
437 DecodedInstruction* dInsn, int callState,
438 LIR** pcrLabel, NextCallInsn nextCallInsn,
439 uint32_t dexIdx, uint32_t methodIdx, bool skipThis)
440{
441 int firstArg = dInsn->vC;
442 int numArgs = dInsn->vA;
443
444 // If we can treat it as non-range (Jumbo ops will use range form)
445 if (numArgs <= 5)
446 return genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pcrLabel,
447 nextCallInsn, dexIdx, methodIdx,
448 skipThis);
449 /*
450 * Make sure range list doesn't span the break between in normal
451 * Dalvik vRegs and the ins.
452 */
453 int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow;
454 int boundaryReg = cUnit->numDalvikRegisters - cUnit->numIns;
455 if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) {
456 LOG(FATAL) << "Argument list spanned locals & args";
457 }
458
459 /*
460 * First load the non-register arguments. Both forms expect all
461 * of the source arguments to be in their home frame location, so
462 * scan the sReg names and flush any that have been promoted to
463 * frame backing storage.
464 */
465 // Scan the rest of the args - if in physReg flush to memory
466 for (int nextArg = 0; nextArg < numArgs;) {
467 RegLocation loc = oatGetRawSrc(cUnit, mir, nextArg);
468 if (loc.wide) {
469 loc = oatUpdateLocWide(cUnit, loc);
470 if ((nextArg >= 2) && (loc.location == kLocPhysReg)) {
471 storeBaseDispWide(cUnit, rSP,
472 oatSRegOffset(cUnit, loc.sRegLow),
473 loc.lowReg, loc.highReg);
474 }
475 nextArg += 2;
476 } else {
477 loc = oatUpdateLoc(cUnit, loc);
478 if ((nextArg >= 3) && (loc.location == kLocPhysReg)) {
479 storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow),
480 loc.lowReg, kWord);
481 }
482 nextArg++;
483 }
484 }
485
486 int startOffset = oatSRegOffset(cUnit,
487 cUnit->regLocation[mir->ssaRep->uses[3]].sRegLow);
488 int outsOffset = 4 /* Method* */ + (3 * 4);
489#if defined(TARGET_MIPS)
490 // Generate memcpy
491 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
492 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
493 int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy));
494 loadConstant(cUnit, rARG2, (numArgs - 3) * 4);
495 callRuntimeHelper(cUnit, rTgt);
496 // Restore Method*
497 loadCurrMethodDirect(cUnit, rARG0);
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700498#elif defined(TARGET_X86)
499 // Generate memcpy
500 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
501 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
502 loadConstant(cUnit, rARG2, (numArgs - 3) * 4);
503 callRuntimeHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy));
504 // Restore Method*
505 loadCurrMethodDirect(cUnit, rARG0);
buzbee31a4a6f2012-02-28 15:36:15 -0800506#else
507 if (numArgs >= 20) {
508 // Generate memcpy
509 opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset);
510 opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset);
511 int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy));
512 loadConstant(cUnit, rARG2, (numArgs - 3) * 4);
513 callRuntimeHelper(cUnit, rTgt);
514 // Restore Method*
515 loadCurrMethodDirect(cUnit, rARG0);
516 } else {
517 // Use vldm/vstm pair using rARG3 as a temp
518 int regsLeft = std::min(numArgs - 3, 16);
519 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
520 opRegRegImm(cUnit, kOpAdd, rARG3, rSP, startOffset);
521 LIR* ld = newLIR3(cUnit, kThumb2Vldms, rARG3, fr0, regsLeft);
522 //TUNING: loosen barrier
523 ld->defMask = ENCODE_ALL;
524 setMemRefType(ld, true /* isLoad */, kDalvikReg);
525 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
526 opRegRegImm(cUnit, kOpAdd, rARG3, rSP, 4 /* Method* */ + (3 * 4));
527 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
528 LIR* st = newLIR3(cUnit, kThumb2Vstms, rARG3, fr0, regsLeft);
529 setMemRefType(st, false /* isLoad */, kDalvikReg);
530 st->defMask = ENCODE_ALL;
531 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
532 }
533#endif
534
535 callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn,
536 dexIdx, methodIdx, skipThis);
537
538 callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx);
539 if (pcrLabel) {
540 *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir);
541 }
542 return callState;
543}
544
buzbee31a4a6f2012-02-28 15:36:15 -0800545} // namespace art