blob: ebc1a986ca2f80a37f28557ccd628a3ab73baa53 [file] [log] [blame]
buzbee31a4a6f2012-02-28 15:36:15 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogers57b86d42012-03-27 16:05:41 -070017#include "oat/runtime/oat_support_entrypoints.h"
buzbee1bc37c62012-11-20 13:35:41 -080018#include "../compiler_ir.h"
19#include "ralloc_util.h"
20#include "codegen_util.h"
Ian Rogers07ec8e12012-12-01 01:26:51 -080021#include "x86/codegen_x86.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070022
buzbee31a4a6f2012-02-28 15:36:15 -080023namespace art {
24
25/*
26 * This source files contains "gen" codegen routines that should
27 * be applicable to most targets. Only mid-level support utilities
28 * and "op" calls may be used here.
29 */
30
buzbee31a4a6f2012-02-28 15:36:15 -080031/*
buzbee02031b12012-11-23 09:41:35 -080032 * To save scheduling time, helper calls are broken into two parts: generation of
33 * the helper target address, and the actuall call to the helper. Because x86
34 * has a memory call operation, part 1 is a NOP for x86. For other targets,
35 * load arguments between the two parts.
36 */
37int Codegen::CallHelperSetup(CompilationUnit* cu, int helper_offset)
38{
39 return (cu->instruction_set == kX86) ? 0 : LoadHelper(cu, helper_offset);
40}
41
42/* NOTE: if r_tgt is a temp, it will be freed following use */
43LIR* Codegen::CallHelper(CompilationUnit* cu, int r_tgt, int helper_offset, bool safepoint_pc)
44{
45 LIR* call_inst;
46 if (cu->instruction_set == kX86) {
47 call_inst = OpThreadMem(cu, kOpBlx, helper_offset);
48 } else {
49 call_inst = OpReg(cu, kOpBlx, r_tgt);
50 FreeTemp(cu, r_tgt);
51 }
52 if (safepoint_pc) {
53 MarkSafepointPC(cu, call_inst);
54 }
55 return call_inst;
56}
57
58void Codegen::CallRuntimeHelperImm(CompilationUnit* cu, int helper_offset, int arg0,
59 bool safepoint_pc) {
60 int r_tgt = CallHelperSetup(cu, helper_offset);
61 LoadConstant(cu, TargetReg(kArg0), arg0);
62 ClobberCalleeSave(cu);
63 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
64}
65
66void Codegen::CallRuntimeHelperReg(CompilationUnit* cu, int helper_offset, int arg0,
67 bool safepoint_pc) {
68 int r_tgt = CallHelperSetup(cu, helper_offset);
69 OpRegCopy(cu, TargetReg(kArg0), arg0);
70 ClobberCalleeSave(cu);
71 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
72}
73
74void Codegen::CallRuntimeHelperRegLocation(CompilationUnit* cu, int helper_offset, RegLocation arg0,
75 bool safepoint_pc) {
76 int r_tgt = CallHelperSetup(cu, helper_offset);
77 if (arg0.wide == 0) {
78 LoadValueDirectFixed(cu, arg0, TargetReg(kArg0));
79 } else {
80 LoadValueDirectWideFixed(cu, arg0, TargetReg(kArg0), TargetReg(kArg1));
81 }
82 ClobberCalleeSave(cu);
83 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
84}
85
86void Codegen::CallRuntimeHelperImmImm(CompilationUnit* cu, int helper_offset, int arg0, int arg1,
87 bool safepoint_pc) {
88 int r_tgt = CallHelperSetup(cu, helper_offset);
89 LoadConstant(cu, TargetReg(kArg0), arg0);
90 LoadConstant(cu, TargetReg(kArg1), arg1);
91 ClobberCalleeSave(cu);
92 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
93}
94
95void Codegen::CallRuntimeHelperImmRegLocation(CompilationUnit* cu, int helper_offset, int arg0,
96 RegLocation arg1, bool safepoint_pc) {
97 int r_tgt = CallHelperSetup(cu, helper_offset);
98 if (arg1.wide == 0) {
99 LoadValueDirectFixed(cu, arg1, TargetReg(kArg1));
100 } else {
101 LoadValueDirectWideFixed(cu, arg1, TargetReg(kArg1), TargetReg(kArg2));
102 }
103 LoadConstant(cu, TargetReg(kArg0), arg0);
104 ClobberCalleeSave(cu);
105 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
106}
107
108void Codegen::CallRuntimeHelperRegLocationImm(CompilationUnit* cu, int helper_offset,
109 RegLocation arg0, int arg1, bool safepoint_pc) {
110 int r_tgt = CallHelperSetup(cu, helper_offset);
111 LoadValueDirectFixed(cu, arg0, TargetReg(kArg0));
112 LoadConstant(cu, TargetReg(kArg1), arg1);
113 ClobberCalleeSave(cu);
114 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
115}
116
117void Codegen::CallRuntimeHelperImmReg(CompilationUnit* cu, int helper_offset, int arg0, int arg1,
118 bool safepoint_pc) {
119 int r_tgt = CallHelperSetup(cu, helper_offset);
120 OpRegCopy(cu, TargetReg(kArg1), arg1);
121 LoadConstant(cu, TargetReg(kArg0), arg0);
122 ClobberCalleeSave(cu);
123 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
124}
125
126void Codegen::CallRuntimeHelperRegImm(CompilationUnit* cu, int helper_offset, int arg0, int arg1,
127 bool safepoint_pc) {
128 int r_tgt = CallHelperSetup(cu, helper_offset);
129 OpRegCopy(cu, TargetReg(kArg0), arg0);
130 LoadConstant(cu, TargetReg(kArg1), arg1);
131 ClobberCalleeSave(cu);
132 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
133}
134
135void Codegen::CallRuntimeHelperImmMethod(CompilationUnit* cu, int helper_offset, int arg0,
136 bool safepoint_pc) {
137 int r_tgt = CallHelperSetup(cu, helper_offset);
138 LoadCurrMethodDirect(cu, TargetReg(kArg1));
139 LoadConstant(cu, TargetReg(kArg0), arg0);
140 ClobberCalleeSave(cu);
141 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
142}
143
144void Codegen::CallRuntimeHelperRegLocationRegLocation(CompilationUnit* cu, int helper_offset,
145 RegLocation arg0, RegLocation arg1,
146 bool safepoint_pc) {
147 int r_tgt = CallHelperSetup(cu, helper_offset);
148 if (arg0.wide == 0) {
149 LoadValueDirectFixed(cu, arg0, arg0.fp ? TargetReg(kFArg0) : TargetReg(kArg0));
150 if (arg1.wide == 0) {
151 if (cu->instruction_set == kMips) {
152 LoadValueDirectFixed(cu, arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg1));
153 } else {
154 LoadValueDirectFixed(cu, arg1, TargetReg(kArg1));
155 }
156 } else {
157 if (cu->instruction_set == kMips) {
158 LoadValueDirectWideFixed(cu, arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg1), arg1.fp ? TargetReg(kFArg3) : TargetReg(kArg2));
159 } else {
160 LoadValueDirectWideFixed(cu, arg1, TargetReg(kArg1), TargetReg(kArg2));
161 }
162 }
163 } else {
164 LoadValueDirectWideFixed(cu, arg0, arg0.fp ? TargetReg(kFArg0) : TargetReg(kArg0), arg0.fp ? TargetReg(kFArg1) : TargetReg(kArg1));
165 if (arg1.wide == 0) {
166 LoadValueDirectFixed(cu, arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg2));
167 } else {
168 LoadValueDirectWideFixed(cu, arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg2), arg1.fp ? TargetReg(kFArg3) : TargetReg(kArg3));
169 }
170 }
171 ClobberCalleeSave(cu);
172 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
173}
174
175void Codegen::CallRuntimeHelperRegReg(CompilationUnit* cu, int helper_offset, int arg0, int arg1,
176 bool safepoint_pc) {
177 int r_tgt = CallHelperSetup(cu, helper_offset);
178 DCHECK_NE(TargetReg(kArg0), arg1); // check copy into arg0 won't clobber arg1
179 OpRegCopy(cu, TargetReg(kArg0), arg0);
180 OpRegCopy(cu, TargetReg(kArg1), arg1);
181 ClobberCalleeSave(cu);
182 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
183}
184
185void Codegen::CallRuntimeHelperRegRegImm(CompilationUnit* cu, int helper_offset, int arg0, int arg1,
186 int arg2, bool safepoint_pc) {
187 int r_tgt = CallHelperSetup(cu, helper_offset);
188 DCHECK_NE(TargetReg(kArg0), arg1); // check copy into arg0 won't clobber arg1
189 OpRegCopy(cu, TargetReg(kArg0), arg0);
190 OpRegCopy(cu, TargetReg(kArg1), arg1);
191 LoadConstant(cu, TargetReg(kArg2), arg2);
192 ClobberCalleeSave(cu);
193 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
194}
195
196void Codegen::CallRuntimeHelperImmMethodRegLocation(CompilationUnit* cu, int helper_offset,
197 int arg0, RegLocation arg2, bool safepoint_pc) {
198 int r_tgt = CallHelperSetup(cu, helper_offset);
199 LoadValueDirectFixed(cu, arg2, TargetReg(kArg2));
200 LoadCurrMethodDirect(cu, TargetReg(kArg1));
201 LoadConstant(cu, TargetReg(kArg0), arg0);
202 ClobberCalleeSave(cu);
203 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
204}
205
206void Codegen::CallRuntimeHelperImmMethodImm(CompilationUnit* cu, int helper_offset, int arg0,
207 int arg2, bool safepoint_pc) {
208 int r_tgt = CallHelperSetup(cu, helper_offset);
209 LoadCurrMethodDirect(cu, TargetReg(kArg1));
210 LoadConstant(cu, TargetReg(kArg2), arg2);
211 LoadConstant(cu, TargetReg(kArg0), arg0);
212 ClobberCalleeSave(cu);
213 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
214}
215
216void Codegen::CallRuntimeHelperImmRegLocationRegLocation(CompilationUnit* cu, int helper_offset,
217 int arg0, RegLocation arg1,
218 RegLocation arg2, bool safepoint_pc) {
219 int r_tgt = CallHelperSetup(cu, helper_offset);
220 LoadValueDirectFixed(cu, arg1, TargetReg(kArg1));
221 if (arg2.wide == 0) {
222 LoadValueDirectFixed(cu, arg2, TargetReg(kArg2));
223 } else {
224 LoadValueDirectWideFixed(cu, arg2, TargetReg(kArg2), TargetReg(kArg3));
225 }
226 LoadConstant(cu, TargetReg(kArg0), arg0);
227 ClobberCalleeSave(cu);
228 CallHelper(cu, r_tgt, helper_offset, safepoint_pc);
229}
230
231/*
buzbee31a4a6f2012-02-28 15:36:15 -0800232 * If there are any ins passed in registers that have not been promoted
233 * to a callee-save register, flush them to the frame. Perform intial
234 * assignment of promoted arguments.
buzbeead8f15e2012-06-18 14:49:45 -0700235 *
buzbee52a77fc2012-11-20 19:50:46 -0800236 * ArgLocs is an array of location records describing the incoming arguments
buzbeead8f15e2012-06-18 14:49:45 -0700237 * with one location record per word of argument.
buzbee31a4a6f2012-02-28 15:36:15 -0800238 */
buzbee02031b12012-11-23 09:41:35 -0800239void Codegen::FlushIns(CompilationUnit* cu, RegLocation* ArgLocs, RegLocation rl_method)
buzbee31a4a6f2012-02-28 15:36:15 -0800240{
Bill Buzbeea114add2012-05-03 15:00:40 -0700241 /*
242 * Dummy up a RegLocation for the incoming Method*
buzbeef0504cd2012-11-13 16:31:10 -0800243 * It will attempt to keep kArg0 live (or copy it to home location
Bill Buzbeea114add2012-05-03 15:00:40 -0700244 * if promoted).
245 */
buzbeefa57c472012-11-21 12:06:18 -0800246 RegLocation rl_src = rl_method;
247 rl_src.location = kLocPhysReg;
248 rl_src.low_reg = TargetReg(kArg0);
249 rl_src.home = false;
250 MarkLive(cu, rl_src.low_reg, rl_src.s_reg_low);
251 StoreValue(cu, rl_method, rl_src);
Bill Buzbeea114add2012-05-03 15:00:40 -0700252 // If Method* has been promoted, explicitly flush
buzbeefa57c472012-11-21 12:06:18 -0800253 if (rl_method.location == kLocPhysReg) {
254 StoreWordDisp(cu, TargetReg(kSp), 0, TargetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700255 }
buzbee9c044ce2012-03-18 13:24:07 -0700256
buzbeefa57c472012-11-21 12:06:18 -0800257 if (cu->num_ins == 0)
Bill Buzbeea114add2012-05-03 15:00:40 -0700258 return;
buzbeefa57c472012-11-21 12:06:18 -0800259 const int num_arg_regs = 3;
260 static SpecialTargetRegister arg_regs[] = {kArg1, kArg2, kArg3};
261 int start_vreg = cu->num_dalvik_registers - cu->num_ins;
Bill Buzbeea114add2012-05-03 15:00:40 -0700262 /*
263 * Copy incoming arguments to their proper home locations.
264 * NOTE: an older version of dx had an issue in which
265 * it would reuse static method argument registers.
266 * This could result in the same Dalvik virtual register
267 * being promoted to both core and fp regs. To account for this,
268 * we only copy to the corresponding promoted physical register
269 * if it matches the type of the SSA name for the incoming
270 * argument. It is also possible that long and double arguments
271 * end up half-promoted. In those cases, we must flush the promoted
272 * half to memory as well.
273 */
buzbeefa57c472012-11-21 12:06:18 -0800274 for (int i = 0; i < cu->num_ins; i++) {
275 PromotionMap* v_map = &cu->promotion_map[start_vreg + i];
276 if (i < num_arg_regs) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700277 // If arriving in register
buzbeefa57c472012-11-21 12:06:18 -0800278 bool need_flush = true;
279 RegLocation* t_loc = &ArgLocs[i];
280 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
281 OpRegCopy(cu, v_map->core_reg, TargetReg(arg_regs[i]));
282 need_flush = false;
283 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
284 OpRegCopy(cu, v_map->FpReg, TargetReg(arg_regs[i]));
285 need_flush = false;
Bill Buzbeea114add2012-05-03 15:00:40 -0700286 } else {
buzbeefa57c472012-11-21 12:06:18 -0800287 need_flush = true;
Bill Buzbeea114add2012-05-03 15:00:40 -0700288 }
buzbee86a4bce2012-03-06 18:15:00 -0800289
Bill Buzbeea114add2012-05-03 15:00:40 -0700290 // For wide args, force flush if only half is promoted
buzbeefa57c472012-11-21 12:06:18 -0800291 if (t_loc->wide) {
292 PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1);
293 need_flush |= (p_map->core_location != v_map->core_location) ||
294 (p_map->fp_location != v_map->fp_location);
Bill Buzbeea114add2012-05-03 15:00:40 -0700295 }
buzbeefa57c472012-11-21 12:06:18 -0800296 if (need_flush) {
297 StoreBaseDisp(cu, TargetReg(kSp), SRegOffset(cu, start_vreg + i),
298 TargetReg(arg_regs[i]), kWord);
Bill Buzbeea114add2012-05-03 15:00:40 -0700299 }
300 } else {
301 // If arriving in frame & promoted
buzbeefa57c472012-11-21 12:06:18 -0800302 if (v_map->core_location == kLocPhysReg) {
303 LoadWordDisp(cu, TargetReg(kSp), SRegOffset(cu, start_vreg + i),
304 v_map->core_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700305 }
buzbeefa57c472012-11-21 12:06:18 -0800306 if (v_map->fp_location == kLocPhysReg) {
307 LoadWordDisp(cu, TargetReg(kSp), SRegOffset(cu, start_vreg + i),
308 v_map->FpReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700309 }
buzbee31a4a6f2012-02-28 15:36:15 -0800310 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700311 }
buzbee31a4a6f2012-02-28 15:36:15 -0800312}
313
314/*
Elliott Hughesbdf6c3d2012-03-20 13:43:53 -0700315 * Bit of a hack here - in the absence of a real scheduling pass,
buzbee31a4a6f2012-02-28 15:36:15 -0800316 * emit the next instruction in static & direct invoke sequences.
317 */
buzbeefa57c472012-11-21 12:06:18 -0800318static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
319 int state, uint32_t dex_idx, uint32_t unused,
320 uintptr_t direct_code, uintptr_t direct_method,
buzbeeaad94382012-11-21 07:40:50 -0800321 InvokeType type)
buzbee31a4a6f2012-02-28 15:36:15 -0800322{
buzbee02031b12012-11-23 09:41:35 -0800323 Codegen* cg = cu->cg.get();
buzbeefa57c472012-11-21 12:06:18 -0800324 if (cu->instruction_set != kThumb2) {
buzbeeb046e162012-10-30 15:48:42 -0700325 // Disable sharpening
buzbeefa57c472012-11-21 12:06:18 -0800326 direct_code = 0;
327 direct_method = 0;
buzbeeb046e162012-10-30 15:48:42 -0700328 }
buzbeefa57c472012-11-21 12:06:18 -0800329 if (direct_code != 0 && direct_method != 0) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700330 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800331 case 0: // Get the current Method* [sets kArg0]
buzbeefa57c472012-11-21 12:06:18 -0800332 if (direct_code != static_cast<unsigned int>(-1)) {
buzbee02031b12012-11-23 09:41:35 -0800333 cg->LoadConstant(cu, cg->TargetReg(kInvokeTgt), direct_code);
Bill Buzbeea114add2012-05-03 15:00:40 -0700334 } else {
buzbeefa57c472012-11-21 12:06:18 -0800335 LIR* data_target = ScanLiteralPool(cu->code_literal_list, dex_idx, 0);
336 if (data_target == NULL) {
337 data_target = AddWordData(cu, &cu->code_literal_list, dex_idx);
338 data_target->operands[1] = type;
Ian Rogers2ed3b952012-03-17 11:49:39 -0700339 }
buzbee02031b12012-11-23 09:41:35 -0800340 LIR* load_pc_rel = cg->OpPcRelLoad(cu, cg->TargetReg(kInvokeTgt), data_target);
buzbeefa57c472012-11-21 12:06:18 -0800341 AppendLIR(cu, load_pc_rel);
342 DCHECK_EQ(cu->instruction_set, kThumb2) << reinterpret_cast<void*>(data_target);
Bill Buzbeea114add2012-05-03 15:00:40 -0700343 }
buzbeefa57c472012-11-21 12:06:18 -0800344 if (direct_method != static_cast<unsigned int>(-1)) {
buzbee02031b12012-11-23 09:41:35 -0800345 cg->LoadConstant(cu, cg->TargetReg(kArg0), direct_method);
Bill Buzbeea114add2012-05-03 15:00:40 -0700346 } else {
buzbeefa57c472012-11-21 12:06:18 -0800347 LIR* data_target = ScanLiteralPool(cu->method_literal_list, dex_idx, 0);
348 if (data_target == NULL) {
349 data_target = AddWordData(cu, &cu->method_literal_list, dex_idx);
350 data_target->operands[1] = type;
Bill Buzbeea114add2012-05-03 15:00:40 -0700351 }
buzbee02031b12012-11-23 09:41:35 -0800352 LIR* load_pc_rel = cg->OpPcRelLoad(cu, cg->TargetReg(kArg0), data_target);
buzbeefa57c472012-11-21 12:06:18 -0800353 AppendLIR(cu, load_pc_rel);
354 DCHECK_EQ(cu->instruction_set, kThumb2) << reinterpret_cast<void*>(data_target);
Bill Buzbeea114add2012-05-03 15:00:40 -0700355 }
356 break;
357 default:
358 return -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800359 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700360 } else {
361 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800362 case 0: // Get the current Method* [sets kArg0]
Ian Rogers137e88f2012-10-08 17:46:47 -0700363 // TUNING: we can save a reg copy if Method* has been promoted.
buzbee02031b12012-11-23 09:41:35 -0800364 cg->LoadCurrMethodDirect(cu, cg->TargetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700365 break;
366 case 1: // Get method->dex_cache_resolved_methods_
buzbee02031b12012-11-23 09:41:35 -0800367 cg->LoadWordDisp(cu, cg->TargetReg(kArg0),
368 AbstractMethod::DexCacheResolvedMethodsOffset().Int32Value(), cg->TargetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700369 // Set up direct code if known.
buzbeefa57c472012-11-21 12:06:18 -0800370 if (direct_code != 0) {
371 if (direct_code != static_cast<unsigned int>(-1)) {
buzbee02031b12012-11-23 09:41:35 -0800372 cg->LoadConstant(cu, cg->TargetReg(kInvokeTgt), direct_code);
Bill Buzbeea114add2012-05-03 15:00:40 -0700373 } else {
buzbeefa57c472012-11-21 12:06:18 -0800374 LIR* data_target = ScanLiteralPool(cu->code_literal_list, dex_idx, 0);
375 if (data_target == NULL) {
376 data_target = AddWordData(cu, &cu->code_literal_list, dex_idx);
377 data_target->operands[1] = type;
Bill Buzbeea114add2012-05-03 15:00:40 -0700378 }
buzbee02031b12012-11-23 09:41:35 -0800379 LIR* load_pc_rel = cg->OpPcRelLoad(cu, cg->TargetReg(kInvokeTgt), data_target);
buzbeefa57c472012-11-21 12:06:18 -0800380 AppendLIR(cu, load_pc_rel);
381 DCHECK_EQ(cu->instruction_set, kThumb2) << reinterpret_cast<void*>(data_target);
Bill Buzbeea114add2012-05-03 15:00:40 -0700382 }
383 }
384 break;
385 case 2: // Grab target method*
buzbee02031b12012-11-23 09:41:35 -0800386 cg->LoadWordDisp(cu, cg->TargetReg(kArg0),
387 Array::DataOffset(sizeof(Object*)).Int32Value() + dex_idx * 4,
388 cg-> TargetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700389 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700390 case 3: // Grab the code from the method*
buzbeefa57c472012-11-21 12:06:18 -0800391 if (cu->instruction_set != kX86) {
392 if (direct_code == 0) {
buzbee02031b12012-11-23 09:41:35 -0800393 cg->LoadWordDisp(cu, cg->TargetReg(kArg0), AbstractMethod::GetCodeOffset().Int32Value(),
394 cg->TargetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700395 }
396 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700397 }
buzbeeb046e162012-10-30 15:48:42 -0700398 // Intentional fallthrough for x86
Bill Buzbeea114add2012-05-03 15:00:40 -0700399 default:
400 return -1;
401 }
402 }
403 return state + 1;
buzbee31a4a6f2012-02-28 15:36:15 -0800404}
405
406/*
Elliott Hughesbdf6c3d2012-03-20 13:43:53 -0700407 * Bit of a hack here - in the absence of a real scheduling pass,
buzbee31a4a6f2012-02-28 15:36:15 -0800408 * emit the next instruction in a virtual invoke sequence.
buzbeef0504cd2012-11-13 16:31:10 -0800409 * We can use kLr as a temp prior to target address loading
buzbee31a4a6f2012-02-28 15:36:15 -0800410 * Note also that we'll load the first argument ("this") into
buzbee52a77fc2012-11-20 19:50:46 -0800411 * kArg1 here rather than the standard LoadArgRegs.
buzbee31a4a6f2012-02-28 15:36:15 -0800412 */
buzbeefa57c472012-11-21 12:06:18 -0800413static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
414 int state, uint32_t dex_idx, uint32_t method_idx,
buzbeeaad94382012-11-21 07:40:50 -0800415 uintptr_t unused, uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800416{
buzbee02031b12012-11-23 09:41:35 -0800417 Codegen* cg = cu->cg.get();
Bill Buzbeea114add2012-05-03 15:00:40 -0700418 /*
419 * This is the fast path in which the target virtual method is
420 * fully resolved at compile time.
421 */
422 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800423 case 0: { // Get "this" [set kArg1]
buzbeefa57c472012-11-21 12:06:18 -0800424 RegLocation rl_arg = info->args[0];
buzbee02031b12012-11-23 09:41:35 -0800425 cg->LoadValueDirectFixed(cu, rl_arg, cg->TargetReg(kArg1));
Bill Buzbeea114add2012-05-03 15:00:40 -0700426 break;
Ian Rogers137e88f2012-10-08 17:46:47 -0700427 }
buzbeef0504cd2012-11-13 16:31:10 -0800428 case 1: // Is "this" null? [use kArg1]
buzbee02031b12012-11-23 09:41:35 -0800429 cg->GenNullCheck(cu, info->args[0].s_reg_low, cg->TargetReg(kArg1), info->opt_flags);
buzbeef0504cd2012-11-13 16:31:10 -0800430 // get this->klass_ [use kArg1, set kInvokeTgt]
buzbee02031b12012-11-23 09:41:35 -0800431 cg->LoadWordDisp(cu, cg->TargetReg(kArg1), Object::ClassOffset().Int32Value(),
432 cg->TargetReg(kInvokeTgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700433 break;
buzbeef0504cd2012-11-13 16:31:10 -0800434 case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt]
buzbee02031b12012-11-23 09:41:35 -0800435 cg->LoadWordDisp(cu, cg->TargetReg(kInvokeTgt), Class::VTableOffset().Int32Value(),
436 cg->TargetReg(kInvokeTgt));
Bill Buzbeea114add2012-05-03 15:00:40 -0700437 break;
buzbeef0504cd2012-11-13 16:31:10 -0800438 case 3: // Get target method [use kInvokeTgt, set kArg0]
buzbee02031b12012-11-23 09:41:35 -0800439 cg->LoadWordDisp(cu, cg->TargetReg(kInvokeTgt), (method_idx * 4) +
440 Array::DataOffset(sizeof(Object*)).Int32Value(), cg->TargetReg(kArg0));
Bill Buzbeea114add2012-05-03 15:00:40 -0700441 break;
buzbeef0504cd2012-11-13 16:31:10 -0800442 case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt]
buzbeefa57c472012-11-21 12:06:18 -0800443 if (cu->instruction_set != kX86) {
buzbee02031b12012-11-23 09:41:35 -0800444 cg->LoadWordDisp(cu, cg->TargetReg(kArg0), AbstractMethod::GetCodeOffset().Int32Value(),
445 cg->TargetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700446 break;
447 }
448 // Intentional fallthrough for X86
Bill Buzbeea114add2012-05-03 15:00:40 -0700449 default:
450 return -1;
451 }
452 return state + 1;
buzbee31a4a6f2012-02-28 15:36:15 -0800453}
454
Ian Rogers137e88f2012-10-08 17:46:47 -0700455/*
456 * All invoke-interface calls bounce off of art_invoke_interface_trampoline,
457 * which will locate the target and continue on via a tail call.
458 */
buzbeefa57c472012-11-21 12:06:18 -0800459static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
460 uint32_t dex_idx, uint32_t unused, uintptr_t unused2,
461 uintptr_t direct_method, InvokeType unused4)
Ian Rogers137e88f2012-10-08 17:46:47 -0700462{
buzbee02031b12012-11-23 09:41:35 -0800463 Codegen* cg = cu->cg.get();
buzbeefa57c472012-11-21 12:06:18 -0800464 if (cu->instruction_set != kThumb2) {
buzbeeb046e162012-10-30 15:48:42 -0700465 // Disable sharpening
buzbeefa57c472012-11-21 12:06:18 -0800466 direct_method = 0;
buzbeeb046e162012-10-30 15:48:42 -0700467 }
buzbeefa57c472012-11-21 12:06:18 -0800468 int trampoline = (cu->instruction_set == kX86) ? 0
buzbeeb046e162012-10-30 15:48:42 -0700469 : ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline);
Ian Rogers137e88f2012-10-08 17:46:47 -0700470
buzbeefa57c472012-11-21 12:06:18 -0800471 if (direct_method != 0) {
Ian Rogers137e88f2012-10-08 17:46:47 -0700472 switch (state) {
buzbeef0504cd2012-11-13 16:31:10 -0800473 case 0: // Load the trampoline target [sets kInvokeTgt].
buzbeefa57c472012-11-21 12:06:18 -0800474 if (cu->instruction_set != kX86) {
buzbee02031b12012-11-23 09:41:35 -0800475 cg->LoadWordDisp(cu, cg->TargetReg(kSelf), trampoline, cg->TargetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700476 }
buzbeef0504cd2012-11-13 16:31:10 -0800477 // Get the interface Method* [sets kArg0]
buzbeefa57c472012-11-21 12:06:18 -0800478 if (direct_method != static_cast<unsigned int>(-1)) {
buzbee02031b12012-11-23 09:41:35 -0800479 cg->LoadConstant(cu, cg->TargetReg(kArg0), direct_method);
Ian Rogers137e88f2012-10-08 17:46:47 -0700480 } else {
buzbeefa57c472012-11-21 12:06:18 -0800481 LIR* data_target = ScanLiteralPool(cu->method_literal_list, dex_idx, 0);
482 if (data_target == NULL) {
483 data_target = AddWordData(cu, &cu->method_literal_list, dex_idx);
484 data_target->operands[1] = kInterface;
Ian Rogers137e88f2012-10-08 17:46:47 -0700485 }
buzbee02031b12012-11-23 09:41:35 -0800486 LIR* load_pc_rel = cg->OpPcRelLoad(cu, cg->TargetReg(kArg0), data_target);
buzbeefa57c472012-11-21 12:06:18 -0800487 AppendLIR(cu, load_pc_rel);
488 DCHECK_EQ(cu->instruction_set, kThumb2) << reinterpret_cast<void*>(data_target);
Ian Rogers137e88f2012-10-08 17:46:47 -0700489 }
490 break;
491 default:
492 return -1;
493 }
494 } else {
495 switch (state) {
496 case 0:
buzbeef0504cd2012-11-13 16:31:10 -0800497 // Get the current Method* [sets kArg0] - TUNING: remove copy of method if it is promoted.
buzbee02031b12012-11-23 09:41:35 -0800498 cg->LoadCurrMethodDirect(cu, cg->TargetReg(kArg0));
buzbeef0504cd2012-11-13 16:31:10 -0800499 // Load the trampoline target [sets kInvokeTgt].
buzbeefa57c472012-11-21 12:06:18 -0800500 if (cu->instruction_set != kX86) {
buzbee02031b12012-11-23 09:41:35 -0800501 cg->LoadWordDisp(cu, cg->TargetReg(kSelf), trampoline, cg->TargetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700502 }
Ian Rogers137e88f2012-10-08 17:46:47 -0700503 break;
buzbeef0504cd2012-11-13 16:31:10 -0800504 case 1: // Get method->dex_cache_resolved_methods_ [set/use kArg0]
buzbee02031b12012-11-23 09:41:35 -0800505 cg->LoadWordDisp(cu, cg->TargetReg(kArg0),
506 AbstractMethod::DexCacheResolvedMethodsOffset().Int32Value(),
507 cg->TargetReg(kArg0));
Ian Rogers137e88f2012-10-08 17:46:47 -0700508 break;
buzbeef0504cd2012-11-13 16:31:10 -0800509 case 2: // Grab target method* [set/use kArg0]
buzbee02031b12012-11-23 09:41:35 -0800510 cg->LoadWordDisp(cu, cg->TargetReg(kArg0),
511 Array::DataOffset(sizeof(Object*)).Int32Value() + dex_idx * 4,
512 cg->TargetReg(kArg0));
Ian Rogers137e88f2012-10-08 17:46:47 -0700513 break;
514 default:
515 return -1;
516 }
517 }
518 return state + 1;
519}
520
buzbeefa57c472012-11-21 12:06:18 -0800521static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, int trampoline,
522 int state, uint32_t dex_idx, uint32_t method_idx)
buzbee31a4a6f2012-02-28 15:36:15 -0800523{
buzbee02031b12012-11-23 09:41:35 -0800524 Codegen* cg = cu->cg.get();
Bill Buzbeea114add2012-05-03 15:00:40 -0700525 /*
526 * This handles the case in which the base method is not fully
527 * resolved at compile time, we bail to a runtime helper.
528 */
529 if (state == 0) {
buzbeefa57c472012-11-21 12:06:18 -0800530 if (cu->instruction_set != kX86) {
buzbeeb046e162012-10-30 15:48:42 -0700531 // Load trampoline target
buzbee02031b12012-11-23 09:41:35 -0800532 cg->LoadWordDisp(cu, cg->TargetReg(kSelf), trampoline, cg->TargetReg(kInvokeTgt));
buzbeeb046e162012-10-30 15:48:42 -0700533 }
buzbeef0504cd2012-11-13 16:31:10 -0800534 // Load kArg0 with method index
buzbee02031b12012-11-23 09:41:35 -0800535 cg->LoadConstant(cu, cg->TargetReg(kArg0), dex_idx);
Bill Buzbeea114add2012-05-03 15:00:40 -0700536 return 1;
537 }
538 return -1;
buzbee31a4a6f2012-02-28 15:36:15 -0800539}
540
buzbeefa57c472012-11-21 12:06:18 -0800541static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
542 int state, uint32_t dex_idx, uint32_t method_idx,
buzbeeaad94382012-11-21 07:40:50 -0800543 uintptr_t unused, uintptr_t unused2,
Brian Carlstromf5822582012-03-19 22:34:31 -0700544 InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800545{
Ian Rogers57b86d42012-03-27 16:05:41 -0700546 int trampoline = ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
buzbeefa57c472012-11-21 12:06:18 -0800547 return NextInvokeInsnSP(cu, info, trampoline, state, dex_idx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800548}
549
buzbeefa57c472012-11-21 12:06:18 -0800550static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
551 uint32_t dex_idx, uint32_t method_idx, uintptr_t unused,
buzbeeaad94382012-11-21 07:40:50 -0800552 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800553{
Ian Rogers57b86d42012-03-27 16:05:41 -0700554 int trampoline = ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
buzbeefa57c472012-11-21 12:06:18 -0800555 return NextInvokeInsnSP(cu, info, trampoline, state, dex_idx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800556}
557
buzbeefa57c472012-11-21 12:06:18 -0800558static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
559 uint32_t dex_idx, uint32_t method_idx, uintptr_t unused,
Brian Carlstromf5822582012-03-19 22:34:31 -0700560 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800561{
Ian Rogers57b86d42012-03-27 16:05:41 -0700562 int trampoline = ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
buzbeefa57c472012-11-21 12:06:18 -0800563 return NextInvokeInsnSP(cu, info, trampoline, state, dex_idx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800564}
565
buzbeefa57c472012-11-21 12:06:18 -0800566static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
567 uint32_t dex_idx, uint32_t method_idx, uintptr_t unused,
buzbeeaad94382012-11-21 07:40:50 -0800568 uintptr_t unused2, InvokeType unused3)
buzbee31a4a6f2012-02-28 15:36:15 -0800569{
Ian Rogers57b86d42012-03-27 16:05:41 -0700570 int trampoline = ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
buzbeefa57c472012-11-21 12:06:18 -0800571 return NextInvokeInsnSP(cu, info, trampoline, state, dex_idx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800572}
573
buzbeefa57c472012-11-21 12:06:18 -0800574static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
buzbeeaad94382012-11-21 07:40:50 -0800575 CallInfo* info, int state,
buzbeefa57c472012-11-21 12:06:18 -0800576 uint32_t dex_idx, uint32_t unused,
buzbee15bf9802012-06-12 17:49:27 -0700577 uintptr_t unused2, uintptr_t unused3,
578 InvokeType unused4)
buzbee31a4a6f2012-02-28 15:36:15 -0800579{
Ian Rogers57b86d42012-03-27 16:05:41 -0700580 int trampoline = ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
buzbeefa57c472012-11-21 12:06:18 -0800581 return NextInvokeInsnSP(cu, info, trampoline, state, dex_idx, 0);
buzbee31a4a6f2012-02-28 15:36:15 -0800582}
583
buzbeefa57c472012-11-21 12:06:18 -0800584static int LoadArgRegs(CompilationUnit* cu, CallInfo* info, int call_state,
585 NextCallInsn next_call_insn, uint32_t dex_idx,
586 uint32_t method_idx, uintptr_t direct_code,
587 uintptr_t direct_method, InvokeType type, bool skip_this)
buzbee31a4a6f2012-02-28 15:36:15 -0800588{
buzbee02031b12012-11-23 09:41:35 -0800589 Codegen* cg = cu->cg.get();
590 int last_arg_reg = cg->TargetReg(kArg3);
591 int next_reg = cg->TargetReg(kArg1);
buzbeefa57c472012-11-21 12:06:18 -0800592 int next_arg = 0;
593 if (skip_this) {
594 next_reg++;
595 next_arg++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700596 }
buzbeefa57c472012-11-21 12:06:18 -0800597 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
598 RegLocation rl_arg = info->args[next_arg++];
599 rl_arg = UpdateRawLoc(cu, rl_arg);
buzbee02031b12012-11-23 09:41:35 -0800600 if (rl_arg.wide && (next_reg <= cg->TargetReg(kArg2))) {
601 cg->LoadValueDirectWideFixed(cu, rl_arg, next_reg, next_reg + 1);
buzbeefa57c472012-11-21 12:06:18 -0800602 next_reg++;
603 next_arg++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700604 } else {
buzbeefa57c472012-11-21 12:06:18 -0800605 rl_arg.wide = false;
buzbee02031b12012-11-23 09:41:35 -0800606 cg->LoadValueDirectFixed(cu, rl_arg, next_reg);
buzbee31a4a6f2012-02-28 15:36:15 -0800607 }
buzbeefa57c472012-11-21 12:06:18 -0800608 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
609 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700610 }
buzbeefa57c472012-11-21 12:06:18 -0800611 return call_state;
buzbee31a4a6f2012-02-28 15:36:15 -0800612}
613
614/*
615 * Load up to 5 arguments, the first three of which will be in
buzbeef0504cd2012-11-13 16:31:10 -0800616 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
buzbee31a4a6f2012-02-28 15:36:15 -0800617 * and as part of the load sequence, it must be replaced with
618 * the target method pointer. Note, this may also be called
619 * for "range" variants if the number of arguments is 5 or fewer.
620 */
buzbee02031b12012-11-23 09:41:35 -0800621int Codegen::GenDalvikArgsNoRange(CompilationUnit* cu, CallInfo* info,
622 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
623 uint32_t dex_idx, uint32_t method_idx, uintptr_t direct_code,
624 uintptr_t direct_method, InvokeType type, bool skip_this)
buzbee31a4a6f2012-02-28 15:36:15 -0800625{
buzbeefa57c472012-11-21 12:06:18 -0800626 RegLocation rl_arg;
buzbee31a4a6f2012-02-28 15:36:15 -0800627
Bill Buzbeea114add2012-05-03 15:00:40 -0700628 /* If no arguments, just return */
buzbeefa57c472012-11-21 12:06:18 -0800629 if (info->num_arg_words == 0)
630 return call_state;
Bill Buzbeea114add2012-05-03 15:00:40 -0700631
buzbeefa57c472012-11-21 12:06:18 -0800632 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
633 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700634
buzbeefa57c472012-11-21 12:06:18 -0800635 DCHECK_LE(info->num_arg_words, 5);
636 if (info->num_arg_words > 3) {
637 int32_t next_use = 3;
Bill Buzbeea114add2012-05-03 15:00:40 -0700638 //Detect special case of wide arg spanning arg3/arg4
buzbeefa57c472012-11-21 12:06:18 -0800639 RegLocation rl_use0 = info->args[0];
640 RegLocation rl_use1 = info->args[1];
641 RegLocation rl_use2 = info->args[2];
642 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) &&
643 rl_use2.wide) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700644 int reg = -1;
645 // Wide spans, we need the 2nd half of uses[2].
buzbeefa57c472012-11-21 12:06:18 -0800646 rl_arg = UpdateLocWide(cu, rl_use2);
647 if (rl_arg.location == kLocPhysReg) {
648 reg = rl_arg.high_reg;
Bill Buzbeea114add2012-05-03 15:00:40 -0700649 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800650 // kArg2 & rArg3 can safely be used here
buzbee52a77fc2012-11-20 19:50:46 -0800651 reg = TargetReg(kArg3);
buzbeefa57c472012-11-21 12:06:18 -0800652 LoadWordDisp(cu, TargetReg(kSp), SRegOffset(cu, rl_arg.s_reg_low) + 4, reg);
653 call_state = next_call_insn(cu, info, call_state, dex_idx,
654 method_idx, direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700655 }
buzbeefa57c472012-11-21 12:06:18 -0800656 StoreBaseDisp(cu, TargetReg(kSp), (next_use + 1) * 4, reg, kWord);
657 StoreBaseDisp(cu, TargetReg(kSp), 16 /* (3+1)*4 */, reg, kWord);
658 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
659 direct_code, direct_method, type);
660 next_use++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700661 }
662 // Loop through the rest
buzbeefa57c472012-11-21 12:06:18 -0800663 while (next_use < info->num_arg_words) {
664 int low_reg;
665 int high_reg = -1;
666 rl_arg = info->args[next_use];
667 rl_arg = UpdateRawLoc(cu, rl_arg);
668 if (rl_arg.location == kLocPhysReg) {
669 low_reg = rl_arg.low_reg;
670 high_reg = rl_arg.high_reg;
Bill Buzbeea114add2012-05-03 15:00:40 -0700671 } else {
buzbeefa57c472012-11-21 12:06:18 -0800672 low_reg = TargetReg(kArg2);
673 if (rl_arg.wide) {
674 high_reg = TargetReg(kArg3);
675 LoadValueDirectWideFixed(cu, rl_arg, low_reg, high_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700676 } else {
buzbeefa57c472012-11-21 12:06:18 -0800677 LoadValueDirectFixed(cu, rl_arg, low_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700678 }
buzbeefa57c472012-11-21 12:06:18 -0800679 call_state = next_call_insn(cu, info, call_state, dex_idx,
680 method_idx, direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700681 }
buzbeefa57c472012-11-21 12:06:18 -0800682 int outs_offset = (next_use + 1) * 4;
683 if (rl_arg.wide) {
684 StoreBaseDispWide(cu, TargetReg(kSp), outs_offset, low_reg, high_reg);
685 next_use += 2;
Bill Buzbeea114add2012-05-03 15:00:40 -0700686 } else {
buzbeefa57c472012-11-21 12:06:18 -0800687 StoreWordDisp(cu, TargetReg(kSp), outs_offset, low_reg);
688 next_use++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700689 }
buzbeefa57c472012-11-21 12:06:18 -0800690 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
691 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700692 }
693 }
694
buzbeefa57c472012-11-21 12:06:18 -0800695 call_state = LoadArgRegs(cu, info, call_state, next_call_insn,
696 dex_idx, method_idx, direct_code, direct_method,
697 type, skip_this);
Bill Buzbeea114add2012-05-03 15:00:40 -0700698
699 if (pcrLabel) {
buzbeefa57c472012-11-21 12:06:18 -0800700 *pcrLabel = GenNullCheck(cu, info->args[0].s_reg_low, TargetReg(kArg1), info->opt_flags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700701 }
buzbeefa57c472012-11-21 12:06:18 -0800702 return call_state;
buzbee31a4a6f2012-02-28 15:36:15 -0800703}
704
705/*
706 * May have 0+ arguments (also used for jumbo). Note that
707 * source virtual registers may be in physical registers, so may
708 * need to be flushed to home location before copying. This
709 * applies to arg3 and above (see below).
710 *
711 * Two general strategies:
712 * If < 20 arguments
713 * Pass args 3-18 using vldm/vstm block copy
buzbeef0504cd2012-11-13 16:31:10 -0800714 * Pass arg0, arg1 & arg2 in kArg1-kArg3
buzbee31a4a6f2012-02-28 15:36:15 -0800715 * If 20+ arguments
716 * Pass args arg19+ using memcpy block copy
buzbeef0504cd2012-11-13 16:31:10 -0800717 * Pass arg0, arg1 & arg2 in kArg1-kArg3
buzbee31a4a6f2012-02-28 15:36:15 -0800718 *
719 */
buzbee02031b12012-11-23 09:41:35 -0800720int Codegen::GenDalvikArgsRange(CompilationUnit* cu, CallInfo* info, int call_state,
721 LIR** pcrLabel, NextCallInsn next_call_insn, uint32_t dex_idx,
722 uint32_t method_idx, uintptr_t direct_code, uintptr_t direct_method,
723 InvokeType type, bool skip_this)
buzbee31a4a6f2012-02-28 15:36:15 -0800724{
buzbee31a4a6f2012-02-28 15:36:15 -0800725
Bill Buzbeea114add2012-05-03 15:00:40 -0700726 // If we can treat it as non-range (Jumbo ops will use range form)
buzbeefa57c472012-11-21 12:06:18 -0800727 if (info->num_arg_words <= 5)
728 return GenDalvikArgsNoRange(cu, info, call_state, pcrLabel,
729 next_call_insn, dex_idx, method_idx,
730 direct_code, direct_method, type, skip_this);
Bill Buzbeea114add2012-05-03 15:00:40 -0700731 /*
Bill Buzbeea114add2012-05-03 15:00:40 -0700732 * First load the non-register arguments. Both forms expect all
733 * of the source arguments to be in their home frame location, so
buzbeefa57c472012-11-21 12:06:18 -0800734 * scan the s_reg names and flush any that have been promoted to
Bill Buzbeea114add2012-05-03 15:00:40 -0700735 * frame backing storage.
736 */
buzbeefa57c472012-11-21 12:06:18 -0800737 // Scan the rest of the args - if in phys_reg flush to memory
738 for (int next_arg = 0; next_arg < info->num_arg_words;) {
739 RegLocation loc = info->args[next_arg];
Bill Buzbeea114add2012-05-03 15:00:40 -0700740 if (loc.wide) {
buzbeefa57c472012-11-21 12:06:18 -0800741 loc = UpdateLocWide(cu, loc);
742 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
743 StoreBaseDispWide(cu, TargetReg(kSp), SRegOffset(cu, loc.s_reg_low),
744 loc.low_reg, loc.high_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700745 }
buzbeefa57c472012-11-21 12:06:18 -0800746 next_arg += 2;
Bill Buzbeea114add2012-05-03 15:00:40 -0700747 } else {
buzbeefa57c472012-11-21 12:06:18 -0800748 loc = UpdateLoc(cu, loc);
749 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
750 StoreBaseDisp(cu, TargetReg(kSp), SRegOffset(cu, loc.s_reg_low),
751 loc.low_reg, kWord);
Bill Buzbeea114add2012-05-03 15:00:40 -0700752 }
buzbeefa57c472012-11-21 12:06:18 -0800753 next_arg++;
buzbee31a4a6f2012-02-28 15:36:15 -0800754 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700755 }
buzbee31a4a6f2012-02-28 15:36:15 -0800756
buzbeefa57c472012-11-21 12:06:18 -0800757 int start_offset = SRegOffset(cu, info->args[3].s_reg_low);
758 int outs_offset = 4 /* Method* */ + (3 * 4);
759 if (cu->instruction_set != kThumb2) {
buzbee31a4a6f2012-02-28 15:36:15 -0800760 // Generate memcpy
buzbeefa57c472012-11-21 12:06:18 -0800761 OpRegRegImm(cu, kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset);
762 OpRegRegImm(cu, kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset);
763 CallRuntimeHelperRegRegImm(cu, ENTRYPOINT_OFFSET(pMemcpy), TargetReg(kArg0),
764 TargetReg(kArg1), (info->num_arg_words - 3) * 4, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700765 } else {
buzbeefa57c472012-11-21 12:06:18 -0800766 if (info->num_arg_words >= 20) {
buzbeeb046e162012-10-30 15:48:42 -0700767 // Generate memcpy
buzbeefa57c472012-11-21 12:06:18 -0800768 OpRegRegImm(cu, kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset);
769 OpRegRegImm(cu, kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset);
770 CallRuntimeHelperRegRegImm(cu, ENTRYPOINT_OFFSET(pMemcpy), TargetReg(kArg0),
771 TargetReg(kArg1), (info->num_arg_words - 3) * 4, false);
buzbeeb046e162012-10-30 15:48:42 -0700772 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800773 // Use vldm/vstm pair using kArg3 as a temp
buzbeefa57c472012-11-21 12:06:18 -0800774 int regs_left = std::min(info->num_arg_words - 3, 16);
775 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
776 direct_code, direct_method, type);
777 OpRegRegImm(cu, kOpAdd, TargetReg(kArg3), TargetReg(kSp), start_offset);
778 LIR* ld = OpVldm(cu, TargetReg(kArg3), regs_left);
buzbeeb046e162012-10-30 15:48:42 -0700779 //TUNING: loosen barrier
buzbeefa57c472012-11-21 12:06:18 -0800780 ld->def_mask = ENCODE_ALL;
buzbee02031b12012-11-23 09:41:35 -0800781 SetMemRefType(cu, ld, true /* is_load */, kDalvikReg);
buzbeefa57c472012-11-21 12:06:18 -0800782 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
783 direct_code, direct_method, type);
784 OpRegRegImm(cu, kOpAdd, TargetReg(kArg3), TargetReg(kSp), 4 /* Method* */ + (3 * 4));
785 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
786 direct_code, direct_method, type);
787 LIR* st = OpVstm(cu, TargetReg(kArg3), regs_left);
buzbee02031b12012-11-23 09:41:35 -0800788 SetMemRefType(cu, st, false /* is_load */, kDalvikReg);
buzbeefa57c472012-11-21 12:06:18 -0800789 st->def_mask = ENCODE_ALL;
790 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
791 direct_code, direct_method, type);
buzbeeb046e162012-10-30 15:48:42 -0700792 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700793 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700794
buzbeefa57c472012-11-21 12:06:18 -0800795 call_state = LoadArgRegs(cu, info, call_state, next_call_insn,
796 dex_idx, method_idx, direct_code, direct_method,
797 type, skip_this);
Bill Buzbeea114add2012-05-03 15:00:40 -0700798
buzbeefa57c472012-11-21 12:06:18 -0800799 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
800 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700801 if (pcrLabel) {
buzbeefa57c472012-11-21 12:06:18 -0800802 *pcrLabel = GenNullCheck(cu, info->args[0].s_reg_low, TargetReg(kArg1),
803 info->opt_flags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700804 }
buzbeefa57c472012-11-21 12:06:18 -0800805 return call_state;
buzbee31a4a6f2012-02-28 15:36:15 -0800806}
807
buzbee02031b12012-11-23 09:41:35 -0800808RegLocation Codegen::InlineTarget(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700809{
Bill Buzbeea114add2012-05-03 15:00:40 -0700810 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700811 if (info->result.location == kLocInvalid) {
buzbeefa57c472012-11-21 12:06:18 -0800812 res = GetReturn(cu, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700813 } else {
buzbee15bf9802012-06-12 17:49:27 -0700814 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700815 }
816 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700817}
818
buzbee02031b12012-11-23 09:41:35 -0800819RegLocation Codegen::InlineTargetWide(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700820{
Bill Buzbeea114add2012-05-03 15:00:40 -0700821 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700822 if (info->result.location == kLocInvalid) {
buzbeefa57c472012-11-21 12:06:18 -0800823 res = GetReturnWide(cu, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700824 } else {
buzbee15bf9802012-06-12 17:49:27 -0700825 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700826 }
827 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700828}
829
buzbee02031b12012-11-23 09:41:35 -0800830bool Codegen::GenInlinedCharAt(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700831{
buzbeefa57c472012-11-21 12:06:18 -0800832 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700833 // TODO - add Mips implementation
834 return false;
835 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700836 // Location of reference to data array
buzbeefa57c472012-11-21 12:06:18 -0800837 int value_offset = String::ValueOffset().Int32Value();
Bill Buzbeea114add2012-05-03 15:00:40 -0700838 // Location of count
buzbeefa57c472012-11-21 12:06:18 -0800839 int count_offset = String::CountOffset().Int32Value();
Bill Buzbeea114add2012-05-03 15:00:40 -0700840 // Starting offset within data array
buzbeefa57c472012-11-21 12:06:18 -0800841 int offset_offset = String::OffsetOffset().Int32Value();
Bill Buzbeea114add2012-05-03 15:00:40 -0700842 // Start of char data with array_
buzbeefa57c472012-11-21 12:06:18 -0800843 int data_offset = Array::DataOffset(sizeof(uint16_t)).Int32Value();
buzbeefc9e6fa2012-03-23 15:14:29 -0700844
buzbeefa57c472012-11-21 12:06:18 -0800845 RegLocation rl_obj = info->args[0];
846 RegLocation rl_idx = info->args[1];
847 rl_obj = LoadValue(cu, rl_obj, kCoreReg);
848 rl_idx = LoadValue(cu, rl_idx, kCoreReg);
849 int reg_max;
850 GenNullCheck(cu, rl_obj.s_reg_low, rl_obj.low_reg, info->opt_flags);
851 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
852 LIR* launch_pad = NULL;
853 int reg_off = INVALID_REG;
854 int reg_ptr = INVALID_REG;
855 if (cu->instruction_set != kX86) {
856 reg_off = AllocTemp(cu);
857 reg_ptr = AllocTemp(cu);
858 if (range_check) {
859 reg_max = AllocTemp(cu);
860 LoadWordDisp(cu, rl_obj.low_reg, count_offset, reg_max);
buzbeeb046e162012-10-30 15:48:42 -0700861 }
buzbeefa57c472012-11-21 12:06:18 -0800862 LoadWordDisp(cu, rl_obj.low_reg, offset_offset, reg_off);
863 LoadWordDisp(cu, rl_obj.low_reg, value_offset, reg_ptr);
864 if (range_check) {
buzbeeb046e162012-10-30 15:48:42 -0700865 // Set up a launch pad to allow retry in case of bounds violation */
buzbeefa57c472012-11-21 12:06:18 -0800866 launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
867 InsertGrowableList(cu, &cu->intrinsic_launchpads,
868 reinterpret_cast<uintptr_t>(launch_pad));
869 OpRegReg(cu, kOpCmp, rl_idx.low_reg, reg_max);
870 FreeTemp(cu, reg_max);
871 OpCondBranch(cu, kCondCs, launch_pad);
buzbeeb046e162012-10-30 15:48:42 -0700872 }
873 } else {
buzbeefa57c472012-11-21 12:06:18 -0800874 if (range_check) {
875 reg_max = AllocTemp(cu);
876 LoadWordDisp(cu, rl_obj.low_reg, count_offset, reg_max);
buzbeeb046e162012-10-30 15:48:42 -0700877 // Set up a launch pad to allow retry in case of bounds violation */
buzbeefa57c472012-11-21 12:06:18 -0800878 launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
879 InsertGrowableList(cu, &cu->intrinsic_launchpads,
880 reinterpret_cast<uintptr_t>(launch_pad));
881 OpRegReg(cu, kOpCmp, rl_idx.low_reg, reg_max);
882 FreeTemp(cu, reg_max);
883 OpCondBranch(cu, kCondCc, launch_pad);
buzbeeb046e162012-10-30 15:48:42 -0700884 }
buzbeefa57c472012-11-21 12:06:18 -0800885 reg_off = AllocTemp(cu);
886 reg_ptr = AllocTemp(cu);
887 LoadWordDisp(cu, rl_obj.low_reg, offset_offset, reg_off);
888 LoadWordDisp(cu, rl_obj.low_reg, value_offset, reg_ptr);
Bill Buzbeea114add2012-05-03 15:00:40 -0700889 }
buzbeefa57c472012-11-21 12:06:18 -0800890 OpRegImm(cu, kOpAdd, reg_ptr, data_offset);
891 OpRegReg(cu, kOpAdd, reg_off, rl_idx.low_reg);
892 FreeTemp(cu, rl_obj.low_reg);
893 FreeTemp(cu, rl_idx.low_reg);
894 RegLocation rl_dest = InlineTarget(cu, info);
895 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
896 LoadBaseIndexed(cu, reg_ptr, reg_off, rl_result.low_reg, 1, kUnsignedHalf);
897 FreeTemp(cu, reg_off);
898 FreeTemp(cu, reg_ptr);
899 StoreValue(cu, rl_dest, rl_result);
900 if (range_check) {
901 launch_pad->operands[2] = 0; // no resumption
Bill Buzbeea114add2012-05-03 15:00:40 -0700902 }
903 // Record that we've already inlined & null checked
buzbeefa57c472012-11-21 12:06:18 -0800904 info->opt_flags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
Bill Buzbeea114add2012-05-03 15:00:40 -0700905 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700906}
907
buzbeefa57c472012-11-21 12:06:18 -0800908// Generates an inlined String.is_empty or String.length.
buzbee02031b12012-11-23 09:41:35 -0800909bool Codegen::GenInlinedStringIsEmptyOrLength(CompilationUnit* cu, CallInfo* info, bool is_empty)
buzbeefc9e6fa2012-03-23 15:14:29 -0700910{
buzbeefa57c472012-11-21 12:06:18 -0800911 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700912 // TODO - add Mips implementation
913 return false;
914 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700915 // dst = src.length();
buzbeefa57c472012-11-21 12:06:18 -0800916 RegLocation rl_obj = info->args[0];
917 rl_obj = LoadValue(cu, rl_obj, kCoreReg);
918 RegLocation rl_dest = InlineTarget(cu, info);
919 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
920 GenNullCheck(cu, rl_obj.s_reg_low, rl_obj.low_reg, info->opt_flags);
921 LoadWordDisp(cu, rl_obj.low_reg, String::CountOffset().Int32Value(),
922 rl_result.low_reg);
923 if (is_empty) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700924 // dst = (dst == 0);
buzbeefa57c472012-11-21 12:06:18 -0800925 if (cu->instruction_set == kThumb2) {
926 int t_reg = AllocTemp(cu);
927 OpRegReg(cu, kOpNeg, t_reg, rl_result.low_reg);
928 OpRegRegReg(cu, kOpAdc, rl_result.low_reg, rl_result.low_reg, t_reg);
buzbeeb046e162012-10-30 15:48:42 -0700929 } else {
buzbeefa57c472012-11-21 12:06:18 -0800930 DCHECK_EQ(cu->instruction_set, kX86);
931 OpRegImm(cu, kOpSub, rl_result.low_reg, 1);
932 OpRegImm(cu, kOpLsr, rl_result.low_reg, 31);
buzbeeb046e162012-10-30 15:48:42 -0700933 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700934 }
buzbeefa57c472012-11-21 12:06:18 -0800935 StoreValue(cu, rl_dest, rl_result);
Bill Buzbeea114add2012-05-03 15:00:40 -0700936 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700937}
938
buzbee02031b12012-11-23 09:41:35 -0800939bool Codegen::GenInlinedAbsInt(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700940{
buzbeefa57c472012-11-21 12:06:18 -0800941 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700942 // TODO - add Mips implementation
943 return false;
944 }
buzbeefa57c472012-11-21 12:06:18 -0800945 RegLocation rl_src = info->args[0];
946 rl_src = LoadValue(cu, rl_src, kCoreReg);
947 RegLocation rl_dest = InlineTarget(cu, info);
948 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
949 int sign_reg = AllocTemp(cu);
Bill Buzbeea114add2012-05-03 15:00:40 -0700950 // abs(x) = y<=x>>31, (x+y)^y.
buzbeefa57c472012-11-21 12:06:18 -0800951 OpRegRegImm(cu, kOpAsr, sign_reg, rl_src.low_reg, 31);
952 OpRegRegReg(cu, kOpAdd, rl_result.low_reg, rl_src.low_reg, sign_reg);
953 OpRegReg(cu, kOpXor, rl_result.low_reg, sign_reg);
954 StoreValue(cu, rl_dest, rl_result);
Bill Buzbeea114add2012-05-03 15:00:40 -0700955 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700956}
957
buzbee02031b12012-11-23 09:41:35 -0800958bool Codegen::GenInlinedAbsLong(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700959{
buzbeefa57c472012-11-21 12:06:18 -0800960 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700961 // TODO - add Mips implementation
962 return false;
963 }
buzbeefa57c472012-11-21 12:06:18 -0800964 if (cu->instruction_set == kThumb2) {
965 RegLocation rl_src = info->args[0];
966 rl_src = LoadValueWide(cu, rl_src, kCoreReg);
967 RegLocation rl_dest = InlineTargetWide(cu, info);
968 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
969 int sign_reg = AllocTemp(cu);
buzbeeb046e162012-10-30 15:48:42 -0700970 // abs(x) = y<=x>>31, (x+y)^y.
buzbeefa57c472012-11-21 12:06:18 -0800971 OpRegRegImm(cu, kOpAsr, sign_reg, rl_src.high_reg, 31);
972 OpRegRegReg(cu, kOpAdd, rl_result.low_reg, rl_src.low_reg, sign_reg);
973 OpRegRegReg(cu, kOpAdc, rl_result.high_reg, rl_src.high_reg, sign_reg);
974 OpRegReg(cu, kOpXor, rl_result.low_reg, sign_reg);
975 OpRegReg(cu, kOpXor, rl_result.high_reg, sign_reg);
976 StoreValueWide(cu, rl_dest, rl_result);
buzbeeb046e162012-10-30 15:48:42 -0700977 return true;
978 } else {
buzbeefa57c472012-11-21 12:06:18 -0800979 DCHECK_EQ(cu->instruction_set, kX86);
buzbeeb046e162012-10-30 15:48:42 -0700980 // Reuse source registers to avoid running out of temps
buzbeefa57c472012-11-21 12:06:18 -0800981 RegLocation rl_src = info->args[0];
982 rl_src = LoadValueWide(cu, rl_src, kCoreReg);
983 RegLocation rl_dest = InlineTargetWide(cu, info);
984 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
985 OpRegCopyWide(cu, rl_result.low_reg, rl_result.high_reg, rl_src.low_reg, rl_src.high_reg);
986 FreeTemp(cu, rl_src.low_reg);
987 FreeTemp(cu, rl_src.high_reg);
988 int sign_reg = AllocTemp(cu);
buzbeeb046e162012-10-30 15:48:42 -0700989 // abs(x) = y<=x>>31, (x+y)^y.
buzbeefa57c472012-11-21 12:06:18 -0800990 OpRegRegImm(cu, kOpAsr, sign_reg, rl_result.high_reg, 31);
991 OpRegReg(cu, kOpAdd, rl_result.low_reg, sign_reg);
992 OpRegReg(cu, kOpAdc, rl_result.high_reg, sign_reg);
993 OpRegReg(cu, kOpXor, rl_result.low_reg, sign_reg);
994 OpRegReg(cu, kOpXor, rl_result.high_reg, sign_reg);
995 StoreValueWide(cu, rl_dest, rl_result);
buzbeeb046e162012-10-30 15:48:42 -0700996 return true;
997 }
buzbeefc9e6fa2012-03-23 15:14:29 -0700998}
999
buzbee02031b12012-11-23 09:41:35 -08001000bool Codegen::GenInlinedFloatCvt(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001001{
buzbeefa57c472012-11-21 12:06:18 -08001002 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001003 // TODO - add Mips implementation
1004 return false;
1005 }
buzbeefa57c472012-11-21 12:06:18 -08001006 RegLocation rl_src = info->args[0];
1007 RegLocation rl_dest = InlineTarget(cu, info);
1008 StoreValue(cu, rl_dest, rl_src);
Bill Buzbeea114add2012-05-03 15:00:40 -07001009 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -07001010}
1011
buzbee02031b12012-11-23 09:41:35 -08001012bool Codegen::GenInlinedDoubleCvt(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001013{
buzbeefa57c472012-11-21 12:06:18 -08001014 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001015 // TODO - add Mips implementation
1016 return false;
1017 }
buzbeefa57c472012-11-21 12:06:18 -08001018 RegLocation rl_src = info->args[0];
1019 RegLocation rl_dest = InlineTargetWide(cu, info);
1020 StoreValueWide(cu, rl_dest, rl_src);
Bill Buzbeea114add2012-05-03 15:00:40 -07001021 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -07001022}
1023
1024/*
buzbeefa57c472012-11-21 12:06:18 -08001025 * Fast string.index_of(I) & (II). Tests for simple case of char <= 0xffff,
buzbeefc9e6fa2012-03-23 15:14:29 -07001026 * otherwise bails to standard library code.
1027 */
buzbee02031b12012-11-23 09:41:35 -08001028bool Codegen::GenInlinedIndexOf(CompilationUnit* cu, CallInfo* info, bool zero_based)
buzbeefc9e6fa2012-03-23 15:14:29 -07001029{
buzbeefa57c472012-11-21 12:06:18 -08001030 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001031 // TODO - add Mips implementation
1032 return false;
1033 }
buzbeefa57c472012-11-21 12:06:18 -08001034 ClobberCalleeSave(cu);
1035 LockCallTemps(cu); // Using fixed registers
1036 int reg_ptr = TargetReg(kArg0);
1037 int reg_char = TargetReg(kArg1);
1038 int reg_start = TargetReg(kArg2);
buzbeefc9e6fa2012-03-23 15:14:29 -07001039
buzbeefa57c472012-11-21 12:06:18 -08001040 RegLocation rl_obj = info->args[0];
1041 RegLocation rl_char = info->args[1];
1042 RegLocation rl_start = info->args[2];
1043 LoadValueDirectFixed(cu, rl_obj, reg_ptr);
1044 LoadValueDirectFixed(cu, rl_char, reg_char);
1045 if (zero_based) {
1046 LoadConstant(cu, reg_start, 0);
Bill Buzbeea114add2012-05-03 15:00:40 -07001047 } else {
buzbeefa57c472012-11-21 12:06:18 -08001048 LoadValueDirectFixed(cu, rl_start, reg_start);
Bill Buzbeea114add2012-05-03 15:00:40 -07001049 }
buzbeefa57c472012-11-21 12:06:18 -08001050 int r_tgt = (cu->instruction_set != kX86) ? LoadHelper(cu, ENTRYPOINT_OFFSET(pIndexOf)) : 0;
1051 GenNullCheck(cu, rl_obj.s_reg_low, reg_ptr, info->opt_flags);
1052 LIR* launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
1053 InsertGrowableList(cu, &cu->intrinsic_launchpads, reinterpret_cast<uintptr_t>(launch_pad));
1054 OpCmpImmBranch(cu, kCondGt, reg_char, 0xFFFF, launch_pad);
buzbee8320f382012-09-11 16:29:42 -07001055 // NOTE: not a safepoint
buzbeefa57c472012-11-21 12:06:18 -08001056 if (cu->instruction_set != kX86) {
1057 OpReg(cu, kOpBlx, r_tgt);
buzbeeb046e162012-10-30 15:48:42 -07001058 } else {
buzbeefa57c472012-11-21 12:06:18 -08001059 OpThreadMem(cu, kOpBlx, ENTRYPOINT_OFFSET(pIndexOf));
buzbeeb046e162012-10-30 15:48:42 -07001060 }
buzbeefa57c472012-11-21 12:06:18 -08001061 LIR* resume_tgt = NewLIR0(cu, kPseudoTargetLabel);
1062 launch_pad->operands[2] = reinterpret_cast<uintptr_t>(resume_tgt);
Bill Buzbeea114add2012-05-03 15:00:40 -07001063 // Record that we've already inlined & null checked
buzbeefa57c472012-11-21 12:06:18 -08001064 info->opt_flags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
1065 RegLocation rl_return = GetReturn(cu, false);
1066 RegLocation rl_dest = InlineTarget(cu, info);
1067 StoreValue(cu, rl_dest, rl_return);
Bill Buzbeea114add2012-05-03 15:00:40 -07001068 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -07001069}
1070
1071/* Fast string.compareTo(Ljava/lang/string;)I. */
buzbee02031b12012-11-23 09:41:35 -08001072bool Codegen::GenInlinedStringCompareTo(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001073{
buzbeefa57c472012-11-21 12:06:18 -08001074 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001075 // TODO - add Mips implementation
1076 return false;
1077 }
buzbeefa57c472012-11-21 12:06:18 -08001078 ClobberCalleeSave(cu);
1079 LockCallTemps(cu); // Using fixed registers
1080 int reg_this = TargetReg(kArg0);
1081 int reg_cmp = TargetReg(kArg1);
buzbeefc9e6fa2012-03-23 15:14:29 -07001082
buzbeefa57c472012-11-21 12:06:18 -08001083 RegLocation rl_this = info->args[0];
1084 RegLocation rl_cmp = info->args[1];
1085 LoadValueDirectFixed(cu, rl_this, reg_this);
1086 LoadValueDirectFixed(cu, rl_cmp, reg_cmp);
1087 int r_tgt = (cu->instruction_set != kX86) ?
1088 LoadHelper(cu, ENTRYPOINT_OFFSET(pStringCompareTo)) : 0;
1089 GenNullCheck(cu, rl_this.s_reg_low, reg_this, info->opt_flags);
1090 //TUNING: check if rl_cmp.s_reg_low is already null checked
1091 LIR* launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
1092 InsertGrowableList(cu, &cu->intrinsic_launchpads, reinterpret_cast<uintptr_t>(launch_pad));
1093 OpCmpImmBranch(cu, kCondEq, reg_cmp, 0, launch_pad);
buzbee8320f382012-09-11 16:29:42 -07001094 // NOTE: not a safepoint
buzbeefa57c472012-11-21 12:06:18 -08001095 if (cu->instruction_set != kX86) {
1096 OpReg(cu, kOpBlx, r_tgt);
buzbeeb046e162012-10-30 15:48:42 -07001097 } else {
buzbeefa57c472012-11-21 12:06:18 -08001098 OpThreadMem(cu, kOpBlx, ENTRYPOINT_OFFSET(pStringCompareTo));
buzbeeb046e162012-10-30 15:48:42 -07001099 }
buzbeefa57c472012-11-21 12:06:18 -08001100 launch_pad->operands[2] = 0; // No return possible
Bill Buzbeea114add2012-05-03 15:00:40 -07001101 // Record that we've already inlined & null checked
buzbeefa57c472012-11-21 12:06:18 -08001102 info->opt_flags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
1103 RegLocation rl_return = GetReturn(cu, false);
1104 RegLocation rl_dest = InlineTarget(cu, info);
1105 StoreValue(cu, rl_dest, rl_return);
Bill Buzbeea114add2012-05-03 15:00:40 -07001106 return true;
Ian Rogers0183dd72012-09-17 23:06:51 -07001107}
1108
Ian Rogers07ec8e12012-12-01 01:26:51 -08001109bool Codegen::GenInlinedCurrentThread(CompilationUnit* cu, CallInfo* info) {
1110 RegLocation rl_dest = InlineTarget(cu, info);
1111 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
1112 int offset = Thread::PeerOffset().Int32Value();
1113 if (cu->instruction_set == kThumb2) {
1114 LoadWordDisp(cu, TargetReg(kSelf), offset, rl_result.low_reg);
1115 } else {
1116 CHECK(cu->instruction_set == kX86);
1117 ((X86Codegen*)this)->OpRegThreadMem(cu, kOpMov, rl_result.low_reg, offset);
1118 }
1119 StoreValue(cu, rl_dest, rl_result);
1120 return true;
1121}
1122
buzbee02031b12012-11-23 09:41:35 -08001123bool Codegen::GenIntrinsic(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001124{
buzbeefa57c472012-11-21 12:06:18 -08001125 if (info->opt_flags & MIR_INLINED) {
buzbeefc9e6fa2012-03-23 15:14:29 -07001126 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07001127 }
1128 /*
1129 * TODO: move these to a target-specific structured constant array
1130 * and use a generic match function. The list of intrinsics may be
1131 * slightly different depending on target.
1132 * TODO: Fold this into a matching function that runs during
1133 * basic block building. This should be part of the action for
1134 * small method inlining and recognition of the special object init
1135 * method. By doing this during basic block construction, we can also
1136 * take advantage of/generate new useful dataflow info.
1137 */
buzbeefa57c472012-11-21 12:06:18 -08001138 std::string tgt_method(PrettyMethod(info->index, *cu->dex_file));
1139 if (tgt_method.find(" java.lang") != std::string::npos) {
1140 if (tgt_method == "long java.lang.Double.doubleToRawLongBits(double)") {
1141 return GenInlinedDoubleCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001142 }
buzbeefa57c472012-11-21 12:06:18 -08001143 if (tgt_method == "double java.lang.Double.longBitsToDouble(long)") {
1144 return GenInlinedDoubleCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001145 }
buzbeefa57c472012-11-21 12:06:18 -08001146 if (tgt_method == "int java.lang.Float.float_to_raw_int_bits(float)") {
1147 return GenInlinedFloatCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001148 }
buzbeefa57c472012-11-21 12:06:18 -08001149 if (tgt_method == "float java.lang.Float.intBitsToFloat(int)") {
1150 return GenInlinedFloatCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001151 }
buzbeefa57c472012-11-21 12:06:18 -08001152 if (tgt_method == "int java.lang.Math.abs(int)" ||
1153 tgt_method == "int java.lang.StrictMath.abs(int)") {
1154 return GenInlinedAbsInt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001155 }
buzbeefa57c472012-11-21 12:06:18 -08001156 if (tgt_method == "long java.lang.Math.abs(long)" ||
1157 tgt_method == "long java.lang.StrictMath.abs(long)") {
1158 return GenInlinedAbsLong(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001159 }
buzbeefa57c472012-11-21 12:06:18 -08001160 if (tgt_method == "int java.lang.Math.max(int, int)" ||
1161 tgt_method == "int java.lang.StrictMath.max(int, int)") {
1162 return GenInlinedMinMaxInt(cu, info, false /* is_min */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001163 }
buzbeefa57c472012-11-21 12:06:18 -08001164 if (tgt_method == "int java.lang.Math.min(int, int)" ||
1165 tgt_method == "int java.lang.StrictMath.min(int, int)") {
1166 return GenInlinedMinMaxInt(cu, info, true /* is_min */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001167 }
buzbeefa57c472012-11-21 12:06:18 -08001168 if (tgt_method == "double java.lang.Math.sqrt(double)" ||
1169 tgt_method == "double java.lang.StrictMath.sqrt(double)") {
1170 return GenInlinedSqrt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001171 }
buzbeefa57c472012-11-21 12:06:18 -08001172 if (tgt_method == "char java.lang.String.charAt(int)") {
1173 return GenInlinedCharAt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001174 }
buzbeefa57c472012-11-21 12:06:18 -08001175 if (tgt_method == "int java.lang.String.compareTo(java.lang.String)") {
1176 return GenInlinedStringCompareTo(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001177 }
buzbeefa57c472012-11-21 12:06:18 -08001178 if (tgt_method == "boolean java.lang.String.is_empty()") {
1179 return GenInlinedStringIsEmptyOrLength(cu, info, true /* is_empty */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001180 }
buzbeefa57c472012-11-21 12:06:18 -08001181 if (tgt_method == "int java.lang.String.index_of(int, int)") {
1182 return GenInlinedIndexOf(cu, info, false /* base 0 */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001183 }
buzbeefa57c472012-11-21 12:06:18 -08001184 if (tgt_method == "int java.lang.String.index_of(int)") {
1185 return GenInlinedIndexOf(cu, info, true /* base 0 */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001186 }
buzbeefa57c472012-11-21 12:06:18 -08001187 if (tgt_method == "int java.lang.String.length()") {
1188 return GenInlinedStringIsEmptyOrLength(cu, info, false /* is_empty */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001189 }
Ian Rogers07ec8e12012-12-01 01:26:51 -08001190 if (tgt_method == "java.lang.Thread java.lang.Thread.currentThread()") {
1191 return GenInlinedCurrentThread(cu, info);
1192 }
buzbeefa57c472012-11-21 12:06:18 -08001193 } else if (tgt_method.find("boolean sun.misc.Unsafe.compareAndSwap") != std::string::npos) {
1194 if (tgt_method == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") {
1195 return GenInlinedCas32(cu, info, false);
Ian Rogers0183dd72012-09-17 23:06:51 -07001196 }
buzbeefa57c472012-11-21 12:06:18 -08001197 if (tgt_method == "boolean sun.misc.Unsafe.compareAndSwapObject(java.lang.Object, long, java.lang.Object, java.lang.Object)") {
1198 return GenInlinedCas32(cu, info, true);
Ian Rogers0183dd72012-09-17 23:06:51 -07001199 }
Ian Rogerse13eafa2012-09-07 11:24:27 -07001200 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001201 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -07001202}
1203
buzbee02031b12012-11-23 09:41:35 -08001204void Codegen::GenInvoke(CompilationUnit* cu, CallInfo* info)
buzbee1bc37c62012-11-20 13:35:41 -08001205{
buzbeefa57c472012-11-21 12:06:18 -08001206 if (GenIntrinsic(cu, info)) {
buzbee1bc37c62012-11-20 13:35:41 -08001207 return;
1208 }
buzbeefa57c472012-11-21 12:06:18 -08001209 InvokeType original_type = info->type; // avoiding mutation by ComputeInvokeInfo
1210 int call_state = 0;
1211 LIR* null_ck;
1212 LIR** p_null_ck = NULL;
1213 NextCallInsn next_call_insn;
1214 FlushAllRegs(cu); /* Everything to home location */
buzbee1bc37c62012-11-20 13:35:41 -08001215 // Explicit register usage
buzbeefa57c472012-11-21 12:06:18 -08001216 LockCallTemps(cu);
buzbee1bc37c62012-11-20 13:35:41 -08001217
buzbeefa57c472012-11-21 12:06:18 -08001218 OatCompilationUnit m_unit(cu->class_loader, cu->class_linker,
1219 *cu->dex_file,
1220 cu->code_item, cu->method_idx,
1221 cu->access_flags);
buzbee1bc37c62012-11-20 13:35:41 -08001222
buzbeefa57c472012-11-21 12:06:18 -08001223 uint32_t dex_method_idx = info->index;
1224 int vtable_idx;
1225 uintptr_t direct_code;
1226 uintptr_t direct_method;
1227 bool skip_this;
1228 bool fast_path =
1229 cu->compiler->ComputeInvokeInfo(dex_method_idx, &m_unit, info->type,
1230 vtable_idx, direct_code,
1231 direct_method)
buzbee1bc37c62012-11-20 13:35:41 -08001232 && !SLOW_INVOKE_PATH;
1233 if (info->type == kInterface) {
buzbeefa57c472012-11-21 12:06:18 -08001234 if (fast_path) {
1235 p_null_ck = &null_ck;
buzbee1bc37c62012-11-20 13:35:41 -08001236 }
buzbeefa57c472012-11-21 12:06:18 -08001237 next_call_insn = fast_path ? NextInterfaceCallInsn
buzbee52a77fc2012-11-20 19:50:46 -08001238 : NextInterfaceCallInsnWithAccessCheck;
buzbeefa57c472012-11-21 12:06:18 -08001239 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001240 } else if (info->type == kDirect) {
buzbeefa57c472012-11-21 12:06:18 -08001241 if (fast_path) {
1242 p_null_ck = &null_ck;
buzbee1bc37c62012-11-20 13:35:41 -08001243 }
buzbeefa57c472012-11-21 12:06:18 -08001244 next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP;
1245 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001246 } else if (info->type == kStatic) {
buzbeefa57c472012-11-21 12:06:18 -08001247 next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP;
1248 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001249 } else if (info->type == kSuper) {
buzbeefa57c472012-11-21 12:06:18 -08001250 DCHECK(!fast_path); // Fast path is a direct call.
1251 next_call_insn = NextSuperCallInsnSP;
1252 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001253 } else {
1254 DCHECK_EQ(info->type, kVirtual);
buzbeefa57c472012-11-21 12:06:18 -08001255 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1256 skip_this = fast_path;
buzbee1bc37c62012-11-20 13:35:41 -08001257 }
buzbeefa57c472012-11-21 12:06:18 -08001258 if (!info->is_range) {
1259 call_state = GenDalvikArgsNoRange(cu, info, call_state, p_null_ck,
1260 next_call_insn, dex_method_idx,
1261 vtable_idx, direct_code, direct_method,
1262 original_type, skip_this);
buzbee1bc37c62012-11-20 13:35:41 -08001263 } else {
buzbeefa57c472012-11-21 12:06:18 -08001264 call_state = GenDalvikArgsRange(cu, info, call_state, p_null_ck,
1265 next_call_insn, dex_method_idx, vtable_idx,
1266 direct_code, direct_method, original_type,
1267 skip_this);
buzbee1bc37c62012-11-20 13:35:41 -08001268 }
1269 // Finish up any of the call sequence not interleaved in arg loading
buzbeefa57c472012-11-21 12:06:18 -08001270 while (call_state >= 0) {
1271 call_state = next_call_insn(cu, info, call_state, dex_method_idx,
1272 vtable_idx, direct_code, direct_method,
1273 original_type);
buzbee1bc37c62012-11-20 13:35:41 -08001274 }
buzbeefa57c472012-11-21 12:06:18 -08001275 if (cu->enable_debug & (1 << kDebugDisplayMissingTargets)) {
1276 GenShowTarget(cu);
buzbee1bc37c62012-11-20 13:35:41 -08001277 }
buzbeefa57c472012-11-21 12:06:18 -08001278 LIR* call_inst;
1279 if (cu->instruction_set != kX86) {
1280 call_inst = OpReg(cu, kOpBlx, TargetReg(kInvokeTgt));
buzbee1bc37c62012-11-20 13:35:41 -08001281 } else {
buzbeefa57c472012-11-21 12:06:18 -08001282 if (fast_path && info->type != kInterface) {
1283 call_inst = OpMem(cu, kOpBlx, TargetReg(kArg0),
buzbee1bc37c62012-11-20 13:35:41 -08001284 AbstractMethod::GetCodeOffset().Int32Value());
1285 } else {
1286 int trampoline = 0;
1287 switch (info->type) {
1288 case kInterface:
buzbeefa57c472012-11-21 12:06:18 -08001289 trampoline = fast_path ? ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline)
buzbee1bc37c62012-11-20 13:35:41 -08001290 : ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
1291 break;
1292 case kDirect:
1293 trampoline = ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
1294 break;
1295 case kStatic:
1296 trampoline = ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
1297 break;
1298 case kSuper:
1299 trampoline = ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
1300 break;
1301 case kVirtual:
1302 trampoline = ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
1303 break;
1304 default:
1305 LOG(FATAL) << "Unexpected invoke type";
1306 }
buzbeefa57c472012-11-21 12:06:18 -08001307 call_inst = OpThreadMem(cu, kOpBlx, trampoline);
buzbee1bc37c62012-11-20 13:35:41 -08001308 }
1309 }
buzbeefa57c472012-11-21 12:06:18 -08001310 MarkSafepointPC(cu, call_inst);
buzbee1bc37c62012-11-20 13:35:41 -08001311
buzbeefa57c472012-11-21 12:06:18 -08001312 ClobberCalleeSave(cu);
buzbee1bc37c62012-11-20 13:35:41 -08001313 if (info->result.location != kLocInvalid) {
1314 // We have a following MOVE_RESULT - do it now.
1315 if (info->result.wide) {
buzbeefa57c472012-11-21 12:06:18 -08001316 RegLocation ret_loc = GetReturnWide(cu, info->result.fp);
1317 StoreValueWide(cu, info->result, ret_loc);
buzbee1bc37c62012-11-20 13:35:41 -08001318 } else {
buzbeefa57c472012-11-21 12:06:18 -08001319 RegLocation ret_loc = GetReturn(cu, info->result.fp);
1320 StoreValue(cu, info->result, ret_loc);
buzbee1bc37c62012-11-20 13:35:41 -08001321 }
1322 }
1323}
1324
1325/*
1326 * Build an array of location records for the incoming arguments.
1327 * Note: one location record per word of arguments, with dummy
1328 * high-word loc for wide arguments. Also pull up any following
1329 * MOVE_RESULT and incorporate it into the invoke.
1330 */
buzbee02031b12012-11-23 09:41:35 -08001331CallInfo* Codegen::NewMemCallInfo(CompilationUnit* cu, BasicBlock* bb, MIR* mir, InvokeType type,
1332 bool is_range)
buzbee1bc37c62012-11-20 13:35:41 -08001333{
buzbeefa57c472012-11-21 12:06:18 -08001334 CallInfo* info = static_cast<CallInfo*>(NewMem(cu, sizeof(CallInfo), true, kAllocMisc));
1335 MIR* move_result_mir = FindMoveResult(cu, bb, mir);
1336 if (move_result_mir == NULL) {
buzbee1bc37c62012-11-20 13:35:41 -08001337 info->result.location = kLocInvalid;
1338 } else {
buzbeefa57c472012-11-21 12:06:18 -08001339 info->result = GetRawDest(cu, move_result_mir);
buzbeea169e1d2012-12-05 14:26:44 -08001340 move_result_mir->meta.original_opcode = move_result_mir->dalvikInsn.opcode;
1341 move_result_mir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop);
buzbee1bc37c62012-11-20 13:35:41 -08001342 }
buzbeefa57c472012-11-21 12:06:18 -08001343 info->num_arg_words = mir->ssa_rep->num_uses;
1344 info->args = (info->num_arg_words == 0) ? NULL : static_cast<RegLocation*>
1345 (NewMem(cu, sizeof(RegLocation) * info->num_arg_words, false, kAllocMisc));
1346 for (int i = 0; i < info->num_arg_words; i++) {
1347 info->args[i] = GetRawSrc(cu, mir, i);
buzbee1bc37c62012-11-20 13:35:41 -08001348 }
buzbeefa57c472012-11-21 12:06:18 -08001349 info->opt_flags = mir->optimization_flags;
buzbee1bc37c62012-11-20 13:35:41 -08001350 info->type = type;
buzbeefa57c472012-11-21 12:06:18 -08001351 info->is_range = is_range;
buzbee1bc37c62012-11-20 13:35:41 -08001352 info->index = mir->dalvikInsn.vB;
1353 info->offset = mir->offset;
1354 return info;
1355}
1356
buzbee31a4a6f2012-02-28 15:36:15 -08001357} // namespace art