blob: f35415259ff6fe4c4f5a3edc2973c8590e1345d1 [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 {
buzbeee6285f92012-12-06 15:57:46 -0800605 if (rl_arg.wide) {
606 rl_arg.wide = false;
607 rl_arg.is_const = false;
608 }
buzbee02031b12012-11-23 09:41:35 -0800609 cg->LoadValueDirectFixed(cu, rl_arg, next_reg);
buzbee31a4a6f2012-02-28 15:36:15 -0800610 }
buzbeefa57c472012-11-21 12:06:18 -0800611 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
612 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700613 }
buzbeefa57c472012-11-21 12:06:18 -0800614 return call_state;
buzbee31a4a6f2012-02-28 15:36:15 -0800615}
616
617/*
618 * Load up to 5 arguments, the first three of which will be in
buzbeef0504cd2012-11-13 16:31:10 -0800619 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
buzbee31a4a6f2012-02-28 15:36:15 -0800620 * and as part of the load sequence, it must be replaced with
621 * the target method pointer. Note, this may also be called
622 * for "range" variants if the number of arguments is 5 or fewer.
623 */
buzbee02031b12012-11-23 09:41:35 -0800624int Codegen::GenDalvikArgsNoRange(CompilationUnit* cu, CallInfo* info,
625 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
626 uint32_t dex_idx, uint32_t method_idx, uintptr_t direct_code,
627 uintptr_t direct_method, InvokeType type, bool skip_this)
buzbee31a4a6f2012-02-28 15:36:15 -0800628{
buzbeefa57c472012-11-21 12:06:18 -0800629 RegLocation rl_arg;
buzbee31a4a6f2012-02-28 15:36:15 -0800630
Bill Buzbeea114add2012-05-03 15:00:40 -0700631 /* If no arguments, just return */
buzbeefa57c472012-11-21 12:06:18 -0800632 if (info->num_arg_words == 0)
633 return call_state;
Bill Buzbeea114add2012-05-03 15:00:40 -0700634
buzbeefa57c472012-11-21 12:06:18 -0800635 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
636 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700637
buzbeefa57c472012-11-21 12:06:18 -0800638 DCHECK_LE(info->num_arg_words, 5);
639 if (info->num_arg_words > 3) {
640 int32_t next_use = 3;
Bill Buzbeea114add2012-05-03 15:00:40 -0700641 //Detect special case of wide arg spanning arg3/arg4
buzbeefa57c472012-11-21 12:06:18 -0800642 RegLocation rl_use0 = info->args[0];
643 RegLocation rl_use1 = info->args[1];
644 RegLocation rl_use2 = info->args[2];
645 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) &&
646 rl_use2.wide) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700647 int reg = -1;
648 // Wide spans, we need the 2nd half of uses[2].
buzbeefa57c472012-11-21 12:06:18 -0800649 rl_arg = UpdateLocWide(cu, rl_use2);
650 if (rl_arg.location == kLocPhysReg) {
651 reg = rl_arg.high_reg;
Bill Buzbeea114add2012-05-03 15:00:40 -0700652 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800653 // kArg2 & rArg3 can safely be used here
buzbee52a77fc2012-11-20 19:50:46 -0800654 reg = TargetReg(kArg3);
buzbeefa57c472012-11-21 12:06:18 -0800655 LoadWordDisp(cu, TargetReg(kSp), SRegOffset(cu, rl_arg.s_reg_low) + 4, reg);
656 call_state = next_call_insn(cu, info, call_state, dex_idx,
657 method_idx, direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700658 }
buzbeefa57c472012-11-21 12:06:18 -0800659 StoreBaseDisp(cu, TargetReg(kSp), (next_use + 1) * 4, reg, kWord);
660 StoreBaseDisp(cu, TargetReg(kSp), 16 /* (3+1)*4 */, reg, kWord);
661 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
662 direct_code, direct_method, type);
663 next_use++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700664 }
665 // Loop through the rest
buzbeefa57c472012-11-21 12:06:18 -0800666 while (next_use < info->num_arg_words) {
667 int low_reg;
668 int high_reg = -1;
669 rl_arg = info->args[next_use];
670 rl_arg = UpdateRawLoc(cu, rl_arg);
671 if (rl_arg.location == kLocPhysReg) {
672 low_reg = rl_arg.low_reg;
673 high_reg = rl_arg.high_reg;
Bill Buzbeea114add2012-05-03 15:00:40 -0700674 } else {
buzbeefa57c472012-11-21 12:06:18 -0800675 low_reg = TargetReg(kArg2);
676 if (rl_arg.wide) {
677 high_reg = TargetReg(kArg3);
678 LoadValueDirectWideFixed(cu, rl_arg, low_reg, high_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700679 } else {
buzbeefa57c472012-11-21 12:06:18 -0800680 LoadValueDirectFixed(cu, rl_arg, low_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700681 }
buzbeefa57c472012-11-21 12:06:18 -0800682 call_state = next_call_insn(cu, info, call_state, dex_idx,
683 method_idx, direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700684 }
buzbeefa57c472012-11-21 12:06:18 -0800685 int outs_offset = (next_use + 1) * 4;
686 if (rl_arg.wide) {
687 StoreBaseDispWide(cu, TargetReg(kSp), outs_offset, low_reg, high_reg);
688 next_use += 2;
Bill Buzbeea114add2012-05-03 15:00:40 -0700689 } else {
buzbeefa57c472012-11-21 12:06:18 -0800690 StoreWordDisp(cu, TargetReg(kSp), outs_offset, low_reg);
691 next_use++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700692 }
buzbeefa57c472012-11-21 12:06:18 -0800693 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
694 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700695 }
696 }
697
buzbeefa57c472012-11-21 12:06:18 -0800698 call_state = LoadArgRegs(cu, info, call_state, next_call_insn,
699 dex_idx, method_idx, direct_code, direct_method,
700 type, skip_this);
Bill Buzbeea114add2012-05-03 15:00:40 -0700701
702 if (pcrLabel) {
buzbeefa57c472012-11-21 12:06:18 -0800703 *pcrLabel = GenNullCheck(cu, info->args[0].s_reg_low, TargetReg(kArg1), info->opt_flags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700704 }
buzbeefa57c472012-11-21 12:06:18 -0800705 return call_state;
buzbee31a4a6f2012-02-28 15:36:15 -0800706}
707
708/*
709 * May have 0+ arguments (also used for jumbo). Note that
710 * source virtual registers may be in physical registers, so may
711 * need to be flushed to home location before copying. This
712 * applies to arg3 and above (see below).
713 *
714 * Two general strategies:
715 * If < 20 arguments
716 * Pass args 3-18 using vldm/vstm block copy
buzbeef0504cd2012-11-13 16:31:10 -0800717 * Pass arg0, arg1 & arg2 in kArg1-kArg3
buzbee31a4a6f2012-02-28 15:36:15 -0800718 * If 20+ arguments
719 * Pass args arg19+ using memcpy block copy
buzbeef0504cd2012-11-13 16:31:10 -0800720 * Pass arg0, arg1 & arg2 in kArg1-kArg3
buzbee31a4a6f2012-02-28 15:36:15 -0800721 *
722 */
buzbee02031b12012-11-23 09:41:35 -0800723int Codegen::GenDalvikArgsRange(CompilationUnit* cu, CallInfo* info, int call_state,
724 LIR** pcrLabel, NextCallInsn next_call_insn, uint32_t dex_idx,
725 uint32_t method_idx, uintptr_t direct_code, uintptr_t direct_method,
726 InvokeType type, bool skip_this)
buzbee31a4a6f2012-02-28 15:36:15 -0800727{
buzbee31a4a6f2012-02-28 15:36:15 -0800728
Bill Buzbeea114add2012-05-03 15:00:40 -0700729 // If we can treat it as non-range (Jumbo ops will use range form)
buzbeefa57c472012-11-21 12:06:18 -0800730 if (info->num_arg_words <= 5)
731 return GenDalvikArgsNoRange(cu, info, call_state, pcrLabel,
732 next_call_insn, dex_idx, method_idx,
733 direct_code, direct_method, type, skip_this);
Bill Buzbeea114add2012-05-03 15:00:40 -0700734 /*
Bill Buzbeea114add2012-05-03 15:00:40 -0700735 * First load the non-register arguments. Both forms expect all
736 * of the source arguments to be in their home frame location, so
buzbeefa57c472012-11-21 12:06:18 -0800737 * scan the s_reg names and flush any that have been promoted to
Bill Buzbeea114add2012-05-03 15:00:40 -0700738 * frame backing storage.
739 */
buzbeefa57c472012-11-21 12:06:18 -0800740 // Scan the rest of the args - if in phys_reg flush to memory
741 for (int next_arg = 0; next_arg < info->num_arg_words;) {
742 RegLocation loc = info->args[next_arg];
Bill Buzbeea114add2012-05-03 15:00:40 -0700743 if (loc.wide) {
buzbeefa57c472012-11-21 12:06:18 -0800744 loc = UpdateLocWide(cu, loc);
745 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
746 StoreBaseDispWide(cu, TargetReg(kSp), SRegOffset(cu, loc.s_reg_low),
747 loc.low_reg, loc.high_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700748 }
buzbeefa57c472012-11-21 12:06:18 -0800749 next_arg += 2;
Bill Buzbeea114add2012-05-03 15:00:40 -0700750 } else {
buzbeefa57c472012-11-21 12:06:18 -0800751 loc = UpdateLoc(cu, loc);
752 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
753 StoreBaseDisp(cu, TargetReg(kSp), SRegOffset(cu, loc.s_reg_low),
754 loc.low_reg, kWord);
Bill Buzbeea114add2012-05-03 15:00:40 -0700755 }
buzbeefa57c472012-11-21 12:06:18 -0800756 next_arg++;
buzbee31a4a6f2012-02-28 15:36:15 -0800757 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700758 }
buzbee31a4a6f2012-02-28 15:36:15 -0800759
buzbeefa57c472012-11-21 12:06:18 -0800760 int start_offset = SRegOffset(cu, info->args[3].s_reg_low);
761 int outs_offset = 4 /* Method* */ + (3 * 4);
762 if (cu->instruction_set != kThumb2) {
buzbee31a4a6f2012-02-28 15:36:15 -0800763 // Generate memcpy
buzbeefa57c472012-11-21 12:06:18 -0800764 OpRegRegImm(cu, kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset);
765 OpRegRegImm(cu, kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset);
766 CallRuntimeHelperRegRegImm(cu, ENTRYPOINT_OFFSET(pMemcpy), TargetReg(kArg0),
767 TargetReg(kArg1), (info->num_arg_words - 3) * 4, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700768 } else {
buzbeefa57c472012-11-21 12:06:18 -0800769 if (info->num_arg_words >= 20) {
buzbeeb046e162012-10-30 15:48:42 -0700770 // Generate memcpy
buzbeefa57c472012-11-21 12:06:18 -0800771 OpRegRegImm(cu, kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset);
772 OpRegRegImm(cu, kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset);
773 CallRuntimeHelperRegRegImm(cu, ENTRYPOINT_OFFSET(pMemcpy), TargetReg(kArg0),
774 TargetReg(kArg1), (info->num_arg_words - 3) * 4, false);
buzbeeb046e162012-10-30 15:48:42 -0700775 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800776 // Use vldm/vstm pair using kArg3 as a temp
buzbeefa57c472012-11-21 12:06:18 -0800777 int regs_left = std::min(info->num_arg_words - 3, 16);
778 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
779 direct_code, direct_method, type);
780 OpRegRegImm(cu, kOpAdd, TargetReg(kArg3), TargetReg(kSp), start_offset);
781 LIR* ld = OpVldm(cu, TargetReg(kArg3), regs_left);
buzbeeb046e162012-10-30 15:48:42 -0700782 //TUNING: loosen barrier
buzbeefa57c472012-11-21 12:06:18 -0800783 ld->def_mask = ENCODE_ALL;
buzbee02031b12012-11-23 09:41:35 -0800784 SetMemRefType(cu, ld, true /* is_load */, kDalvikReg);
buzbeefa57c472012-11-21 12:06:18 -0800785 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
786 direct_code, direct_method, type);
787 OpRegRegImm(cu, kOpAdd, TargetReg(kArg3), TargetReg(kSp), 4 /* Method* */ + (3 * 4));
788 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
789 direct_code, direct_method, type);
790 LIR* st = OpVstm(cu, TargetReg(kArg3), regs_left);
buzbee02031b12012-11-23 09:41:35 -0800791 SetMemRefType(cu, st, false /* is_load */, kDalvikReg);
buzbeefa57c472012-11-21 12:06:18 -0800792 st->def_mask = ENCODE_ALL;
793 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
794 direct_code, direct_method, type);
buzbeeb046e162012-10-30 15:48:42 -0700795 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700796 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700797
buzbeefa57c472012-11-21 12:06:18 -0800798 call_state = LoadArgRegs(cu, info, call_state, next_call_insn,
799 dex_idx, method_idx, direct_code, direct_method,
800 type, skip_this);
Bill Buzbeea114add2012-05-03 15:00:40 -0700801
buzbeefa57c472012-11-21 12:06:18 -0800802 call_state = next_call_insn(cu, info, call_state, dex_idx, method_idx,
803 direct_code, direct_method, type);
Bill Buzbeea114add2012-05-03 15:00:40 -0700804 if (pcrLabel) {
buzbeefa57c472012-11-21 12:06:18 -0800805 *pcrLabel = GenNullCheck(cu, info->args[0].s_reg_low, TargetReg(kArg1),
806 info->opt_flags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700807 }
buzbeefa57c472012-11-21 12:06:18 -0800808 return call_state;
buzbee31a4a6f2012-02-28 15:36:15 -0800809}
810
buzbee02031b12012-11-23 09:41:35 -0800811RegLocation Codegen::InlineTarget(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700812{
Bill Buzbeea114add2012-05-03 15:00:40 -0700813 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700814 if (info->result.location == kLocInvalid) {
buzbeefa57c472012-11-21 12:06:18 -0800815 res = GetReturn(cu, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700816 } else {
buzbee15bf9802012-06-12 17:49:27 -0700817 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700818 }
819 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700820}
821
buzbee02031b12012-11-23 09:41:35 -0800822RegLocation Codegen::InlineTargetWide(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700823{
Bill Buzbeea114add2012-05-03 15:00:40 -0700824 RegLocation res;
buzbee15bf9802012-06-12 17:49:27 -0700825 if (info->result.location == kLocInvalid) {
buzbeefa57c472012-11-21 12:06:18 -0800826 res = GetReturnWide(cu, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700827 } else {
buzbee15bf9802012-06-12 17:49:27 -0700828 res = info->result;
Bill Buzbeea114add2012-05-03 15:00:40 -0700829 }
830 return res;
buzbeefc9e6fa2012-03-23 15:14:29 -0700831}
832
buzbee02031b12012-11-23 09:41:35 -0800833bool Codegen::GenInlinedCharAt(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700834{
buzbeefa57c472012-11-21 12:06:18 -0800835 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700836 // TODO - add Mips implementation
837 return false;
838 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700839 // Location of reference to data array
buzbeefa57c472012-11-21 12:06:18 -0800840 int value_offset = String::ValueOffset().Int32Value();
Bill Buzbeea114add2012-05-03 15:00:40 -0700841 // Location of count
buzbeefa57c472012-11-21 12:06:18 -0800842 int count_offset = String::CountOffset().Int32Value();
Bill Buzbeea114add2012-05-03 15:00:40 -0700843 // Starting offset within data array
buzbeefa57c472012-11-21 12:06:18 -0800844 int offset_offset = String::OffsetOffset().Int32Value();
Bill Buzbeea114add2012-05-03 15:00:40 -0700845 // Start of char data with array_
buzbeefa57c472012-11-21 12:06:18 -0800846 int data_offset = Array::DataOffset(sizeof(uint16_t)).Int32Value();
buzbeefc9e6fa2012-03-23 15:14:29 -0700847
buzbeefa57c472012-11-21 12:06:18 -0800848 RegLocation rl_obj = info->args[0];
849 RegLocation rl_idx = info->args[1];
850 rl_obj = LoadValue(cu, rl_obj, kCoreReg);
851 rl_idx = LoadValue(cu, rl_idx, kCoreReg);
852 int reg_max;
853 GenNullCheck(cu, rl_obj.s_reg_low, rl_obj.low_reg, info->opt_flags);
854 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
855 LIR* launch_pad = NULL;
856 int reg_off = INVALID_REG;
857 int reg_ptr = INVALID_REG;
858 if (cu->instruction_set != kX86) {
859 reg_off = AllocTemp(cu);
860 reg_ptr = AllocTemp(cu);
861 if (range_check) {
862 reg_max = AllocTemp(cu);
863 LoadWordDisp(cu, rl_obj.low_reg, count_offset, reg_max);
buzbeeb046e162012-10-30 15:48:42 -0700864 }
buzbeefa57c472012-11-21 12:06:18 -0800865 LoadWordDisp(cu, rl_obj.low_reg, offset_offset, reg_off);
866 LoadWordDisp(cu, rl_obj.low_reg, value_offset, reg_ptr);
867 if (range_check) {
buzbeeb046e162012-10-30 15:48:42 -0700868 // Set up a launch pad to allow retry in case of bounds violation */
buzbeefa57c472012-11-21 12:06:18 -0800869 launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
870 InsertGrowableList(cu, &cu->intrinsic_launchpads,
871 reinterpret_cast<uintptr_t>(launch_pad));
872 OpRegReg(cu, kOpCmp, rl_idx.low_reg, reg_max);
873 FreeTemp(cu, reg_max);
874 OpCondBranch(cu, kCondCs, launch_pad);
buzbeeb046e162012-10-30 15:48:42 -0700875 }
876 } else {
buzbeefa57c472012-11-21 12:06:18 -0800877 if (range_check) {
878 reg_max = AllocTemp(cu);
879 LoadWordDisp(cu, rl_obj.low_reg, count_offset, reg_max);
buzbeeb046e162012-10-30 15:48:42 -0700880 // Set up a launch pad to allow retry in case of bounds violation */
buzbeefa57c472012-11-21 12:06:18 -0800881 launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
882 InsertGrowableList(cu, &cu->intrinsic_launchpads,
883 reinterpret_cast<uintptr_t>(launch_pad));
884 OpRegReg(cu, kOpCmp, rl_idx.low_reg, reg_max);
885 FreeTemp(cu, reg_max);
886 OpCondBranch(cu, kCondCc, launch_pad);
buzbeeb046e162012-10-30 15:48:42 -0700887 }
buzbeefa57c472012-11-21 12:06:18 -0800888 reg_off = AllocTemp(cu);
889 reg_ptr = AllocTemp(cu);
890 LoadWordDisp(cu, rl_obj.low_reg, offset_offset, reg_off);
891 LoadWordDisp(cu, rl_obj.low_reg, value_offset, reg_ptr);
Bill Buzbeea114add2012-05-03 15:00:40 -0700892 }
buzbeefa57c472012-11-21 12:06:18 -0800893 OpRegImm(cu, kOpAdd, reg_ptr, data_offset);
894 OpRegReg(cu, kOpAdd, reg_off, rl_idx.low_reg);
895 FreeTemp(cu, rl_obj.low_reg);
896 FreeTemp(cu, rl_idx.low_reg);
897 RegLocation rl_dest = InlineTarget(cu, info);
898 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
899 LoadBaseIndexed(cu, reg_ptr, reg_off, rl_result.low_reg, 1, kUnsignedHalf);
900 FreeTemp(cu, reg_off);
901 FreeTemp(cu, reg_ptr);
902 StoreValue(cu, rl_dest, rl_result);
903 if (range_check) {
904 launch_pad->operands[2] = 0; // no resumption
Bill Buzbeea114add2012-05-03 15:00:40 -0700905 }
906 // Record that we've already inlined & null checked
buzbeefa57c472012-11-21 12:06:18 -0800907 info->opt_flags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
Bill Buzbeea114add2012-05-03 15:00:40 -0700908 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700909}
910
buzbeefa57c472012-11-21 12:06:18 -0800911// Generates an inlined String.is_empty or String.length.
buzbee02031b12012-11-23 09:41:35 -0800912bool Codegen::GenInlinedStringIsEmptyOrLength(CompilationUnit* cu, CallInfo* info, bool is_empty)
buzbeefc9e6fa2012-03-23 15:14:29 -0700913{
buzbeefa57c472012-11-21 12:06:18 -0800914 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700915 // TODO - add Mips implementation
916 return false;
917 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700918 // dst = src.length();
buzbeefa57c472012-11-21 12:06:18 -0800919 RegLocation rl_obj = info->args[0];
920 rl_obj = LoadValue(cu, rl_obj, kCoreReg);
921 RegLocation rl_dest = InlineTarget(cu, info);
922 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
923 GenNullCheck(cu, rl_obj.s_reg_low, rl_obj.low_reg, info->opt_flags);
924 LoadWordDisp(cu, rl_obj.low_reg, String::CountOffset().Int32Value(),
925 rl_result.low_reg);
926 if (is_empty) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700927 // dst = (dst == 0);
buzbeefa57c472012-11-21 12:06:18 -0800928 if (cu->instruction_set == kThumb2) {
929 int t_reg = AllocTemp(cu);
930 OpRegReg(cu, kOpNeg, t_reg, rl_result.low_reg);
931 OpRegRegReg(cu, kOpAdc, rl_result.low_reg, rl_result.low_reg, t_reg);
buzbeeb046e162012-10-30 15:48:42 -0700932 } else {
buzbeefa57c472012-11-21 12:06:18 -0800933 DCHECK_EQ(cu->instruction_set, kX86);
934 OpRegImm(cu, kOpSub, rl_result.low_reg, 1);
935 OpRegImm(cu, kOpLsr, rl_result.low_reg, 31);
buzbeeb046e162012-10-30 15:48:42 -0700936 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700937 }
buzbeefa57c472012-11-21 12:06:18 -0800938 StoreValue(cu, rl_dest, rl_result);
Bill Buzbeea114add2012-05-03 15:00:40 -0700939 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700940}
941
buzbee02031b12012-11-23 09:41:35 -0800942bool Codegen::GenInlinedAbsInt(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700943{
buzbeefa57c472012-11-21 12:06:18 -0800944 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700945 // TODO - add Mips implementation
946 return false;
947 }
buzbeefa57c472012-11-21 12:06:18 -0800948 RegLocation rl_src = info->args[0];
949 rl_src = LoadValue(cu, rl_src, kCoreReg);
950 RegLocation rl_dest = InlineTarget(cu, info);
951 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
952 int sign_reg = AllocTemp(cu);
Bill Buzbeea114add2012-05-03 15:00:40 -0700953 // abs(x) = y<=x>>31, (x+y)^y.
buzbeefa57c472012-11-21 12:06:18 -0800954 OpRegRegImm(cu, kOpAsr, sign_reg, rl_src.low_reg, 31);
955 OpRegRegReg(cu, kOpAdd, rl_result.low_reg, rl_src.low_reg, sign_reg);
956 OpRegReg(cu, kOpXor, rl_result.low_reg, sign_reg);
957 StoreValue(cu, rl_dest, rl_result);
Bill Buzbeea114add2012-05-03 15:00:40 -0700958 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -0700959}
960
buzbee02031b12012-11-23 09:41:35 -0800961bool Codegen::GenInlinedAbsLong(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -0700962{
buzbeefa57c472012-11-21 12:06:18 -0800963 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -0700964 // TODO - add Mips implementation
965 return false;
966 }
buzbeefa57c472012-11-21 12:06:18 -0800967 if (cu->instruction_set == kThumb2) {
968 RegLocation rl_src = info->args[0];
969 rl_src = LoadValueWide(cu, rl_src, kCoreReg);
970 RegLocation rl_dest = InlineTargetWide(cu, info);
971 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
972 int sign_reg = AllocTemp(cu);
buzbeeb046e162012-10-30 15:48:42 -0700973 // abs(x) = y<=x>>31, (x+y)^y.
buzbeefa57c472012-11-21 12:06:18 -0800974 OpRegRegImm(cu, kOpAsr, sign_reg, rl_src.high_reg, 31);
975 OpRegRegReg(cu, kOpAdd, rl_result.low_reg, rl_src.low_reg, sign_reg);
976 OpRegRegReg(cu, kOpAdc, rl_result.high_reg, rl_src.high_reg, sign_reg);
977 OpRegReg(cu, kOpXor, rl_result.low_reg, sign_reg);
978 OpRegReg(cu, kOpXor, rl_result.high_reg, sign_reg);
979 StoreValueWide(cu, rl_dest, rl_result);
buzbeeb046e162012-10-30 15:48:42 -0700980 return true;
981 } else {
buzbeefa57c472012-11-21 12:06:18 -0800982 DCHECK_EQ(cu->instruction_set, kX86);
buzbeeb046e162012-10-30 15:48:42 -0700983 // Reuse source registers to avoid running out of temps
buzbeefa57c472012-11-21 12:06:18 -0800984 RegLocation rl_src = info->args[0];
985 rl_src = LoadValueWide(cu, rl_src, kCoreReg);
986 RegLocation rl_dest = InlineTargetWide(cu, info);
987 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
988 OpRegCopyWide(cu, rl_result.low_reg, rl_result.high_reg, rl_src.low_reg, rl_src.high_reg);
989 FreeTemp(cu, rl_src.low_reg);
990 FreeTemp(cu, rl_src.high_reg);
991 int sign_reg = AllocTemp(cu);
buzbeeb046e162012-10-30 15:48:42 -0700992 // abs(x) = y<=x>>31, (x+y)^y.
buzbeefa57c472012-11-21 12:06:18 -0800993 OpRegRegImm(cu, kOpAsr, sign_reg, rl_result.high_reg, 31);
994 OpRegReg(cu, kOpAdd, rl_result.low_reg, sign_reg);
995 OpRegReg(cu, kOpAdc, rl_result.high_reg, sign_reg);
996 OpRegReg(cu, kOpXor, rl_result.low_reg, sign_reg);
997 OpRegReg(cu, kOpXor, rl_result.high_reg, sign_reg);
998 StoreValueWide(cu, rl_dest, rl_result);
buzbeeb046e162012-10-30 15:48:42 -0700999 return true;
1000 }
buzbeefc9e6fa2012-03-23 15:14:29 -07001001}
1002
buzbee02031b12012-11-23 09:41:35 -08001003bool Codegen::GenInlinedFloatCvt(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001004{
buzbeefa57c472012-11-21 12:06:18 -08001005 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001006 // TODO - add Mips implementation
1007 return false;
1008 }
buzbeefa57c472012-11-21 12:06:18 -08001009 RegLocation rl_src = info->args[0];
1010 RegLocation rl_dest = InlineTarget(cu, info);
1011 StoreValue(cu, rl_dest, rl_src);
Bill Buzbeea114add2012-05-03 15:00:40 -07001012 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -07001013}
1014
buzbee02031b12012-11-23 09:41:35 -08001015bool Codegen::GenInlinedDoubleCvt(CompilationUnit *cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001016{
buzbeefa57c472012-11-21 12:06:18 -08001017 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001018 // TODO - add Mips implementation
1019 return false;
1020 }
buzbeefa57c472012-11-21 12:06:18 -08001021 RegLocation rl_src = info->args[0];
1022 RegLocation rl_dest = InlineTargetWide(cu, info);
1023 StoreValueWide(cu, rl_dest, rl_src);
Bill Buzbeea114add2012-05-03 15:00:40 -07001024 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -07001025}
1026
1027/*
buzbeefa57c472012-11-21 12:06:18 -08001028 * Fast string.index_of(I) & (II). Tests for simple case of char <= 0xffff,
buzbeefc9e6fa2012-03-23 15:14:29 -07001029 * otherwise bails to standard library code.
1030 */
buzbee02031b12012-11-23 09:41:35 -08001031bool Codegen::GenInlinedIndexOf(CompilationUnit* cu, CallInfo* info, bool zero_based)
buzbeefc9e6fa2012-03-23 15:14:29 -07001032{
buzbeefa57c472012-11-21 12:06:18 -08001033 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001034 // TODO - add Mips implementation
1035 return false;
1036 }
buzbeefa57c472012-11-21 12:06:18 -08001037 ClobberCalleeSave(cu);
1038 LockCallTemps(cu); // Using fixed registers
1039 int reg_ptr = TargetReg(kArg0);
1040 int reg_char = TargetReg(kArg1);
1041 int reg_start = TargetReg(kArg2);
buzbeefc9e6fa2012-03-23 15:14:29 -07001042
buzbeefa57c472012-11-21 12:06:18 -08001043 RegLocation rl_obj = info->args[0];
1044 RegLocation rl_char = info->args[1];
1045 RegLocation rl_start = info->args[2];
1046 LoadValueDirectFixed(cu, rl_obj, reg_ptr);
1047 LoadValueDirectFixed(cu, rl_char, reg_char);
1048 if (zero_based) {
1049 LoadConstant(cu, reg_start, 0);
Bill Buzbeea114add2012-05-03 15:00:40 -07001050 } else {
buzbeefa57c472012-11-21 12:06:18 -08001051 LoadValueDirectFixed(cu, rl_start, reg_start);
Bill Buzbeea114add2012-05-03 15:00:40 -07001052 }
buzbeefa57c472012-11-21 12:06:18 -08001053 int r_tgt = (cu->instruction_set != kX86) ? LoadHelper(cu, ENTRYPOINT_OFFSET(pIndexOf)) : 0;
1054 GenNullCheck(cu, rl_obj.s_reg_low, reg_ptr, info->opt_flags);
1055 LIR* launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
1056 InsertGrowableList(cu, &cu->intrinsic_launchpads, reinterpret_cast<uintptr_t>(launch_pad));
1057 OpCmpImmBranch(cu, kCondGt, reg_char, 0xFFFF, launch_pad);
buzbee8320f382012-09-11 16:29:42 -07001058 // NOTE: not a safepoint
buzbeefa57c472012-11-21 12:06:18 -08001059 if (cu->instruction_set != kX86) {
1060 OpReg(cu, kOpBlx, r_tgt);
buzbeeb046e162012-10-30 15:48:42 -07001061 } else {
buzbeefa57c472012-11-21 12:06:18 -08001062 OpThreadMem(cu, kOpBlx, ENTRYPOINT_OFFSET(pIndexOf));
buzbeeb046e162012-10-30 15:48:42 -07001063 }
buzbeefa57c472012-11-21 12:06:18 -08001064 LIR* resume_tgt = NewLIR0(cu, kPseudoTargetLabel);
1065 launch_pad->operands[2] = reinterpret_cast<uintptr_t>(resume_tgt);
Bill Buzbeea114add2012-05-03 15:00:40 -07001066 // Record that we've already inlined & null checked
buzbeefa57c472012-11-21 12:06:18 -08001067 info->opt_flags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
1068 RegLocation rl_return = GetReturn(cu, false);
1069 RegLocation rl_dest = InlineTarget(cu, info);
1070 StoreValue(cu, rl_dest, rl_return);
Bill Buzbeea114add2012-05-03 15:00:40 -07001071 return true;
buzbeefc9e6fa2012-03-23 15:14:29 -07001072}
1073
1074/* Fast string.compareTo(Ljava/lang/string;)I. */
buzbee02031b12012-11-23 09:41:35 -08001075bool Codegen::GenInlinedStringCompareTo(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001076{
buzbeefa57c472012-11-21 12:06:18 -08001077 if (cu->instruction_set == kMips) {
buzbeeb046e162012-10-30 15:48:42 -07001078 // TODO - add Mips implementation
1079 return false;
1080 }
buzbeefa57c472012-11-21 12:06:18 -08001081 ClobberCalleeSave(cu);
1082 LockCallTemps(cu); // Using fixed registers
1083 int reg_this = TargetReg(kArg0);
1084 int reg_cmp = TargetReg(kArg1);
buzbeefc9e6fa2012-03-23 15:14:29 -07001085
buzbeefa57c472012-11-21 12:06:18 -08001086 RegLocation rl_this = info->args[0];
1087 RegLocation rl_cmp = info->args[1];
1088 LoadValueDirectFixed(cu, rl_this, reg_this);
1089 LoadValueDirectFixed(cu, rl_cmp, reg_cmp);
1090 int r_tgt = (cu->instruction_set != kX86) ?
1091 LoadHelper(cu, ENTRYPOINT_OFFSET(pStringCompareTo)) : 0;
1092 GenNullCheck(cu, rl_this.s_reg_low, reg_this, info->opt_flags);
1093 //TUNING: check if rl_cmp.s_reg_low is already null checked
1094 LIR* launch_pad = RawLIR(cu, 0, kPseudoIntrinsicRetry, reinterpret_cast<uintptr_t>(info));
1095 InsertGrowableList(cu, &cu->intrinsic_launchpads, reinterpret_cast<uintptr_t>(launch_pad));
1096 OpCmpImmBranch(cu, kCondEq, reg_cmp, 0, launch_pad);
buzbee8320f382012-09-11 16:29:42 -07001097 // NOTE: not a safepoint
buzbeefa57c472012-11-21 12:06:18 -08001098 if (cu->instruction_set != kX86) {
1099 OpReg(cu, kOpBlx, r_tgt);
buzbeeb046e162012-10-30 15:48:42 -07001100 } else {
buzbeefa57c472012-11-21 12:06:18 -08001101 OpThreadMem(cu, kOpBlx, ENTRYPOINT_OFFSET(pStringCompareTo));
buzbeeb046e162012-10-30 15:48:42 -07001102 }
buzbeefa57c472012-11-21 12:06:18 -08001103 launch_pad->operands[2] = 0; // No return possible
Bill Buzbeea114add2012-05-03 15:00:40 -07001104 // Record that we've already inlined & null checked
buzbeefa57c472012-11-21 12:06:18 -08001105 info->opt_flags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK);
1106 RegLocation rl_return = GetReturn(cu, false);
1107 RegLocation rl_dest = InlineTarget(cu, info);
1108 StoreValue(cu, rl_dest, rl_return);
Bill Buzbeea114add2012-05-03 15:00:40 -07001109 return true;
Ian Rogers0183dd72012-09-17 23:06:51 -07001110}
1111
Ian Rogers07ec8e12012-12-01 01:26:51 -08001112bool Codegen::GenInlinedCurrentThread(CompilationUnit* cu, CallInfo* info) {
1113 RegLocation rl_dest = InlineTarget(cu, info);
1114 RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true);
1115 int offset = Thread::PeerOffset().Int32Value();
1116 if (cu->instruction_set == kThumb2) {
1117 LoadWordDisp(cu, TargetReg(kSelf), offset, rl_result.low_reg);
1118 } else {
1119 CHECK(cu->instruction_set == kX86);
1120 ((X86Codegen*)this)->OpRegThreadMem(cu, kOpMov, rl_result.low_reg, offset);
1121 }
1122 StoreValue(cu, rl_dest, rl_result);
1123 return true;
1124}
1125
buzbee02031b12012-11-23 09:41:35 -08001126bool Codegen::GenIntrinsic(CompilationUnit* cu, CallInfo* info)
buzbeefc9e6fa2012-03-23 15:14:29 -07001127{
buzbeefa57c472012-11-21 12:06:18 -08001128 if (info->opt_flags & MIR_INLINED) {
buzbeefc9e6fa2012-03-23 15:14:29 -07001129 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07001130 }
1131 /*
1132 * TODO: move these to a target-specific structured constant array
1133 * and use a generic match function. The list of intrinsics may be
1134 * slightly different depending on target.
1135 * TODO: Fold this into a matching function that runs during
1136 * basic block building. This should be part of the action for
1137 * small method inlining and recognition of the special object init
1138 * method. By doing this during basic block construction, we can also
1139 * take advantage of/generate new useful dataflow info.
1140 */
buzbeefa57c472012-11-21 12:06:18 -08001141 std::string tgt_method(PrettyMethod(info->index, *cu->dex_file));
1142 if (tgt_method.find(" java.lang") != std::string::npos) {
1143 if (tgt_method == "long java.lang.Double.doubleToRawLongBits(double)") {
1144 return GenInlinedDoubleCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001145 }
buzbeefa57c472012-11-21 12:06:18 -08001146 if (tgt_method == "double java.lang.Double.longBitsToDouble(long)") {
1147 return GenInlinedDoubleCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001148 }
buzbeefa57c472012-11-21 12:06:18 -08001149 if (tgt_method == "int java.lang.Float.float_to_raw_int_bits(float)") {
1150 return GenInlinedFloatCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001151 }
buzbeefa57c472012-11-21 12:06:18 -08001152 if (tgt_method == "float java.lang.Float.intBitsToFloat(int)") {
1153 return GenInlinedFloatCvt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001154 }
buzbeefa57c472012-11-21 12:06:18 -08001155 if (tgt_method == "int java.lang.Math.abs(int)" ||
1156 tgt_method == "int java.lang.StrictMath.abs(int)") {
1157 return GenInlinedAbsInt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001158 }
buzbeefa57c472012-11-21 12:06:18 -08001159 if (tgt_method == "long java.lang.Math.abs(long)" ||
1160 tgt_method == "long java.lang.StrictMath.abs(long)") {
1161 return GenInlinedAbsLong(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001162 }
buzbeefa57c472012-11-21 12:06:18 -08001163 if (tgt_method == "int java.lang.Math.max(int, int)" ||
1164 tgt_method == "int java.lang.StrictMath.max(int, int)") {
1165 return GenInlinedMinMaxInt(cu, info, false /* is_min */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001166 }
buzbeefa57c472012-11-21 12:06:18 -08001167 if (tgt_method == "int java.lang.Math.min(int, int)" ||
1168 tgt_method == "int java.lang.StrictMath.min(int, int)") {
1169 return GenInlinedMinMaxInt(cu, info, true /* is_min */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001170 }
buzbeefa57c472012-11-21 12:06:18 -08001171 if (tgt_method == "double java.lang.Math.sqrt(double)" ||
1172 tgt_method == "double java.lang.StrictMath.sqrt(double)") {
1173 return GenInlinedSqrt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001174 }
buzbeefa57c472012-11-21 12:06:18 -08001175 if (tgt_method == "char java.lang.String.charAt(int)") {
1176 return GenInlinedCharAt(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001177 }
buzbeefa57c472012-11-21 12:06:18 -08001178 if (tgt_method == "int java.lang.String.compareTo(java.lang.String)") {
1179 return GenInlinedStringCompareTo(cu, info);
Ian Rogers0183dd72012-09-17 23:06:51 -07001180 }
buzbeefa57c472012-11-21 12:06:18 -08001181 if (tgt_method == "boolean java.lang.String.is_empty()") {
1182 return GenInlinedStringIsEmptyOrLength(cu, info, true /* is_empty */);
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, int)") {
1185 return GenInlinedIndexOf(cu, info, false /* base 0 */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001186 }
buzbeefa57c472012-11-21 12:06:18 -08001187 if (tgt_method == "int java.lang.String.index_of(int)") {
1188 return GenInlinedIndexOf(cu, info, true /* base 0 */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001189 }
buzbeefa57c472012-11-21 12:06:18 -08001190 if (tgt_method == "int java.lang.String.length()") {
1191 return GenInlinedStringIsEmptyOrLength(cu, info, false /* is_empty */);
Ian Rogers0183dd72012-09-17 23:06:51 -07001192 }
Ian Rogers07ec8e12012-12-01 01:26:51 -08001193 if (tgt_method == "java.lang.Thread java.lang.Thread.currentThread()") {
1194 return GenInlinedCurrentThread(cu, info);
1195 }
buzbeefa57c472012-11-21 12:06:18 -08001196 } else if (tgt_method.find("boolean sun.misc.Unsafe.compareAndSwap") != std::string::npos) {
1197 if (tgt_method == "boolean sun.misc.Unsafe.compareAndSwapInt(java.lang.Object, long, int, int)") {
1198 return GenInlinedCas32(cu, info, false);
Ian Rogers0183dd72012-09-17 23:06:51 -07001199 }
buzbeefa57c472012-11-21 12:06:18 -08001200 if (tgt_method == "boolean sun.misc.Unsafe.compareAndSwapObject(java.lang.Object, long, java.lang.Object, java.lang.Object)") {
1201 return GenInlinedCas32(cu, info, true);
Ian Rogers0183dd72012-09-17 23:06:51 -07001202 }
Ian Rogerse13eafa2012-09-07 11:24:27 -07001203 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001204 return false;
buzbeefc9e6fa2012-03-23 15:14:29 -07001205}
1206
buzbee02031b12012-11-23 09:41:35 -08001207void Codegen::GenInvoke(CompilationUnit* cu, CallInfo* info)
buzbee1bc37c62012-11-20 13:35:41 -08001208{
buzbeefa57c472012-11-21 12:06:18 -08001209 if (GenIntrinsic(cu, info)) {
buzbee1bc37c62012-11-20 13:35:41 -08001210 return;
1211 }
buzbeefa57c472012-11-21 12:06:18 -08001212 InvokeType original_type = info->type; // avoiding mutation by ComputeInvokeInfo
1213 int call_state = 0;
1214 LIR* null_ck;
1215 LIR** p_null_ck = NULL;
1216 NextCallInsn next_call_insn;
1217 FlushAllRegs(cu); /* Everything to home location */
buzbee1bc37c62012-11-20 13:35:41 -08001218 // Explicit register usage
buzbeefa57c472012-11-21 12:06:18 -08001219 LockCallTemps(cu);
buzbee1bc37c62012-11-20 13:35:41 -08001220
buzbeefa57c472012-11-21 12:06:18 -08001221 OatCompilationUnit m_unit(cu->class_loader, cu->class_linker,
1222 *cu->dex_file,
1223 cu->code_item, cu->method_idx,
1224 cu->access_flags);
buzbee1bc37c62012-11-20 13:35:41 -08001225
buzbeefa57c472012-11-21 12:06:18 -08001226 uint32_t dex_method_idx = info->index;
1227 int vtable_idx;
1228 uintptr_t direct_code;
1229 uintptr_t direct_method;
1230 bool skip_this;
1231 bool fast_path =
1232 cu->compiler->ComputeInvokeInfo(dex_method_idx, &m_unit, info->type,
1233 vtable_idx, direct_code,
1234 direct_method)
buzbee1bc37c62012-11-20 13:35:41 -08001235 && !SLOW_INVOKE_PATH;
1236 if (info->type == kInterface) {
buzbeefa57c472012-11-21 12:06:18 -08001237 if (fast_path) {
1238 p_null_ck = &null_ck;
buzbee1bc37c62012-11-20 13:35:41 -08001239 }
buzbeefa57c472012-11-21 12:06:18 -08001240 next_call_insn = fast_path ? NextInterfaceCallInsn
buzbee52a77fc2012-11-20 19:50:46 -08001241 : NextInterfaceCallInsnWithAccessCheck;
buzbeefa57c472012-11-21 12:06:18 -08001242 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001243 } else if (info->type == kDirect) {
buzbeefa57c472012-11-21 12:06:18 -08001244 if (fast_path) {
1245 p_null_ck = &null_ck;
buzbee1bc37c62012-11-20 13:35:41 -08001246 }
buzbeefa57c472012-11-21 12:06:18 -08001247 next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP;
1248 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001249 } else if (info->type == kStatic) {
buzbeefa57c472012-11-21 12:06:18 -08001250 next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP;
1251 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001252 } else if (info->type == kSuper) {
buzbeefa57c472012-11-21 12:06:18 -08001253 DCHECK(!fast_path); // Fast path is a direct call.
1254 next_call_insn = NextSuperCallInsnSP;
1255 skip_this = false;
buzbee1bc37c62012-11-20 13:35:41 -08001256 } else {
1257 DCHECK_EQ(info->type, kVirtual);
buzbeefa57c472012-11-21 12:06:18 -08001258 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1259 skip_this = fast_path;
buzbee1bc37c62012-11-20 13:35:41 -08001260 }
buzbeefa57c472012-11-21 12:06:18 -08001261 if (!info->is_range) {
1262 call_state = GenDalvikArgsNoRange(cu, info, call_state, p_null_ck,
1263 next_call_insn, dex_method_idx,
1264 vtable_idx, direct_code, direct_method,
1265 original_type, skip_this);
buzbee1bc37c62012-11-20 13:35:41 -08001266 } else {
buzbeefa57c472012-11-21 12:06:18 -08001267 call_state = GenDalvikArgsRange(cu, info, call_state, p_null_ck,
1268 next_call_insn, dex_method_idx, vtable_idx,
1269 direct_code, direct_method, original_type,
1270 skip_this);
buzbee1bc37c62012-11-20 13:35:41 -08001271 }
1272 // Finish up any of the call sequence not interleaved in arg loading
buzbeefa57c472012-11-21 12:06:18 -08001273 while (call_state >= 0) {
1274 call_state = next_call_insn(cu, info, call_state, dex_method_idx,
1275 vtable_idx, direct_code, direct_method,
1276 original_type);
buzbee1bc37c62012-11-20 13:35:41 -08001277 }
buzbeefa57c472012-11-21 12:06:18 -08001278 if (cu->enable_debug & (1 << kDebugDisplayMissingTargets)) {
1279 GenShowTarget(cu);
buzbee1bc37c62012-11-20 13:35:41 -08001280 }
buzbeefa57c472012-11-21 12:06:18 -08001281 LIR* call_inst;
1282 if (cu->instruction_set != kX86) {
1283 call_inst = OpReg(cu, kOpBlx, TargetReg(kInvokeTgt));
buzbee1bc37c62012-11-20 13:35:41 -08001284 } else {
buzbeefa57c472012-11-21 12:06:18 -08001285 if (fast_path && info->type != kInterface) {
1286 call_inst = OpMem(cu, kOpBlx, TargetReg(kArg0),
buzbee1bc37c62012-11-20 13:35:41 -08001287 AbstractMethod::GetCodeOffset().Int32Value());
1288 } else {
1289 int trampoline = 0;
1290 switch (info->type) {
1291 case kInterface:
buzbeefa57c472012-11-21 12:06:18 -08001292 trampoline = fast_path ? ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline)
buzbee1bc37c62012-11-20 13:35:41 -08001293 : ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
1294 break;
1295 case kDirect:
1296 trampoline = ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
1297 break;
1298 case kStatic:
1299 trampoline = ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
1300 break;
1301 case kSuper:
1302 trampoline = ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
1303 break;
1304 case kVirtual:
1305 trampoline = ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
1306 break;
1307 default:
1308 LOG(FATAL) << "Unexpected invoke type";
1309 }
buzbeefa57c472012-11-21 12:06:18 -08001310 call_inst = OpThreadMem(cu, kOpBlx, trampoline);
buzbee1bc37c62012-11-20 13:35:41 -08001311 }
1312 }
buzbeefa57c472012-11-21 12:06:18 -08001313 MarkSafepointPC(cu, call_inst);
buzbee1bc37c62012-11-20 13:35:41 -08001314
buzbeefa57c472012-11-21 12:06:18 -08001315 ClobberCalleeSave(cu);
buzbee1bc37c62012-11-20 13:35:41 -08001316 if (info->result.location != kLocInvalid) {
1317 // We have a following MOVE_RESULT - do it now.
1318 if (info->result.wide) {
buzbeefa57c472012-11-21 12:06:18 -08001319 RegLocation ret_loc = GetReturnWide(cu, info->result.fp);
1320 StoreValueWide(cu, info->result, ret_loc);
buzbee1bc37c62012-11-20 13:35:41 -08001321 } else {
buzbeefa57c472012-11-21 12:06:18 -08001322 RegLocation ret_loc = GetReturn(cu, info->result.fp);
1323 StoreValue(cu, info->result, ret_loc);
buzbee1bc37c62012-11-20 13:35:41 -08001324 }
1325 }
1326}
1327
1328/*
1329 * Build an array of location records for the incoming arguments.
1330 * Note: one location record per word of arguments, with dummy
1331 * high-word loc for wide arguments. Also pull up any following
1332 * MOVE_RESULT and incorporate it into the invoke.
1333 */
buzbee02031b12012-11-23 09:41:35 -08001334CallInfo* Codegen::NewMemCallInfo(CompilationUnit* cu, BasicBlock* bb, MIR* mir, InvokeType type,
1335 bool is_range)
buzbee1bc37c62012-11-20 13:35:41 -08001336{
buzbeefa57c472012-11-21 12:06:18 -08001337 CallInfo* info = static_cast<CallInfo*>(NewMem(cu, sizeof(CallInfo), true, kAllocMisc));
1338 MIR* move_result_mir = FindMoveResult(cu, bb, mir);
1339 if (move_result_mir == NULL) {
buzbee1bc37c62012-11-20 13:35:41 -08001340 info->result.location = kLocInvalid;
1341 } else {
buzbeefa57c472012-11-21 12:06:18 -08001342 info->result = GetRawDest(cu, move_result_mir);
buzbeea169e1d2012-12-05 14:26:44 -08001343 move_result_mir->meta.original_opcode = move_result_mir->dalvikInsn.opcode;
1344 move_result_mir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop);
buzbee1bc37c62012-11-20 13:35:41 -08001345 }
buzbeefa57c472012-11-21 12:06:18 -08001346 info->num_arg_words = mir->ssa_rep->num_uses;
1347 info->args = (info->num_arg_words == 0) ? NULL : static_cast<RegLocation*>
1348 (NewMem(cu, sizeof(RegLocation) * info->num_arg_words, false, kAllocMisc));
1349 for (int i = 0; i < info->num_arg_words; i++) {
1350 info->args[i] = GetRawSrc(cu, mir, i);
buzbee1bc37c62012-11-20 13:35:41 -08001351 }
buzbeefa57c472012-11-21 12:06:18 -08001352 info->opt_flags = mir->optimization_flags;
buzbee1bc37c62012-11-20 13:35:41 -08001353 info->type = type;
buzbeefa57c472012-11-21 12:06:18 -08001354 info->is_range = is_range;
buzbee1bc37c62012-11-20 13:35:41 -08001355 info->index = mir->dalvikInsn.vB;
1356 info->offset = mir->offset;
1357 return info;
1358}
1359
buzbee31a4a6f2012-02-28 15:36:15 -08001360} // namespace art