blob: 859a033c214b336ac996505c01cd721d8695301c [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]
Dave Allisonb373e092014-02-20 16:06:36 -0800492 cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700493 // get this->klass_ [use kArg1, set kInvokeTgt]
494 cg->LoadWordDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(),
495 cg->TargetReg(kInvokeTgt));
Dave Allisonb373e092014-02-20 16:06:36 -0800496 cg->MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700497 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700498 case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700499 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), mirror::Class::VTableOffset().Int32Value(),
500 cg->TargetReg(kInvokeTgt));
501 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700502 case 3: // Get target method [use kInvokeTgt, set kArg0]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700503 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), (method_idx * 4) +
504 mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(),
505 cg->TargetReg(kArg0));
506 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700507 case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700508 if (cu->instruction_set != kX86) {
509 cg->LoadWordDisp(cg->TargetReg(kArg0),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800510 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700511 cg->TargetReg(kInvokeTgt));
512 break;
513 }
514 // Intentional fallthrough for X86
515 default:
516 return -1;
517 }
518 return state + 1;
519}
520
521/*
Jeff Hao88474b42013-10-23 16:24:40 -0700522 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
523 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
524 * more than one interface method map to the same index. Note also that we'll load the first
525 * argument ("this") into kArg1 here rather than the standard LoadArgRegs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700526 */
527static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
528 const MethodReference& target_method,
Jeff Hao88474b42013-10-23 16:24:40 -0700529 uint32_t method_idx, uintptr_t unused,
530 uintptr_t direct_method, InvokeType unused2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700531 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700532
Jeff Hao88474b42013-10-23 16:24:40 -0700533 switch (state) {
534 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700535 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
536 cg->LoadConstant(cg->TargetReg(kHiddenArg), target_method.dex_method_index);
537 if (cu->instruction_set == kX86) {
538 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg), cg->TargetReg(kHiddenArg));
539 }
540 break;
541 case 1: { // Get "this" [set kArg1]
542 RegLocation rl_arg = info->args[0];
543 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1));
544 break;
545 }
546 case 2: // Is "this" null? [use kArg1]
Dave Allisonb373e092014-02-20 16:06:36 -0800547 cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags);
Jeff Hao88474b42013-10-23 16:24:40 -0700548 // Get this->klass_ [use kArg1, set kInvokeTgt]
549 cg->LoadWordDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(),
550 cg->TargetReg(kInvokeTgt));
Dave Allisonb373e092014-02-20 16:06:36 -0800551 cg->MarkPossibleNullPointerException(info->opt_flags);
Jeff Hao88474b42013-10-23 16:24:40 -0700552 break;
553 case 3: // Get this->klass_->imtable [use kInvokeTgt, set kInvokeTgt]
554 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), mirror::Class::ImTableOffset().Int32Value(),
555 cg->TargetReg(kInvokeTgt));
556 break;
557 case 4: // Get target method [use kInvokeTgt, set kArg0]
558 cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), ((method_idx % ClassLinker::kImtSize) * 4) +
559 mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700560 cg->TargetReg(kArg0));
561 break;
Jeff Hao88474b42013-10-23 16:24:40 -0700562 case 5: // Get the compiled code address [use kArg0, set kInvokeTgt]
563 if (cu->instruction_set != kX86) {
564 cg->LoadWordDisp(cg->TargetReg(kArg0),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800565 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Jeff Hao88474b42013-10-23 16:24:40 -0700566 cg->TargetReg(kInvokeTgt));
567 break;
568 }
569 // Intentional fallthrough for X86
Brian Carlstrom7940e442013-07-12 13:46:57 -0700570 default:
571 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700572 }
573 return state + 1;
574}
575
Ian Rogers848871b2013-08-05 10:56:33 -0700576static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, ThreadOffset trampoline,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700577 int state, const MethodReference& target_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700578 uint32_t method_idx) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700579 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
580 /*
581 * This handles the case in which the base method is not fully
582 * resolved at compile time, we bail to a runtime helper.
583 */
584 if (state == 0) {
585 if (cu->instruction_set != kX86) {
586 // Load trampoline target
Ian Rogers848871b2013-08-05 10:56:33 -0700587 cg->LoadWordDisp(cg->TargetReg(kSelf), trampoline.Int32Value(), cg->TargetReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700588 }
589 // Load kArg0 with method index
590 CHECK_EQ(cu->dex_file, target_method.dex_file);
591 cg->LoadConstant(cg->TargetReg(kArg0), target_method.dex_method_index);
592 return 1;
593 }
594 return -1;
595}
596
597static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
598 int state,
599 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000600 uint32_t unused, uintptr_t unused2,
601 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700602 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700603 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
604}
605
606static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
607 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000608 uint32_t unused, uintptr_t unused2,
609 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700610 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700611 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
612}
613
614static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
615 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000616 uint32_t unused, uintptr_t unused2,
617 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700618 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700619 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
620}
621
622static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
623 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000624 uint32_t unused, uintptr_t unused2,
625 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700626 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700627 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
628}
629
630static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
631 CallInfo* info, int state,
632 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000633 uint32_t unused, uintptr_t unused2,
634 uintptr_t unused3, InvokeType unused4) {
Ian Rogers848871b2013-08-05 10:56:33 -0700635 ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700636 return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0);
637}
638
639int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
640 NextCallInsn next_call_insn,
641 const MethodReference& target_method,
642 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700643 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700644 int last_arg_reg = TargetReg(kArg3);
645 int next_reg = TargetReg(kArg1);
646 int next_arg = 0;
647 if (skip_this) {
648 next_reg++;
649 next_arg++;
650 }
651 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
652 RegLocation rl_arg = info->args[next_arg++];
653 rl_arg = UpdateRawLoc(rl_arg);
654 if (rl_arg.wide && (next_reg <= TargetReg(kArg2))) {
655 LoadValueDirectWideFixed(rl_arg, next_reg, next_reg + 1);
656 next_reg++;
657 next_arg++;
658 } else {
659 if (rl_arg.wide) {
660 rl_arg.wide = false;
661 rl_arg.is_const = false;
662 }
663 LoadValueDirectFixed(rl_arg, next_reg);
664 }
665 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
666 direct_code, direct_method, type);
667 }
668 return call_state;
669}
670
671/*
672 * Load up to 5 arguments, the first three of which will be in
673 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
674 * and as part of the load sequence, it must be replaced with
675 * the target method pointer. Note, this may also be called
676 * for "range" variants if the number of arguments is 5 or fewer.
677 */
678int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info,
679 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
680 const MethodReference& target_method,
681 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700682 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700683 RegLocation rl_arg;
684
685 /* If no arguments, just return */
686 if (info->num_arg_words == 0)
687 return call_state;
688
689 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
690 direct_code, direct_method, type);
691
692 DCHECK_LE(info->num_arg_words, 5);
693 if (info->num_arg_words > 3) {
694 int32_t next_use = 3;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700695 // Detect special case of wide arg spanning arg3/arg4
Brian Carlstrom7940e442013-07-12 13:46:57 -0700696 RegLocation rl_use0 = info->args[0];
697 RegLocation rl_use1 = info->args[1];
698 RegLocation rl_use2 = info->args[2];
699 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) &&
700 rl_use2.wide) {
701 int reg = -1;
702 // Wide spans, we need the 2nd half of uses[2].
703 rl_arg = UpdateLocWide(rl_use2);
704 if (rl_arg.location == kLocPhysReg) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000705 reg = rl_arg.reg.GetHighReg();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700706 } else {
707 // kArg2 & rArg3 can safely be used here
708 reg = TargetReg(kArg3);
709 LoadWordDisp(TargetReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg);
710 call_state = next_call_insn(cu_, info, call_state, target_method,
711 vtable_idx, direct_code, direct_method, type);
712 }
713 StoreBaseDisp(TargetReg(kSp), (next_use + 1) * 4, reg, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700714 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
715 direct_code, direct_method, type);
716 next_use++;
717 }
718 // Loop through the rest
719 while (next_use < info->num_arg_words) {
720 int low_reg;
721 int high_reg = -1;
722 rl_arg = info->args[next_use];
723 rl_arg = UpdateRawLoc(rl_arg);
724 if (rl_arg.location == kLocPhysReg) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000725 low_reg = rl_arg.reg.GetReg();
726 if (rl_arg.wide) {
727 high_reg = rl_arg.reg.GetHighReg();
728 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700729 } else {
730 low_reg = TargetReg(kArg2);
731 if (rl_arg.wide) {
732 high_reg = TargetReg(kArg3);
733 LoadValueDirectWideFixed(rl_arg, low_reg, high_reg);
734 } else {
735 LoadValueDirectFixed(rl_arg, low_reg);
736 }
737 call_state = next_call_insn(cu_, info, call_state, target_method,
738 vtable_idx, direct_code, direct_method, type);
739 }
740 int outs_offset = (next_use + 1) * 4;
741 if (rl_arg.wide) {
742 StoreBaseDispWide(TargetReg(kSp), outs_offset, low_reg, high_reg);
743 next_use += 2;
744 } else {
745 StoreWordDisp(TargetReg(kSp), outs_offset, low_reg);
746 next_use++;
747 }
748 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
749 direct_code, direct_method, type);
750 }
751 }
752
753 call_state = LoadArgRegs(info, call_state, next_call_insn,
754 target_method, vtable_idx, direct_code, direct_method,
755 type, skip_this);
756
757 if (pcrLabel) {
Dave Allisonb373e092014-02-20 16:06:36 -0800758 *pcrLabel = GenNullCheck(TargetReg(kArg1), info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700759 }
760 return call_state;
761}
762
763/*
764 * May have 0+ arguments (also used for jumbo). Note that
765 * source virtual registers may be in physical registers, so may
766 * need to be flushed to home location before copying. This
767 * applies to arg3 and above (see below).
768 *
769 * Two general strategies:
770 * If < 20 arguments
771 * Pass args 3-18 using vldm/vstm block copy
772 * Pass arg0, arg1 & arg2 in kArg1-kArg3
773 * If 20+ arguments
774 * Pass args arg19+ using memcpy block copy
775 * Pass arg0, arg1 & arg2 in kArg1-kArg3
776 *
777 */
778int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state,
779 LIR** pcrLabel, NextCallInsn next_call_insn,
780 const MethodReference& target_method,
781 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700782 InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700783 // If we can treat it as non-range (Jumbo ops will use range form)
784 if (info->num_arg_words <= 5)
785 return GenDalvikArgsNoRange(info, call_state, pcrLabel,
786 next_call_insn, target_method, vtable_idx,
787 direct_code, direct_method, type, skip_this);
788 /*
789 * First load the non-register arguments. Both forms expect all
790 * of the source arguments to be in their home frame location, so
791 * scan the s_reg names and flush any that have been promoted to
792 * frame backing storage.
793 */
794 // Scan the rest of the args - if in phys_reg flush to memory
795 for (int next_arg = 0; next_arg < info->num_arg_words;) {
796 RegLocation loc = info->args[next_arg];
797 if (loc.wide) {
798 loc = UpdateLocWide(loc);
799 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
800 StoreBaseDispWide(TargetReg(kSp), SRegOffset(loc.s_reg_low),
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000801 loc.reg.GetReg(), loc.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700802 }
803 next_arg += 2;
804 } else {
805 loc = UpdateLoc(loc);
806 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
807 StoreBaseDisp(TargetReg(kSp), SRegOffset(loc.s_reg_low),
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000808 loc.reg.GetReg(), kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700809 }
810 next_arg++;
811 }
812 }
813
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800814 // Logic below assumes that Method pointer is at offset zero from SP.
815 DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0);
816
817 // The first 3 arguments are passed via registers.
818 // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either
819 // get size of uintptr_t or size of object reference according to model being used.
820 int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700821 int start_offset = SRegOffset(info->args[3].s_reg_low);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800822 int regs_left_to_pass_via_stack = info->num_arg_words - 3;
823 DCHECK_GT(regs_left_to_pass_via_stack, 0);
824
825 if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) {
826 // Use vldm/vstm pair using kArg3 as a temp
827 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
828 direct_code, direct_method, type);
829 OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), start_offset);
830 LIR* ld = OpVldm(TargetReg(kArg3), regs_left_to_pass_via_stack);
831 // TUNING: loosen barrier
832 ld->u.m.def_mask = ENCODE_ALL;
833 SetMemRefType(ld, true /* is_load */, kDalvikReg);
834 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
835 direct_code, direct_method, type);
836 OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), 4 /* Method* */ + (3 * 4));
837 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
838 direct_code, direct_method, type);
839 LIR* st = OpVstm(TargetReg(kArg3), regs_left_to_pass_via_stack);
840 SetMemRefType(st, false /* is_load */, kDalvikReg);
841 st->u.m.def_mask = ENCODE_ALL;
842 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
843 direct_code, direct_method, type);
844 } else if (cu_->instruction_set == kX86) {
845 int current_src_offset = start_offset;
846 int current_dest_offset = outs_offset;
847
848 while (regs_left_to_pass_via_stack > 0) {
849 // This is based on the knowledge that the stack itself is 16-byte aligned.
850 bool src_is_16b_aligned = (current_src_offset & 0xF) == 0;
851 bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0;
852 size_t bytes_to_move;
853
854 /*
855 * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a
856 * a 128-bit move because we won't get the chance to try to aligned. If there are more than
857 * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned.
858 * We do this because we could potentially do a smaller move to align.
859 */
860 if (regs_left_to_pass_via_stack == 4 ||
861 (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) {
862 // Moving 128-bits via xmm register.
863 bytes_to_move = sizeof(uint32_t) * 4;
864
865 // Allocate a free xmm temp. Since we are working through the calling sequence,
866 // we expect to have an xmm temporary available.
867 int temp = AllocTempDouble();
868 CHECK_GT(temp, 0);
869
870 LIR* ld1 = nullptr;
871 LIR* ld2 = nullptr;
872 LIR* st1 = nullptr;
873 LIR* st2 = nullptr;
874
875 /*
876 * The logic is similar for both loads and stores. If we have 16-byte alignment,
877 * do an aligned move. If we have 8-byte alignment, then do the move in two
878 * parts. This approach prevents possible cache line splits. Finally, fall back
879 * to doing an unaligned move. In most cases we likely won't split the cache
880 * line but we cannot prove it and thus take a conservative approach.
881 */
882 bool src_is_8b_aligned = (current_src_offset & 0x7) == 0;
883 bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0;
884
885 if (src_is_16b_aligned) {
886 ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovA128FP);
887 } else if (src_is_8b_aligned) {
888 ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovLo128FP);
889 ld2 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset + (bytes_to_move >> 1), kMovHi128FP);
890 } else {
891 ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovU128FP);
892 }
893
894 if (dest_is_16b_aligned) {
895 st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovA128FP);
896 } else if (dest_is_8b_aligned) {
897 st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovLo128FP);
898 st2 = OpMovMemReg(TargetReg(kSp), current_dest_offset + (bytes_to_move >> 1), temp, kMovHi128FP);
899 } else {
900 st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovU128FP);
901 }
902
903 // TODO If we could keep track of aliasing information for memory accesses that are wider
904 // than 64-bit, we wouldn't need to set up a barrier.
905 if (ld1 != nullptr) {
906 if (ld2 != nullptr) {
907 // For 64-bit load we can actually set up the aliasing information.
908 AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true);
909 AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true, true);
910 } else {
911 // Set barrier for 128-bit load.
912 SetMemRefType(ld1, true /* is_load */, kDalvikReg);
913 ld1->u.m.def_mask = ENCODE_ALL;
914 }
915 }
916 if (st1 != nullptr) {
917 if (st2 != nullptr) {
918 // For 64-bit store we can actually set up the aliasing information.
919 AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true);
920 AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false, true);
921 } else {
922 // Set barrier for 128-bit store.
923 SetMemRefType(st1, false /* is_load */, kDalvikReg);
924 st1->u.m.def_mask = ENCODE_ALL;
925 }
926 }
927
928 // Free the temporary used for the data movement.
929 FreeTemp(temp);
930 } else {
931 // Moving 32-bits via general purpose register.
932 bytes_to_move = sizeof(uint32_t);
933
934 // Instead of allocating a new temp, simply reuse one of the registers being used
935 // for argument passing.
936 int temp = TargetReg(kArg3);
937
938 // Now load the argument VR and store to the outs.
939 LoadWordDisp(TargetReg(kSp), current_src_offset, temp);
940 StoreWordDisp(TargetReg(kSp), current_dest_offset, temp);
941 }
942
943 current_src_offset += bytes_to_move;
944 current_dest_offset += bytes_to_move;
945 regs_left_to_pass_via_stack -= (bytes_to_move >> 2);
946 }
947 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700948 // Generate memcpy
949 OpRegRegImm(kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset);
950 OpRegRegImm(kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset);
Ian Rogers7655f292013-07-29 11:07:13 -0700951 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(pMemcpy), TargetReg(kArg0),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700952 TargetReg(kArg1), (info->num_arg_words - 3) * 4, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700953 }
954
955 call_state = LoadArgRegs(info, call_state, next_call_insn,
956 target_method, vtable_idx, direct_code, direct_method,
957 type, skip_this);
958
959 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
960 direct_code, direct_method, type);
961 if (pcrLabel) {
Dave Allisonb373e092014-02-20 16:06:36 -0800962 *pcrLabel = GenNullCheck(TargetReg(kArg1), info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700963 }
964 return call_state;
965}
966
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700967RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700968 RegLocation res;
969 if (info->result.location == kLocInvalid) {
970 res = GetReturn(false);
971 } else {
972 res = info->result;
973 }
974 return res;
975}
976
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700977RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700978 RegLocation res;
979 if (info->result.location == kLocInvalid) {
980 res = GetReturnWide(false);
981 } else {
982 res = info->result;
983 }
984 return res;
985}
986
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700987bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700988 if (cu_->instruction_set == kMips) {
989 // TODO - add Mips implementation
990 return false;
991 }
992 // Location of reference to data array
993 int value_offset = mirror::String::ValueOffset().Int32Value();
994 // Location of count
995 int count_offset = mirror::String::CountOffset().Int32Value();
996 // Starting offset within data array
997 int offset_offset = mirror::String::OffsetOffset().Int32Value();
998 // Start of char data with array_
999 int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value();
1000
1001 RegLocation rl_obj = info->args[0];
1002 RegLocation rl_idx = info->args[1];
1003 rl_obj = LoadValue(rl_obj, kCoreReg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001004 // X86 wants to avoid putting a constant index into a register.
1005 if (!(cu_->instruction_set == kX86 && rl_idx.is_const)) {
1006 rl_idx = LoadValue(rl_idx, kCoreReg);
1007 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001008 int reg_max;
Dave Allisonb373e092014-02-20 16:06:36 -08001009 GenNullCheck(rl_obj.reg.GetReg(), info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001010 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001011 LIR* range_check_branch = nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001012 int reg_off = INVALID_REG;
1013 int reg_ptr = INVALID_REG;
1014 if (cu_->instruction_set != kX86) {
1015 reg_off = AllocTemp();
1016 reg_ptr = AllocTemp();
1017 if (range_check) {
1018 reg_max = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001019 LoadWordDisp(rl_obj.reg.GetReg(), count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -08001020 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001021 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001022 LoadWordDisp(rl_obj.reg.GetReg(), offset_offset, reg_off);
Dave Allisonb373e092014-02-20 16:06:36 -08001023 MarkPossibleNullPointerException(info->opt_flags);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001024 LoadWordDisp(rl_obj.reg.GetReg(), value_offset, reg_ptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001025 if (range_check) {
1026 // Set up a launch pad to allow retry in case of bounds violation */
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001027 OpRegReg(kOpCmp, rl_idx.reg.GetReg(), reg_max);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001028 FreeTemp(reg_max);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001029 range_check_branch = OpCondBranch(kCondUge, nullptr);
Brian Carlstrom6f485c62013-07-18 15:35:35 -07001030 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001031 OpRegImm(kOpAdd, reg_ptr, data_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001032 } else {
1033 if (range_check) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001034 // On x86, we can compare to memory directly
Brian Carlstrom7940e442013-07-12 13:46:57 -07001035 // Set up a launch pad to allow retry in case of bounds violation */
Mark Mendell2b724cb2014-02-06 05:24:20 -08001036 if (rl_idx.is_const) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001037 range_check_branch = OpCmpMemImmBranch(
1038 kCondUlt, INVALID_REG, rl_obj.reg.GetReg(), count_offset,
1039 mir_graph_->ConstantValue(rl_idx.orig_sreg), nullptr);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001040 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001041 OpRegMem(kOpCmp, rl_idx.reg.GetReg(), rl_obj.reg.GetReg(), count_offset);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001042 range_check_branch = OpCondBranch(kCondUge, nullptr);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001043 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001044 }
1045 reg_off = AllocTemp();
1046 reg_ptr = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001047 LoadWordDisp(rl_obj.reg.GetReg(), offset_offset, reg_off);
1048 LoadWordDisp(rl_obj.reg.GetReg(), value_offset, reg_ptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001049 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001050 if (rl_idx.is_const) {
1051 OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg));
1052 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001053 OpRegReg(kOpAdd, reg_off, rl_idx.reg.GetReg());
Mark Mendell2b724cb2014-02-06 05:24:20 -08001054 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001055 FreeTemp(rl_obj.reg.GetReg());
1056 if (rl_idx.location == kLocPhysReg) {
1057 FreeTemp(rl_idx.reg.GetReg());
Mark Mendell2b724cb2014-02-06 05:24:20 -08001058 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001059 RegLocation rl_dest = InlineTarget(info);
1060 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001061 if (cu_->instruction_set != kX86) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001062 LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg.GetReg(), 1, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001063 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001064 LoadBaseIndexedDisp(reg_ptr, reg_off, 1, data_offset, rl_result.reg.GetReg(),
Mark Mendell2b724cb2014-02-06 05:24:20 -08001065 INVALID_REG, kUnsignedHalf, INVALID_SREG);
1066 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001067 FreeTemp(reg_off);
1068 FreeTemp(reg_ptr);
1069 StoreValue(rl_dest, rl_result);
1070 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001071 DCHECK(range_check_branch != nullptr);
1072 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
1073 AddIntrinsicLaunchpad(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001074 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001075 return true;
1076}
1077
1078// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001079bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001080 if (cu_->instruction_set == kMips) {
1081 // TODO - add Mips implementation
1082 return false;
1083 }
1084 // dst = src.length();
1085 RegLocation rl_obj = info->args[0];
1086 rl_obj = LoadValue(rl_obj, kCoreReg);
1087 RegLocation rl_dest = InlineTarget(info);
1088 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Dave Allisonb373e092014-02-20 16:06:36 -08001089 GenNullCheck(rl_obj.reg.GetReg(), info->opt_flags);
1090 LoadWordDisp(rl_obj.reg.GetReg(), mirror::String::CountOffset().Int32Value(),
1091 rl_result.reg.GetReg());
1092 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001093 if (is_empty) {
1094 // dst = (dst == 0);
1095 if (cu_->instruction_set == kThumb2) {
1096 int t_reg = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001097 OpRegReg(kOpNeg, t_reg, rl_result.reg.GetReg());
1098 OpRegRegReg(kOpAdc, rl_result.reg.GetReg(), rl_result.reg.GetReg(), t_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001099 } else {
1100 DCHECK_EQ(cu_->instruction_set, kX86);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001101 OpRegImm(kOpSub, rl_result.reg.GetReg(), 1);
1102 OpRegImm(kOpLsr, rl_result.reg.GetReg(), 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001103 }
1104 }
1105 StoreValue(rl_dest, rl_result);
1106 return true;
1107}
1108
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001109bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
1110 if (cu_->instruction_set == kMips) {
1111 // TODO - add Mips implementation
1112 return false;
1113 }
1114 RegLocation rl_src_i = info->args[0];
Mark Mendell55d0eac2014-02-06 11:02:52 -08001115 RegLocation rl_dest = (size == kLong) ? InlineTargetWide(info) : InlineTarget(info); // result reg
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001116 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1117 if (size == kLong) {
1118 RegLocation rl_i = LoadValueWide(rl_src_i, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001119 int r_i_low = rl_i.reg.GetReg();
1120 if (rl_i.reg.GetReg() == rl_result.reg.GetReg()) {
1121 // 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 +00001122 r_i_low = AllocTemp();
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001123 OpRegCopy(r_i_low, rl_i.reg.GetReg());
Vladimir Markof246af22013-11-27 12:30:15 +00001124 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001125 OpRegReg(kOpRev, rl_result.reg.GetReg(), rl_i.reg.GetHighReg());
1126 OpRegReg(kOpRev, rl_result.reg.GetHighReg(), r_i_low);
1127 if (rl_i.reg.GetReg() == rl_result.reg.GetReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001128 FreeTemp(r_i_low);
1129 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001130 StoreValueWide(rl_dest, rl_result);
1131 } else {
1132 DCHECK(size == kWord || size == kSignedHalf);
1133 OpKind op = (size == kWord) ? kOpRev : kOpRevsh;
1134 RegLocation rl_i = LoadValue(rl_src_i, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001135 OpRegReg(op, rl_result.reg.GetReg(), rl_i.reg.GetReg());
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001136 StoreValue(rl_dest, rl_result);
1137 }
1138 return true;
1139}
1140
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001141bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001142 if (cu_->instruction_set == kMips) {
1143 // TODO - add Mips implementation
1144 return false;
1145 }
1146 RegLocation rl_src = info->args[0];
1147 rl_src = LoadValue(rl_src, kCoreReg);
1148 RegLocation rl_dest = InlineTarget(info);
1149 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1150 int sign_reg = AllocTemp();
1151 // abs(x) = y<=x>>31, (x+y)^y.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001152 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetReg(), 31);
1153 OpRegRegReg(kOpAdd, rl_result.reg.GetReg(), rl_src.reg.GetReg(), sign_reg);
1154 OpRegReg(kOpXor, rl_result.reg.GetReg(), sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001155 StoreValue(rl_dest, rl_result);
1156 return true;
1157}
1158
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001159bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001160 if (cu_->instruction_set == kMips) {
1161 // TODO - add Mips implementation
1162 return false;
1163 }
1164 if (cu_->instruction_set == kThumb2) {
1165 RegLocation rl_src = info->args[0];
1166 rl_src = LoadValueWide(rl_src, kCoreReg);
1167 RegLocation rl_dest = InlineTargetWide(info);
1168 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1169 int sign_reg = AllocTemp();
1170 // abs(x) = y<=x>>31, (x+y)^y.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001171 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHighReg(), 31);
1172 OpRegRegReg(kOpAdd, rl_result.reg.GetReg(), rl_src.reg.GetReg(), sign_reg);
1173 OpRegRegReg(kOpAdc, rl_result.reg.GetHighReg(), rl_src.reg.GetHighReg(), sign_reg);
1174 OpRegReg(kOpXor, rl_result.reg.GetReg(), sign_reg);
1175 OpRegReg(kOpXor, rl_result.reg.GetHighReg(), sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001176 StoreValueWide(rl_dest, rl_result);
1177 return true;
1178 } else {
1179 DCHECK_EQ(cu_->instruction_set, kX86);
1180 // Reuse source registers to avoid running out of temps
1181 RegLocation rl_src = info->args[0];
1182 rl_src = LoadValueWide(rl_src, kCoreReg);
1183 RegLocation rl_dest = InlineTargetWide(info);
1184 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001185 OpRegCopyWide(rl_result.reg.GetReg(), rl_result.reg.GetHighReg(), rl_src.reg.GetReg(), rl_src.reg.GetHighReg());
1186 FreeTemp(rl_src.reg.GetReg());
1187 FreeTemp(rl_src.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001188 int sign_reg = AllocTemp();
1189 // abs(x) = y<=x>>31, (x+y)^y.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001190 OpRegRegImm(kOpAsr, sign_reg, rl_result.reg.GetHighReg(), 31);
1191 OpRegReg(kOpAdd, rl_result.reg.GetReg(), sign_reg);
1192 OpRegReg(kOpAdc, rl_result.reg.GetHighReg(), sign_reg);
1193 OpRegReg(kOpXor, rl_result.reg.GetReg(), sign_reg);
1194 OpRegReg(kOpXor, rl_result.reg.GetHighReg(), sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001195 StoreValueWide(rl_dest, rl_result);
1196 return true;
1197 }
1198}
1199
Yixin Shoudbb17e32014-02-07 05:09:30 -08001200bool Mir2Lir::GenInlinedAbsFloat(CallInfo* info) {
1201 if (cu_->instruction_set == kMips) {
1202 // TODO - add Mips implementation
1203 return false;
1204 }
1205 RegLocation rl_src = info->args[0];
1206 rl_src = LoadValue(rl_src, kCoreReg);
1207 RegLocation rl_dest = InlineTarget(info);
1208 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1209 int signMask = AllocTemp();
1210 LoadConstant(signMask, 0x7fffffff);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001211 OpRegRegReg(kOpAnd, rl_result.reg.GetReg(), rl_src.reg.GetReg(), signMask);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001212 FreeTemp(signMask);
1213 StoreValue(rl_dest, rl_result);
1214 return true;
1215}
1216
1217bool Mir2Lir::GenInlinedAbsDouble(CallInfo* info) {
1218 if (cu_->instruction_set == kMips) {
1219 // TODO - add Mips implementation
1220 return false;
1221 }
1222 RegLocation rl_src = info->args[0];
1223 rl_src = LoadValueWide(rl_src, kCoreReg);
1224 RegLocation rl_dest = InlineTargetWide(info);
1225 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001226 OpRegCopyWide(rl_result.reg.GetReg(), rl_result.reg.GetHighReg(), rl_src.reg.GetReg(), rl_src.reg.GetHighReg());
1227 FreeTemp(rl_src.reg.GetReg());
1228 FreeTemp(rl_src.reg.GetHighReg());
Yixin Shoudbb17e32014-02-07 05:09:30 -08001229 int signMask = AllocTemp();
1230 LoadConstant(signMask, 0x7fffffff);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001231 OpRegReg(kOpAnd, rl_result.reg.GetHighReg(), signMask);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001232 FreeTemp(signMask);
1233 StoreValueWide(rl_dest, rl_result);
1234 return true;
1235}
1236
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001237bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001238 if (cu_->instruction_set == kMips) {
1239 // TODO - add Mips implementation
1240 return false;
1241 }
1242 RegLocation rl_src = info->args[0];
1243 RegLocation rl_dest = InlineTarget(info);
1244 StoreValue(rl_dest, rl_src);
1245 return true;
1246}
1247
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001248bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001249 if (cu_->instruction_set == kMips) {
1250 // TODO - add Mips implementation
1251 return false;
1252 }
1253 RegLocation rl_src = info->args[0];
1254 RegLocation rl_dest = InlineTargetWide(info);
1255 StoreValueWide(rl_dest, rl_src);
1256 return true;
1257}
1258
1259/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001260 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001261 * otherwise bails to standard library code.
1262 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001263bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001264 if (cu_->instruction_set == kMips) {
1265 // TODO - add Mips implementation
1266 return false;
1267 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001268 RegLocation rl_obj = info->args[0];
1269 RegLocation rl_char = info->args[1];
1270 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1271 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1272 return false;
1273 }
1274
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001275 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001276 LockCallTemps(); // Using fixed registers
1277 int reg_ptr = TargetReg(kArg0);
1278 int reg_char = TargetReg(kArg1);
1279 int reg_start = TargetReg(kArg2);
1280
Brian Carlstrom7940e442013-07-12 13:46:57 -07001281 LoadValueDirectFixed(rl_obj, reg_ptr);
1282 LoadValueDirectFixed(rl_char, reg_char);
1283 if (zero_based) {
1284 LoadConstant(reg_start, 0);
1285 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001286 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001287 LoadValueDirectFixed(rl_start, reg_start);
1288 }
Mark Mendell4028a6c2014-02-19 20:06:20 -08001289 int r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(pIndexOf));
Dave Allisonb373e092014-02-20 16:06:36 -08001290 GenNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001291 LIR* high_code_point_branch =
1292 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001293 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001294 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001295 if (!rl_char.is_const) {
1296 // Add the slow path for code points beyond 0xFFFF.
1297 DCHECK(high_code_point_branch != nullptr);
1298 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1299 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
1300 AddIntrinsicLaunchpad(info, high_code_point_branch, resume_tgt);
1301 } else {
1302 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1303 DCHECK(high_code_point_branch == nullptr);
1304 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001305 RegLocation rl_return = GetReturn(false);
1306 RegLocation rl_dest = InlineTarget(info);
1307 StoreValue(rl_dest, rl_return);
1308 return true;
1309}
1310
1311/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001312bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001313 if (cu_->instruction_set == kMips) {
1314 // TODO - add Mips implementation
1315 return false;
1316 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001317 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001318 LockCallTemps(); // Using fixed registers
1319 int reg_this = TargetReg(kArg0);
1320 int reg_cmp = TargetReg(kArg1);
1321
1322 RegLocation rl_this = info->args[0];
1323 RegLocation rl_cmp = info->args[1];
1324 LoadValueDirectFixed(rl_this, reg_this);
1325 LoadValueDirectFixed(rl_cmp, reg_cmp);
1326 int r_tgt = (cu_->instruction_set != kX86) ?
Ian Rogers7655f292013-07-29 11:07:13 -07001327 LoadHelper(QUICK_ENTRYPOINT_OFFSET(pStringCompareTo)) : 0;
Dave Allisonb373e092014-02-20 16:06:36 -08001328 GenNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001329 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001330 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001331 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
1332 AddIntrinsicLaunchpad(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001333 // NOTE: not a safepoint
1334 if (cu_->instruction_set != kX86) {
1335 OpReg(kOpBlx, r_tgt);
1336 } else {
Ian Rogers7655f292013-07-29 11:07:13 -07001337 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(pStringCompareTo));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001338 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001339 RegLocation rl_return = GetReturn(false);
1340 RegLocation rl_dest = InlineTarget(info);
1341 StoreValue(rl_dest, rl_return);
1342 return true;
1343}
1344
1345bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1346 RegLocation rl_dest = InlineTarget(info);
1347 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Ian Rogers848871b2013-08-05 10:56:33 -07001348 ThreadOffset offset = Thread::PeerOffset();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001349 if (cu_->instruction_set == kThumb2 || cu_->instruction_set == kMips) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001350 LoadWordDisp(TargetReg(kSelf), offset.Int32Value(), rl_result.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001351 } else {
1352 CHECK(cu_->instruction_set == kX86);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001353 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg.GetReg(), offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001354 }
1355 StoreValue(rl_dest, rl_result);
1356 return true;
1357}
1358
1359bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
1360 bool is_long, bool is_volatile) {
1361 if (cu_->instruction_set == kMips) {
1362 // TODO - add Mips implementation
1363 return false;
1364 }
1365 // Unused - RegLocation rl_src_unsafe = info->args[0];
1366 RegLocation rl_src_obj = info->args[1]; // Object
1367 RegLocation rl_src_offset = info->args[2]; // long low
1368 rl_src_offset.wide = 0; // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001369 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Brian Carlstrom7940e442013-07-12 13:46:57 -07001370 if (is_volatile) {
1371 GenMemBarrier(kLoadLoad);
1372 }
1373 RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg);
1374 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1375 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1376 if (is_long) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001377 OpRegReg(kOpAdd, rl_object.reg.GetReg(), rl_offset.reg.GetReg());
1378 LoadBaseDispWide(rl_object.reg.GetReg(), 0, rl_result.reg.GetReg(), rl_result.reg.GetHighReg(), INVALID_SREG);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001379 StoreValueWide(rl_dest, rl_result);
1380 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001381 LoadBaseIndexed(rl_object.reg.GetReg(), rl_offset.reg.GetReg(), rl_result.reg.GetReg(), 0, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001382 StoreValue(rl_dest, rl_result);
1383 }
1384 return true;
1385}
1386
1387bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1388 bool is_object, bool is_volatile, bool is_ordered) {
1389 if (cu_->instruction_set == kMips) {
1390 // TODO - add Mips implementation
1391 return false;
1392 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001393 // Unused - RegLocation rl_src_unsafe = info->args[0];
1394 RegLocation rl_src_obj = info->args[1]; // Object
1395 RegLocation rl_src_offset = info->args[2]; // long low
1396 rl_src_offset.wide = 0; // ignore high half in info->args[3]
1397 RegLocation rl_src_value = info->args[4]; // value to store
1398 if (is_volatile || is_ordered) {
1399 GenMemBarrier(kStoreStore);
1400 }
1401 RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg);
1402 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1403 RegLocation rl_value;
1404 if (is_long) {
1405 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001406 OpRegReg(kOpAdd, rl_object.reg.GetReg(), rl_offset.reg.GetReg());
1407 StoreBaseDispWide(rl_object.reg.GetReg(), 0, rl_value.reg.GetReg(), rl_value.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001408 } else {
1409 rl_value = LoadValue(rl_src_value, kCoreReg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001410 StoreBaseIndexed(rl_object.reg.GetReg(), rl_offset.reg.GetReg(), rl_value.reg.GetReg(), 0, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001411 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001412
1413 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001414 FreeTemp(rl_offset.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001415 if (is_volatile) {
1416 GenMemBarrier(kStoreLoad);
1417 }
1418 if (is_object) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001419 MarkGCCard(rl_value.reg.GetReg(), rl_object.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001420 }
1421 return true;
1422}
1423
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001424void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001425 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
1426 if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file)
1427 ->GenIntrinsic(this, info)) {
1428 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001429 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001430 GenInvokeNoInline(info);
1431}
1432
1433void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001434 int call_state = 0;
1435 LIR* null_ck;
1436 LIR** p_null_ck = NULL;
1437 NextCallInsn next_call_insn;
1438 FlushAllRegs(); /* Everything to home location */
1439 // Explicit register usage
1440 LockCallTemps();
1441
Vladimir Markof096aad2014-01-23 15:51:58 +00001442 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
1443 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
1444 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
1445 info->type = static_cast<InvokeType>(method_info.GetSharpType());
1446 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001447 bool skip_this;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001448 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001449 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001450 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001451 } else if (info->type == kDirect) {
1452 if (fast_path) {
1453 p_null_ck = &null_ck;
1454 }
1455 next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP;
1456 skip_this = false;
1457 } else if (info->type == kStatic) {
1458 next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP;
1459 skip_this = false;
1460 } else if (info->type == kSuper) {
1461 DCHECK(!fast_path); // Fast path is a direct call.
1462 next_call_insn = NextSuperCallInsnSP;
1463 skip_this = false;
1464 } else {
1465 DCHECK_EQ(info->type, kVirtual);
1466 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1467 skip_this = fast_path;
1468 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001469 MethodReference target_method = method_info.GetTargetMethod();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001470 if (!info->is_range) {
1471 call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001472 next_call_insn, target_method, method_info.VTableIndex(),
1473 method_info.DirectCode(), method_info.DirectMethod(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001474 original_type, skip_this);
1475 } else {
1476 call_state = GenDalvikArgsRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001477 next_call_insn, target_method, method_info.VTableIndex(),
1478 method_info.DirectCode(), method_info.DirectMethod(),
1479 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001480 }
1481 // Finish up any of the call sequence not interleaved in arg loading
1482 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001483 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
1484 method_info.DirectCode(), method_info.DirectMethod(), original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001485 }
1486 LIR* call_inst;
1487 if (cu_->instruction_set != kX86) {
1488 call_inst = OpReg(kOpBlx, TargetReg(kInvokeTgt));
1489 } else {
Jeff Hao88474b42013-10-23 16:24:40 -07001490 if (fast_path) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001491 if (method_info.DirectCode() == static_cast<uintptr_t>(-1)) {
Mark Mendell55d0eac2014-02-06 11:02:52 -08001492 // We can have the linker fixup a call relative.
1493 call_inst =
Jeff Hao49161ce2014-03-12 11:05:25 -07001494 reinterpret_cast<X86Mir2Lir*>(this)->CallWithLinkerFixup(target_method, info->type);
Mark Mendell55d0eac2014-02-06 11:02:52 -08001495 } else {
1496 call_inst = OpMem(kOpBlx, TargetReg(kArg0),
1497 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
1498 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001499 } else {
Ian Rogers848871b2013-08-05 10:56:33 -07001500 ThreadOffset trampoline(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001501 switch (info->type) {
1502 case kInterface:
Jeff Hao88474b42013-10-23 16:24:40 -07001503 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001504 break;
1505 case kDirect:
Ian Rogers7655f292013-07-29 11:07:13 -07001506 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001507 break;
1508 case kStatic:
Ian Rogers7655f292013-07-29 11:07:13 -07001509 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001510 break;
1511 case kSuper:
Ian Rogers7655f292013-07-29 11:07:13 -07001512 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001513 break;
1514 case kVirtual:
Ian Rogers7655f292013-07-29 11:07:13 -07001515 trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001516 break;
1517 default:
1518 LOG(FATAL) << "Unexpected invoke type";
1519 }
1520 call_inst = OpThreadMem(kOpBlx, trampoline);
1521 }
1522 }
1523 MarkSafepointPC(call_inst);
1524
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001525 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001526 if (info->result.location != kLocInvalid) {
1527 // We have a following MOVE_RESULT - do it now.
1528 if (info->result.wide) {
1529 RegLocation ret_loc = GetReturnWide(info->result.fp);
1530 StoreValueWide(info->result, ret_loc);
1531 } else {
1532 RegLocation ret_loc = GetReturn(info->result.fp);
1533 StoreValue(info->result, ret_loc);
1534 }
1535 }
1536}
1537
1538} // namespace art