blob: 5d2886ea10006d6ec019fb17f6bdf5655695068e [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
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
17#include "dex/compiler_ir.h"
Vladimir Marko5c96e6b2013-11-14 15:34:17 +000018#include "dex/frontend.h"
19#include "dex/quick/dex_file_method_inliner.h"
20#include "dex/quick/dex_file_to_method_inliner_map.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include "dex_file-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070022#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023#include "invoke_type.h"
24#include "mirror/array.h"
25#include "mirror/string.h"
26#include "mir_to_lir-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070027#include "x86/codegen_x86.h"
28
29namespace art {
30
31/*
32 * This source files contains "gen" codegen routines that should
33 * be applicable to most targets. Only mid-level support utilities
34 * and "op" calls may be used here.
35 */
36
Vladimir Marko3bc86152014-03-13 14:11:28 +000037void Mir2Lir::AddIntrinsicLaunchpad(CallInfo* info, LIR* branch, LIR* resume) {
38 class IntrinsicLaunchpadPath : public Mir2Lir::LIRSlowPath {
39 public:
40 IntrinsicLaunchpadPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr)
41 : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) {
42 }
43
44 void Compile() {
45 m2l_->ResetRegPool();
46 m2l_->ResetDefTracking();
47 LIR* label = GenerateTargetLabel();
48 label->opcode = kPseudoIntrinsicRetry;
49 // NOTE: GenInvokeNoInline() handles MarkSafepointPC.
50 m2l_->GenInvokeNoInline(info_);
51 if (cont_ != nullptr) {
52 m2l_->OpUnconditionalBranch(cont_);
53 }
54 }
55
56 private:
57 CallInfo* const info_;
58 };
59
60 AddSlowPath(new (arena_) IntrinsicLaunchpadPath(this, info, branch, resume));
61}
62
Brian Carlstrom7940e442013-07-12 13:46:57 -070063/*
64 * To save scheduling time, helper calls are broken into two parts: generation of
65 * the helper target address, and the actuall call to the helper. Because x86
66 * has a memory call operation, part 1 is a NOP for x86. For other targets,
67 * load arguments between the two parts.
68 */
Ian Rogers848871b2013-08-05 10:56:33 -070069int Mir2Lir::CallHelperSetup(ThreadOffset helper_offset) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070070 return (cu_->instruction_set == kX86) ? 0 : LoadHelper(helper_offset);
71}
72
73/* NOTE: if r_tgt is a temp, it will be freed following use */
Ian Rogers848871b2013-08-05 10:56:33 -070074LIR* Mir2Lir::CallHelper(int r_tgt, ThreadOffset helper_offset, bool safepoint_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070075 LIR* call_inst;
76 if (cu_->instruction_set == kX86) {
77 call_inst = OpThreadMem(kOpBlx, helper_offset);
78 } else {
79 call_inst = OpReg(kOpBlx, r_tgt);
80 FreeTemp(r_tgt);
81 }
82 if (safepoint_pc) {
83 MarkSafepointPC(call_inst);
84 }
85 return call_inst;
86}
87
Ian Rogers848871b2013-08-05 10:56:33 -070088void Mir2Lir::CallRuntimeHelperImm(ThreadOffset helper_offset, int arg0, bool safepoint_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070089 int r_tgt = CallHelperSetup(helper_offset);
90 LoadConstant(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +000091 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -070092 CallHelper(r_tgt, helper_offset, safepoint_pc);
93}
94
Ian Rogers848871b2013-08-05 10:56:33 -070095void Mir2Lir::CallRuntimeHelperReg(ThreadOffset helper_offset, int arg0, bool safepoint_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070096 int r_tgt = CallHelperSetup(helper_offset);
97 OpRegCopy(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +000098 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -070099 CallHelper(r_tgt, helper_offset, safepoint_pc);
100}
101
Ian Rogers848871b2013-08-05 10:56:33 -0700102void Mir2Lir::CallRuntimeHelperRegLocation(ThreadOffset helper_offset, RegLocation arg0,
103 bool safepoint_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104 int r_tgt = CallHelperSetup(helper_offset);
105 if (arg0.wide == 0) {
106 LoadValueDirectFixed(arg0, TargetReg(kArg0));
107 } else {
108 LoadValueDirectWideFixed(arg0, TargetReg(kArg0), TargetReg(kArg1));
109 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000110 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700111 CallHelper(r_tgt, helper_offset, safepoint_pc);
112}
113
Ian Rogers848871b2013-08-05 10:56:33 -0700114void Mir2Lir::CallRuntimeHelperImmImm(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700115 bool safepoint_pc) {
116 int r_tgt = CallHelperSetup(helper_offset);
117 LoadConstant(TargetReg(kArg0), arg0);
118 LoadConstant(TargetReg(kArg1), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000119 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700120 CallHelper(r_tgt, helper_offset, safepoint_pc);
121}
122
Ian Rogers848871b2013-08-05 10:56:33 -0700123void Mir2Lir::CallRuntimeHelperImmRegLocation(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124 RegLocation arg1, bool safepoint_pc) {
125 int r_tgt = CallHelperSetup(helper_offset);
126 if (arg1.wide == 0) {
127 LoadValueDirectFixed(arg1, TargetReg(kArg1));
128 } else {
129 LoadValueDirectWideFixed(arg1, TargetReg(kArg1), TargetReg(kArg2));
130 }
131 LoadConstant(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000132 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700133 CallHelper(r_tgt, helper_offset, safepoint_pc);
134}
135
Ian Rogers848871b2013-08-05 10:56:33 -0700136void Mir2Lir::CallRuntimeHelperRegLocationImm(ThreadOffset helper_offset, RegLocation arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700137 bool safepoint_pc) {
138 int r_tgt = CallHelperSetup(helper_offset);
139 LoadValueDirectFixed(arg0, TargetReg(kArg0));
140 LoadConstant(TargetReg(kArg1), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000141 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700142 CallHelper(r_tgt, helper_offset, safepoint_pc);
143}
144
Ian Rogers848871b2013-08-05 10:56:33 -0700145void Mir2Lir::CallRuntimeHelperImmReg(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700146 bool safepoint_pc) {
147 int r_tgt = CallHelperSetup(helper_offset);
148 OpRegCopy(TargetReg(kArg1), arg1);
149 LoadConstant(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000150 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700151 CallHelper(r_tgt, helper_offset, safepoint_pc);
152}
153
Ian Rogers848871b2013-08-05 10:56:33 -0700154void Mir2Lir::CallRuntimeHelperRegImm(ThreadOffset helper_offset, int arg0, int arg1,
155 bool safepoint_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700156 int r_tgt = CallHelperSetup(helper_offset);
157 OpRegCopy(TargetReg(kArg0), arg0);
158 LoadConstant(TargetReg(kArg1), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000159 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700160 CallHelper(r_tgt, helper_offset, safepoint_pc);
161}
162
Ian Rogers848871b2013-08-05 10:56:33 -0700163void Mir2Lir::CallRuntimeHelperImmMethod(ThreadOffset helper_offset, int arg0, bool safepoint_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700164 int r_tgt = CallHelperSetup(helper_offset);
165 LoadCurrMethodDirect(TargetReg(kArg1));
166 LoadConstant(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000167 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700168 CallHelper(r_tgt, helper_offset, safepoint_pc);
169}
170
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800171void Mir2Lir::CallRuntimeHelperRegMethod(ThreadOffset helper_offset, int arg0, bool safepoint_pc) {
172 int r_tgt = CallHelperSetup(helper_offset);
173 DCHECK_NE(TargetReg(kArg1), arg0);
174 if (TargetReg(kArg0) != arg0) {
175 OpRegCopy(TargetReg(kArg0), arg0);
176 }
177 LoadCurrMethodDirect(TargetReg(kArg1));
178 ClobberCallerSave();
179 CallHelper(r_tgt, helper_offset, safepoint_pc);
180}
181
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800182void Mir2Lir::CallRuntimeHelperRegMethodRegLocation(ThreadOffset helper_offset, int arg0,
183 RegLocation arg2, bool safepoint_pc) {
184 int r_tgt = CallHelperSetup(helper_offset);
185 DCHECK_NE(TargetReg(kArg1), arg0);
186 if (TargetReg(kArg0) != arg0) {
187 OpRegCopy(TargetReg(kArg0), arg0);
188 }
189 LoadCurrMethodDirect(TargetReg(kArg1));
190 LoadValueDirectFixed(arg2, TargetReg(kArg2));
191 ClobberCallerSave();
192 CallHelper(r_tgt, helper_offset, safepoint_pc);
193}
194
Ian Rogers848871b2013-08-05 10:56:33 -0700195void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(ThreadOffset helper_offset, RegLocation arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700196 RegLocation arg1, bool safepoint_pc) {
197 int r_tgt = CallHelperSetup(helper_offset);
198 if (arg0.wide == 0) {
199 LoadValueDirectFixed(arg0, arg0.fp ? TargetReg(kFArg0) : TargetReg(kArg0));
200 if (arg1.wide == 0) {
201 if (cu_->instruction_set == kMips) {
202 LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg1));
203 } else {
204 LoadValueDirectFixed(arg1, TargetReg(kArg1));
205 }
206 } else {
207 if (cu_->instruction_set == kMips) {
208 LoadValueDirectWideFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg1), arg1.fp ? TargetReg(kFArg3) : TargetReg(kArg2));
209 } else {
210 LoadValueDirectWideFixed(arg1, TargetReg(kArg1), TargetReg(kArg2));
211 }
212 }
213 } else {
214 LoadValueDirectWideFixed(arg0, arg0.fp ? TargetReg(kFArg0) : TargetReg(kArg0), arg0.fp ? TargetReg(kFArg1) : TargetReg(kArg1));
215 if (arg1.wide == 0) {
216 LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg2));
217 } else {
218 LoadValueDirectWideFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg2), arg1.fp ? TargetReg(kFArg3) : TargetReg(kArg3));
219 }
220 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000221 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700222 CallHelper(r_tgt, helper_offset, safepoint_pc);
223}
224
Ian Rogers848871b2013-08-05 10:56:33 -0700225void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset helper_offset, int arg0, int arg1,
226 bool safepoint_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700227 int r_tgt = CallHelperSetup(helper_offset);
228 DCHECK_NE(TargetReg(kArg0), arg1); // check copy into arg0 won't clobber arg1
229 OpRegCopy(TargetReg(kArg0), arg0);
230 OpRegCopy(TargetReg(kArg1), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000231 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700232 CallHelper(r_tgt, helper_offset, safepoint_pc);
233}
234
Ian Rogers848871b2013-08-05 10:56:33 -0700235void Mir2Lir::CallRuntimeHelperRegRegImm(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700236 int arg2, bool safepoint_pc) {
237 int r_tgt = CallHelperSetup(helper_offset);
238 DCHECK_NE(TargetReg(kArg0), arg1); // check copy into arg0 won't clobber arg1
239 OpRegCopy(TargetReg(kArg0), arg0);
240 OpRegCopy(TargetReg(kArg1), arg1);
241 LoadConstant(TargetReg(kArg2), arg2);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000242 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700243 CallHelper(r_tgt, helper_offset, safepoint_pc);
244}
245
Ian Rogers848871b2013-08-05 10:56:33 -0700246void Mir2Lir::CallRuntimeHelperImmMethodRegLocation(ThreadOffset helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700247 int arg0, RegLocation arg2, bool safepoint_pc) {
248 int r_tgt = CallHelperSetup(helper_offset);
249 LoadValueDirectFixed(arg2, TargetReg(kArg2));
250 LoadCurrMethodDirect(TargetReg(kArg1));
251 LoadConstant(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000252 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700253 CallHelper(r_tgt, helper_offset, safepoint_pc);
254}
255
Ian Rogers848871b2013-08-05 10:56:33 -0700256void Mir2Lir::CallRuntimeHelperImmMethodImm(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700257 int arg2, bool safepoint_pc) {
258 int r_tgt = CallHelperSetup(helper_offset);
259 LoadCurrMethodDirect(TargetReg(kArg1));
260 LoadConstant(TargetReg(kArg2), arg2);
261 LoadConstant(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000262 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700263 CallHelper(r_tgt, helper_offset, safepoint_pc);
264}
265
Ian Rogers848871b2013-08-05 10:56:33 -0700266void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700267 int arg0, RegLocation arg1,
268 RegLocation arg2, bool safepoint_pc) {
269 int r_tgt = CallHelperSetup(helper_offset);
Ian Rogersa9a82542013-10-04 11:17:26 -0700270 DCHECK_EQ(arg1.wide, 0U);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700271 LoadValueDirectFixed(arg1, TargetReg(kArg1));
272 if (arg2.wide == 0) {
273 LoadValueDirectFixed(arg2, TargetReg(kArg2));
274 } else {
275 LoadValueDirectWideFixed(arg2, TargetReg(kArg2), TargetReg(kArg3));
276 }
277 LoadConstant(TargetReg(kArg0), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000278 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700279 CallHelper(r_tgt, helper_offset, safepoint_pc);
280}
281
Ian Rogersa9a82542013-10-04 11:17:26 -0700282void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(ThreadOffset helper_offset,
283 RegLocation arg0, RegLocation arg1,
284 RegLocation arg2,
285 bool safepoint_pc) {
286 int r_tgt = CallHelperSetup(helper_offset);
287 DCHECK_EQ(arg0.wide, 0U);
288 LoadValueDirectFixed(arg0, TargetReg(kArg0));
289 DCHECK_EQ(arg1.wide, 0U);
290 LoadValueDirectFixed(arg1, TargetReg(kArg1));
291 DCHECK_EQ(arg1.wide, 0U);
292 LoadValueDirectFixed(arg2, TargetReg(kArg2));
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000293 ClobberCallerSave();
Ian Rogersa9a82542013-10-04 11:17:26 -0700294 CallHelper(r_tgt, helper_offset, safepoint_pc);
295}
296
Brian Carlstrom7940e442013-07-12 13:46:57 -0700297/*
298 * If there are any ins passed in registers that have not been promoted
299 * to a callee-save register, flush them to the frame. Perform intial
300 * assignment of promoted arguments.
301 *
302 * ArgLocs is an array of location records describing the incoming arguments
303 * with one location record per word of argument.
304 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700305void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700306 /*
307 * Dummy up a RegLocation for the incoming Method*
308 * It will attempt to keep kArg0 live (or copy it to home location
309 * if promoted).
310 */
311 RegLocation rl_src = rl_method;
312 rl_src.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000313 rl_src.reg = RegStorage(RegStorage::k32BitSolo, TargetReg(kArg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 rl_src.home = false;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000315 MarkLive(rl_src.reg.GetReg(), rl_src.s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700316 StoreValue(rl_method, rl_src);
317 // If Method* has been promoted, explicitly flush
318 if (rl_method.location == kLocPhysReg) {
319 StoreWordDisp(TargetReg(kSp), 0, TargetReg(kArg0));
320 }
321
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800322 if (cu_->num_ins == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700323 return;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800324 }
325
Brian Carlstrom7940e442013-07-12 13:46:57 -0700326 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
327 /*
328 * Copy incoming arguments to their proper home locations.
329 * NOTE: an older version of dx had an issue in which
330 * it would reuse static method argument registers.
331 * This could result in the same Dalvik virtual register
332 * being promoted to both core and fp regs. To account for this,
333 * we only copy to the corresponding promoted physical register
334 * if it matches the type of the SSA name for the incoming
335 * argument. It is also possible that long and double arguments
336 * end up half-promoted. In those cases, we must flush the promoted
337 * half to memory as well.
338 */
339 for (int i = 0; i < cu_->num_ins; i++) {
340 PromotionMap* v_map = &promotion_map_[start_vreg + i];
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800341 int reg = GetArgMappingToPhysicalReg(i);
342
343 if (reg != INVALID_REG) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700344 // If arriving in register
345 bool need_flush = true;
346 RegLocation* t_loc = &ArgLocs[i];
347 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800348 OpRegCopy(v_map->core_reg, reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700349 need_flush = false;
350 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800351 OpRegCopy(v_map->FpReg, reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700352 need_flush = false;
353 } else {
354 need_flush = true;
355 }
356
buzbeed0a03b82013-09-14 08:21:05 -0700357 // For wide args, force flush if not fully promoted
Brian Carlstrom7940e442013-07-12 13:46:57 -0700358 if (t_loc->wide) {
359 PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1);
buzbeed0a03b82013-09-14 08:21:05 -0700360 // Is only half promoted?
Brian Carlstrom7940e442013-07-12 13:46:57 -0700361 need_flush |= (p_map->core_location != v_map->core_location) ||
362 (p_map->fp_location != v_map->fp_location);
buzbeed0a03b82013-09-14 08:21:05 -0700363 if ((cu_->instruction_set == kThumb2) && t_loc->fp && !need_flush) {
364 /*
365 * In Arm, a double is represented as a pair of consecutive single float
366 * registers starting at an even number. It's possible that both Dalvik vRegs
367 * representing the incoming double were independently promoted as singles - but
368 * not in a form usable as a double. If so, we need to flush - even though the
369 * incoming arg appears fully in register. At this point in the code, both
370 * halves of the double are promoted. Make sure they are in a usable form.
371 */
372 int lowreg_index = start_vreg + i + (t_loc->high_word ? -1 : 0);
373 int low_reg = promotion_map_[lowreg_index].FpReg;
374 int high_reg = promotion_map_[lowreg_index + 1].FpReg;
375 if (((low_reg & 0x1) != 0) || (high_reg != (low_reg + 1))) {
376 need_flush = true;
377 }
378 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700379 }
380 if (need_flush) {
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800381 StoreBaseDisp(TargetReg(kSp), SRegOffset(start_vreg + i), reg, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700382 }
383 } else {
384 // If arriving in frame & promoted
385 if (v_map->core_location == kLocPhysReg) {
386 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i),
387 v_map->core_reg);
388 }
389 if (v_map->fp_location == kLocPhysReg) {
390 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i),
391 v_map->FpReg);
392 }
393 }
394 }
395}
396
397/*
398 * Bit of a hack here - in the absence of a real scheduling pass,
399 * emit the next instruction in static & direct invoke sequences.
400 */
401static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
402 int state, const MethodReference& target_method,
403 uint32_t unused,
404 uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700405 InvokeType type) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700406 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700407 if (direct_code != 0 && direct_method != 0) {
408 switch (state) {
409 case 0: // Get the current Method* [sets kArg0]
410 if (direct_code != static_cast<unsigned int>(-1)) {
Ian Rogers83883d72013-10-21 21:07:24 -0700411 if (cu->instruction_set != kX86) {
412 cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code);
413 }
Mark Mendell55d0eac2014-02-06 11:02:52 -0800414 } else if (cu->instruction_set != kX86) {
Jeff Hao49161ce2014-03-12 11:05:25 -0700415 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700416 }
417 if (direct_method != static_cast<unsigned int>(-1)) {
418 cg->LoadConstant(cg->TargetReg(kArg0), direct_method);
419 } else {
Jeff Hao49161ce2014-03-12 11:05:25 -0700420 cg->LoadMethodAddress(target_method, type, kArg0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700421 }
422 break;
423 default:
424 return -1;
425 }
426 } else {
427 switch (state) {
428 case 0: // Get the current Method* [sets kArg0]
429 // TUNING: we can save a reg copy if Method* has been promoted.
430 cg->LoadCurrMethodDirect(cg->TargetReg(kArg0));
431 break;
432 case 1: // Get method->dex_cache_resolved_methods_
433 cg->LoadWordDisp(cg->TargetReg(kArg0),
Brian Carlstromea46f952013-07-30 01:26:50 -0700434 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(), cg->TargetReg(kArg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700435 // Set up direct code if known.
436 if (direct_code != 0) {
437 if (direct_code != static_cast<unsigned int>(-1)) {
438 cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code);
Mark Mendell55d0eac2014-02-06 11:02:52 -0800439 } else if (cu->instruction_set != kX86) {
Ian Rogers83883d72013-10-21 21:07:24 -0700440 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Jeff Hao49161ce2014-03-12 11:05:25 -0700441 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700442 }
443 }
444 break;
445 case 2: // Grab target method*
446 CHECK_EQ(cu->dex_file, target_method.dex_file);
447 cg->LoadWordDisp(cg->TargetReg(kArg0),
448 mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() +
449 (target_method.dex_method_index * 4),
450 cg-> TargetReg(kArg0));
451 break;
452 case 3: // Grab the code from the method*
453 if (cu->instruction_set != kX86) {
454 if (direct_code == 0) {
455 cg->LoadWordDisp(cg->TargetReg(kArg0),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800456 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700457 cg->TargetReg(kInvokeTgt));
458 }
459 break;
460 }
461 // Intentional fallthrough for x86
462 default:
463 return -1;
464 }
465 }
466 return state + 1;
467}
468
469/*
470 * Bit of a hack here - in the absence of a real scheduling pass,
471 * emit the next instruction in a virtual invoke sequence.
472 * We can use kLr as a temp prior to target address loading
473 * Note also that we'll load the first argument ("this") into
474 * kArg1 here rather than the standard LoadArgRegs.
475 */
476static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
477 int state, const MethodReference& target_method,
478 uint32_t method_idx, uintptr_t unused, uintptr_t unused2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700479 InvokeType unused3) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700480 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
481 /*
482 * This is the fast path in which the target virtual method is
483 * fully resolved at compile time.
484 */
485 switch (state) {
486 case 0: { // Get "this" [set kArg1]
487 RegLocation rl_arg = info->args[0];
488 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1));
489 break;
490 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700491 case 1: // Is "this" null? [use kArg1]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700492 cg->GenNullCheck(info->args[0].s_reg_low, cg->TargetReg(kArg1), info->opt_flags);
493 // get this->klass_ [use kArg1, set kInvokeTgt]
494 cg->LoadWordDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(),
495 cg->TargetReg(kInvokeTgt));
496 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700497 case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700498 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), mirror::Class::VTableOffset().Int32Value(),
499 cg->TargetReg(kInvokeTgt));
500 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700501 case 3: // Get target method [use kInvokeTgt, set kArg0]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700502 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), (method_idx * 4) +
503 mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(),
504 cg->TargetReg(kArg0));
505 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700506 case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700507 if (cu->instruction_set != kX86) {
508 cg->LoadWordDisp(cg->TargetReg(kArg0),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800509 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700510 cg->TargetReg(kInvokeTgt));
511 break;
512 }
513 // Intentional fallthrough for X86
514 default:
515 return -1;
516 }
517 return state + 1;
518}
519
520/*
Jeff Hao88474b42013-10-23 16:24:40 -0700521 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
522 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
523 * more than one interface method map to the same index. Note also that we'll load the first
524 * argument ("this") into kArg1 here rather than the standard LoadArgRegs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700525 */
526static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
527 const MethodReference& target_method,
Jeff Hao88474b42013-10-23 16:24:40 -0700528 uint32_t method_idx, uintptr_t unused,
529 uintptr_t direct_method, InvokeType unused2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700530 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700531
Jeff Hao88474b42013-10-23 16:24:40 -0700532 switch (state) {
533 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700534 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
535 cg->LoadConstant(cg->TargetReg(kHiddenArg), target_method.dex_method_index);
536 if (cu->instruction_set == kX86) {
537 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg), cg->TargetReg(kHiddenArg));
538 }
539 break;
540 case 1: { // Get "this" [set kArg1]
541 RegLocation rl_arg = info->args[0];
542 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1));
543 break;
544 }
545 case 2: // Is "this" null? [use kArg1]
546 cg->GenNullCheck(info->args[0].s_reg_low, cg->TargetReg(kArg1), info->opt_flags);
547 // Get this->klass_ [use kArg1, set kInvokeTgt]
548 cg->LoadWordDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(),
549 cg->TargetReg(kInvokeTgt));
550 break;
551 case 3: // Get this->klass_->imtable [use kInvokeTgt, set kInvokeTgt]
552 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), mirror::Class::ImTableOffset().Int32Value(),
553 cg->TargetReg(kInvokeTgt));
554 break;
555 case 4: // Get target method [use kInvokeTgt, set kArg0]
556 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), ((method_idx % ClassLinker::kImtSize) * 4) +
557 mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700558 cg->TargetReg(kArg0));
559 break;
Jeff Hao88474b42013-10-23 16:24:40 -0700560 case 5: // Get the compiled code address [use kArg0, set kInvokeTgt]
561 if (cu->instruction_set != kX86) {
562 cg->LoadWordDisp(cg->TargetReg(kArg0),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800563 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Jeff Hao88474b42013-10-23 16:24:40 -0700564 cg->TargetReg(kInvokeTgt));
565 break;
566 }
567 // Intentional fallthrough for X86
Brian Carlstrom7940e442013-07-12 13:46:57 -0700568 default:
569 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700570 }
571 return state + 1;
572}
573
Ian Rogers848871b2013-08-05 10:56:33 -0700574static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, ThreadOffset trampoline,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700575 int state, const MethodReference& target_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700576 uint32_t method_idx) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700577 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
578 /*
579 * This handles the case in which the base method is not fully
580 * resolved at compile time, we bail to a runtime helper.
581 */
582 if (state == 0) {
583 if (cu->instruction_set != kX86) {
584 // Load trampoline target
Ian Rogers848871b2013-08-05 10:56:33 -0700585 cg->LoadWordDisp(cg->TargetReg(kSelf), trampoline.Int32Value(), cg->TargetReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700586 }
587 // Load kArg0 with method index
588 CHECK_EQ(cu->dex_file, target_method.dex_file);
589 cg->LoadConstant(cg->TargetReg(kArg0), target_method.dex_method_index);
590 return 1;
591 }
592 return -1;
593}
594
595static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
596 int state,
597 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000598 uint32_t unused, uintptr_t unused2,
599 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700600 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700601 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
602}
603
604static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
605 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000606 uint32_t unused, uintptr_t unused2,
607 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700608 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700609 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
610}
611
612static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
613 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000614 uint32_t unused, uintptr_t unused2,
615 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700616 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700617 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
618}
619
620static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
621 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000622 uint32_t unused, uintptr_t unused2,
623 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700624 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700625 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
626}
627
628static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
629 CallInfo* info, int state,
630 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000631 uint32_t unused, uintptr_t unused2,
632 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700633 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700634 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
635}
636
637int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
638 NextCallInsn next_call_insn,
639 const MethodReference& target_method,
640 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700641 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700642 int last_arg_reg = TargetReg(kArg3);
643 int next_reg = TargetReg(kArg1);
644 int next_arg = 0;
645 if (skip_this) {
646 next_reg++;
647 next_arg++;
648 }
649 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
650 RegLocation rl_arg = info->args[next_arg++];
651 rl_arg = UpdateRawLoc(rl_arg);
652 if (rl_arg.wide && (next_reg <= TargetReg(kArg2))) {
653 LoadValueDirectWideFixed(rl_arg, next_reg, next_reg + 1);
654 next_reg++;
655 next_arg++;
656 } else {
657 if (rl_arg.wide) {
658 rl_arg.wide = false;
659 rl_arg.is_const = false;
660 }
661 LoadValueDirectFixed(rl_arg, next_reg);
662 }
663 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
664 direct_code, direct_method, type);
665 }
666 return call_state;
667}
668
669/*
670 * Load up to 5 arguments, the first three of which will be in
671 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
672 * and as part of the load sequence, it must be replaced with
673 * the target method pointer. Note, this may also be called
674 * for "range" variants if the number of arguments is 5 or fewer.
675 */
676int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info,
677 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
678 const MethodReference& target_method,
679 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700680 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700681 RegLocation rl_arg;
682
683 /* If no arguments, just return */
684 if (info->num_arg_words == 0)
685 return call_state;
686
687 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
688 direct_code, direct_method, type);
689
690 DCHECK_LE(info->num_arg_words, 5);
691 if (info->num_arg_words > 3) {
692 int32_t next_use = 3;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700693 // Detect special case of wide arg spanning arg3/arg4
Brian Carlstrom7940e442013-07-12 13:46:57 -0700694 RegLocation rl_use0 = info->args[0];
695 RegLocation rl_use1 = info->args[1];
696 RegLocation rl_use2 = info->args[2];
697 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) &&
698 rl_use2.wide) {
699 int reg = -1;
700 // Wide spans, we need the 2nd half of uses[2].
701 rl_arg = UpdateLocWide(rl_use2);
702 if (rl_arg.location == kLocPhysReg) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000703 reg = rl_arg.reg.GetHighReg();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700704 } else {
705 // kArg2 & rArg3 can safely be used here
706 reg = TargetReg(kArg3);
707 LoadWordDisp(TargetReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg);
708 call_state = next_call_insn(cu_, info, call_state, target_method,
709 vtable_idx, direct_code, direct_method, type);
710 }
711 StoreBaseDisp(TargetReg(kSp), (next_use + 1) * 4, reg, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700712 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
713 direct_code, direct_method, type);
714 next_use++;
715 }
716 // Loop through the rest
717 while (next_use < info->num_arg_words) {
718 int low_reg;
719 int high_reg = -1;
720 rl_arg = info->args[next_use];
721 rl_arg = UpdateRawLoc(rl_arg);
722 if (rl_arg.location == kLocPhysReg) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000723 low_reg = rl_arg.reg.GetReg();
724 if (rl_arg.wide) {
725 high_reg = rl_arg.reg.GetHighReg();
726 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700727 } else {
728 low_reg = TargetReg(kArg2);
729 if (rl_arg.wide) {
730 high_reg = TargetReg(kArg3);
731 LoadValueDirectWideFixed(rl_arg, low_reg, high_reg);
732 } else {
733 LoadValueDirectFixed(rl_arg, low_reg);
734 }
735 call_state = next_call_insn(cu_, info, call_state, target_method,
736 vtable_idx, direct_code, direct_method, type);
737 }
738 int outs_offset = (next_use + 1) * 4;
739 if (rl_arg.wide) {
740 StoreBaseDispWide(TargetReg(kSp), outs_offset, low_reg, high_reg);
741 next_use += 2;
742 } else {
743 StoreWordDisp(TargetReg(kSp), outs_offset, low_reg);
744 next_use++;
745 }
746 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
747 direct_code, direct_method, type);
748 }
749 }
750
751 call_state = LoadArgRegs(info, call_state, next_call_insn,
752 target_method, vtable_idx, direct_code, direct_method,
753 type, skip_this);
754
755 if (pcrLabel) {
756 *pcrLabel = GenNullCheck(info->args[0].s_reg_low, TargetReg(kArg1), info->opt_flags);
757 }
758 return call_state;
759}
760
761/*
762 * May have 0+ arguments (also used for jumbo). Note that
763 * source virtual registers may be in physical registers, so may
764 * need to be flushed to home location before copying. This
765 * applies to arg3 and above (see below).
766 *
767 * Two general strategies:
768 * If < 20 arguments
769 * Pass args 3-18 using vldm/vstm block copy
770 * Pass arg0, arg1 & arg2 in kArg1-kArg3
771 * If 20+ arguments
772 * Pass args arg19+ using memcpy block copy
773 * Pass arg0, arg1 & arg2 in kArg1-kArg3
774 *
775 */
776int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state,
777 LIR** pcrLabel, NextCallInsn next_call_insn,
778 const MethodReference& target_method,
779 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700780 InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700781 // If we can treat it as non-range (Jumbo ops will use range form)
782 if (info->num_arg_words <= 5)
783 return GenDalvikArgsNoRange(info, call_state, pcrLabel,
784 next_call_insn, target_method, vtable_idx,
785 direct_code, direct_method, type, skip_this);
786 /*
787 * First load the non-register arguments. Both forms expect all
788 * of the source arguments to be in their home frame location, so
789 * scan the s_reg names and flush any that have been promoted to
790 * frame backing storage.
791 */
792 // Scan the rest of the args - if in phys_reg flush to memory
793 for (int next_arg = 0; next_arg < info->num_arg_words;) {
794 RegLocation loc = info->args[next_arg];
795 if (loc.wide) {
796 loc = UpdateLocWide(loc);
797 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
798 StoreBaseDispWide(TargetReg(kSp), SRegOffset(loc.s_reg_low),
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000799 loc.reg.GetReg(), loc.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700800 }
801 next_arg += 2;
802 } else {
803 loc = UpdateLoc(loc);
804 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
805 StoreBaseDisp(TargetReg(kSp), SRegOffset(loc.s_reg_low),
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000806 loc.reg.GetReg(), kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700807 }
808 next_arg++;
809 }
810 }
811
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800812 // Logic below assumes that Method pointer is at offset zero from SP.
813 DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0);
814
815 // The first 3 arguments are passed via registers.
816 // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either
817 // get size of uintptr_t or size of object reference according to model being used.
818 int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700819 int start_offset = SRegOffset(info->args[3].s_reg_low);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800820 int regs_left_to_pass_via_stack = info->num_arg_words - 3;
821 DCHECK_GT(regs_left_to_pass_via_stack, 0);
822
823 if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) {
824 // Use vldm/vstm pair using kArg3 as a temp
825 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
826 direct_code, direct_method, type);
827 OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), start_offset);
828 LIR* ld = OpVldm(TargetReg(kArg3), regs_left_to_pass_via_stack);
829 // TUNING: loosen barrier
830 ld->u.m.def_mask = ENCODE_ALL;
831 SetMemRefType(ld, true /* is_load */, kDalvikReg);
832 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
833 direct_code, direct_method, type);
834 OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), 4 /* Method* */ + (3 * 4));
835 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
836 direct_code, direct_method, type);
837 LIR* st = OpVstm(TargetReg(kArg3), regs_left_to_pass_via_stack);
838 SetMemRefType(st, false /* is_load */, kDalvikReg);
839 st->u.m.def_mask = ENCODE_ALL;
840 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
841 direct_code, direct_method, type);
842 } else if (cu_->instruction_set == kX86) {
843 int current_src_offset = start_offset;
844 int current_dest_offset = outs_offset;
845
846 while (regs_left_to_pass_via_stack > 0) {
847 // This is based on the knowledge that the stack itself is 16-byte aligned.
848 bool src_is_16b_aligned = (current_src_offset & 0xF) == 0;
849 bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0;
850 size_t bytes_to_move;
851
852 /*
853 * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a
854 * a 128-bit move because we won't get the chance to try to aligned. If there are more than
855 * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned.
856 * We do this because we could potentially do a smaller move to align.
857 */
858 if (regs_left_to_pass_via_stack == 4 ||
859 (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) {
860 // Moving 128-bits via xmm register.
861 bytes_to_move = sizeof(uint32_t) * 4;
862
863 // Allocate a free xmm temp. Since we are working through the calling sequence,
864 // we expect to have an xmm temporary available.
865 int temp = AllocTempDouble();
866 CHECK_GT(temp, 0);
867
868 LIR* ld1 = nullptr;
869 LIR* ld2 = nullptr;
870 LIR* st1 = nullptr;
871 LIR* st2 = nullptr;
872
873 /*
874 * The logic is similar for both loads and stores. If we have 16-byte alignment,
875 * do an aligned move. If we have 8-byte alignment, then do the move in two
876 * parts. This approach prevents possible cache line splits. Finally, fall back
877 * to doing an unaligned move. In most cases we likely won't split the cache
878 * line but we cannot prove it and thus take a conservative approach.
879 */
880 bool src_is_8b_aligned = (current_src_offset & 0x7) == 0;
881 bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0;
882
883 if (src_is_16b_aligned) {
884 ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovA128FP);
885 } else if (src_is_8b_aligned) {
886 ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovLo128FP);
887 ld2 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset + (bytes_to_move >> 1), kMovHi128FP);
888 } else {
889 ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovU128FP);
890 }
891
892 if (dest_is_16b_aligned) {
893 st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovA128FP);
894 } else if (dest_is_8b_aligned) {
895 st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovLo128FP);
896 st2 = OpMovMemReg(TargetReg(kSp), current_dest_offset + (bytes_to_move >> 1), temp, kMovHi128FP);
897 } else {
898 st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovU128FP);
899 }
900
901 // TODO If we could keep track of aliasing information for memory accesses that are wider
902 // than 64-bit, we wouldn't need to set up a barrier.
903 if (ld1 != nullptr) {
904 if (ld2 != nullptr) {
905 // For 64-bit load we can actually set up the aliasing information.
906 AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true);
907 AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true, true);
908 } else {
909 // Set barrier for 128-bit load.
910 SetMemRefType(ld1, true /* is_load */, kDalvikReg);
911 ld1->u.m.def_mask = ENCODE_ALL;
912 }
913 }
914 if (st1 != nullptr) {
915 if (st2 != nullptr) {
916 // For 64-bit store we can actually set up the aliasing information.
917 AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true);
918 AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false, true);
919 } else {
920 // Set barrier for 128-bit store.
921 SetMemRefType(st1, false /* is_load */, kDalvikReg);
922 st1->u.m.def_mask = ENCODE_ALL;
923 }
924 }
925
926 // Free the temporary used for the data movement.
927 FreeTemp(temp);
928 } else {
929 // Moving 32-bits via general purpose register.
930 bytes_to_move = sizeof(uint32_t);
931
932 // Instead of allocating a new temp, simply reuse one of the registers being used
933 // for argument passing.
934 int temp = TargetReg(kArg3);
935
936 // Now load the argument VR and store to the outs.
937 LoadWordDisp(TargetReg(kSp), current_src_offset, temp);
938 StoreWordDisp(TargetReg(kSp), current_dest_offset, temp);
939 }
940
941 current_src_offset += bytes_to_move;
942 current_dest_offset += bytes_to_move;
943 regs_left_to_pass_via_stack -= (bytes_to_move >> 2);
944 }
945 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700946 // Generate memcpy
947 OpRegRegImm(kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset);
948 OpRegRegImm(kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset);
Ian Rogers7655f292013-07-29 11:07:13 -0700949 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(pMemcpy), TargetReg(kArg0),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700950 TargetReg(kArg1), (info->num_arg_words - 3) * 4, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700951 }
952
953 call_state = LoadArgRegs(info, call_state, next_call_insn,
954 target_method, vtable_idx, direct_code, direct_method,
955 type, skip_this);
956
957 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
958 direct_code, direct_method, type);
959 if (pcrLabel) {
960 *pcrLabel = GenNullCheck(info->args[0].s_reg_low, TargetReg(kArg1), info->opt_flags);
961 }
962 return call_state;
963}
964
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700965RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700966 RegLocation res;
967 if (info->result.location == kLocInvalid) {
968 res = GetReturn(false);
969 } else {
970 res = info->result;
971 }
972 return res;
973}
974
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700975RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700976 RegLocation res;
977 if (info->result.location == kLocInvalid) {
978 res = GetReturnWide(false);
979 } else {
980 res = info->result;
981 }
982 return res;
983}
984
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700985bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700986 if (cu_->instruction_set == kMips) {
987 // TODO - add Mips implementation
988 return false;
989 }
990 // Location of reference to data array
991 int value_offset = mirror::String::ValueOffset().Int32Value();
992 // Location of count
993 int count_offset = mirror::String::CountOffset().Int32Value();
994 // Starting offset within data array
995 int offset_offset = mirror::String::OffsetOffset().Int32Value();
996 // Start of char data with array_
997 int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value();
998
999 RegLocation rl_obj = info->args[0];
1000 RegLocation rl_idx = info->args[1];
1001 rl_obj = LoadValue(rl_obj, kCoreReg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001002 // X86 wants to avoid putting a constant index into a register.
1003 if (!(cu_->instruction_set == kX86 && rl_idx.is_const)) {
1004 rl_idx = LoadValue(rl_idx, kCoreReg);
1005 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001006 int reg_max;
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001007 GenNullCheck(rl_obj.s_reg_low, rl_obj.reg.GetReg(), info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001008 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001009 LIR* range_check_branch = nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001010 int reg_off = INVALID_REG;
1011 int reg_ptr = INVALID_REG;
1012 if (cu_->instruction_set != kX86) {
1013 reg_off = AllocTemp();
1014 reg_ptr = AllocTemp();
1015 if (range_check) {
1016 reg_max = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001017 LoadWordDisp(rl_obj.reg.GetReg(), count_offset, reg_max);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001018 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001019 LoadWordDisp(rl_obj.reg.GetReg(), offset_offset, reg_off);
1020 LoadWordDisp(rl_obj.reg.GetReg(), value_offset, reg_ptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001021 if (range_check) {
1022 // Set up a launch pad to allow retry in case of bounds violation */
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001023 OpRegReg(kOpCmp, rl_idx.reg.GetReg(), reg_max);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001024 FreeTemp(reg_max);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001025 range_check_branch = OpCondBranch(kCondUge, nullptr);
Brian Carlstrom6f485c62013-07-18 15:35:35 -07001026 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001027 OpRegImm(kOpAdd, reg_ptr, data_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001028 } else {
1029 if (range_check) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001030 // On x86, we can compare to memory directly
Brian Carlstrom7940e442013-07-12 13:46:57 -07001031 // Set up a launch pad to allow retry in case of bounds violation */
Mark Mendell2b724cb2014-02-06 05:24:20 -08001032 if (rl_idx.is_const) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001033 range_check_branch = OpCmpMemImmBranch(
1034 kCondUlt, INVALID_REG, rl_obj.reg.GetReg(), count_offset,
1035 mir_graph_->ConstantValue(rl_idx.orig_sreg), nullptr);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001036 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001037 OpRegMem(kOpCmp, rl_idx.reg.GetReg(), rl_obj.reg.GetReg(), count_offset);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001038 range_check_branch = OpCondBranch(kCondUge, nullptr);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001039 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001040 }
1041 reg_off = AllocTemp();
1042 reg_ptr = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001043 LoadWordDisp(rl_obj.reg.GetReg(), offset_offset, reg_off);
1044 LoadWordDisp(rl_obj.reg.GetReg(), value_offset, reg_ptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001045 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001046 if (rl_idx.is_const) {
1047 OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg));
1048 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001049 OpRegReg(kOpAdd, reg_off, rl_idx.reg.GetReg());
Mark Mendell2b724cb2014-02-06 05:24:20 -08001050 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001051 FreeTemp(rl_obj.reg.GetReg());
1052 if (rl_idx.location == kLocPhysReg) {
1053 FreeTemp(rl_idx.reg.GetReg());
Mark Mendell2b724cb2014-02-06 05:24:20 -08001054 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001055 RegLocation rl_dest = InlineTarget(info);
1056 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001057 if (cu_->instruction_set != kX86) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001058 LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg.GetReg(), 1, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001059 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001060 LoadBaseIndexedDisp(reg_ptr, reg_off, 1, data_offset, rl_result.reg.GetReg(),
Mark Mendell2b724cb2014-02-06 05:24:20 -08001061 INVALID_REG, kUnsignedHalf, INVALID_SREG);
1062 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001063 FreeTemp(reg_off);
1064 FreeTemp(reg_ptr);
1065 StoreValue(rl_dest, rl_result);
1066 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001067 DCHECK(range_check_branch != nullptr);
1068 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
1069 AddIntrinsicLaunchpad(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001070 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001071 return true;
1072}
1073
1074// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001075bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001076 if (cu_->instruction_set == kMips) {
1077 // TODO - add Mips implementation
1078 return false;
1079 }
1080 // dst = src.length();
1081 RegLocation rl_obj = info->args[0];
1082 rl_obj = LoadValue(rl_obj, kCoreReg);
1083 RegLocation rl_dest = InlineTarget(info);
1084 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001085 GenNullCheck(rl_obj.s_reg_low, rl_obj.reg.GetReg(), info->opt_flags);
1086 LoadWordDisp(rl_obj.reg.GetReg(), mirror::String::CountOffset().Int32Value(), rl_result.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001087 if (is_empty) {
1088 // dst = (dst == 0);
1089 if (cu_->instruction_set == kThumb2) {
1090 int t_reg = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001091 OpRegReg(kOpNeg, t_reg, rl_result.reg.GetReg());
1092 OpRegRegReg(kOpAdc, rl_result.reg.GetReg(), rl_result.reg.GetReg(), t_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001093 } else {
1094 DCHECK_EQ(cu_->instruction_set, kX86);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001095 OpRegImm(kOpSub, rl_result.reg.GetReg(), 1);
1096 OpRegImm(kOpLsr, rl_result.reg.GetReg(), 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001097 }
1098 }
1099 StoreValue(rl_dest, rl_result);
1100 return true;
1101}
1102
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001103bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
1104 if (cu_->instruction_set == kMips) {
1105 // TODO - add Mips implementation
1106 return false;
1107 }
1108 RegLocation rl_src_i = info->args[0];
Mark Mendell55d0eac2014-02-06 11:02:52 -08001109 RegLocation rl_dest = (size == kLong) ? InlineTargetWide(info) : InlineTarget(info); // result reg
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001110 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1111 if (size == kLong) {
1112 RegLocation rl_i = LoadValueWide(rl_src_i, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001113 int r_i_low = rl_i.reg.GetReg();
1114 if (rl_i.reg.GetReg() == rl_result.reg.GetReg()) {
1115 // First REV shall clobber rl_result.reg.GetReg(), save the value in a temp for the second REV.
Vladimir Markof246af22013-11-27 12:30:15 +00001116 r_i_low = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001117 OpRegCopy(r_i_low, rl_i.reg.GetReg());
Vladimir Markof246af22013-11-27 12:30:15 +00001118 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001119 OpRegReg(kOpRev, rl_result.reg.GetReg(), rl_i.reg.GetHighReg());
1120 OpRegReg(kOpRev, rl_result.reg.GetHighReg(), r_i_low);
1121 if (rl_i.reg.GetReg() == rl_result.reg.GetReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001122 FreeTemp(r_i_low);
1123 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001124 StoreValueWide(rl_dest, rl_result);
1125 } else {
1126 DCHECK(size == kWord || size == kSignedHalf);
1127 OpKind op = (size == kWord) ? kOpRev : kOpRevsh;
1128 RegLocation rl_i = LoadValue(rl_src_i, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001129 OpRegReg(op, rl_result.reg.GetReg(), rl_i.reg.GetReg());
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001130 StoreValue(rl_dest, rl_result);
1131 }
1132 return true;
1133}
1134
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001135bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001136 if (cu_->instruction_set == kMips) {
1137 // TODO - add Mips implementation
1138 return false;
1139 }
1140 RegLocation rl_src = info->args[0];
1141 rl_src = LoadValue(rl_src, kCoreReg);
1142 RegLocation rl_dest = InlineTarget(info);
1143 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1144 int sign_reg = AllocTemp();
1145 // abs(x) = y<=x>>31, (x+y)^y.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001146 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetReg(), 31);
1147 OpRegRegReg(kOpAdd, rl_result.reg.GetReg(), rl_src.reg.GetReg(), sign_reg);
1148 OpRegReg(kOpXor, rl_result.reg.GetReg(), sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001149 StoreValue(rl_dest, rl_result);
1150 return true;
1151}
1152
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001153bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001154 if (cu_->instruction_set == kMips) {
1155 // TODO - add Mips implementation
1156 return false;
1157 }
1158 if (cu_->instruction_set == kThumb2) {
1159 RegLocation rl_src = info->args[0];
1160 rl_src = LoadValueWide(rl_src, kCoreReg);
1161 RegLocation rl_dest = InlineTargetWide(info);
1162 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1163 int sign_reg = AllocTemp();
1164 // abs(x) = y<=x>>31, (x+y)^y.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001165 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHighReg(), 31);
1166 OpRegRegReg(kOpAdd, rl_result.reg.GetReg(), rl_src.reg.GetReg(), sign_reg);
1167 OpRegRegReg(kOpAdc, rl_result.reg.GetHighReg(), rl_src.reg.GetHighReg(), sign_reg);
1168 OpRegReg(kOpXor, rl_result.reg.GetReg(), sign_reg);
1169 OpRegReg(kOpXor, rl_result.reg.GetHighReg(), sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001170 StoreValueWide(rl_dest, rl_result);
1171 return true;
1172 } else {
1173 DCHECK_EQ(cu_->instruction_set, kX86);
1174 // Reuse source registers to avoid running out of temps
1175 RegLocation rl_src = info->args[0];
1176 rl_src = LoadValueWide(rl_src, kCoreReg);
1177 RegLocation rl_dest = InlineTargetWide(info);
1178 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001179 OpRegCopyWide(rl_result.reg.GetReg(), rl_result.reg.GetHighReg(), rl_src.reg.GetReg(), rl_src.reg.GetHighReg());
1180 FreeTemp(rl_src.reg.GetReg());
1181 FreeTemp(rl_src.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001182 int sign_reg = AllocTemp();
1183 // abs(x) = y<=x>>31, (x+y)^y.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001184 OpRegRegImm(kOpAsr, sign_reg, rl_result.reg.GetHighReg(), 31);
1185 OpRegReg(kOpAdd, rl_result.reg.GetReg(), sign_reg);
1186 OpRegReg(kOpAdc, rl_result.reg.GetHighReg(), sign_reg);
1187 OpRegReg(kOpXor, rl_result.reg.GetReg(), sign_reg);
1188 OpRegReg(kOpXor, rl_result.reg.GetHighReg(), sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001189 StoreValueWide(rl_dest, rl_result);
1190 return true;
1191 }
1192}
1193
Yixin Shoudbb17e32014-02-07 05:09:30 -08001194bool Mir2Lir::GenInlinedAbsFloat(CallInfo* info) {
1195 if (cu_->instruction_set == kMips) {
1196 // TODO - add Mips implementation
1197 return false;
1198 }
1199 RegLocation rl_src = info->args[0];
1200 rl_src = LoadValue(rl_src, kCoreReg);
1201 RegLocation rl_dest = InlineTarget(info);
1202 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1203 int signMask = AllocTemp();
1204 LoadConstant(signMask, 0x7fffffff);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001205 OpRegRegReg(kOpAnd, rl_result.reg.GetReg(), rl_src.reg.GetReg(), signMask);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001206 FreeTemp(signMask);
1207 StoreValue(rl_dest, rl_result);
1208 return true;
1209}
1210
1211bool Mir2Lir::GenInlinedAbsDouble(CallInfo* info) {
1212 if (cu_->instruction_set == kMips) {
1213 // TODO - add Mips implementation
1214 return false;
1215 }
1216 RegLocation rl_src = info->args[0];
1217 rl_src = LoadValueWide(rl_src, kCoreReg);
1218 RegLocation rl_dest = InlineTargetWide(info);
1219 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001220 OpRegCopyWide(rl_result.reg.GetReg(), rl_result.reg.GetHighReg(), rl_src.reg.GetReg(), rl_src.reg.GetHighReg());
1221 FreeTemp(rl_src.reg.GetReg());
1222 FreeTemp(rl_src.reg.GetHighReg());
Yixin Shoudbb17e32014-02-07 05:09:30 -08001223 int signMask = AllocTemp();
1224 LoadConstant(signMask, 0x7fffffff);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001225 OpRegReg(kOpAnd, rl_result.reg.GetHighReg(), signMask);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001226 FreeTemp(signMask);
1227 StoreValueWide(rl_dest, rl_result);
1228 return true;
1229}
1230
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001231bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001232 if (cu_->instruction_set == kMips) {
1233 // TODO - add Mips implementation
1234 return false;
1235 }
1236 RegLocation rl_src = info->args[0];
1237 RegLocation rl_dest = InlineTarget(info);
1238 StoreValue(rl_dest, rl_src);
1239 return true;
1240}
1241
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001242bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001243 if (cu_->instruction_set == kMips) {
1244 // TODO - add Mips implementation
1245 return false;
1246 }
1247 RegLocation rl_src = info->args[0];
1248 RegLocation rl_dest = InlineTargetWide(info);
1249 StoreValueWide(rl_dest, rl_src);
1250 return true;
1251}
1252
1253/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001254 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001255 * otherwise bails to standard library code.
1256 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001257bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001258 if (cu_->instruction_set == kMips) {
1259 // TODO - add Mips implementation
1260 return false;
1261 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001262 RegLocation rl_obj = info->args[0];
1263 RegLocation rl_char = info->args[1];
1264 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1265 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1266 return false;
1267 }
1268
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001269 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001270 LockCallTemps(); // Using fixed registers
1271 int reg_ptr = TargetReg(kArg0);
1272 int reg_char = TargetReg(kArg1);
1273 int reg_start = TargetReg(kArg2);
1274
Brian Carlstrom7940e442013-07-12 13:46:57 -07001275 LoadValueDirectFixed(rl_obj, reg_ptr);
1276 LoadValueDirectFixed(rl_char, reg_char);
1277 if (zero_based) {
1278 LoadConstant(reg_start, 0);
1279 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001280 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001281 LoadValueDirectFixed(rl_start, reg_start);
1282 }
Mark Mendell4028a6c2014-02-19 20:06:20 -08001283 int r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(pIndexOf));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001284 GenNullCheck(rl_obj.s_reg_low, reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001285 LIR* high_code_point_branch =
1286 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001287 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001288 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001289 if (!rl_char.is_const) {
1290 // Add the slow path for code points beyond 0xFFFF.
1291 DCHECK(high_code_point_branch != nullptr);
1292 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1293 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
1294 AddIntrinsicLaunchpad(info, high_code_point_branch, resume_tgt);
1295 } else {
1296 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1297 DCHECK(high_code_point_branch == nullptr);
1298 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001299 RegLocation rl_return = GetReturn(false);
1300 RegLocation rl_dest = InlineTarget(info);
1301 StoreValue(rl_dest, rl_return);
1302 return true;
1303}
1304
1305/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001306bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001307 if (cu_->instruction_set == kMips) {
1308 // TODO - add Mips implementation
1309 return false;
1310 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001311 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001312 LockCallTemps(); // Using fixed registers
1313 int reg_this = TargetReg(kArg0);
1314 int reg_cmp = TargetReg(kArg1);
1315
1316 RegLocation rl_this = info->args[0];
1317 RegLocation rl_cmp = info->args[1];
1318 LoadValueDirectFixed(rl_this, reg_this);
1319 LoadValueDirectFixed(rl_cmp, reg_cmp);
1320 int r_tgt = (cu_->instruction_set != kX86) ?
Ian Rogers7655f292013-07-29 11:07:13 -07001321 LoadHelper(QUICK_ENTRYPOINT_OFFSET(pStringCompareTo)) : 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001322 GenNullCheck(rl_this.s_reg_low, reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001323 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001324 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001325 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
1326 AddIntrinsicLaunchpad(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001327 // NOTE: not a safepoint
1328 if (cu_->instruction_set != kX86) {
1329 OpReg(kOpBlx, r_tgt);
1330 } else {
Ian Rogers7655f292013-07-29 11:07:13 -07001331 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(pStringCompareTo));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001332 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001333 RegLocation rl_return = GetReturn(false);
1334 RegLocation rl_dest = InlineTarget(info);
1335 StoreValue(rl_dest, rl_return);
1336 return true;
1337}
1338
1339bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1340 RegLocation rl_dest = InlineTarget(info);
1341 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Ian Rogers848871b2013-08-05 10:56:33 -07001342 ThreadOffset offset = Thread::PeerOffset();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001343 if (cu_->instruction_set == kThumb2 || cu_->instruction_set == kMips) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001344 LoadWordDisp(TargetReg(kSelf), offset.Int32Value(), rl_result.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001345 } else {
1346 CHECK(cu_->instruction_set == kX86);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001347 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg.GetReg(), offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001348 }
1349 StoreValue(rl_dest, rl_result);
1350 return true;
1351}
1352
1353bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
1354 bool is_long, bool is_volatile) {
1355 if (cu_->instruction_set == kMips) {
1356 // TODO - add Mips implementation
1357 return false;
1358 }
1359 // Unused - RegLocation rl_src_unsafe = info->args[0];
1360 RegLocation rl_src_obj = info->args[1]; // Object
1361 RegLocation rl_src_offset = info->args[2]; // long low
1362 rl_src_offset.wide = 0; // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001363 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Brian Carlstrom7940e442013-07-12 13:46:57 -07001364 if (is_volatile) {
1365 GenMemBarrier(kLoadLoad);
1366 }
1367 RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg);
1368 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1369 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1370 if (is_long) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001371 OpRegReg(kOpAdd, rl_object.reg.GetReg(), rl_offset.reg.GetReg());
1372 LoadBaseDispWide(rl_object.reg.GetReg(), 0, rl_result.reg.GetReg(), rl_result.reg.GetHighReg(), INVALID_SREG);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001373 StoreValueWide(rl_dest, rl_result);
1374 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001375 LoadBaseIndexed(rl_object.reg.GetReg(), rl_offset.reg.GetReg(), rl_result.reg.GetReg(), 0, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001376 StoreValue(rl_dest, rl_result);
1377 }
1378 return true;
1379}
1380
1381bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1382 bool is_object, bool is_volatile, bool is_ordered) {
1383 if (cu_->instruction_set == kMips) {
1384 // TODO - add Mips implementation
1385 return false;
1386 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001387 // Unused - RegLocation rl_src_unsafe = info->args[0];
1388 RegLocation rl_src_obj = info->args[1]; // Object
1389 RegLocation rl_src_offset = info->args[2]; // long low
1390 rl_src_offset.wide = 0; // ignore high half in info->args[3]
1391 RegLocation rl_src_value = info->args[4]; // value to store
1392 if (is_volatile || is_ordered) {
1393 GenMemBarrier(kStoreStore);
1394 }
1395 RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg);
1396 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1397 RegLocation rl_value;
1398 if (is_long) {
1399 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001400 OpRegReg(kOpAdd, rl_object.reg.GetReg(), rl_offset.reg.GetReg());
1401 StoreBaseDispWide(rl_object.reg.GetReg(), 0, rl_value.reg.GetReg(), rl_value.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001402 } else {
1403 rl_value = LoadValue(rl_src_value, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001404 StoreBaseIndexed(rl_object.reg.GetReg(), rl_offset.reg.GetReg(), rl_value.reg.GetReg(), 0, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001405 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001406
1407 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001408 FreeTemp(rl_offset.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001409 if (is_volatile) {
1410 GenMemBarrier(kStoreLoad);
1411 }
1412 if (is_object) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001413 MarkGCCard(rl_value.reg.GetReg(), rl_object.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001414 }
1415 return true;
1416}
1417
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001418void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001419 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
1420 if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file)
1421 ->GenIntrinsic(this, info)) {
1422 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001423 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001424 GenInvokeNoInline(info);
1425}
1426
1427void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001428 int call_state = 0;
1429 LIR* null_ck;
1430 LIR** p_null_ck = NULL;
1431 NextCallInsn next_call_insn;
1432 FlushAllRegs(); /* Everything to home location */
1433 // Explicit register usage
1434 LockCallTemps();
1435
Vladimir Markof096aad2014-01-23 15:51:58 +00001436 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
1437 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
1438 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
1439 info->type = static_cast<InvokeType>(method_info.GetSharpType());
1440 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001441 bool skip_this;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001442 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001443 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001444 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001445 } else if (info->type == kDirect) {
1446 if (fast_path) {
1447 p_null_ck = &null_ck;
1448 }
1449 next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP;
1450 skip_this = false;
1451 } else if (info->type == kStatic) {
1452 next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP;
1453 skip_this = false;
1454 } else if (info->type == kSuper) {
1455 DCHECK(!fast_path); // Fast path is a direct call.
1456 next_call_insn = NextSuperCallInsnSP;
1457 skip_this = false;
1458 } else {
1459 DCHECK_EQ(info->type, kVirtual);
1460 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1461 skip_this = fast_path;
1462 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001463 MethodReference target_method = method_info.GetTargetMethod();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001464 if (!info->is_range) {
1465 call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001466 next_call_insn, target_method, method_info.VTableIndex(),
1467 method_info.DirectCode(), method_info.DirectMethod(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001468 original_type, skip_this);
1469 } else {
1470 call_state = GenDalvikArgsRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001471 next_call_insn, target_method, method_info.VTableIndex(),
1472 method_info.DirectCode(), method_info.DirectMethod(),
1473 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001474 }
1475 // Finish up any of the call sequence not interleaved in arg loading
1476 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001477 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
1478 method_info.DirectCode(), method_info.DirectMethod(), original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001479 }
1480 LIR* call_inst;
1481 if (cu_->instruction_set != kX86) {
1482 call_inst = OpReg(kOpBlx, TargetReg(kInvokeTgt));
1483 } else {
Jeff Hao88474b42013-10-23 16:24:40 -07001484 if (fast_path) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001485 if (method_info.DirectCode() == static_cast<uintptr_t>(-1)) {
Mark Mendell55d0eac2014-02-06 11:02:52 -08001486 // We can have the linker fixup a call relative.
1487 call_inst =
Jeff Hao49161ce2014-03-12 11:05:25 -07001488 reinterpret_cast<X86Mir2Lir*>(this)->CallWithLinkerFixup(target_method, info->type);
Mark Mendell55d0eac2014-02-06 11:02:52 -08001489 } else {
1490 call_inst = OpMem(kOpBlx, TargetReg(kArg0),
1491 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
1492 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001493 } else {
Ian Rogers848871b2013-08-05 10:56:33 -07001494 ThreadOffset trampoline(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001495 switch (info->type) {
1496 case kInterface:
Jeff Hao88474b42013-10-23 16:24:40 -07001497 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001498 break;
1499 case kDirect:
Ian Rogers7655f292013-07-29 11:07:13 -07001500 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001501 break;
1502 case kStatic:
Ian Rogers7655f292013-07-29 11:07:13 -07001503 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001504 break;
1505 case kSuper:
Ian Rogers7655f292013-07-29 11:07:13 -07001506 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001507 break;
1508 case kVirtual:
Ian Rogers7655f292013-07-29 11:07:13 -07001509 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001510 break;
1511 default:
1512 LOG(FATAL) << "Unexpected invoke type";
1513 }
1514 call_inst = OpThreadMem(kOpBlx, trampoline);
1515 }
1516 }
1517 MarkSafepointPC(call_inst);
1518
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001519 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001520 if (info->result.location != kLocInvalid) {
1521 // We have a following MOVE_RESULT - do it now.
1522 if (info->result.wide) {
1523 RegLocation ret_loc = GetReturnWide(info->result.fp);
1524 StoreValueWide(info->result, ret_loc);
1525 } else {
1526 RegLocation ret_loc = GetReturn(info->result.fp);
1527 StoreValue(info->result, ret_loc);
1528 }
1529 }
1530}
1531
1532} // namespace art