blob: 4dd55d763a1cc104da400f1c6820012392fd184f [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "dex/compiler_ir.h"
18#include "dex/compiler_internals.h"
19#include "dex/quick/mir_to_lir-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070020#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include "mirror/array.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022#include "verifier/method_verifier.h"
23
24namespace art {
25
26/*
27 * This source files contains "gen" codegen routines that should
28 * be applicable to most targets. Only mid-level support utilities
29 * and "op" calls may be used here.
30 */
31
32/*
33 * Generate an kPseudoBarrier marker to indicate the boundary of special
34 * blocks.
35 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070036void Mir2Lir::GenBarrier() {
Brian Carlstrom7940e442013-07-12 13:46:57 -070037 LIR* barrier = NewLIR0(kPseudoBarrier);
38 /* Mark all resources as being clobbered */
39 barrier->def_mask = -1;
40}
41
42// FIXME: need to do some work to split out targets with
43// condition codes and those without
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070044LIR* Mir2Lir::GenCheck(ConditionCode c_code, ThrowKind kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070045 DCHECK_NE(cu_->instruction_set, kMips);
46 LIR* tgt = RawLIR(0, kPseudoThrowTarget, kind, current_dalvik_offset_);
47 LIR* branch = OpCondBranch(c_code, tgt);
48 // Remember branch target - will process later
49 throw_launchpads_.Insert(tgt);
50 return branch;
51}
52
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070053LIR* Mir2Lir::GenImmedCheck(ConditionCode c_code, int reg, int imm_val, ThrowKind kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070054 LIR* tgt = RawLIR(0, kPseudoThrowTarget, kind, current_dalvik_offset_, reg, imm_val);
55 LIR* branch;
56 if (c_code == kCondAl) {
57 branch = OpUnconditionalBranch(tgt);
58 } else {
59 branch = OpCmpImmBranch(c_code, reg, imm_val, tgt);
60 }
61 // Remember branch target - will process later
62 throw_launchpads_.Insert(tgt);
63 return branch;
64}
65
66/* Perform null-check on a register. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070067LIR* Mir2Lir::GenNullCheck(int s_reg, int m_reg, int opt_flags) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070068 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) &&
69 opt_flags & MIR_IGNORE_NULL_CHECK) {
70 return NULL;
71 }
72 return GenImmedCheck(kCondEq, m_reg, 0, kThrowNullPointer);
73}
74
75/* Perform check on two registers */
76LIR* Mir2Lir::GenRegRegCheck(ConditionCode c_code, int reg1, int reg2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070077 ThrowKind kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070078 LIR* tgt = RawLIR(0, kPseudoThrowTarget, kind, current_dalvik_offset_, reg1, reg2);
79 LIR* branch = OpCmpBranch(c_code, reg1, reg2, tgt);
80 // Remember branch target - will process later
81 throw_launchpads_.Insert(tgt);
82 return branch;
83}
84
85void Mir2Lir::GenCompareAndBranch(Instruction::Code opcode, RegLocation rl_src1,
86 RegLocation rl_src2, LIR* taken,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070087 LIR* fall_through) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070088 ConditionCode cond;
89 switch (opcode) {
90 case Instruction::IF_EQ:
91 cond = kCondEq;
92 break;
93 case Instruction::IF_NE:
94 cond = kCondNe;
95 break;
96 case Instruction::IF_LT:
97 cond = kCondLt;
98 break;
99 case Instruction::IF_GE:
100 cond = kCondGe;
101 break;
102 case Instruction::IF_GT:
103 cond = kCondGt;
104 break;
105 case Instruction::IF_LE:
106 cond = kCondLe;
107 break;
108 default:
109 cond = static_cast<ConditionCode>(0);
110 LOG(FATAL) << "Unexpected opcode " << opcode;
111 }
112
113 // Normalize such that if either operand is constant, src2 will be constant
114 if (rl_src1.is_const) {
115 RegLocation rl_temp = rl_src1;
116 rl_src1 = rl_src2;
117 rl_src2 = rl_temp;
118 cond = FlipComparisonOrder(cond);
119 }
120
121 rl_src1 = LoadValue(rl_src1, kCoreReg);
122 // Is this really an immediate comparison?
123 if (rl_src2.is_const) {
124 // If it's already live in a register or not easily materialized, just keep going
125 RegLocation rl_temp = UpdateLoc(rl_src2);
126 if ((rl_temp.location == kLocDalvikFrame) &&
127 InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src2))) {
128 // OK - convert this to a compare immediate and branch
129 OpCmpImmBranch(cond, rl_src1.low_reg, mir_graph_->ConstantValue(rl_src2), taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700130 return;
131 }
132 }
133 rl_src2 = LoadValue(rl_src2, kCoreReg);
134 OpCmpBranch(cond, rl_src1.low_reg, rl_src2.low_reg, taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700135}
136
137void Mir2Lir::GenCompareZeroAndBranch(Instruction::Code opcode, RegLocation rl_src, LIR* taken,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700138 LIR* fall_through) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700139 ConditionCode cond;
140 rl_src = LoadValue(rl_src, kCoreReg);
141 switch (opcode) {
142 case Instruction::IF_EQZ:
143 cond = kCondEq;
144 break;
145 case Instruction::IF_NEZ:
146 cond = kCondNe;
147 break;
148 case Instruction::IF_LTZ:
149 cond = kCondLt;
150 break;
151 case Instruction::IF_GEZ:
152 cond = kCondGe;
153 break;
154 case Instruction::IF_GTZ:
155 cond = kCondGt;
156 break;
157 case Instruction::IF_LEZ:
158 cond = kCondLe;
159 break;
160 default:
161 cond = static_cast<ConditionCode>(0);
162 LOG(FATAL) << "Unexpected opcode " << opcode;
163 }
164 OpCmpImmBranch(cond, rl_src.low_reg, 0, taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700165}
166
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700167void Mir2Lir::GenIntToLong(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700168 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
169 if (rl_src.location == kLocPhysReg) {
170 OpRegCopy(rl_result.low_reg, rl_src.low_reg);
171 } else {
172 LoadValueDirect(rl_src, rl_result.low_reg);
173 }
174 OpRegRegImm(kOpAsr, rl_result.high_reg, rl_result.low_reg, 31);
175 StoreValueWide(rl_dest, rl_result);
176}
177
178void Mir2Lir::GenIntNarrowing(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700179 RegLocation rl_src) {
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700180 rl_src = LoadValue(rl_src, kCoreReg);
181 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
182 OpKind op = kOpInvalid;
183 switch (opcode) {
184 case Instruction::INT_TO_BYTE:
185 op = kOp2Byte;
186 break;
187 case Instruction::INT_TO_SHORT:
188 op = kOp2Short;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700189 break;
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700190 case Instruction::INT_TO_CHAR:
191 op = kOp2Char;
192 break;
193 default:
194 LOG(ERROR) << "Bad int conversion type";
195 }
196 OpRegReg(op, rl_result.low_reg, rl_src.low_reg);
197 StoreValue(rl_dest, rl_result);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700198}
199
200/*
201 * Let helper function take care of everything. Will call
202 * Array::AllocFromCode(type_idx, method, count);
203 * Note: AllocFromCode will handle checks for errNegativeArraySize.
204 */
205void Mir2Lir::GenNewArray(uint32_t type_idx, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700206 RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700207 FlushAllRegs(); /* Everything to home location */
Ian Rogers848871b2013-08-05 10:56:33 -0700208 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700209 if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *cu_->dex_file,
210 type_idx)) {
Ian Rogers848871b2013-08-05 10:56:33 -0700211 func_offset = QUICK_ENTRYPOINT_OFFSET(pAllocArray);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700212 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700213 func_offset= QUICK_ENTRYPOINT_OFFSET(pAllocArrayWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700214 }
215 CallRuntimeHelperImmMethodRegLocation(func_offset, type_idx, rl_src, true);
216 RegLocation rl_result = GetReturn(false);
217 StoreValue(rl_dest, rl_result);
218}
219
220/*
221 * Similar to GenNewArray, but with post-allocation initialization.
222 * Verifier guarantees we're dealing with an array class. Current
223 * code throws runtime exception "bad Filled array req" for 'D' and 'J'.
224 * Current code also throws internal unimp if not 'L', '[' or 'I'.
225 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700226void Mir2Lir::GenFilledNewArray(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700227 int elems = info->num_arg_words;
228 int type_idx = info->index;
229 FlushAllRegs(); /* Everything to home location */
Ian Rogers848871b2013-08-05 10:56:33 -0700230 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700231 if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *cu_->dex_file,
232 type_idx)) {
Ian Rogers848871b2013-08-05 10:56:33 -0700233 func_offset = QUICK_ENTRYPOINT_OFFSET(pCheckAndAllocArray);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700234 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700235 func_offset = QUICK_ENTRYPOINT_OFFSET(pCheckAndAllocArrayWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700236 }
237 CallRuntimeHelperImmMethodImm(func_offset, type_idx, elems, true);
238 FreeTemp(TargetReg(kArg2));
239 FreeTemp(TargetReg(kArg1));
240 /*
241 * NOTE: the implicit target for Instruction::FILLED_NEW_ARRAY is the
242 * return region. Because AllocFromCode placed the new array
243 * in kRet0, we'll just lock it into place. When debugger support is
244 * added, it may be necessary to additionally copy all return
245 * values to a home location in thread-local storage
246 */
247 LockTemp(TargetReg(kRet0));
248
249 // TODO: use the correct component size, currently all supported types
250 // share array alignment with ints (see comment at head of function)
251 size_t component_size = sizeof(int32_t);
252
253 // Having a range of 0 is legal
254 if (info->is_range && (elems > 0)) {
255 /*
256 * Bit of ugliness here. We're going generate a mem copy loop
257 * on the register range, but it is possible that some regs
258 * in the range have been promoted. This is unlikely, but
259 * before generating the copy, we'll just force a flush
260 * of any regs in the source range that have been promoted to
261 * home location.
262 */
263 for (int i = 0; i < elems; i++) {
264 RegLocation loc = UpdateLoc(info->args[i]);
265 if (loc.location == kLocPhysReg) {
266 StoreBaseDisp(TargetReg(kSp), SRegOffset(loc.s_reg_low),
267 loc.low_reg, kWord);
268 }
269 }
270 /*
271 * TUNING note: generated code here could be much improved, but
272 * this is an uncommon operation and isn't especially performance
273 * critical.
274 */
275 int r_src = AllocTemp();
276 int r_dst = AllocTemp();
277 int r_idx = AllocTemp();
278 int r_val = INVALID_REG;
Brian Carlstromdf629502013-07-17 22:39:56 -0700279 switch (cu_->instruction_set) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700280 case kThumb2:
281 r_val = TargetReg(kLr);
282 break;
283 case kX86:
284 FreeTemp(TargetReg(kRet0));
285 r_val = AllocTemp();
286 break;
287 case kMips:
288 r_val = AllocTemp();
289 break;
290 default: LOG(FATAL) << "Unexpected instruction set: " << cu_->instruction_set;
291 }
292 // Set up source pointer
293 RegLocation rl_first = info->args[0];
294 OpRegRegImm(kOpAdd, r_src, TargetReg(kSp), SRegOffset(rl_first.s_reg_low));
295 // Set up the target pointer
296 OpRegRegImm(kOpAdd, r_dst, TargetReg(kRet0),
297 mirror::Array::DataOffset(component_size).Int32Value());
298 // Set up the loop counter (known to be > 0)
299 LoadConstant(r_idx, elems - 1);
300 // Generate the copy loop. Going backwards for convenience
301 LIR* target = NewLIR0(kPseudoTargetLabel);
302 // Copy next element
303 LoadBaseIndexed(r_src, r_idx, r_val, 2, kWord);
304 StoreBaseIndexed(r_dst, r_idx, r_val, 2, kWord);
305 FreeTemp(r_val);
306 OpDecAndBranch(kCondGe, r_idx, target);
307 if (cu_->instruction_set == kX86) {
308 // Restore the target pointer
309 OpRegRegImm(kOpAdd, TargetReg(kRet0), r_dst,
310 -mirror::Array::DataOffset(component_size).Int32Value());
311 }
312 } else if (!info->is_range) {
313 // TUNING: interleave
314 for (int i = 0; i < elems; i++) {
315 RegLocation rl_arg = LoadValue(info->args[i], kCoreReg);
316 StoreBaseDisp(TargetReg(kRet0),
317 mirror::Array::DataOffset(component_size).Int32Value() +
318 i * 4, rl_arg.low_reg, kWord);
319 // If the LoadValue caused a temp to be allocated, free it
320 if (IsTemp(rl_arg.low_reg)) {
321 FreeTemp(rl_arg.low_reg);
322 }
323 }
324 }
325 if (info->result.location != kLocInvalid) {
326 StoreValue(info->result, GetReturn(false /* not fp */));
327 }
328}
329
330void Mir2Lir::GenSput(uint32_t field_idx, RegLocation rl_src, bool is_long_or_double,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700331 bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700332 int field_offset;
333 int ssb_index;
334 bool is_volatile;
335 bool is_referrers_class;
336 bool fast_path = cu_->compiler_driver->ComputeStaticFieldInfo(
Ian Rogers9b297bf2013-09-06 11:11:25 -0700337 field_idx, mir_graph_->GetCurrentDexCompilationUnit(), true,
338 &field_offset, &ssb_index, &is_referrers_class, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700339 if (fast_path && !SLOW_FIELD_PATH) {
340 DCHECK_GE(field_offset, 0);
341 int rBase;
342 if (is_referrers_class) {
343 // Fast path, static storage base is this method's class
344 RegLocation rl_method = LoadCurrMethod();
345 rBase = AllocTemp();
346 LoadWordDisp(rl_method.low_reg,
Brian Carlstromea46f952013-07-30 01:26:50 -0700347 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), rBase);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700348 if (IsTemp(rl_method.low_reg)) {
349 FreeTemp(rl_method.low_reg);
350 }
351 } else {
352 // Medium path, static storage base in a different class which requires checks that the other
353 // class is initialized.
354 // TODO: remove initialized check now that we are initializing classes in the compiler driver.
355 DCHECK_GE(ssb_index, 0);
356 // May do runtime call so everything to home locations.
357 FlushAllRegs();
358 // Using fixed register to sync with possible call to runtime support.
359 int r_method = TargetReg(kArg1);
360 LockTemp(r_method);
361 LoadCurrMethodDirect(r_method);
362 rBase = TargetReg(kArg0);
363 LockTemp(rBase);
364 LoadWordDisp(r_method,
Brian Carlstromea46f952013-07-30 01:26:50 -0700365 mirror::ArtMethod::DexCacheInitializedStaticStorageOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700366 rBase);
367 LoadWordDisp(rBase,
368 mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() +
369 sizeof(int32_t*) * ssb_index, rBase);
370 // rBase now points at appropriate static storage base (Class*)
371 // or NULL if not initialized. Check for NULL and call helper if NULL.
372 // TUNING: fast path should fall through
373 LIR* branch_over = OpCmpImmBranch(kCondNe, rBase, 0, NULL);
374 LoadConstant(TargetReg(kArg0), ssb_index);
Ian Rogers7655f292013-07-29 11:07:13 -0700375 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssb_index, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700376 if (cu_->instruction_set == kMips) {
377 // For Arm, kRet0 = kArg0 = rBase, for Mips, we need to copy
378 OpRegCopy(rBase, TargetReg(kRet0));
379 }
380 LIR* skip_target = NewLIR0(kPseudoTargetLabel);
381 branch_over->target = skip_target;
382 FreeTemp(r_method);
383 }
384 // rBase now holds static storage base
385 if (is_long_or_double) {
386 rl_src = LoadValueWide(rl_src, kAnyReg);
387 } else {
388 rl_src = LoadValue(rl_src, kAnyReg);
389 }
390 if (is_volatile) {
391 GenMemBarrier(kStoreStore);
392 }
393 if (is_long_or_double) {
394 StoreBaseDispWide(rBase, field_offset, rl_src.low_reg,
395 rl_src.high_reg);
396 } else {
397 StoreWordDisp(rBase, field_offset, rl_src.low_reg);
398 }
399 if (is_volatile) {
400 GenMemBarrier(kStoreLoad);
401 }
402 if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) {
403 MarkGCCard(rl_src.low_reg, rBase);
404 }
405 FreeTemp(rBase);
406 } else {
407 FlushAllRegs(); // Everything to home locations
Ian Rogers848871b2013-08-05 10:56:33 -0700408 ThreadOffset setter_offset =
409 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pSet64Static)
410 : (is_object ? QUICK_ENTRYPOINT_OFFSET(pSetObjStatic)
411 : QUICK_ENTRYPOINT_OFFSET(pSet32Static));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700412 CallRuntimeHelperImmRegLocation(setter_offset, field_idx, rl_src, true);
413 }
414}
415
416void Mir2Lir::GenSget(uint32_t field_idx, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700417 bool is_long_or_double, bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700418 int field_offset;
419 int ssb_index;
420 bool is_volatile;
421 bool is_referrers_class;
422 bool fast_path = cu_->compiler_driver->ComputeStaticFieldInfo(
Ian Rogers9b297bf2013-09-06 11:11:25 -0700423 field_idx, mir_graph_->GetCurrentDexCompilationUnit(), false,
424 &field_offset, &ssb_index, &is_referrers_class, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700425 if (fast_path && !SLOW_FIELD_PATH) {
426 DCHECK_GE(field_offset, 0);
427 int rBase;
428 if (is_referrers_class) {
429 // Fast path, static storage base is this method's class
430 RegLocation rl_method = LoadCurrMethod();
431 rBase = AllocTemp();
432 LoadWordDisp(rl_method.low_reg,
Brian Carlstromea46f952013-07-30 01:26:50 -0700433 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), rBase);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700434 } else {
435 // Medium path, static storage base in a different class which requires checks that the other
436 // class is initialized
437 // TODO: remove initialized check now that we are initializing classes in the compiler driver.
438 DCHECK_GE(ssb_index, 0);
439 // May do runtime call so everything to home locations.
440 FlushAllRegs();
441 // Using fixed register to sync with possible call to runtime support.
442 int r_method = TargetReg(kArg1);
443 LockTemp(r_method);
444 LoadCurrMethodDirect(r_method);
445 rBase = TargetReg(kArg0);
446 LockTemp(rBase);
447 LoadWordDisp(r_method,
Brian Carlstromea46f952013-07-30 01:26:50 -0700448 mirror::ArtMethod::DexCacheInitializedStaticStorageOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700449 rBase);
450 LoadWordDisp(rBase, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() +
451 sizeof(int32_t*) * ssb_index, rBase);
452 // rBase now points at appropriate static storage base (Class*)
453 // or NULL if not initialized. Check for NULL and call helper if NULL.
454 // TUNING: fast path should fall through
455 LIR* branch_over = OpCmpImmBranch(kCondNe, rBase, 0, NULL);
Ian Rogers7655f292013-07-29 11:07:13 -0700456 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssb_index, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700457 if (cu_->instruction_set == kMips) {
458 // For Arm, kRet0 = kArg0 = rBase, for Mips, we need to copy
459 OpRegCopy(rBase, TargetReg(kRet0));
460 }
461 LIR* skip_target = NewLIR0(kPseudoTargetLabel);
462 branch_over->target = skip_target;
463 FreeTemp(r_method);
464 }
465 // rBase now holds static storage base
466 RegLocation rl_result = EvalLoc(rl_dest, kAnyReg, true);
467 if (is_volatile) {
468 GenMemBarrier(kLoadLoad);
469 }
470 if (is_long_or_double) {
471 LoadBaseDispWide(rBase, field_offset, rl_result.low_reg,
472 rl_result.high_reg, INVALID_SREG);
473 } else {
474 LoadWordDisp(rBase, field_offset, rl_result.low_reg);
475 }
476 FreeTemp(rBase);
477 if (is_long_or_double) {
478 StoreValueWide(rl_dest, rl_result);
479 } else {
480 StoreValue(rl_dest, rl_result);
481 }
482 } else {
483 FlushAllRegs(); // Everything to home locations
Ian Rogers848871b2013-08-05 10:56:33 -0700484 ThreadOffset getterOffset =
485 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pGet64Static)
486 :(is_object ? QUICK_ENTRYPOINT_OFFSET(pGetObjStatic)
487 : QUICK_ENTRYPOINT_OFFSET(pGet32Static));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700488 CallRuntimeHelperImm(getterOffset, field_idx, true);
489 if (is_long_or_double) {
490 RegLocation rl_result = GetReturnWide(rl_dest.fp);
491 StoreValueWide(rl_dest, rl_result);
492 } else {
493 RegLocation rl_result = GetReturn(rl_dest.fp);
494 StoreValue(rl_dest, rl_result);
495 }
496 }
497}
498
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700499void Mir2Lir::HandleSuspendLaunchPads() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700500 int num_elems = suspend_launchpads_.Size();
Ian Rogers848871b2013-08-05 10:56:33 -0700501 ThreadOffset helper_offset = QUICK_ENTRYPOINT_OFFSET(pTestSuspend);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700502 for (int i = 0; i < num_elems; i++) {
503 ResetRegPool();
504 ResetDefTracking();
505 LIR* lab = suspend_launchpads_.Get(i);
506 LIR* resume_lab = reinterpret_cast<LIR*>(lab->operands[0]);
507 current_dalvik_offset_ = lab->operands[1];
508 AppendLIR(lab);
509 int r_tgt = CallHelperSetup(helper_offset);
510 CallHelper(r_tgt, helper_offset, true /* MarkSafepointPC */);
511 OpUnconditionalBranch(resume_lab);
512 }
513}
514
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700515void Mir2Lir::HandleIntrinsicLaunchPads() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700516 int num_elems = intrinsic_launchpads_.Size();
517 for (int i = 0; i < num_elems; i++) {
518 ResetRegPool();
519 ResetDefTracking();
520 LIR* lab = intrinsic_launchpads_.Get(i);
521 CallInfo* info = reinterpret_cast<CallInfo*>(lab->operands[0]);
522 current_dalvik_offset_ = info->offset;
523 AppendLIR(lab);
524 // NOTE: GenInvoke handles MarkSafepointPC
525 GenInvoke(info);
526 LIR* resume_lab = reinterpret_cast<LIR*>(lab->operands[2]);
527 if (resume_lab != NULL) {
528 OpUnconditionalBranch(resume_lab);
529 }
530 }
531}
532
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700533void Mir2Lir::HandleThrowLaunchPads() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700534 int num_elems = throw_launchpads_.Size();
535 for (int i = 0; i < num_elems; i++) {
536 ResetRegPool();
537 ResetDefTracking();
538 LIR* lab = throw_launchpads_.Get(i);
539 current_dalvik_offset_ = lab->operands[1];
540 AppendLIR(lab);
Ian Rogers848871b2013-08-05 10:56:33 -0700541 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700542 int v1 = lab->operands[2];
543 int v2 = lab->operands[3];
544 bool target_x86 = (cu_->instruction_set == kX86);
545 switch (lab->operands[0]) {
546 case kThrowNullPointer:
Ian Rogers848871b2013-08-05 10:56:33 -0700547 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowNullPointer);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700548 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700549 case kThrowConstantArrayBounds: // v1 is length reg (for Arm/Mips), v2 constant index
Brian Carlstrom7940e442013-07-12 13:46:57 -0700550 // v1 holds the constant array index. Mips/Arm uses v2 for length, x86 reloads.
551 if (target_x86) {
552 OpRegMem(kOpMov, TargetReg(kArg1), v1, mirror::Array::LengthOffset().Int32Value());
553 } else {
554 OpRegCopy(TargetReg(kArg1), v1);
555 }
556 // Make sure the following LoadConstant doesn't mess with kArg1.
557 LockTemp(TargetReg(kArg1));
558 LoadConstant(TargetReg(kArg0), v2);
Ian Rogers848871b2013-08-05 10:56:33 -0700559 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700560 break;
561 case kThrowArrayBounds:
562 // Move v1 (array index) to kArg0 and v2 (array length) to kArg1
563 if (v2 != TargetReg(kArg0)) {
564 OpRegCopy(TargetReg(kArg0), v1);
565 if (target_x86) {
566 // x86 leaves the array pointer in v2, so load the array length that the handler expects
567 OpRegMem(kOpMov, TargetReg(kArg1), v2, mirror::Array::LengthOffset().Int32Value());
568 } else {
569 OpRegCopy(TargetReg(kArg1), v2);
570 }
571 } else {
572 if (v1 == TargetReg(kArg1)) {
573 // Swap v1 and v2, using kArg2 as a temp
574 OpRegCopy(TargetReg(kArg2), v1);
575 if (target_x86) {
576 // x86 leaves the array pointer in v2; load the array length that the handler expects
577 OpRegMem(kOpMov, TargetReg(kArg1), v2, mirror::Array::LengthOffset().Int32Value());
578 } else {
579 OpRegCopy(TargetReg(kArg1), v2);
580 }
581 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2));
582 } else {
583 if (target_x86) {
584 // x86 leaves the array pointer in v2; load the array length that the handler expects
585 OpRegMem(kOpMov, TargetReg(kArg1), v2, mirror::Array::LengthOffset().Int32Value());
586 } else {
587 OpRegCopy(TargetReg(kArg1), v2);
588 }
589 OpRegCopy(TargetReg(kArg0), v1);
590 }
591 }
Ian Rogers848871b2013-08-05 10:56:33 -0700592 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700593 break;
594 case kThrowDivZero:
Ian Rogers848871b2013-08-05 10:56:33 -0700595 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowDivZero);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700596 break;
597 case kThrowNoSuchMethod:
598 OpRegCopy(TargetReg(kArg0), v1);
599 func_offset =
Ian Rogers848871b2013-08-05 10:56:33 -0700600 QUICK_ENTRYPOINT_OFFSET(pThrowNoSuchMethod);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700601 break;
602 case kThrowStackOverflow:
Ian Rogers848871b2013-08-05 10:56:33 -0700603 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowStackOverflow);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700604 // Restore stack alignment
605 if (target_x86) {
606 OpRegImm(kOpAdd, TargetReg(kSp), frame_size_);
607 } else {
608 OpRegImm(kOpAdd, TargetReg(kSp), (num_core_spills_ + num_fp_spills_) * 4);
609 }
610 break;
611 default:
612 LOG(FATAL) << "Unexpected throw kind: " << lab->operands[0];
613 }
614 ClobberCalleeSave();
615 int r_tgt = CallHelperSetup(func_offset);
616 CallHelper(r_tgt, func_offset, true /* MarkSafepointPC */);
617 }
618}
619
620void Mir2Lir::GenIGet(uint32_t field_idx, int opt_flags, OpSize size,
621 RegLocation rl_dest, RegLocation rl_obj, bool is_long_or_double,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700622 bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700623 int field_offset;
624 bool is_volatile;
625
Ian Rogers9b297bf2013-09-06 11:11:25 -0700626 bool fast_path = FastInstance(field_idx, false, &field_offset, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700627
628 if (fast_path && !SLOW_FIELD_PATH) {
629 RegLocation rl_result;
630 RegisterClass reg_class = oat_reg_class_by_size(size);
631 DCHECK_GE(field_offset, 0);
632 rl_obj = LoadValue(rl_obj, kCoreReg);
633 if (is_long_or_double) {
634 DCHECK(rl_dest.wide);
635 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
636 if (cu_->instruction_set == kX86) {
637 rl_result = EvalLoc(rl_dest, reg_class, true);
638 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
639 LoadBaseDispWide(rl_obj.low_reg, field_offset, rl_result.low_reg,
640 rl_result.high_reg, rl_obj.s_reg_low);
641 if (is_volatile) {
642 GenMemBarrier(kLoadLoad);
643 }
644 } else {
645 int reg_ptr = AllocTemp();
646 OpRegRegImm(kOpAdd, reg_ptr, rl_obj.low_reg, field_offset);
647 rl_result = EvalLoc(rl_dest, reg_class, true);
648 LoadBaseDispWide(reg_ptr, 0, rl_result.low_reg, rl_result.high_reg, INVALID_SREG);
649 if (is_volatile) {
650 GenMemBarrier(kLoadLoad);
651 }
652 FreeTemp(reg_ptr);
653 }
654 StoreValueWide(rl_dest, rl_result);
655 } else {
656 rl_result = EvalLoc(rl_dest, reg_class, true);
657 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
658 LoadBaseDisp(rl_obj.low_reg, field_offset, rl_result.low_reg,
659 kWord, rl_obj.s_reg_low);
660 if (is_volatile) {
661 GenMemBarrier(kLoadLoad);
662 }
663 StoreValue(rl_dest, rl_result);
664 }
665 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700666 ThreadOffset getterOffset =
667 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pGet64Instance)
668 : (is_object ? QUICK_ENTRYPOINT_OFFSET(pGetObjInstance)
669 : QUICK_ENTRYPOINT_OFFSET(pGet32Instance));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700670 CallRuntimeHelperImmRegLocation(getterOffset, field_idx, rl_obj, true);
671 if (is_long_or_double) {
672 RegLocation rl_result = GetReturnWide(rl_dest.fp);
673 StoreValueWide(rl_dest, rl_result);
674 } else {
675 RegLocation rl_result = GetReturn(rl_dest.fp);
676 StoreValue(rl_dest, rl_result);
677 }
678 }
679}
680
681void Mir2Lir::GenIPut(uint32_t field_idx, int opt_flags, OpSize size,
682 RegLocation rl_src, RegLocation rl_obj, bool is_long_or_double,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700683 bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700684 int field_offset;
685 bool is_volatile;
686
Ian Rogers9b297bf2013-09-06 11:11:25 -0700687 bool fast_path = FastInstance(field_idx, true, &field_offset, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700688 if (fast_path && !SLOW_FIELD_PATH) {
689 RegisterClass reg_class = oat_reg_class_by_size(size);
690 DCHECK_GE(field_offset, 0);
691 rl_obj = LoadValue(rl_obj, kCoreReg);
692 if (is_long_or_double) {
693 int reg_ptr;
694 rl_src = LoadValueWide(rl_src, kAnyReg);
695 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
696 reg_ptr = AllocTemp();
697 OpRegRegImm(kOpAdd, reg_ptr, rl_obj.low_reg, field_offset);
698 if (is_volatile) {
699 GenMemBarrier(kStoreStore);
700 }
701 StoreBaseDispWide(reg_ptr, 0, rl_src.low_reg, rl_src.high_reg);
702 if (is_volatile) {
703 GenMemBarrier(kLoadLoad);
704 }
705 FreeTemp(reg_ptr);
706 } else {
707 rl_src = LoadValue(rl_src, reg_class);
708 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
709 if (is_volatile) {
710 GenMemBarrier(kStoreStore);
711 }
712 StoreBaseDisp(rl_obj.low_reg, field_offset, rl_src.low_reg, kWord);
713 if (is_volatile) {
714 GenMemBarrier(kLoadLoad);
715 }
716 if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) {
717 MarkGCCard(rl_src.low_reg, rl_obj.low_reg);
718 }
719 }
720 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700721 ThreadOffset setter_offset =
722 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pSet64Instance)
723 : (is_object ? QUICK_ENTRYPOINT_OFFSET(pSetObjInstance)
724 : QUICK_ENTRYPOINT_OFFSET(pSet32Instance));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700725 CallRuntimeHelperImmRegLocationRegLocation(setter_offset, field_idx, rl_obj, rl_src, true);
726 }
727}
728
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700729void Mir2Lir::GenConstClass(uint32_t type_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700730 RegLocation rl_method = LoadCurrMethod();
731 int res_reg = AllocTemp();
732 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
733 if (!cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
734 *cu_->dex_file,
735 type_idx)) {
736 // Call out to helper which resolves type and verifies access.
737 // Resolved type returned in kRet0.
Ian Rogers848871b2013-08-05 10:56:33 -0700738 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccess),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700739 type_idx, rl_method.low_reg, true);
740 RegLocation rl_result = GetReturn(false);
741 StoreValue(rl_dest, rl_result);
742 } else {
743 // We're don't need access checks, load type from dex cache
744 int32_t dex_cache_offset =
Brian Carlstromea46f952013-07-30 01:26:50 -0700745 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700746 LoadWordDisp(rl_method.low_reg, dex_cache_offset, res_reg);
747 int32_t offset_of_type =
748 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*)
749 * type_idx);
750 LoadWordDisp(res_reg, offset_of_type, rl_result.low_reg);
751 if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file,
752 type_idx) || SLOW_TYPE_PATH) {
753 // Slow path, at runtime test if type is null and if so initialize
754 FlushAllRegs();
755 LIR* branch1 = OpCmpImmBranch(kCondEq, rl_result.low_reg, 0, NULL);
756 // Resolved, store and hop over following code
757 StoreValue(rl_dest, rl_result);
758 /*
759 * Because we have stores of the target value on two paths,
760 * clobber temp tracking for the destination using the ssa name
761 */
762 ClobberSReg(rl_dest.s_reg_low);
763 LIR* branch2 = OpUnconditionalBranch(0);
764 // TUNING: move slow path to end & remove unconditional branch
765 LIR* target1 = NewLIR0(kPseudoTargetLabel);
766 // Call out to helper, which will return resolved type in kArg0
Ian Rogers848871b2013-08-05 10:56:33 -0700767 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeType), type_idx,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700768 rl_method.low_reg, true);
769 RegLocation rl_result = GetReturn(false);
770 StoreValue(rl_dest, rl_result);
771 /*
772 * Because we have stores of the target value on two paths,
773 * clobber temp tracking for the destination using the ssa name
774 */
775 ClobberSReg(rl_dest.s_reg_low);
776 // Rejoin code paths
777 LIR* target2 = NewLIR0(kPseudoTargetLabel);
778 branch1->target = target1;
779 branch2->target = target2;
780 } else {
781 // Fast path, we're done - just store result
782 StoreValue(rl_dest, rl_result);
783 }
784 }
785}
786
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700787void Mir2Lir::GenConstString(uint32_t string_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700788 /* NOTE: Most strings should be available at compile time */
789 int32_t offset_of_string = mirror::Array::DataOffset(sizeof(mirror::String*)).Int32Value() +
790 (sizeof(mirror::String*) * string_idx);
791 if (!cu_->compiler_driver->CanAssumeStringIsPresentInDexCache(
792 *cu_->dex_file, string_idx) || SLOW_STRING_PATH) {
793 // slow path, resolve string if not in dex cache
794 FlushAllRegs();
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700795 LockCallTemps(); // Using explicit registers
Brian Carlstrom7940e442013-07-12 13:46:57 -0700796 LoadCurrMethodDirect(TargetReg(kArg2));
797 LoadWordDisp(TargetReg(kArg2),
Brian Carlstromea46f952013-07-30 01:26:50 -0700798 mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), TargetReg(kArg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700799 // Might call out to helper, which will return resolved string in kRet0
Ian Rogers848871b2013-08-05 10:56:33 -0700800 int r_tgt = CallHelperSetup(QUICK_ENTRYPOINT_OFFSET(pResolveString));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700801 LoadWordDisp(TargetReg(kArg0), offset_of_string, TargetReg(kRet0));
802 LoadConstant(TargetReg(kArg1), string_idx);
803 if (cu_->instruction_set == kThumb2) {
804 OpRegImm(kOpCmp, TargetReg(kRet0), 0); // Is resolved?
805 GenBarrier();
806 // For testing, always force through helper
807 if (!EXERCISE_SLOWEST_STRING_PATH) {
808 OpIT(kCondEq, "T");
809 }
810 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .eq
811 LIR* call_inst = OpReg(kOpBlx, r_tgt); // .eq, helper(Method*, string_idx)
812 MarkSafepointPC(call_inst);
813 FreeTemp(r_tgt);
814 } else if (cu_->instruction_set == kMips) {
815 LIR* branch = OpCmpImmBranch(kCondNe, TargetReg(kRet0), 0, NULL);
816 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .eq
817 LIR* call_inst = OpReg(kOpBlx, r_tgt);
818 MarkSafepointPC(call_inst);
819 FreeTemp(r_tgt);
820 LIR* target = NewLIR0(kPseudoTargetLabel);
821 branch->target = target;
822 } else {
823 DCHECK_EQ(cu_->instruction_set, kX86);
Ian Rogers848871b2013-08-05 10:56:33 -0700824 CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(pResolveString), TargetReg(kArg2),
Ian Rogers7655f292013-07-29 11:07:13 -0700825 TargetReg(kArg1), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700826 }
827 GenBarrier();
828 StoreValue(rl_dest, GetReturn(false));
829 } else {
830 RegLocation rl_method = LoadCurrMethod();
831 int res_reg = AllocTemp();
832 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
833 LoadWordDisp(rl_method.low_reg,
Brian Carlstromea46f952013-07-30 01:26:50 -0700834 mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), res_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700835 LoadWordDisp(res_reg, offset_of_string, rl_result.low_reg);
836 StoreValue(rl_dest, rl_result);
837 }
838}
839
840/*
841 * Let helper function take care of everything. Will
842 * call Class::NewInstanceFromCode(type_idx, method);
843 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700844void Mir2Lir::GenNewInstance(uint32_t type_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700845 FlushAllRegs(); /* Everything to home location */
846 // alloc will always check for resolution, do we also need to verify
847 // access because the verifier was unable to?
Ian Rogers848871b2013-08-05 10:56:33 -0700848 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700849 if (cu_->compiler_driver->CanAccessInstantiableTypeWithoutChecks(
850 cu_->method_idx, *cu_->dex_file, type_idx)) {
Ian Rogers848871b2013-08-05 10:56:33 -0700851 func_offset = QUICK_ENTRYPOINT_OFFSET(pAllocObject);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700852 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700853 func_offset = QUICK_ENTRYPOINT_OFFSET(pAllocObjectWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700854 }
855 CallRuntimeHelperImmMethod(func_offset, type_idx, true);
856 RegLocation rl_result = GetReturn(false);
857 StoreValue(rl_dest, rl_result);
858}
859
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700860void Mir2Lir::GenThrow(RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700861 FlushAllRegs();
Ian Rogers7655f292013-07-29 11:07:13 -0700862 CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(pDeliverException), rl_src, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700863}
864
865// For final classes there are no sub-classes to check and so we can answer the instance-of
866// question with simple comparisons.
867void Mir2Lir::GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
868 RegLocation rl_src) {
869 RegLocation object = LoadValue(rl_src, kCoreReg);
870 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
871 int result_reg = rl_result.low_reg;
872 if (result_reg == object.low_reg) {
873 result_reg = AllocTypedTemp(false, kCoreReg);
874 }
875 LoadConstant(result_reg, 0); // assume false
876 LIR* null_branchover = OpCmpImmBranch(kCondEq, object.low_reg, 0, NULL);
877
878 int check_class = AllocTypedTemp(false, kCoreReg);
879 int object_class = AllocTypedTemp(false, kCoreReg);
880
881 LoadCurrMethodDirect(check_class);
882 if (use_declaring_class) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700883 LoadWordDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700884 check_class);
885 LoadWordDisp(object.low_reg, mirror::Object::ClassOffset().Int32Value(), object_class);
886 } else {
Brian Carlstromea46f952013-07-30 01:26:50 -0700887 LoadWordDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700888 check_class);
889 LoadWordDisp(object.low_reg, mirror::Object::ClassOffset().Int32Value(), object_class);
890 int32_t offset_of_type =
891 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() +
892 (sizeof(mirror::Class*) * type_idx);
893 LoadWordDisp(check_class, offset_of_type, check_class);
894 }
895
896 LIR* ne_branchover = NULL;
897 if (cu_->instruction_set == kThumb2) {
898 OpRegReg(kOpCmp, check_class, object_class); // Same?
899 OpIT(kCondEq, ""); // if-convert the test
900 LoadConstant(result_reg, 1); // .eq case - load true
901 } else {
902 ne_branchover = OpCmpBranch(kCondNe, check_class, object_class, NULL);
903 LoadConstant(result_reg, 1); // eq case - load true
904 }
905 LIR* target = NewLIR0(kPseudoTargetLabel);
906 null_branchover->target = target;
907 if (ne_branchover != NULL) {
908 ne_branchover->target = target;
909 }
910 FreeTemp(object_class);
911 FreeTemp(check_class);
912 if (IsTemp(result_reg)) {
913 OpRegCopy(rl_result.low_reg, result_reg);
914 FreeTemp(result_reg);
915 }
916 StoreValue(rl_dest, rl_result);
917}
918
919void Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
920 bool type_known_abstract, bool use_declaring_class,
921 bool can_assume_type_is_in_dex_cache,
922 uint32_t type_idx, RegLocation rl_dest,
923 RegLocation rl_src) {
924 FlushAllRegs();
925 // May generate a call - use explicit registers
926 LockCallTemps();
927 LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method*
928 int class_reg = TargetReg(kArg2); // kArg2 will hold the Class*
929 if (needs_access_check) {
930 // Check we have access to type_idx and if not throw IllegalAccessError,
931 // returns Class* in kArg0
Ian Rogers848871b2013-08-05 10:56:33 -0700932 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccess),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700933 type_idx, true);
934 OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path
935 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
936 } else if (use_declaring_class) {
937 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
938 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -0700939 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700940 } else {
941 // Load dex cache entry into class_reg (kArg2)
942 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
943 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -0700944 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700945 int32_t offset_of_type =
946 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*)
947 * type_idx);
948 LoadWordDisp(class_reg, offset_of_type, class_reg);
949 if (!can_assume_type_is_in_dex_cache) {
950 // Need to test presence of type in dex cache at runtime
951 LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL);
952 // Not resolved
953 // Call out to helper, which will return resolved type in kRet0
Ian Rogers848871b2013-08-05 10:56:33 -0700954 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeType), type_idx, true);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700955 OpRegCopy(TargetReg(kArg2), TargetReg(kRet0)); // Align usage with fast path
Brian Carlstrom7940e442013-07-12 13:46:57 -0700956 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); /* reload Ref */
957 // Rejoin code paths
958 LIR* hop_target = NewLIR0(kPseudoTargetLabel);
959 hop_branch->target = hop_target;
960 }
961 }
962 /* kArg0 is ref, kArg2 is class. If ref==null, use directly as bool result */
963 RegLocation rl_result = GetReturn(false);
964 if (cu_->instruction_set == kMips) {
965 // On MIPS rArg0 != rl_result, place false in result if branch is taken.
966 LoadConstant(rl_result.low_reg, 0);
967 }
968 LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL);
969
970 /* load object->klass_ */
971 DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0);
972 LoadWordDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1));
973 /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class */
974 LIR* branchover = NULL;
975 if (type_known_final) {
976 // rl_result == ref == null == 0.
977 if (cu_->instruction_set == kThumb2) {
978 OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same?
979 OpIT(kCondEq, "E"); // if-convert the test
980 LoadConstant(rl_result.low_reg, 1); // .eq case - load true
981 LoadConstant(rl_result.low_reg, 0); // .ne case - load false
982 } else {
983 LoadConstant(rl_result.low_reg, 0); // ne case - load false
984 branchover = OpCmpBranch(kCondNe, TargetReg(kArg1), TargetReg(kArg2), NULL);
985 LoadConstant(rl_result.low_reg, 1); // eq case - load true
986 }
987 } else {
988 if (cu_->instruction_set == kThumb2) {
Ian Rogers848871b2013-08-05 10:56:33 -0700989 int r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(pInstanceofNonTrivial));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700990 if (!type_known_abstract) {
991 /* Uses conditional nullification */
992 OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same?
993 OpIT(kCondEq, "EE"); // if-convert the test
994 LoadConstant(TargetReg(kArg0), 1); // .eq case - load true
995 }
996 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class
997 OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class)
998 FreeTemp(r_tgt);
999 } else {
1000 if (!type_known_abstract) {
1001 /* Uses branchovers */
1002 LoadConstant(rl_result.low_reg, 1); // assume true
1003 branchover = OpCmpBranch(kCondEq, TargetReg(kArg1), TargetReg(kArg2), NULL);
1004 }
1005 if (cu_->instruction_set != kX86) {
Ian Rogers848871b2013-08-05 10:56:33 -07001006 int r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(pInstanceofNonTrivial));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001007 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class
1008 OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class)
1009 FreeTemp(r_tgt);
1010 } else {
1011 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2));
Ian Rogers848871b2013-08-05 10:56:33 -07001012 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(pInstanceofNonTrivial));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001013 }
1014 }
1015 }
1016 // TODO: only clobber when type isn't final?
1017 ClobberCalleeSave();
1018 /* branch targets here */
1019 LIR* target = NewLIR0(kPseudoTargetLabel);
1020 StoreValue(rl_dest, rl_result);
1021 branch1->target = target;
1022 if (branchover != NULL) {
1023 branchover->target = target;
1024 }
1025}
1026
1027void Mir2Lir::GenInstanceof(uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src) {
1028 bool type_known_final, type_known_abstract, use_declaring_class;
1029 bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
1030 *cu_->dex_file,
1031 type_idx,
1032 &type_known_final,
1033 &type_known_abstract,
1034 &use_declaring_class);
1035 bool can_assume_type_is_in_dex_cache = !needs_access_check &&
1036 cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx);
1037
1038 if ((use_declaring_class || can_assume_type_is_in_dex_cache) && type_known_final) {
1039 GenInstanceofFinal(use_declaring_class, type_idx, rl_dest, rl_src);
1040 } else {
1041 GenInstanceofCallingHelper(needs_access_check, type_known_final, type_known_abstract,
1042 use_declaring_class, can_assume_type_is_in_dex_cache,
1043 type_idx, rl_dest, rl_src);
1044 }
1045}
1046
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001047void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001048 bool type_known_final, type_known_abstract, use_declaring_class;
1049 bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
1050 *cu_->dex_file,
1051 type_idx,
1052 &type_known_final,
1053 &type_known_abstract,
1054 &use_declaring_class);
1055 // Note: currently type_known_final is unused, as optimizing will only improve the performance
1056 // of the exception throw path.
1057 DexCompilationUnit* cu = mir_graph_->GetCurrentDexCompilationUnit();
1058 const MethodReference mr(cu->GetDexFile(), cu->GetDexMethodIndex());
1059 if (!needs_access_check && cu_->compiler_driver->IsSafeCast(mr, insn_idx)) {
1060 // Verifier type analysis proved this check cast would never cause an exception.
1061 return;
1062 }
1063 FlushAllRegs();
1064 // May generate a call - use explicit registers
1065 LockCallTemps();
1066 LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method*
1067 int class_reg = TargetReg(kArg2); // kArg2 will hold the Class*
1068 if (needs_access_check) {
1069 // Check we have access to type_idx and if not throw IllegalAccessError,
1070 // returns Class* in kRet0
1071 // InitializeTypeAndVerifyAccess(idx, method)
Ian Rogers848871b2013-08-05 10:56:33 -07001072 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccess),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001073 type_idx, TargetReg(kArg1), true);
1074 OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path
1075 } else if (use_declaring_class) {
1076 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -07001077 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001078 } else {
1079 // Load dex cache entry into class_reg (kArg2)
1080 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -07001081 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001082 int32_t offset_of_type =
1083 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() +
1084 (sizeof(mirror::Class*) * type_idx);
1085 LoadWordDisp(class_reg, offset_of_type, class_reg);
1086 if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx)) {
1087 // Need to test presence of type in dex cache at runtime
1088 LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL);
1089 // Not resolved
1090 // Call out to helper, which will return resolved type in kArg0
1091 // InitializeTypeFromCode(idx, method)
Ian Rogers848871b2013-08-05 10:56:33 -07001092 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeType), type_idx,
Ian Rogers7655f292013-07-29 11:07:13 -07001093 TargetReg(kArg1), true);
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001094 OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path
Brian Carlstrom7940e442013-07-12 13:46:57 -07001095 // Rejoin code paths
1096 LIR* hop_target = NewLIR0(kPseudoTargetLabel);
1097 hop_branch->target = hop_target;
1098 }
1099 }
1100 // At this point, class_reg (kArg2) has class
1101 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
1102 /* Null is OK - continue */
1103 LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL);
1104 /* load object->klass_ */
1105 DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0);
1106 LoadWordDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1));
1107 /* kArg1 now contains object->klass_ */
1108 LIR* branch2 = NULL;
1109 if (!type_known_abstract) {
1110 branch2 = OpCmpBranch(kCondEq, TargetReg(kArg1), class_reg, NULL);
1111 }
Ian Rogers848871b2013-08-05 10:56:33 -07001112 CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(pCheckCast), TargetReg(kArg1),
Ian Rogers7655f292013-07-29 11:07:13 -07001113 TargetReg(kArg2), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001114 /* branch target here */
1115 LIR* target = NewLIR0(kPseudoTargetLabel);
1116 branch1->target = target;
1117 if (branch2 != NULL) {
1118 branch2->target = target;
1119 }
1120}
1121
1122void Mir2Lir::GenLong3Addr(OpKind first_op, OpKind second_op, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001123 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001124 RegLocation rl_result;
1125 if (cu_->instruction_set == kThumb2) {
1126 /*
1127 * NOTE: This is the one place in the code in which we might have
1128 * as many as six live temporary registers. There are 5 in the normal
1129 * set for Arm. Until we have spill capabilities, temporarily add
1130 * lr to the temp set. It is safe to do this locally, but note that
1131 * lr is used explicitly elsewhere in the code generator and cannot
1132 * normally be used as a general temp register.
1133 */
1134 MarkTemp(TargetReg(kLr)); // Add lr to the temp pool
1135 FreeTemp(TargetReg(kLr)); // and make it available
1136 }
1137 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
1138 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
1139 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1140 // The longs may overlap - use intermediate temp if so
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001141 if ((rl_result.low_reg == rl_src1.high_reg) || (rl_result.low_reg == rl_src2.high_reg)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001142 int t_reg = AllocTemp();
1143 OpRegRegReg(first_op, t_reg, rl_src1.low_reg, rl_src2.low_reg);
1144 OpRegRegReg(second_op, rl_result.high_reg, rl_src1.high_reg, rl_src2.high_reg);
1145 OpRegCopy(rl_result.low_reg, t_reg);
1146 FreeTemp(t_reg);
1147 } else {
1148 OpRegRegReg(first_op, rl_result.low_reg, rl_src1.low_reg, rl_src2.low_reg);
1149 OpRegRegReg(second_op, rl_result.high_reg, rl_src1.high_reg,
1150 rl_src2.high_reg);
1151 }
1152 /*
1153 * NOTE: If rl_dest refers to a frame variable in a large frame, the
1154 * following StoreValueWide might need to allocate a temp register.
1155 * To further work around the lack of a spill capability, explicitly
1156 * free any temps from rl_src1 & rl_src2 that aren't still live in rl_result.
1157 * Remove when spill is functional.
1158 */
1159 FreeRegLocTemps(rl_result, rl_src1);
1160 FreeRegLocTemps(rl_result, rl_src2);
1161 StoreValueWide(rl_dest, rl_result);
1162 if (cu_->instruction_set == kThumb2) {
1163 Clobber(TargetReg(kLr));
1164 UnmarkTemp(TargetReg(kLr)); // Remove lr from the temp pool
1165 }
1166}
1167
1168
1169void Mir2Lir::GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001170 RegLocation rl_src1, RegLocation rl_shift) {
Ian Rogers848871b2013-08-05 10:56:33 -07001171 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001172
1173 switch (opcode) {
1174 case Instruction::SHL_LONG:
1175 case Instruction::SHL_LONG_2ADDR:
Ian Rogers7655f292013-07-29 11:07:13 -07001176 func_offset = QUICK_ENTRYPOINT_OFFSET(pShlLong);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001177 break;
1178 case Instruction::SHR_LONG:
1179 case Instruction::SHR_LONG_2ADDR:
Ian Rogers7655f292013-07-29 11:07:13 -07001180 func_offset = QUICK_ENTRYPOINT_OFFSET(pShrLong);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001181 break;
1182 case Instruction::USHR_LONG:
1183 case Instruction::USHR_LONG_2ADDR:
Ian Rogers7655f292013-07-29 11:07:13 -07001184 func_offset = QUICK_ENTRYPOINT_OFFSET(pUshrLong);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001185 break;
1186 default:
1187 LOG(FATAL) << "Unexpected case";
1188 }
1189 FlushAllRegs(); /* Send everything to home location */
1190 CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_shift, false);
1191 RegLocation rl_result = GetReturnWide(false);
1192 StoreValueWide(rl_dest, rl_result);
1193}
1194
1195
1196void Mir2Lir::GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001197 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001198 OpKind op = kOpBkpt;
1199 bool is_div_rem = false;
1200 bool check_zero = false;
1201 bool unary = false;
1202 RegLocation rl_result;
1203 bool shift_op = false;
1204 switch (opcode) {
1205 case Instruction::NEG_INT:
1206 op = kOpNeg;
1207 unary = true;
1208 break;
1209 case Instruction::NOT_INT:
1210 op = kOpMvn;
1211 unary = true;
1212 break;
1213 case Instruction::ADD_INT:
1214 case Instruction::ADD_INT_2ADDR:
1215 op = kOpAdd;
1216 break;
1217 case Instruction::SUB_INT:
1218 case Instruction::SUB_INT_2ADDR:
1219 op = kOpSub;
1220 break;
1221 case Instruction::MUL_INT:
1222 case Instruction::MUL_INT_2ADDR:
1223 op = kOpMul;
1224 break;
1225 case Instruction::DIV_INT:
1226 case Instruction::DIV_INT_2ADDR:
1227 check_zero = true;
1228 op = kOpDiv;
1229 is_div_rem = true;
1230 break;
1231 /* NOTE: returns in kArg1 */
1232 case Instruction::REM_INT:
1233 case Instruction::REM_INT_2ADDR:
1234 check_zero = true;
1235 op = kOpRem;
1236 is_div_rem = true;
1237 break;
1238 case Instruction::AND_INT:
1239 case Instruction::AND_INT_2ADDR:
1240 op = kOpAnd;
1241 break;
1242 case Instruction::OR_INT:
1243 case Instruction::OR_INT_2ADDR:
1244 op = kOpOr;
1245 break;
1246 case Instruction::XOR_INT:
1247 case Instruction::XOR_INT_2ADDR:
1248 op = kOpXor;
1249 break;
1250 case Instruction::SHL_INT:
1251 case Instruction::SHL_INT_2ADDR:
1252 shift_op = true;
1253 op = kOpLsl;
1254 break;
1255 case Instruction::SHR_INT:
1256 case Instruction::SHR_INT_2ADDR:
1257 shift_op = true;
1258 op = kOpAsr;
1259 break;
1260 case Instruction::USHR_INT:
1261 case Instruction::USHR_INT_2ADDR:
1262 shift_op = true;
1263 op = kOpLsr;
1264 break;
1265 default:
1266 LOG(FATAL) << "Invalid word arith op: " << opcode;
1267 }
1268 if (!is_div_rem) {
1269 if (unary) {
1270 rl_src1 = LoadValue(rl_src1, kCoreReg);
1271 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1272 OpRegReg(op, rl_result.low_reg, rl_src1.low_reg);
1273 } else {
1274 if (shift_op) {
1275 int t_reg = INVALID_REG;
1276 if (cu_->instruction_set == kX86) {
1277 // X86 doesn't require masking and must use ECX
1278 t_reg = TargetReg(kCount); // rCX
1279 LoadValueDirectFixed(rl_src2, t_reg);
1280 } else {
1281 rl_src2 = LoadValue(rl_src2, kCoreReg);
1282 t_reg = AllocTemp();
1283 OpRegRegImm(kOpAnd, t_reg, rl_src2.low_reg, 31);
1284 }
1285 rl_src1 = LoadValue(rl_src1, kCoreReg);
1286 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1287 OpRegRegReg(op, rl_result.low_reg, rl_src1.low_reg, t_reg);
1288 FreeTemp(t_reg);
1289 } else {
1290 rl_src1 = LoadValue(rl_src1, kCoreReg);
1291 rl_src2 = LoadValue(rl_src2, kCoreReg);
1292 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1293 OpRegRegReg(op, rl_result.low_reg, rl_src1.low_reg, rl_src2.low_reg);
1294 }
1295 }
1296 StoreValue(rl_dest, rl_result);
1297 } else {
1298 if (cu_->instruction_set == kMips) {
1299 rl_src1 = LoadValue(rl_src1, kCoreReg);
1300 rl_src2 = LoadValue(rl_src2, kCoreReg);
1301 if (check_zero) {
1302 GenImmedCheck(kCondEq, rl_src2.low_reg, 0, kThrowDivZero);
1303 }
1304 rl_result = GenDivRem(rl_dest, rl_src1.low_reg, rl_src2.low_reg, op == kOpDiv);
1305 } else {
Ian Rogers848871b2013-08-05 10:56:33 -07001306 ThreadOffset func_offset = QUICK_ENTRYPOINT_OFFSET(pIdivmod);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001307 FlushAllRegs(); /* Send everything to home location */
1308 LoadValueDirectFixed(rl_src2, TargetReg(kArg1));
1309 int r_tgt = CallHelperSetup(func_offset);
1310 LoadValueDirectFixed(rl_src1, TargetReg(kArg0));
1311 if (check_zero) {
1312 GenImmedCheck(kCondEq, TargetReg(kArg1), 0, kThrowDivZero);
1313 }
1314 // NOTE: callout here is not a safepoint
Brian Carlstromdf629502013-07-17 22:39:56 -07001315 CallHelper(r_tgt, func_offset, false /* not a safepoint */);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001316 if (op == kOpDiv)
1317 rl_result = GetReturn(false);
1318 else
1319 rl_result = GetReturnAlt();
1320 }
1321 StoreValue(rl_dest, rl_result);
1322 }
1323}
1324
1325/*
1326 * The following are the first-level codegen routines that analyze the format
1327 * of each bytecode then either dispatch special purpose codegen routines
1328 * or produce corresponding Thumb instructions directly.
1329 */
1330
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001331static bool IsPowerOfTwo(int x) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001332 return (x & (x - 1)) == 0;
1333}
1334
1335// Returns true if no more than two bits are set in 'x'.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001336static bool IsPopCountLE2(unsigned int x) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001337 x &= x - 1;
1338 return (x & (x - 1)) == 0;
1339}
1340
1341// Returns the index of the lowest set bit in 'x'.
1342static int LowestSetBit(unsigned int x) {
1343 int bit_posn = 0;
1344 while ((x & 0xf) == 0) {
1345 bit_posn += 4;
1346 x >>= 4;
1347 }
1348 while ((x & 1) == 0) {
1349 bit_posn++;
1350 x >>= 1;
1351 }
1352 return bit_posn;
1353}
1354
1355// Returns true if it added instructions to 'cu' to divide 'rl_src' by 'lit'
1356// and store the result in 'rl_dest'.
buzbee11b63d12013-08-27 07:34:17 -07001357bool Mir2Lir::HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001358 RegLocation rl_src, RegLocation rl_dest, int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001359 if ((lit < 2) || ((cu_->instruction_set != kThumb2) && !IsPowerOfTwo(lit))) {
1360 return false;
1361 }
1362 // No divide instruction for Arm, so check for more special cases
1363 if ((cu_->instruction_set == kThumb2) && !IsPowerOfTwo(lit)) {
buzbee11b63d12013-08-27 07:34:17 -07001364 return SmallLiteralDivRem(dalvik_opcode, is_div, rl_src, rl_dest, lit);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001365 }
1366 int k = LowestSetBit(lit);
1367 if (k >= 30) {
1368 // Avoid special cases.
1369 return false;
1370 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001371 rl_src = LoadValue(rl_src, kCoreReg);
1372 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee11b63d12013-08-27 07:34:17 -07001373 if (is_div) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001374 int t_reg = AllocTemp();
1375 if (lit == 2) {
1376 // Division by 2 is by far the most common division by constant.
1377 OpRegRegImm(kOpLsr, t_reg, rl_src.low_reg, 32 - k);
1378 OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.low_reg);
1379 OpRegRegImm(kOpAsr, rl_result.low_reg, t_reg, k);
1380 } else {
1381 OpRegRegImm(kOpAsr, t_reg, rl_src.low_reg, 31);
1382 OpRegRegImm(kOpLsr, t_reg, t_reg, 32 - k);
1383 OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.low_reg);
1384 OpRegRegImm(kOpAsr, rl_result.low_reg, t_reg, k);
1385 }
1386 } else {
1387 int t_reg1 = AllocTemp();
1388 int t_reg2 = AllocTemp();
1389 if (lit == 2) {
1390 OpRegRegImm(kOpLsr, t_reg1, rl_src.low_reg, 32 - k);
1391 OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.low_reg);
1392 OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit -1);
1393 OpRegRegReg(kOpSub, rl_result.low_reg, t_reg2, t_reg1);
1394 } else {
1395 OpRegRegImm(kOpAsr, t_reg1, rl_src.low_reg, 31);
1396 OpRegRegImm(kOpLsr, t_reg1, t_reg1, 32 - k);
1397 OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.low_reg);
1398 OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit - 1);
1399 OpRegRegReg(kOpSub, rl_result.low_reg, t_reg2, t_reg1);
1400 }
1401 }
1402 StoreValue(rl_dest, rl_result);
1403 return true;
1404}
1405
1406// Returns true if it added instructions to 'cu' to multiply 'rl_src' by 'lit'
1407// and store the result in 'rl_dest'.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001408bool Mir2Lir::HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001409 // Can we simplify this multiplication?
1410 bool power_of_two = false;
1411 bool pop_count_le2 = false;
1412 bool power_of_two_minus_one = false;
1413 if (lit < 2) {
1414 // Avoid special cases.
1415 return false;
1416 } else if (IsPowerOfTwo(lit)) {
1417 power_of_two = true;
1418 } else if (IsPopCountLE2(lit)) {
1419 pop_count_le2 = true;
1420 } else if (IsPowerOfTwo(lit + 1)) {
1421 power_of_two_minus_one = true;
1422 } else {
1423 return false;
1424 }
1425 rl_src = LoadValue(rl_src, kCoreReg);
1426 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1427 if (power_of_two) {
1428 // Shift.
1429 OpRegRegImm(kOpLsl, rl_result.low_reg, rl_src.low_reg, LowestSetBit(lit));
1430 } else if (pop_count_le2) {
1431 // Shift and add and shift.
1432 int first_bit = LowestSetBit(lit);
1433 int second_bit = LowestSetBit(lit ^ (1 << first_bit));
1434 GenMultiplyByTwoBitMultiplier(rl_src, rl_result, lit, first_bit, second_bit);
1435 } else {
1436 // Reverse subtract: (src << (shift + 1)) - src.
1437 DCHECK(power_of_two_minus_one);
1438 // TUNING: rsb dst, src, src lsl#LowestSetBit(lit + 1)
1439 int t_reg = AllocTemp();
1440 OpRegRegImm(kOpLsl, t_reg, rl_src.low_reg, LowestSetBit(lit + 1));
1441 OpRegRegReg(kOpSub, rl_result.low_reg, t_reg, rl_src.low_reg);
1442 }
1443 StoreValue(rl_dest, rl_result);
1444 return true;
1445}
1446
1447void Mir2Lir::GenArithOpIntLit(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001448 int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001449 RegLocation rl_result;
1450 OpKind op = static_cast<OpKind>(0); /* Make gcc happy */
1451 int shift_op = false;
1452 bool is_div = false;
1453
1454 switch (opcode) {
1455 case Instruction::RSUB_INT_LIT8:
1456 case Instruction::RSUB_INT: {
1457 rl_src = LoadValue(rl_src, kCoreReg);
1458 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1459 if (cu_->instruction_set == kThumb2) {
1460 OpRegRegImm(kOpRsub, rl_result.low_reg, rl_src.low_reg, lit);
1461 } else {
1462 OpRegReg(kOpNeg, rl_result.low_reg, rl_src.low_reg);
1463 OpRegImm(kOpAdd, rl_result.low_reg, lit);
1464 }
1465 StoreValue(rl_dest, rl_result);
1466 return;
1467 }
1468
1469 case Instruction::SUB_INT:
1470 case Instruction::SUB_INT_2ADDR:
1471 lit = -lit;
1472 // Intended fallthrough
1473 case Instruction::ADD_INT:
1474 case Instruction::ADD_INT_2ADDR:
1475 case Instruction::ADD_INT_LIT8:
1476 case Instruction::ADD_INT_LIT16:
1477 op = kOpAdd;
1478 break;
1479 case Instruction::MUL_INT:
1480 case Instruction::MUL_INT_2ADDR:
1481 case Instruction::MUL_INT_LIT8:
1482 case Instruction::MUL_INT_LIT16: {
1483 if (HandleEasyMultiply(rl_src, rl_dest, lit)) {
1484 return;
1485 }
1486 op = kOpMul;
1487 break;
1488 }
1489 case Instruction::AND_INT:
1490 case Instruction::AND_INT_2ADDR:
1491 case Instruction::AND_INT_LIT8:
1492 case Instruction::AND_INT_LIT16:
1493 op = kOpAnd;
1494 break;
1495 case Instruction::OR_INT:
1496 case Instruction::OR_INT_2ADDR:
1497 case Instruction::OR_INT_LIT8:
1498 case Instruction::OR_INT_LIT16:
1499 op = kOpOr;
1500 break;
1501 case Instruction::XOR_INT:
1502 case Instruction::XOR_INT_2ADDR:
1503 case Instruction::XOR_INT_LIT8:
1504 case Instruction::XOR_INT_LIT16:
1505 op = kOpXor;
1506 break;
1507 case Instruction::SHL_INT_LIT8:
1508 case Instruction::SHL_INT:
1509 case Instruction::SHL_INT_2ADDR:
1510 lit &= 31;
1511 shift_op = true;
1512 op = kOpLsl;
1513 break;
1514 case Instruction::SHR_INT_LIT8:
1515 case Instruction::SHR_INT:
1516 case Instruction::SHR_INT_2ADDR:
1517 lit &= 31;
1518 shift_op = true;
1519 op = kOpAsr;
1520 break;
1521 case Instruction::USHR_INT_LIT8:
1522 case Instruction::USHR_INT:
1523 case Instruction::USHR_INT_2ADDR:
1524 lit &= 31;
1525 shift_op = true;
1526 op = kOpLsr;
1527 break;
1528
1529 case Instruction::DIV_INT:
1530 case Instruction::DIV_INT_2ADDR:
1531 case Instruction::DIV_INT_LIT8:
1532 case Instruction::DIV_INT_LIT16:
1533 case Instruction::REM_INT:
1534 case Instruction::REM_INT_2ADDR:
1535 case Instruction::REM_INT_LIT8:
1536 case Instruction::REM_INT_LIT16: {
1537 if (lit == 0) {
1538 GenImmedCheck(kCondAl, 0, 0, kThrowDivZero);
1539 return;
1540 }
buzbee11b63d12013-08-27 07:34:17 -07001541 if ((opcode == Instruction::DIV_INT) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -07001542 (opcode == Instruction::DIV_INT_2ADDR) ||
buzbee11b63d12013-08-27 07:34:17 -07001543 (opcode == Instruction::DIV_INT_LIT8) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -07001544 (opcode == Instruction::DIV_INT_LIT16)) {
1545 is_div = true;
1546 } else {
1547 is_div = false;
1548 }
buzbee11b63d12013-08-27 07:34:17 -07001549 if (HandleEasyDivRem(opcode, is_div, rl_src, rl_dest, lit)) {
1550 return;
1551 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001552 if (cu_->instruction_set == kMips) {
1553 rl_src = LoadValue(rl_src, kCoreReg);
1554 rl_result = GenDivRemLit(rl_dest, rl_src.low_reg, lit, is_div);
1555 } else {
1556 FlushAllRegs(); /* Everything to home location */
1557 LoadValueDirectFixed(rl_src, TargetReg(kArg0));
1558 Clobber(TargetReg(kArg0));
Ian Rogers848871b2013-08-05 10:56:33 -07001559 ThreadOffset func_offset = QUICK_ENTRYPOINT_OFFSET(pIdivmod);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001560 CallRuntimeHelperRegImm(func_offset, TargetReg(kArg0), lit, false);
1561 if (is_div)
1562 rl_result = GetReturn(false);
1563 else
1564 rl_result = GetReturnAlt();
1565 }
1566 StoreValue(rl_dest, rl_result);
1567 return;
1568 }
1569 default:
1570 LOG(FATAL) << "Unexpected opcode " << opcode;
1571 }
1572 rl_src = LoadValue(rl_src, kCoreReg);
1573 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1574 // Avoid shifts by literal 0 - no support in Thumb. Change to copy
1575 if (shift_op && (lit == 0)) {
1576 OpRegCopy(rl_result.low_reg, rl_src.low_reg);
1577 } else {
1578 OpRegRegImm(op, rl_result.low_reg, rl_src.low_reg, lit);
1579 }
1580 StoreValue(rl_dest, rl_result);
1581}
1582
1583void Mir2Lir::GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001584 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001585 RegLocation rl_result;
1586 OpKind first_op = kOpBkpt;
1587 OpKind second_op = kOpBkpt;
1588 bool call_out = false;
1589 bool check_zero = false;
Ian Rogers848871b2013-08-05 10:56:33 -07001590 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001591 int ret_reg = TargetReg(kRet0);
1592
1593 switch (opcode) {
1594 case Instruction::NOT_LONG:
1595 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
1596 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1597 // Check for destructive overlap
1598 if (rl_result.low_reg == rl_src2.high_reg) {
1599 int t_reg = AllocTemp();
1600 OpRegCopy(t_reg, rl_src2.high_reg);
1601 OpRegReg(kOpMvn, rl_result.low_reg, rl_src2.low_reg);
1602 OpRegReg(kOpMvn, rl_result.high_reg, t_reg);
1603 FreeTemp(t_reg);
1604 } else {
1605 OpRegReg(kOpMvn, rl_result.low_reg, rl_src2.low_reg);
1606 OpRegReg(kOpMvn, rl_result.high_reg, rl_src2.high_reg);
1607 }
1608 StoreValueWide(rl_dest, rl_result);
1609 return;
1610 case Instruction::ADD_LONG:
1611 case Instruction::ADD_LONG_2ADDR:
1612 if (cu_->instruction_set != kThumb2) {
1613 GenAddLong(rl_dest, rl_src1, rl_src2);
1614 return;
1615 }
1616 first_op = kOpAdd;
1617 second_op = kOpAdc;
1618 break;
1619 case Instruction::SUB_LONG:
1620 case Instruction::SUB_LONG_2ADDR:
1621 if (cu_->instruction_set != kThumb2) {
1622 GenSubLong(rl_dest, rl_src1, rl_src2);
1623 return;
1624 }
1625 first_op = kOpSub;
1626 second_op = kOpSbc;
1627 break;
1628 case Instruction::MUL_LONG:
1629 case Instruction::MUL_LONG_2ADDR:
1630 if (cu_->instruction_set == kThumb2) {
1631 GenMulLong(rl_dest, rl_src1, rl_src2);
1632 return;
1633 } else {
1634 call_out = true;
1635 ret_reg = TargetReg(kRet0);
Ian Rogers7655f292013-07-29 11:07:13 -07001636 func_offset = QUICK_ENTRYPOINT_OFFSET(pLmul);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001637 }
1638 break;
1639 case Instruction::DIV_LONG:
1640 case Instruction::DIV_LONG_2ADDR:
1641 call_out = true;
1642 check_zero = true;
1643 ret_reg = TargetReg(kRet0);
Ian Rogers7655f292013-07-29 11:07:13 -07001644 func_offset = QUICK_ENTRYPOINT_OFFSET(pLdiv);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001645 break;
1646 case Instruction::REM_LONG:
1647 case Instruction::REM_LONG_2ADDR:
1648 call_out = true;
1649 check_zero = true;
Ian Rogers7655f292013-07-29 11:07:13 -07001650 func_offset = QUICK_ENTRYPOINT_OFFSET(pLdivmod);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001651 /* NOTE - for Arm, result is in kArg2/kArg3 instead of kRet0/kRet1 */
1652 ret_reg = (cu_->instruction_set == kThumb2) ? TargetReg(kArg2) : TargetReg(kRet0);
1653 break;
1654 case Instruction::AND_LONG_2ADDR:
1655 case Instruction::AND_LONG:
1656 if (cu_->instruction_set == kX86) {
1657 return GenAndLong(rl_dest, rl_src1, rl_src2);
1658 }
1659 first_op = kOpAnd;
1660 second_op = kOpAnd;
1661 break;
1662 case Instruction::OR_LONG:
1663 case Instruction::OR_LONG_2ADDR:
1664 if (cu_->instruction_set == kX86) {
1665 GenOrLong(rl_dest, rl_src1, rl_src2);
1666 return;
1667 }
1668 first_op = kOpOr;
1669 second_op = kOpOr;
1670 break;
1671 case Instruction::XOR_LONG:
1672 case Instruction::XOR_LONG_2ADDR:
1673 if (cu_->instruction_set == kX86) {
1674 GenXorLong(rl_dest, rl_src1, rl_src2);
1675 return;
1676 }
1677 first_op = kOpXor;
1678 second_op = kOpXor;
1679 break;
1680 case Instruction::NEG_LONG: {
1681 GenNegLong(rl_dest, rl_src2);
1682 return;
1683 }
1684 default:
1685 LOG(FATAL) << "Invalid long arith op";
1686 }
1687 if (!call_out) {
1688 GenLong3Addr(first_op, second_op, rl_dest, rl_src1, rl_src2);
1689 } else {
1690 FlushAllRegs(); /* Send everything to home location */
1691 if (check_zero) {
1692 LoadValueDirectWideFixed(rl_src2, TargetReg(kArg2), TargetReg(kArg3));
1693 int r_tgt = CallHelperSetup(func_offset);
1694 GenDivZeroCheck(TargetReg(kArg2), TargetReg(kArg3));
1695 LoadValueDirectWideFixed(rl_src1, TargetReg(kArg0), TargetReg(kArg1));
1696 // NOTE: callout here is not a safepoint
1697 CallHelper(r_tgt, func_offset, false /* not safepoint */);
1698 } else {
1699 CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_src2, false);
1700 }
1701 // Adjust return regs in to handle case of rem returning kArg2/kArg3
1702 if (ret_reg == TargetReg(kRet0))
1703 rl_result = GetReturnWide(false);
1704 else
1705 rl_result = GetReturnWideAlt();
1706 StoreValueWide(rl_dest, rl_result);
1707 }
1708}
1709
Ian Rogers848871b2013-08-05 10:56:33 -07001710void Mir2Lir::GenConversionCall(ThreadOffset func_offset,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001711 RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001712 /*
1713 * Don't optimize the register usage since it calls out to support
1714 * functions
1715 */
1716 FlushAllRegs(); /* Send everything to home location */
1717 if (rl_src.wide) {
1718 LoadValueDirectWideFixed(rl_src, rl_src.fp ? TargetReg(kFArg0) : TargetReg(kArg0),
1719 rl_src.fp ? TargetReg(kFArg1) : TargetReg(kArg1));
1720 } else {
1721 LoadValueDirectFixed(rl_src, rl_src.fp ? TargetReg(kFArg0) : TargetReg(kArg0));
1722 }
1723 CallRuntimeHelperRegLocation(func_offset, rl_src, false);
1724 if (rl_dest.wide) {
1725 RegLocation rl_result;
1726 rl_result = GetReturnWide(rl_dest.fp);
1727 StoreValueWide(rl_dest, rl_result);
1728 } else {
1729 RegLocation rl_result;
1730 rl_result = GetReturn(rl_dest.fp);
1731 StoreValue(rl_dest, rl_result);
1732 }
1733}
1734
1735/* Check if we need to check for pending suspend request */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001736void Mir2Lir::GenSuspendTest(int opt_flags) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001737 if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) {
1738 return;
1739 }
1740 FlushAllRegs();
1741 LIR* branch = OpTestSuspend(NULL);
1742 LIR* ret_lab = NewLIR0(kPseudoTargetLabel);
1743 LIR* target = RawLIR(current_dalvik_offset_, kPseudoSuspendTarget,
1744 reinterpret_cast<uintptr_t>(ret_lab), current_dalvik_offset_);
1745 branch->target = target;
1746 suspend_launchpads_.Insert(target);
1747}
1748
1749/* Check if we need to check for pending suspend request */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001750void Mir2Lir::GenSuspendTestAndBranch(int opt_flags, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001751 if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) {
1752 OpUnconditionalBranch(target);
1753 return;
1754 }
1755 OpTestSuspend(target);
1756 LIR* launch_pad =
1757 RawLIR(current_dalvik_offset_, kPseudoSuspendTarget,
1758 reinterpret_cast<uintptr_t>(target), current_dalvik_offset_);
1759 FlushAllRegs();
1760 OpUnconditionalBranch(launch_pad);
1761 suspend_launchpads_.Insert(launch_pad);
1762}
1763
1764} // namespace art