blob: aa45d98cf65500752a9cf48feb432f586a49f9a6 [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);
130 OpUnconditionalBranch(fall_through);
131 return;
132 }
133 }
134 rl_src2 = LoadValue(rl_src2, kCoreReg);
135 OpCmpBranch(cond, rl_src1.low_reg, rl_src2.low_reg, taken);
136 OpUnconditionalBranch(fall_through);
137}
138
139void Mir2Lir::GenCompareZeroAndBranch(Instruction::Code opcode, RegLocation rl_src, LIR* taken,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700140 LIR* fall_through) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700141 ConditionCode cond;
142 rl_src = LoadValue(rl_src, kCoreReg);
143 switch (opcode) {
144 case Instruction::IF_EQZ:
145 cond = kCondEq;
146 break;
147 case Instruction::IF_NEZ:
148 cond = kCondNe;
149 break;
150 case Instruction::IF_LTZ:
151 cond = kCondLt;
152 break;
153 case Instruction::IF_GEZ:
154 cond = kCondGe;
155 break;
156 case Instruction::IF_GTZ:
157 cond = kCondGt;
158 break;
159 case Instruction::IF_LEZ:
160 cond = kCondLe;
161 break;
162 default:
163 cond = static_cast<ConditionCode>(0);
164 LOG(FATAL) << "Unexpected opcode " << opcode;
165 }
166 OpCmpImmBranch(cond, rl_src.low_reg, 0, taken);
167 OpUnconditionalBranch(fall_through);
168}
169
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700170void Mir2Lir::GenIntToLong(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700171 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
172 if (rl_src.location == kLocPhysReg) {
173 OpRegCopy(rl_result.low_reg, rl_src.low_reg);
174 } else {
175 LoadValueDirect(rl_src, rl_result.low_reg);
176 }
177 OpRegRegImm(kOpAsr, rl_result.high_reg, rl_result.low_reg, 31);
178 StoreValueWide(rl_dest, rl_result);
179}
180
181void Mir2Lir::GenIntNarrowing(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700182 RegLocation rl_src) {
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700183 rl_src = LoadValue(rl_src, kCoreReg);
184 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
185 OpKind op = kOpInvalid;
186 switch (opcode) {
187 case Instruction::INT_TO_BYTE:
188 op = kOp2Byte;
189 break;
190 case Instruction::INT_TO_SHORT:
191 op = kOp2Short;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700192 break;
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700193 case Instruction::INT_TO_CHAR:
194 op = kOp2Char;
195 break;
196 default:
197 LOG(ERROR) << "Bad int conversion type";
198 }
199 OpRegReg(op, rl_result.low_reg, rl_src.low_reg);
200 StoreValue(rl_dest, rl_result);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700201}
202
203/*
204 * Let helper function take care of everything. Will call
205 * Array::AllocFromCode(type_idx, method, count);
206 * Note: AllocFromCode will handle checks for errNegativeArraySize.
207 */
208void Mir2Lir::GenNewArray(uint32_t type_idx, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700209 RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700210 FlushAllRegs(); /* Everything to home location */
Ian Rogers848871b2013-08-05 10:56:33 -0700211 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700212 if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *cu_->dex_file,
213 type_idx)) {
Ian Rogers848871b2013-08-05 10:56:33 -0700214 func_offset = QUICK_ENTRYPOINT_OFFSET(pAllocArray);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700215 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700216 func_offset= QUICK_ENTRYPOINT_OFFSET(pAllocArrayWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700217 }
218 CallRuntimeHelperImmMethodRegLocation(func_offset, type_idx, rl_src, true);
219 RegLocation rl_result = GetReturn(false);
220 StoreValue(rl_dest, rl_result);
221}
222
223/*
224 * Similar to GenNewArray, but with post-allocation initialization.
225 * Verifier guarantees we're dealing with an array class. Current
226 * code throws runtime exception "bad Filled array req" for 'D' and 'J'.
227 * Current code also throws internal unimp if not 'L', '[' or 'I'.
228 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700229void Mir2Lir::GenFilledNewArray(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700230 int elems = info->num_arg_words;
231 int type_idx = info->index;
232 FlushAllRegs(); /* Everything to home location */
Ian Rogers848871b2013-08-05 10:56:33 -0700233 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700234 if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *cu_->dex_file,
235 type_idx)) {
Ian Rogers848871b2013-08-05 10:56:33 -0700236 func_offset = QUICK_ENTRYPOINT_OFFSET(pCheckAndAllocArray);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700237 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700238 func_offset = QUICK_ENTRYPOINT_OFFSET(pCheckAndAllocArrayWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700239 }
240 CallRuntimeHelperImmMethodImm(func_offset, type_idx, elems, true);
241 FreeTemp(TargetReg(kArg2));
242 FreeTemp(TargetReg(kArg1));
243 /*
244 * NOTE: the implicit target for Instruction::FILLED_NEW_ARRAY is the
245 * return region. Because AllocFromCode placed the new array
246 * in kRet0, we'll just lock it into place. When debugger support is
247 * added, it may be necessary to additionally copy all return
248 * values to a home location in thread-local storage
249 */
250 LockTemp(TargetReg(kRet0));
251
252 // TODO: use the correct component size, currently all supported types
253 // share array alignment with ints (see comment at head of function)
254 size_t component_size = sizeof(int32_t);
255
256 // Having a range of 0 is legal
257 if (info->is_range && (elems > 0)) {
258 /*
259 * Bit of ugliness here. We're going generate a mem copy loop
260 * on the register range, but it is possible that some regs
261 * in the range have been promoted. This is unlikely, but
262 * before generating the copy, we'll just force a flush
263 * of any regs in the source range that have been promoted to
264 * home location.
265 */
266 for (int i = 0; i < elems; i++) {
267 RegLocation loc = UpdateLoc(info->args[i]);
268 if (loc.location == kLocPhysReg) {
269 StoreBaseDisp(TargetReg(kSp), SRegOffset(loc.s_reg_low),
270 loc.low_reg, kWord);
271 }
272 }
273 /*
274 * TUNING note: generated code here could be much improved, but
275 * this is an uncommon operation and isn't especially performance
276 * critical.
277 */
278 int r_src = AllocTemp();
279 int r_dst = AllocTemp();
280 int r_idx = AllocTemp();
281 int r_val = INVALID_REG;
Brian Carlstromdf629502013-07-17 22:39:56 -0700282 switch (cu_->instruction_set) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700283 case kThumb2:
284 r_val = TargetReg(kLr);
285 break;
286 case kX86:
287 FreeTemp(TargetReg(kRet0));
288 r_val = AllocTemp();
289 break;
290 case kMips:
291 r_val = AllocTemp();
292 break;
293 default: LOG(FATAL) << "Unexpected instruction set: " << cu_->instruction_set;
294 }
295 // Set up source pointer
296 RegLocation rl_first = info->args[0];
297 OpRegRegImm(kOpAdd, r_src, TargetReg(kSp), SRegOffset(rl_first.s_reg_low));
298 // Set up the target pointer
299 OpRegRegImm(kOpAdd, r_dst, TargetReg(kRet0),
300 mirror::Array::DataOffset(component_size).Int32Value());
301 // Set up the loop counter (known to be > 0)
302 LoadConstant(r_idx, elems - 1);
303 // Generate the copy loop. Going backwards for convenience
304 LIR* target = NewLIR0(kPseudoTargetLabel);
305 // Copy next element
306 LoadBaseIndexed(r_src, r_idx, r_val, 2, kWord);
307 StoreBaseIndexed(r_dst, r_idx, r_val, 2, kWord);
308 FreeTemp(r_val);
309 OpDecAndBranch(kCondGe, r_idx, target);
310 if (cu_->instruction_set == kX86) {
311 // Restore the target pointer
312 OpRegRegImm(kOpAdd, TargetReg(kRet0), r_dst,
313 -mirror::Array::DataOffset(component_size).Int32Value());
314 }
315 } else if (!info->is_range) {
316 // TUNING: interleave
317 for (int i = 0; i < elems; i++) {
318 RegLocation rl_arg = LoadValue(info->args[i], kCoreReg);
319 StoreBaseDisp(TargetReg(kRet0),
320 mirror::Array::DataOffset(component_size).Int32Value() +
321 i * 4, rl_arg.low_reg, kWord);
322 // If the LoadValue caused a temp to be allocated, free it
323 if (IsTemp(rl_arg.low_reg)) {
324 FreeTemp(rl_arg.low_reg);
325 }
326 }
327 }
328 if (info->result.location != kLocInvalid) {
329 StoreValue(info->result, GetReturn(false /* not fp */));
330 }
331}
332
333void Mir2Lir::GenSput(uint32_t field_idx, RegLocation rl_src, bool is_long_or_double,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700334 bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700335 int field_offset;
336 int ssb_index;
337 bool is_volatile;
338 bool is_referrers_class;
339 bool fast_path = cu_->compiler_driver->ComputeStaticFieldInfo(
Ian Rogers9b297bf2013-09-06 11:11:25 -0700340 field_idx, mir_graph_->GetCurrentDexCompilationUnit(), true,
341 &field_offset, &ssb_index, &is_referrers_class, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700342 if (fast_path && !SLOW_FIELD_PATH) {
343 DCHECK_GE(field_offset, 0);
344 int rBase;
345 if (is_referrers_class) {
346 // Fast path, static storage base is this method's class
347 RegLocation rl_method = LoadCurrMethod();
348 rBase = AllocTemp();
349 LoadWordDisp(rl_method.low_reg,
Brian Carlstromea46f952013-07-30 01:26:50 -0700350 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), rBase);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700351 if (IsTemp(rl_method.low_reg)) {
352 FreeTemp(rl_method.low_reg);
353 }
354 } else {
355 // Medium path, static storage base in a different class which requires checks that the other
356 // class is initialized.
357 // TODO: remove initialized check now that we are initializing classes in the compiler driver.
358 DCHECK_GE(ssb_index, 0);
359 // May do runtime call so everything to home locations.
360 FlushAllRegs();
361 // Using fixed register to sync with possible call to runtime support.
362 int r_method = TargetReg(kArg1);
363 LockTemp(r_method);
364 LoadCurrMethodDirect(r_method);
365 rBase = TargetReg(kArg0);
366 LockTemp(rBase);
367 LoadWordDisp(r_method,
Brian Carlstromea46f952013-07-30 01:26:50 -0700368 mirror::ArtMethod::DexCacheInitializedStaticStorageOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700369 rBase);
370 LoadWordDisp(rBase,
371 mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() +
372 sizeof(int32_t*) * ssb_index, rBase);
373 // rBase now points at appropriate static storage base (Class*)
374 // or NULL if not initialized. Check for NULL and call helper if NULL.
375 // TUNING: fast path should fall through
376 LIR* branch_over = OpCmpImmBranch(kCondNe, rBase, 0, NULL);
377 LoadConstant(TargetReg(kArg0), ssb_index);
Ian Rogers7655f292013-07-29 11:07:13 -0700378 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssb_index, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700379 if (cu_->instruction_set == kMips) {
380 // For Arm, kRet0 = kArg0 = rBase, for Mips, we need to copy
381 OpRegCopy(rBase, TargetReg(kRet0));
382 }
383 LIR* skip_target = NewLIR0(kPseudoTargetLabel);
384 branch_over->target = skip_target;
385 FreeTemp(r_method);
386 }
387 // rBase now holds static storage base
388 if (is_long_or_double) {
389 rl_src = LoadValueWide(rl_src, kAnyReg);
390 } else {
391 rl_src = LoadValue(rl_src, kAnyReg);
392 }
393 if (is_volatile) {
394 GenMemBarrier(kStoreStore);
395 }
396 if (is_long_or_double) {
397 StoreBaseDispWide(rBase, field_offset, rl_src.low_reg,
398 rl_src.high_reg);
399 } else {
400 StoreWordDisp(rBase, field_offset, rl_src.low_reg);
401 }
402 if (is_volatile) {
403 GenMemBarrier(kStoreLoad);
404 }
405 if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) {
406 MarkGCCard(rl_src.low_reg, rBase);
407 }
408 FreeTemp(rBase);
409 } else {
410 FlushAllRegs(); // Everything to home locations
Ian Rogers848871b2013-08-05 10:56:33 -0700411 ThreadOffset setter_offset =
412 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pSet64Static)
413 : (is_object ? QUICK_ENTRYPOINT_OFFSET(pSetObjStatic)
414 : QUICK_ENTRYPOINT_OFFSET(pSet32Static));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700415 CallRuntimeHelperImmRegLocation(setter_offset, field_idx, rl_src, true);
416 }
417}
418
419void Mir2Lir::GenSget(uint32_t field_idx, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700420 bool is_long_or_double, bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700421 int field_offset;
422 int ssb_index;
423 bool is_volatile;
424 bool is_referrers_class;
425 bool fast_path = cu_->compiler_driver->ComputeStaticFieldInfo(
Ian Rogers9b297bf2013-09-06 11:11:25 -0700426 field_idx, mir_graph_->GetCurrentDexCompilationUnit(), false,
427 &field_offset, &ssb_index, &is_referrers_class, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700428 if (fast_path && !SLOW_FIELD_PATH) {
429 DCHECK_GE(field_offset, 0);
430 int rBase;
431 if (is_referrers_class) {
432 // Fast path, static storage base is this method's class
433 RegLocation rl_method = LoadCurrMethod();
434 rBase = AllocTemp();
435 LoadWordDisp(rl_method.low_reg,
Brian Carlstromea46f952013-07-30 01:26:50 -0700436 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), rBase);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700437 } else {
438 // Medium path, static storage base in a different class which requires checks that the other
439 // class is initialized
440 // TODO: remove initialized check now that we are initializing classes in the compiler driver.
441 DCHECK_GE(ssb_index, 0);
442 // May do runtime call so everything to home locations.
443 FlushAllRegs();
444 // Using fixed register to sync with possible call to runtime support.
445 int r_method = TargetReg(kArg1);
446 LockTemp(r_method);
447 LoadCurrMethodDirect(r_method);
448 rBase = TargetReg(kArg0);
449 LockTemp(rBase);
450 LoadWordDisp(r_method,
Brian Carlstromea46f952013-07-30 01:26:50 -0700451 mirror::ArtMethod::DexCacheInitializedStaticStorageOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700452 rBase);
453 LoadWordDisp(rBase, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() +
454 sizeof(int32_t*) * ssb_index, rBase);
455 // rBase now points at appropriate static storage base (Class*)
456 // or NULL if not initialized. Check for NULL and call helper if NULL.
457 // TUNING: fast path should fall through
458 LIR* branch_over = OpCmpImmBranch(kCondNe, rBase, 0, NULL);
Ian Rogers7655f292013-07-29 11:07:13 -0700459 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssb_index, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700460 if (cu_->instruction_set == kMips) {
461 // For Arm, kRet0 = kArg0 = rBase, for Mips, we need to copy
462 OpRegCopy(rBase, TargetReg(kRet0));
463 }
464 LIR* skip_target = NewLIR0(kPseudoTargetLabel);
465 branch_over->target = skip_target;
466 FreeTemp(r_method);
467 }
468 // rBase now holds static storage base
469 RegLocation rl_result = EvalLoc(rl_dest, kAnyReg, true);
470 if (is_volatile) {
471 GenMemBarrier(kLoadLoad);
472 }
473 if (is_long_or_double) {
474 LoadBaseDispWide(rBase, field_offset, rl_result.low_reg,
475 rl_result.high_reg, INVALID_SREG);
476 } else {
477 LoadWordDisp(rBase, field_offset, rl_result.low_reg);
478 }
479 FreeTemp(rBase);
480 if (is_long_or_double) {
481 StoreValueWide(rl_dest, rl_result);
482 } else {
483 StoreValue(rl_dest, rl_result);
484 }
485 } else {
486 FlushAllRegs(); // Everything to home locations
Ian Rogers848871b2013-08-05 10:56:33 -0700487 ThreadOffset getterOffset =
488 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pGet64Static)
489 :(is_object ? QUICK_ENTRYPOINT_OFFSET(pGetObjStatic)
490 : QUICK_ENTRYPOINT_OFFSET(pGet32Static));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700491 CallRuntimeHelperImm(getterOffset, field_idx, true);
492 if (is_long_or_double) {
493 RegLocation rl_result = GetReturnWide(rl_dest.fp);
494 StoreValueWide(rl_dest, rl_result);
495 } else {
496 RegLocation rl_result = GetReturn(rl_dest.fp);
497 StoreValue(rl_dest, rl_result);
498 }
499 }
500}
501
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700502void Mir2Lir::HandleSuspendLaunchPads() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700503 int num_elems = suspend_launchpads_.Size();
Ian Rogers848871b2013-08-05 10:56:33 -0700504 ThreadOffset helper_offset = QUICK_ENTRYPOINT_OFFSET(pTestSuspend);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700505 for (int i = 0; i < num_elems; i++) {
506 ResetRegPool();
507 ResetDefTracking();
508 LIR* lab = suspend_launchpads_.Get(i);
509 LIR* resume_lab = reinterpret_cast<LIR*>(lab->operands[0]);
510 current_dalvik_offset_ = lab->operands[1];
511 AppendLIR(lab);
512 int r_tgt = CallHelperSetup(helper_offset);
513 CallHelper(r_tgt, helper_offset, true /* MarkSafepointPC */);
514 OpUnconditionalBranch(resume_lab);
515 }
516}
517
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700518void Mir2Lir::HandleIntrinsicLaunchPads() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700519 int num_elems = intrinsic_launchpads_.Size();
520 for (int i = 0; i < num_elems; i++) {
521 ResetRegPool();
522 ResetDefTracking();
523 LIR* lab = intrinsic_launchpads_.Get(i);
524 CallInfo* info = reinterpret_cast<CallInfo*>(lab->operands[0]);
525 current_dalvik_offset_ = info->offset;
526 AppendLIR(lab);
527 // NOTE: GenInvoke handles MarkSafepointPC
528 GenInvoke(info);
529 LIR* resume_lab = reinterpret_cast<LIR*>(lab->operands[2]);
530 if (resume_lab != NULL) {
531 OpUnconditionalBranch(resume_lab);
532 }
533 }
534}
535
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700536void Mir2Lir::HandleThrowLaunchPads() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700537 int num_elems = throw_launchpads_.Size();
538 for (int i = 0; i < num_elems; i++) {
539 ResetRegPool();
540 ResetDefTracking();
541 LIR* lab = throw_launchpads_.Get(i);
542 current_dalvik_offset_ = lab->operands[1];
543 AppendLIR(lab);
Ian Rogers848871b2013-08-05 10:56:33 -0700544 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700545 int v1 = lab->operands[2];
546 int v2 = lab->operands[3];
547 bool target_x86 = (cu_->instruction_set == kX86);
548 switch (lab->operands[0]) {
549 case kThrowNullPointer:
Ian Rogers848871b2013-08-05 10:56:33 -0700550 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowNullPointer);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700551 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700552 case kThrowConstantArrayBounds: // v1 is length reg (for Arm/Mips), v2 constant index
Brian Carlstrom7940e442013-07-12 13:46:57 -0700553 // v1 holds the constant array index. Mips/Arm uses v2 for length, x86 reloads.
554 if (target_x86) {
555 OpRegMem(kOpMov, TargetReg(kArg1), v1, mirror::Array::LengthOffset().Int32Value());
556 } else {
557 OpRegCopy(TargetReg(kArg1), v1);
558 }
559 // Make sure the following LoadConstant doesn't mess with kArg1.
560 LockTemp(TargetReg(kArg1));
561 LoadConstant(TargetReg(kArg0), v2);
Ian Rogers848871b2013-08-05 10:56:33 -0700562 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700563 break;
564 case kThrowArrayBounds:
565 // Move v1 (array index) to kArg0 and v2 (array length) to kArg1
566 if (v2 != TargetReg(kArg0)) {
567 OpRegCopy(TargetReg(kArg0), v1);
568 if (target_x86) {
569 // x86 leaves the array pointer in v2, so load the array length that the handler expects
570 OpRegMem(kOpMov, TargetReg(kArg1), v2, mirror::Array::LengthOffset().Int32Value());
571 } else {
572 OpRegCopy(TargetReg(kArg1), v2);
573 }
574 } else {
575 if (v1 == TargetReg(kArg1)) {
576 // Swap v1 and v2, using kArg2 as a temp
577 OpRegCopy(TargetReg(kArg2), v1);
578 if (target_x86) {
579 // x86 leaves the array pointer in v2; load the array length that the handler expects
580 OpRegMem(kOpMov, TargetReg(kArg1), v2, mirror::Array::LengthOffset().Int32Value());
581 } else {
582 OpRegCopy(TargetReg(kArg1), v2);
583 }
584 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2));
585 } else {
586 if (target_x86) {
587 // x86 leaves the array pointer in v2; load the array length that the handler expects
588 OpRegMem(kOpMov, TargetReg(kArg1), v2, mirror::Array::LengthOffset().Int32Value());
589 } else {
590 OpRegCopy(TargetReg(kArg1), v2);
591 }
592 OpRegCopy(TargetReg(kArg0), v1);
593 }
594 }
Ian Rogers848871b2013-08-05 10:56:33 -0700595 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700596 break;
597 case kThrowDivZero:
Ian Rogers848871b2013-08-05 10:56:33 -0700598 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowDivZero);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700599 break;
600 case kThrowNoSuchMethod:
601 OpRegCopy(TargetReg(kArg0), v1);
602 func_offset =
Ian Rogers848871b2013-08-05 10:56:33 -0700603 QUICK_ENTRYPOINT_OFFSET(pThrowNoSuchMethod);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700604 break;
605 case kThrowStackOverflow:
Ian Rogers848871b2013-08-05 10:56:33 -0700606 func_offset = QUICK_ENTRYPOINT_OFFSET(pThrowStackOverflow);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700607 // Restore stack alignment
608 if (target_x86) {
609 OpRegImm(kOpAdd, TargetReg(kSp), frame_size_);
610 } else {
611 OpRegImm(kOpAdd, TargetReg(kSp), (num_core_spills_ + num_fp_spills_) * 4);
612 }
613 break;
614 default:
615 LOG(FATAL) << "Unexpected throw kind: " << lab->operands[0];
616 }
617 ClobberCalleeSave();
618 int r_tgt = CallHelperSetup(func_offset);
619 CallHelper(r_tgt, func_offset, true /* MarkSafepointPC */);
620 }
621}
622
623void Mir2Lir::GenIGet(uint32_t field_idx, int opt_flags, OpSize size,
624 RegLocation rl_dest, RegLocation rl_obj, bool is_long_or_double,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700625 bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700626 int field_offset;
627 bool is_volatile;
628
Ian Rogers9b297bf2013-09-06 11:11:25 -0700629 bool fast_path = FastInstance(field_idx, false, &field_offset, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700630
631 if (fast_path && !SLOW_FIELD_PATH) {
632 RegLocation rl_result;
633 RegisterClass reg_class = oat_reg_class_by_size(size);
634 DCHECK_GE(field_offset, 0);
635 rl_obj = LoadValue(rl_obj, kCoreReg);
636 if (is_long_or_double) {
637 DCHECK(rl_dest.wide);
638 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
639 if (cu_->instruction_set == kX86) {
640 rl_result = EvalLoc(rl_dest, reg_class, true);
641 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
642 LoadBaseDispWide(rl_obj.low_reg, field_offset, rl_result.low_reg,
643 rl_result.high_reg, rl_obj.s_reg_low);
644 if (is_volatile) {
645 GenMemBarrier(kLoadLoad);
646 }
647 } else {
648 int reg_ptr = AllocTemp();
649 OpRegRegImm(kOpAdd, reg_ptr, rl_obj.low_reg, field_offset);
650 rl_result = EvalLoc(rl_dest, reg_class, true);
651 LoadBaseDispWide(reg_ptr, 0, rl_result.low_reg, rl_result.high_reg, INVALID_SREG);
652 if (is_volatile) {
653 GenMemBarrier(kLoadLoad);
654 }
655 FreeTemp(reg_ptr);
656 }
657 StoreValueWide(rl_dest, rl_result);
658 } else {
659 rl_result = EvalLoc(rl_dest, reg_class, true);
660 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
661 LoadBaseDisp(rl_obj.low_reg, field_offset, rl_result.low_reg,
662 kWord, rl_obj.s_reg_low);
663 if (is_volatile) {
664 GenMemBarrier(kLoadLoad);
665 }
666 StoreValue(rl_dest, rl_result);
667 }
668 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700669 ThreadOffset getterOffset =
670 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pGet64Instance)
671 : (is_object ? QUICK_ENTRYPOINT_OFFSET(pGetObjInstance)
672 : QUICK_ENTRYPOINT_OFFSET(pGet32Instance));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700673 CallRuntimeHelperImmRegLocation(getterOffset, field_idx, rl_obj, true);
674 if (is_long_or_double) {
675 RegLocation rl_result = GetReturnWide(rl_dest.fp);
676 StoreValueWide(rl_dest, rl_result);
677 } else {
678 RegLocation rl_result = GetReturn(rl_dest.fp);
679 StoreValue(rl_dest, rl_result);
680 }
681 }
682}
683
684void Mir2Lir::GenIPut(uint32_t field_idx, int opt_flags, OpSize size,
685 RegLocation rl_src, RegLocation rl_obj, bool is_long_or_double,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700686 bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700687 int field_offset;
688 bool is_volatile;
689
Ian Rogers9b297bf2013-09-06 11:11:25 -0700690 bool fast_path = FastInstance(field_idx, true, &field_offset, &is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700691 if (fast_path && !SLOW_FIELD_PATH) {
692 RegisterClass reg_class = oat_reg_class_by_size(size);
693 DCHECK_GE(field_offset, 0);
694 rl_obj = LoadValue(rl_obj, kCoreReg);
695 if (is_long_or_double) {
696 int reg_ptr;
697 rl_src = LoadValueWide(rl_src, kAnyReg);
698 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
699 reg_ptr = AllocTemp();
700 OpRegRegImm(kOpAdd, reg_ptr, rl_obj.low_reg, field_offset);
701 if (is_volatile) {
702 GenMemBarrier(kStoreStore);
703 }
704 StoreBaseDispWide(reg_ptr, 0, rl_src.low_reg, rl_src.high_reg);
705 if (is_volatile) {
706 GenMemBarrier(kLoadLoad);
707 }
708 FreeTemp(reg_ptr);
709 } else {
710 rl_src = LoadValue(rl_src, reg_class);
711 GenNullCheck(rl_obj.s_reg_low, rl_obj.low_reg, opt_flags);
712 if (is_volatile) {
713 GenMemBarrier(kStoreStore);
714 }
715 StoreBaseDisp(rl_obj.low_reg, field_offset, rl_src.low_reg, kWord);
716 if (is_volatile) {
717 GenMemBarrier(kLoadLoad);
718 }
719 if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) {
720 MarkGCCard(rl_src.low_reg, rl_obj.low_reg);
721 }
722 }
723 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700724 ThreadOffset setter_offset =
725 is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(pSet64Instance)
726 : (is_object ? QUICK_ENTRYPOINT_OFFSET(pSetObjInstance)
727 : QUICK_ENTRYPOINT_OFFSET(pSet32Instance));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700728 CallRuntimeHelperImmRegLocationRegLocation(setter_offset, field_idx, rl_obj, rl_src, true);
729 }
730}
731
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700732void Mir2Lir::GenConstClass(uint32_t type_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700733 RegLocation rl_method = LoadCurrMethod();
734 int res_reg = AllocTemp();
735 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
736 if (!cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
737 *cu_->dex_file,
738 type_idx)) {
739 // Call out to helper which resolves type and verifies access.
740 // Resolved type returned in kRet0.
Ian Rogers848871b2013-08-05 10:56:33 -0700741 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccess),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700742 type_idx, rl_method.low_reg, true);
743 RegLocation rl_result = GetReturn(false);
744 StoreValue(rl_dest, rl_result);
745 } else {
746 // We're don't need access checks, load type from dex cache
747 int32_t dex_cache_offset =
Brian Carlstromea46f952013-07-30 01:26:50 -0700748 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700749 LoadWordDisp(rl_method.low_reg, dex_cache_offset, res_reg);
750 int32_t offset_of_type =
751 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*)
752 * type_idx);
753 LoadWordDisp(res_reg, offset_of_type, rl_result.low_reg);
754 if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file,
755 type_idx) || SLOW_TYPE_PATH) {
756 // Slow path, at runtime test if type is null and if so initialize
757 FlushAllRegs();
758 LIR* branch1 = OpCmpImmBranch(kCondEq, rl_result.low_reg, 0, NULL);
759 // Resolved, store and hop over following code
760 StoreValue(rl_dest, rl_result);
761 /*
762 * Because we have stores of the target value on two paths,
763 * clobber temp tracking for the destination using the ssa name
764 */
765 ClobberSReg(rl_dest.s_reg_low);
766 LIR* branch2 = OpUnconditionalBranch(0);
767 // TUNING: move slow path to end & remove unconditional branch
768 LIR* target1 = NewLIR0(kPseudoTargetLabel);
769 // Call out to helper, which will return resolved type in kArg0
Ian Rogers848871b2013-08-05 10:56:33 -0700770 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeType), type_idx,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700771 rl_method.low_reg, true);
772 RegLocation rl_result = GetReturn(false);
773 StoreValue(rl_dest, rl_result);
774 /*
775 * Because we have stores of the target value on two paths,
776 * clobber temp tracking for the destination using the ssa name
777 */
778 ClobberSReg(rl_dest.s_reg_low);
779 // Rejoin code paths
780 LIR* target2 = NewLIR0(kPseudoTargetLabel);
781 branch1->target = target1;
782 branch2->target = target2;
783 } else {
784 // Fast path, we're done - just store result
785 StoreValue(rl_dest, rl_result);
786 }
787 }
788}
789
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700790void Mir2Lir::GenConstString(uint32_t string_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700791 /* NOTE: Most strings should be available at compile time */
792 int32_t offset_of_string = mirror::Array::DataOffset(sizeof(mirror::String*)).Int32Value() +
793 (sizeof(mirror::String*) * string_idx);
794 if (!cu_->compiler_driver->CanAssumeStringIsPresentInDexCache(
795 *cu_->dex_file, string_idx) || SLOW_STRING_PATH) {
796 // slow path, resolve string if not in dex cache
797 FlushAllRegs();
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700798 LockCallTemps(); // Using explicit registers
Brian Carlstrom7940e442013-07-12 13:46:57 -0700799 LoadCurrMethodDirect(TargetReg(kArg2));
800 LoadWordDisp(TargetReg(kArg2),
Brian Carlstromea46f952013-07-30 01:26:50 -0700801 mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), TargetReg(kArg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700802 // Might call out to helper, which will return resolved string in kRet0
Ian Rogers848871b2013-08-05 10:56:33 -0700803 int r_tgt = CallHelperSetup(QUICK_ENTRYPOINT_OFFSET(pResolveString));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700804 LoadWordDisp(TargetReg(kArg0), offset_of_string, TargetReg(kRet0));
805 LoadConstant(TargetReg(kArg1), string_idx);
806 if (cu_->instruction_set == kThumb2) {
807 OpRegImm(kOpCmp, TargetReg(kRet0), 0); // Is resolved?
808 GenBarrier();
809 // For testing, always force through helper
810 if (!EXERCISE_SLOWEST_STRING_PATH) {
811 OpIT(kCondEq, "T");
812 }
813 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .eq
814 LIR* call_inst = OpReg(kOpBlx, r_tgt); // .eq, helper(Method*, string_idx)
815 MarkSafepointPC(call_inst);
816 FreeTemp(r_tgt);
817 } else if (cu_->instruction_set == kMips) {
818 LIR* branch = OpCmpImmBranch(kCondNe, TargetReg(kRet0), 0, NULL);
819 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .eq
820 LIR* call_inst = OpReg(kOpBlx, r_tgt);
821 MarkSafepointPC(call_inst);
822 FreeTemp(r_tgt);
823 LIR* target = NewLIR0(kPseudoTargetLabel);
824 branch->target = target;
825 } else {
826 DCHECK_EQ(cu_->instruction_set, kX86);
Ian Rogers848871b2013-08-05 10:56:33 -0700827 CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(pResolveString), TargetReg(kArg2),
Ian Rogers7655f292013-07-29 11:07:13 -0700828 TargetReg(kArg1), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700829 }
830 GenBarrier();
831 StoreValue(rl_dest, GetReturn(false));
832 } else {
833 RegLocation rl_method = LoadCurrMethod();
834 int res_reg = AllocTemp();
835 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
836 LoadWordDisp(rl_method.low_reg,
Brian Carlstromea46f952013-07-30 01:26:50 -0700837 mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), res_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700838 LoadWordDisp(res_reg, offset_of_string, rl_result.low_reg);
839 StoreValue(rl_dest, rl_result);
840 }
841}
842
843/*
844 * Let helper function take care of everything. Will
845 * call Class::NewInstanceFromCode(type_idx, method);
846 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700847void Mir2Lir::GenNewInstance(uint32_t type_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700848 FlushAllRegs(); /* Everything to home location */
849 // alloc will always check for resolution, do we also need to verify
850 // access because the verifier was unable to?
Ian Rogers848871b2013-08-05 10:56:33 -0700851 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700852 if (cu_->compiler_driver->CanAccessInstantiableTypeWithoutChecks(
853 cu_->method_idx, *cu_->dex_file, type_idx)) {
Ian Rogers848871b2013-08-05 10:56:33 -0700854 func_offset = QUICK_ENTRYPOINT_OFFSET(pAllocObject);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700855 } else {
Ian Rogers848871b2013-08-05 10:56:33 -0700856 func_offset = QUICK_ENTRYPOINT_OFFSET(pAllocObjectWithAccessCheck);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700857 }
858 CallRuntimeHelperImmMethod(func_offset, type_idx, true);
859 RegLocation rl_result = GetReturn(false);
860 StoreValue(rl_dest, rl_result);
861}
862
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700863void Mir2Lir::GenThrow(RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700864 FlushAllRegs();
Ian Rogers7655f292013-07-29 11:07:13 -0700865 CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(pDeliverException), rl_src, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700866}
867
868// For final classes there are no sub-classes to check and so we can answer the instance-of
869// question with simple comparisons.
870void Mir2Lir::GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
871 RegLocation rl_src) {
872 RegLocation object = LoadValue(rl_src, kCoreReg);
873 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
874 int result_reg = rl_result.low_reg;
875 if (result_reg == object.low_reg) {
876 result_reg = AllocTypedTemp(false, kCoreReg);
877 }
878 LoadConstant(result_reg, 0); // assume false
879 LIR* null_branchover = OpCmpImmBranch(kCondEq, object.low_reg, 0, NULL);
880
881 int check_class = AllocTypedTemp(false, kCoreReg);
882 int object_class = AllocTypedTemp(false, kCoreReg);
883
884 LoadCurrMethodDirect(check_class);
885 if (use_declaring_class) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700886 LoadWordDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700887 check_class);
888 LoadWordDisp(object.low_reg, mirror::Object::ClassOffset().Int32Value(), object_class);
889 } else {
Brian Carlstromea46f952013-07-30 01:26:50 -0700890 LoadWordDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700891 check_class);
892 LoadWordDisp(object.low_reg, mirror::Object::ClassOffset().Int32Value(), object_class);
893 int32_t offset_of_type =
894 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() +
895 (sizeof(mirror::Class*) * type_idx);
896 LoadWordDisp(check_class, offset_of_type, check_class);
897 }
898
899 LIR* ne_branchover = NULL;
900 if (cu_->instruction_set == kThumb2) {
901 OpRegReg(kOpCmp, check_class, object_class); // Same?
902 OpIT(kCondEq, ""); // if-convert the test
903 LoadConstant(result_reg, 1); // .eq case - load true
904 } else {
905 ne_branchover = OpCmpBranch(kCondNe, check_class, object_class, NULL);
906 LoadConstant(result_reg, 1); // eq case - load true
907 }
908 LIR* target = NewLIR0(kPseudoTargetLabel);
909 null_branchover->target = target;
910 if (ne_branchover != NULL) {
911 ne_branchover->target = target;
912 }
913 FreeTemp(object_class);
914 FreeTemp(check_class);
915 if (IsTemp(result_reg)) {
916 OpRegCopy(rl_result.low_reg, result_reg);
917 FreeTemp(result_reg);
918 }
919 StoreValue(rl_dest, rl_result);
920}
921
922void Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
923 bool type_known_abstract, bool use_declaring_class,
924 bool can_assume_type_is_in_dex_cache,
925 uint32_t type_idx, RegLocation rl_dest,
926 RegLocation rl_src) {
927 FlushAllRegs();
928 // May generate a call - use explicit registers
929 LockCallTemps();
930 LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method*
931 int class_reg = TargetReg(kArg2); // kArg2 will hold the Class*
932 if (needs_access_check) {
933 // Check we have access to type_idx and if not throw IllegalAccessError,
934 // returns Class* in kArg0
Ian Rogers848871b2013-08-05 10:56:33 -0700935 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccess),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700936 type_idx, true);
937 OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path
938 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
939 } else if (use_declaring_class) {
940 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
941 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -0700942 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700943 } else {
944 // Load dex cache entry into class_reg (kArg2)
945 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
946 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -0700947 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700948 int32_t offset_of_type =
949 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*)
950 * type_idx);
951 LoadWordDisp(class_reg, offset_of_type, class_reg);
952 if (!can_assume_type_is_in_dex_cache) {
953 // Need to test presence of type in dex cache at runtime
954 LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL);
955 // Not resolved
956 // Call out to helper, which will return resolved type in kRet0
Ian Rogers848871b2013-08-05 10:56:33 -0700957 CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(pInitializeType), type_idx, true);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700958 OpRegCopy(TargetReg(kArg2), TargetReg(kRet0)); // Align usage with fast path
Brian Carlstrom7940e442013-07-12 13:46:57 -0700959 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); /* reload Ref */
960 // Rejoin code paths
961 LIR* hop_target = NewLIR0(kPseudoTargetLabel);
962 hop_branch->target = hop_target;
963 }
964 }
965 /* kArg0 is ref, kArg2 is class. If ref==null, use directly as bool result */
966 RegLocation rl_result = GetReturn(false);
967 if (cu_->instruction_set == kMips) {
968 // On MIPS rArg0 != rl_result, place false in result if branch is taken.
969 LoadConstant(rl_result.low_reg, 0);
970 }
971 LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL);
972
973 /* load object->klass_ */
974 DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0);
975 LoadWordDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1));
976 /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class */
977 LIR* branchover = NULL;
978 if (type_known_final) {
979 // rl_result == ref == null == 0.
980 if (cu_->instruction_set == kThumb2) {
981 OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same?
982 OpIT(kCondEq, "E"); // if-convert the test
983 LoadConstant(rl_result.low_reg, 1); // .eq case - load true
984 LoadConstant(rl_result.low_reg, 0); // .ne case - load false
985 } else {
986 LoadConstant(rl_result.low_reg, 0); // ne case - load false
987 branchover = OpCmpBranch(kCondNe, TargetReg(kArg1), TargetReg(kArg2), NULL);
988 LoadConstant(rl_result.low_reg, 1); // eq case - load true
989 }
990 } else {
991 if (cu_->instruction_set == kThumb2) {
Ian Rogers848871b2013-08-05 10:56:33 -0700992 int r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(pInstanceofNonTrivial));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700993 if (!type_known_abstract) {
994 /* Uses conditional nullification */
995 OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same?
996 OpIT(kCondEq, "EE"); // if-convert the test
997 LoadConstant(TargetReg(kArg0), 1); // .eq case - load true
998 }
999 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class
1000 OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class)
1001 FreeTemp(r_tgt);
1002 } else {
1003 if (!type_known_abstract) {
1004 /* Uses branchovers */
1005 LoadConstant(rl_result.low_reg, 1); // assume true
1006 branchover = OpCmpBranch(kCondEq, TargetReg(kArg1), TargetReg(kArg2), NULL);
1007 }
1008 if (cu_->instruction_set != kX86) {
Ian Rogers848871b2013-08-05 10:56:33 -07001009 int r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(pInstanceofNonTrivial));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001010 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class
1011 OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class)
1012 FreeTemp(r_tgt);
1013 } else {
1014 OpRegCopy(TargetReg(kArg0), TargetReg(kArg2));
Ian Rogers848871b2013-08-05 10:56:33 -07001015 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(pInstanceofNonTrivial));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001016 }
1017 }
1018 }
1019 // TODO: only clobber when type isn't final?
1020 ClobberCalleeSave();
1021 /* branch targets here */
1022 LIR* target = NewLIR0(kPseudoTargetLabel);
1023 StoreValue(rl_dest, rl_result);
1024 branch1->target = target;
1025 if (branchover != NULL) {
1026 branchover->target = target;
1027 }
1028}
1029
1030void Mir2Lir::GenInstanceof(uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src) {
1031 bool type_known_final, type_known_abstract, use_declaring_class;
1032 bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
1033 *cu_->dex_file,
1034 type_idx,
1035 &type_known_final,
1036 &type_known_abstract,
1037 &use_declaring_class);
1038 bool can_assume_type_is_in_dex_cache = !needs_access_check &&
1039 cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx);
1040
1041 if ((use_declaring_class || can_assume_type_is_in_dex_cache) && type_known_final) {
1042 GenInstanceofFinal(use_declaring_class, type_idx, rl_dest, rl_src);
1043 } else {
1044 GenInstanceofCallingHelper(needs_access_check, type_known_final, type_known_abstract,
1045 use_declaring_class, can_assume_type_is_in_dex_cache,
1046 type_idx, rl_dest, rl_src);
1047 }
1048}
1049
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001050void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001051 bool type_known_final, type_known_abstract, use_declaring_class;
1052 bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
1053 *cu_->dex_file,
1054 type_idx,
1055 &type_known_final,
1056 &type_known_abstract,
1057 &use_declaring_class);
1058 // Note: currently type_known_final is unused, as optimizing will only improve the performance
1059 // of the exception throw path.
1060 DexCompilationUnit* cu = mir_graph_->GetCurrentDexCompilationUnit();
1061 const MethodReference mr(cu->GetDexFile(), cu->GetDexMethodIndex());
1062 if (!needs_access_check && cu_->compiler_driver->IsSafeCast(mr, insn_idx)) {
1063 // Verifier type analysis proved this check cast would never cause an exception.
1064 return;
1065 }
1066 FlushAllRegs();
1067 // May generate a call - use explicit registers
1068 LockCallTemps();
1069 LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method*
1070 int class_reg = TargetReg(kArg2); // kArg2 will hold the Class*
1071 if (needs_access_check) {
1072 // Check we have access to type_idx and if not throw IllegalAccessError,
1073 // returns Class* in kRet0
1074 // InitializeTypeAndVerifyAccess(idx, method)
Ian Rogers848871b2013-08-05 10:56:33 -07001075 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccess),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001076 type_idx, TargetReg(kArg1), true);
1077 OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path
1078 } else if (use_declaring_class) {
1079 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -07001080 mirror::ArtMethod::DeclaringClassOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001081 } else {
1082 // Load dex cache entry into class_reg (kArg2)
1083 LoadWordDisp(TargetReg(kArg1),
Brian Carlstromea46f952013-07-30 01:26:50 -07001084 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), class_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001085 int32_t offset_of_type =
1086 mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() +
1087 (sizeof(mirror::Class*) * type_idx);
1088 LoadWordDisp(class_reg, offset_of_type, class_reg);
1089 if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx)) {
1090 // Need to test presence of type in dex cache at runtime
1091 LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL);
1092 // Not resolved
1093 // Call out to helper, which will return resolved type in kArg0
1094 // InitializeTypeFromCode(idx, method)
Ian Rogers848871b2013-08-05 10:56:33 -07001095 CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(pInitializeType), type_idx,
Ian Rogers7655f292013-07-29 11:07:13 -07001096 TargetReg(kArg1), true);
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001097 OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path
Brian Carlstrom7940e442013-07-12 13:46:57 -07001098 // Rejoin code paths
1099 LIR* hop_target = NewLIR0(kPseudoTargetLabel);
1100 hop_branch->target = hop_target;
1101 }
1102 }
1103 // At this point, class_reg (kArg2) has class
1104 LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref
1105 /* Null is OK - continue */
1106 LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL);
1107 /* load object->klass_ */
1108 DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0);
1109 LoadWordDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1));
1110 /* kArg1 now contains object->klass_ */
1111 LIR* branch2 = NULL;
1112 if (!type_known_abstract) {
1113 branch2 = OpCmpBranch(kCondEq, TargetReg(kArg1), class_reg, NULL);
1114 }
Ian Rogers848871b2013-08-05 10:56:33 -07001115 CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(pCheckCast), TargetReg(kArg1),
Ian Rogers7655f292013-07-29 11:07:13 -07001116 TargetReg(kArg2), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001117 /* branch target here */
1118 LIR* target = NewLIR0(kPseudoTargetLabel);
1119 branch1->target = target;
1120 if (branch2 != NULL) {
1121 branch2->target = target;
1122 }
1123}
1124
1125void Mir2Lir::GenLong3Addr(OpKind first_op, OpKind second_op, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001126 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001127 RegLocation rl_result;
1128 if (cu_->instruction_set == kThumb2) {
1129 /*
1130 * NOTE: This is the one place in the code in which we might have
1131 * as many as six live temporary registers. There are 5 in the normal
1132 * set for Arm. Until we have spill capabilities, temporarily add
1133 * lr to the temp set. It is safe to do this locally, but note that
1134 * lr is used explicitly elsewhere in the code generator and cannot
1135 * normally be used as a general temp register.
1136 */
1137 MarkTemp(TargetReg(kLr)); // Add lr to the temp pool
1138 FreeTemp(TargetReg(kLr)); // and make it available
1139 }
1140 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
1141 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
1142 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1143 // The longs may overlap - use intermediate temp if so
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001144 if ((rl_result.low_reg == rl_src1.high_reg) || (rl_result.low_reg == rl_src2.high_reg)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001145 int t_reg = AllocTemp();
1146 OpRegRegReg(first_op, t_reg, rl_src1.low_reg, rl_src2.low_reg);
1147 OpRegRegReg(second_op, rl_result.high_reg, rl_src1.high_reg, rl_src2.high_reg);
1148 OpRegCopy(rl_result.low_reg, t_reg);
1149 FreeTemp(t_reg);
1150 } else {
1151 OpRegRegReg(first_op, rl_result.low_reg, rl_src1.low_reg, rl_src2.low_reg);
1152 OpRegRegReg(second_op, rl_result.high_reg, rl_src1.high_reg,
1153 rl_src2.high_reg);
1154 }
1155 /*
1156 * NOTE: If rl_dest refers to a frame variable in a large frame, the
1157 * following StoreValueWide might need to allocate a temp register.
1158 * To further work around the lack of a spill capability, explicitly
1159 * free any temps from rl_src1 & rl_src2 that aren't still live in rl_result.
1160 * Remove when spill is functional.
1161 */
1162 FreeRegLocTemps(rl_result, rl_src1);
1163 FreeRegLocTemps(rl_result, rl_src2);
1164 StoreValueWide(rl_dest, rl_result);
1165 if (cu_->instruction_set == kThumb2) {
1166 Clobber(TargetReg(kLr));
1167 UnmarkTemp(TargetReg(kLr)); // Remove lr from the temp pool
1168 }
1169}
1170
1171
1172void Mir2Lir::GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001173 RegLocation rl_src1, RegLocation rl_shift) {
Ian Rogers848871b2013-08-05 10:56:33 -07001174 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001175
1176 switch (opcode) {
1177 case Instruction::SHL_LONG:
1178 case Instruction::SHL_LONG_2ADDR:
Ian Rogers7655f292013-07-29 11:07:13 -07001179 func_offset = QUICK_ENTRYPOINT_OFFSET(pShlLong);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001180 break;
1181 case Instruction::SHR_LONG:
1182 case Instruction::SHR_LONG_2ADDR:
Ian Rogers7655f292013-07-29 11:07:13 -07001183 func_offset = QUICK_ENTRYPOINT_OFFSET(pShrLong);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001184 break;
1185 case Instruction::USHR_LONG:
1186 case Instruction::USHR_LONG_2ADDR:
Ian Rogers7655f292013-07-29 11:07:13 -07001187 func_offset = QUICK_ENTRYPOINT_OFFSET(pUshrLong);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001188 break;
1189 default:
1190 LOG(FATAL) << "Unexpected case";
1191 }
1192 FlushAllRegs(); /* Send everything to home location */
1193 CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_shift, false);
1194 RegLocation rl_result = GetReturnWide(false);
1195 StoreValueWide(rl_dest, rl_result);
1196}
1197
1198
1199void Mir2Lir::GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001200 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001201 OpKind op = kOpBkpt;
1202 bool is_div_rem = false;
1203 bool check_zero = false;
1204 bool unary = false;
1205 RegLocation rl_result;
1206 bool shift_op = false;
1207 switch (opcode) {
1208 case Instruction::NEG_INT:
1209 op = kOpNeg;
1210 unary = true;
1211 break;
1212 case Instruction::NOT_INT:
1213 op = kOpMvn;
1214 unary = true;
1215 break;
1216 case Instruction::ADD_INT:
1217 case Instruction::ADD_INT_2ADDR:
1218 op = kOpAdd;
1219 break;
1220 case Instruction::SUB_INT:
1221 case Instruction::SUB_INT_2ADDR:
1222 op = kOpSub;
1223 break;
1224 case Instruction::MUL_INT:
1225 case Instruction::MUL_INT_2ADDR:
1226 op = kOpMul;
1227 break;
1228 case Instruction::DIV_INT:
1229 case Instruction::DIV_INT_2ADDR:
1230 check_zero = true;
1231 op = kOpDiv;
1232 is_div_rem = true;
1233 break;
1234 /* NOTE: returns in kArg1 */
1235 case Instruction::REM_INT:
1236 case Instruction::REM_INT_2ADDR:
1237 check_zero = true;
1238 op = kOpRem;
1239 is_div_rem = true;
1240 break;
1241 case Instruction::AND_INT:
1242 case Instruction::AND_INT_2ADDR:
1243 op = kOpAnd;
1244 break;
1245 case Instruction::OR_INT:
1246 case Instruction::OR_INT_2ADDR:
1247 op = kOpOr;
1248 break;
1249 case Instruction::XOR_INT:
1250 case Instruction::XOR_INT_2ADDR:
1251 op = kOpXor;
1252 break;
1253 case Instruction::SHL_INT:
1254 case Instruction::SHL_INT_2ADDR:
1255 shift_op = true;
1256 op = kOpLsl;
1257 break;
1258 case Instruction::SHR_INT:
1259 case Instruction::SHR_INT_2ADDR:
1260 shift_op = true;
1261 op = kOpAsr;
1262 break;
1263 case Instruction::USHR_INT:
1264 case Instruction::USHR_INT_2ADDR:
1265 shift_op = true;
1266 op = kOpLsr;
1267 break;
1268 default:
1269 LOG(FATAL) << "Invalid word arith op: " << opcode;
1270 }
1271 if (!is_div_rem) {
1272 if (unary) {
1273 rl_src1 = LoadValue(rl_src1, kCoreReg);
1274 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1275 OpRegReg(op, rl_result.low_reg, rl_src1.low_reg);
1276 } else {
1277 if (shift_op) {
1278 int t_reg = INVALID_REG;
1279 if (cu_->instruction_set == kX86) {
1280 // X86 doesn't require masking and must use ECX
1281 t_reg = TargetReg(kCount); // rCX
1282 LoadValueDirectFixed(rl_src2, t_reg);
1283 } else {
1284 rl_src2 = LoadValue(rl_src2, kCoreReg);
1285 t_reg = AllocTemp();
1286 OpRegRegImm(kOpAnd, t_reg, rl_src2.low_reg, 31);
1287 }
1288 rl_src1 = LoadValue(rl_src1, kCoreReg);
1289 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1290 OpRegRegReg(op, rl_result.low_reg, rl_src1.low_reg, t_reg);
1291 FreeTemp(t_reg);
1292 } else {
1293 rl_src1 = LoadValue(rl_src1, kCoreReg);
1294 rl_src2 = LoadValue(rl_src2, kCoreReg);
1295 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1296 OpRegRegReg(op, rl_result.low_reg, rl_src1.low_reg, rl_src2.low_reg);
1297 }
1298 }
1299 StoreValue(rl_dest, rl_result);
1300 } else {
1301 if (cu_->instruction_set == kMips) {
1302 rl_src1 = LoadValue(rl_src1, kCoreReg);
1303 rl_src2 = LoadValue(rl_src2, kCoreReg);
1304 if (check_zero) {
1305 GenImmedCheck(kCondEq, rl_src2.low_reg, 0, kThrowDivZero);
1306 }
1307 rl_result = GenDivRem(rl_dest, rl_src1.low_reg, rl_src2.low_reg, op == kOpDiv);
1308 } else {
Ian Rogers848871b2013-08-05 10:56:33 -07001309 ThreadOffset func_offset = QUICK_ENTRYPOINT_OFFSET(pIdivmod);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001310 FlushAllRegs(); /* Send everything to home location */
1311 LoadValueDirectFixed(rl_src2, TargetReg(kArg1));
1312 int r_tgt = CallHelperSetup(func_offset);
1313 LoadValueDirectFixed(rl_src1, TargetReg(kArg0));
1314 if (check_zero) {
1315 GenImmedCheck(kCondEq, TargetReg(kArg1), 0, kThrowDivZero);
1316 }
1317 // NOTE: callout here is not a safepoint
Brian Carlstromdf629502013-07-17 22:39:56 -07001318 CallHelper(r_tgt, func_offset, false /* not a safepoint */);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001319 if (op == kOpDiv)
1320 rl_result = GetReturn(false);
1321 else
1322 rl_result = GetReturnAlt();
1323 }
1324 StoreValue(rl_dest, rl_result);
1325 }
1326}
1327
1328/*
1329 * The following are the first-level codegen routines that analyze the format
1330 * of each bytecode then either dispatch special purpose codegen routines
1331 * or produce corresponding Thumb instructions directly.
1332 */
1333
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001334static bool IsPowerOfTwo(int x) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001335 return (x & (x - 1)) == 0;
1336}
1337
1338// Returns true if no more than two bits are set in 'x'.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001339static bool IsPopCountLE2(unsigned int x) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001340 x &= x - 1;
1341 return (x & (x - 1)) == 0;
1342}
1343
1344// Returns the index of the lowest set bit in 'x'.
1345static int LowestSetBit(unsigned int x) {
1346 int bit_posn = 0;
1347 while ((x & 0xf) == 0) {
1348 bit_posn += 4;
1349 x >>= 4;
1350 }
1351 while ((x & 1) == 0) {
1352 bit_posn++;
1353 x >>= 1;
1354 }
1355 return bit_posn;
1356}
1357
1358// Returns true if it added instructions to 'cu' to divide 'rl_src' by 'lit'
1359// and store the result in 'rl_dest'.
buzbee11b63d12013-08-27 07:34:17 -07001360bool Mir2Lir::HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001361 RegLocation rl_src, RegLocation rl_dest, int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001362 if ((lit < 2) || ((cu_->instruction_set != kThumb2) && !IsPowerOfTwo(lit))) {
1363 return false;
1364 }
1365 // No divide instruction for Arm, so check for more special cases
1366 if ((cu_->instruction_set == kThumb2) && !IsPowerOfTwo(lit)) {
buzbee11b63d12013-08-27 07:34:17 -07001367 return SmallLiteralDivRem(dalvik_opcode, is_div, rl_src, rl_dest, lit);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001368 }
1369 int k = LowestSetBit(lit);
1370 if (k >= 30) {
1371 // Avoid special cases.
1372 return false;
1373 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001374 rl_src = LoadValue(rl_src, kCoreReg);
1375 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee11b63d12013-08-27 07:34:17 -07001376 if (is_div) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001377 int t_reg = AllocTemp();
1378 if (lit == 2) {
1379 // Division by 2 is by far the most common division by constant.
1380 OpRegRegImm(kOpLsr, t_reg, rl_src.low_reg, 32 - k);
1381 OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.low_reg);
1382 OpRegRegImm(kOpAsr, rl_result.low_reg, t_reg, k);
1383 } else {
1384 OpRegRegImm(kOpAsr, t_reg, rl_src.low_reg, 31);
1385 OpRegRegImm(kOpLsr, t_reg, t_reg, 32 - k);
1386 OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.low_reg);
1387 OpRegRegImm(kOpAsr, rl_result.low_reg, t_reg, k);
1388 }
1389 } else {
1390 int t_reg1 = AllocTemp();
1391 int t_reg2 = AllocTemp();
1392 if (lit == 2) {
1393 OpRegRegImm(kOpLsr, t_reg1, rl_src.low_reg, 32 - k);
1394 OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.low_reg);
1395 OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit -1);
1396 OpRegRegReg(kOpSub, rl_result.low_reg, t_reg2, t_reg1);
1397 } else {
1398 OpRegRegImm(kOpAsr, t_reg1, rl_src.low_reg, 31);
1399 OpRegRegImm(kOpLsr, t_reg1, t_reg1, 32 - k);
1400 OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.low_reg);
1401 OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit - 1);
1402 OpRegRegReg(kOpSub, rl_result.low_reg, t_reg2, t_reg1);
1403 }
1404 }
1405 StoreValue(rl_dest, rl_result);
1406 return true;
1407}
1408
1409// Returns true if it added instructions to 'cu' to multiply 'rl_src' by 'lit'
1410// and store the result in 'rl_dest'.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001411bool Mir2Lir::HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001412 // Can we simplify this multiplication?
1413 bool power_of_two = false;
1414 bool pop_count_le2 = false;
1415 bool power_of_two_minus_one = false;
1416 if (lit < 2) {
1417 // Avoid special cases.
1418 return false;
1419 } else if (IsPowerOfTwo(lit)) {
1420 power_of_two = true;
1421 } else if (IsPopCountLE2(lit)) {
1422 pop_count_le2 = true;
1423 } else if (IsPowerOfTwo(lit + 1)) {
1424 power_of_two_minus_one = true;
1425 } else {
1426 return false;
1427 }
1428 rl_src = LoadValue(rl_src, kCoreReg);
1429 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1430 if (power_of_two) {
1431 // Shift.
1432 OpRegRegImm(kOpLsl, rl_result.low_reg, rl_src.low_reg, LowestSetBit(lit));
1433 } else if (pop_count_le2) {
1434 // Shift and add and shift.
1435 int first_bit = LowestSetBit(lit);
1436 int second_bit = LowestSetBit(lit ^ (1 << first_bit));
1437 GenMultiplyByTwoBitMultiplier(rl_src, rl_result, lit, first_bit, second_bit);
1438 } else {
1439 // Reverse subtract: (src << (shift + 1)) - src.
1440 DCHECK(power_of_two_minus_one);
1441 // TUNING: rsb dst, src, src lsl#LowestSetBit(lit + 1)
1442 int t_reg = AllocTemp();
1443 OpRegRegImm(kOpLsl, t_reg, rl_src.low_reg, LowestSetBit(lit + 1));
1444 OpRegRegReg(kOpSub, rl_result.low_reg, t_reg, rl_src.low_reg);
1445 }
1446 StoreValue(rl_dest, rl_result);
1447 return true;
1448}
1449
1450void Mir2Lir::GenArithOpIntLit(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001451 int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001452 RegLocation rl_result;
1453 OpKind op = static_cast<OpKind>(0); /* Make gcc happy */
1454 int shift_op = false;
1455 bool is_div = false;
1456
1457 switch (opcode) {
1458 case Instruction::RSUB_INT_LIT8:
1459 case Instruction::RSUB_INT: {
1460 rl_src = LoadValue(rl_src, kCoreReg);
1461 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1462 if (cu_->instruction_set == kThumb2) {
1463 OpRegRegImm(kOpRsub, rl_result.low_reg, rl_src.low_reg, lit);
1464 } else {
1465 OpRegReg(kOpNeg, rl_result.low_reg, rl_src.low_reg);
1466 OpRegImm(kOpAdd, rl_result.low_reg, lit);
1467 }
1468 StoreValue(rl_dest, rl_result);
1469 return;
1470 }
1471
1472 case Instruction::SUB_INT:
1473 case Instruction::SUB_INT_2ADDR:
1474 lit = -lit;
1475 // Intended fallthrough
1476 case Instruction::ADD_INT:
1477 case Instruction::ADD_INT_2ADDR:
1478 case Instruction::ADD_INT_LIT8:
1479 case Instruction::ADD_INT_LIT16:
1480 op = kOpAdd;
1481 break;
1482 case Instruction::MUL_INT:
1483 case Instruction::MUL_INT_2ADDR:
1484 case Instruction::MUL_INT_LIT8:
1485 case Instruction::MUL_INT_LIT16: {
1486 if (HandleEasyMultiply(rl_src, rl_dest, lit)) {
1487 return;
1488 }
1489 op = kOpMul;
1490 break;
1491 }
1492 case Instruction::AND_INT:
1493 case Instruction::AND_INT_2ADDR:
1494 case Instruction::AND_INT_LIT8:
1495 case Instruction::AND_INT_LIT16:
1496 op = kOpAnd;
1497 break;
1498 case Instruction::OR_INT:
1499 case Instruction::OR_INT_2ADDR:
1500 case Instruction::OR_INT_LIT8:
1501 case Instruction::OR_INT_LIT16:
1502 op = kOpOr;
1503 break;
1504 case Instruction::XOR_INT:
1505 case Instruction::XOR_INT_2ADDR:
1506 case Instruction::XOR_INT_LIT8:
1507 case Instruction::XOR_INT_LIT16:
1508 op = kOpXor;
1509 break;
1510 case Instruction::SHL_INT_LIT8:
1511 case Instruction::SHL_INT:
1512 case Instruction::SHL_INT_2ADDR:
1513 lit &= 31;
1514 shift_op = true;
1515 op = kOpLsl;
1516 break;
1517 case Instruction::SHR_INT_LIT8:
1518 case Instruction::SHR_INT:
1519 case Instruction::SHR_INT_2ADDR:
1520 lit &= 31;
1521 shift_op = true;
1522 op = kOpAsr;
1523 break;
1524 case Instruction::USHR_INT_LIT8:
1525 case Instruction::USHR_INT:
1526 case Instruction::USHR_INT_2ADDR:
1527 lit &= 31;
1528 shift_op = true;
1529 op = kOpLsr;
1530 break;
1531
1532 case Instruction::DIV_INT:
1533 case Instruction::DIV_INT_2ADDR:
1534 case Instruction::DIV_INT_LIT8:
1535 case Instruction::DIV_INT_LIT16:
1536 case Instruction::REM_INT:
1537 case Instruction::REM_INT_2ADDR:
1538 case Instruction::REM_INT_LIT8:
1539 case Instruction::REM_INT_LIT16: {
1540 if (lit == 0) {
1541 GenImmedCheck(kCondAl, 0, 0, kThrowDivZero);
1542 return;
1543 }
buzbee11b63d12013-08-27 07:34:17 -07001544 if ((opcode == Instruction::DIV_INT) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -07001545 (opcode == Instruction::DIV_INT_2ADDR) ||
buzbee11b63d12013-08-27 07:34:17 -07001546 (opcode == Instruction::DIV_INT_LIT8) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -07001547 (opcode == Instruction::DIV_INT_LIT16)) {
1548 is_div = true;
1549 } else {
1550 is_div = false;
1551 }
buzbee11b63d12013-08-27 07:34:17 -07001552 if (HandleEasyDivRem(opcode, is_div, rl_src, rl_dest, lit)) {
1553 return;
1554 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001555 if (cu_->instruction_set == kMips) {
1556 rl_src = LoadValue(rl_src, kCoreReg);
1557 rl_result = GenDivRemLit(rl_dest, rl_src.low_reg, lit, is_div);
1558 } else {
1559 FlushAllRegs(); /* Everything to home location */
1560 LoadValueDirectFixed(rl_src, TargetReg(kArg0));
1561 Clobber(TargetReg(kArg0));
Ian Rogers848871b2013-08-05 10:56:33 -07001562 ThreadOffset func_offset = QUICK_ENTRYPOINT_OFFSET(pIdivmod);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001563 CallRuntimeHelperRegImm(func_offset, TargetReg(kArg0), lit, false);
1564 if (is_div)
1565 rl_result = GetReturn(false);
1566 else
1567 rl_result = GetReturnAlt();
1568 }
1569 StoreValue(rl_dest, rl_result);
1570 return;
1571 }
1572 default:
1573 LOG(FATAL) << "Unexpected opcode " << opcode;
1574 }
1575 rl_src = LoadValue(rl_src, kCoreReg);
1576 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1577 // Avoid shifts by literal 0 - no support in Thumb. Change to copy
1578 if (shift_op && (lit == 0)) {
1579 OpRegCopy(rl_result.low_reg, rl_src.low_reg);
1580 } else {
1581 OpRegRegImm(op, rl_result.low_reg, rl_src.low_reg, lit);
1582 }
1583 StoreValue(rl_dest, rl_result);
1584}
1585
1586void Mir2Lir::GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001587 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001588 RegLocation rl_result;
1589 OpKind first_op = kOpBkpt;
1590 OpKind second_op = kOpBkpt;
1591 bool call_out = false;
1592 bool check_zero = false;
Ian Rogers848871b2013-08-05 10:56:33 -07001593 ThreadOffset func_offset(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001594 int ret_reg = TargetReg(kRet0);
1595
1596 switch (opcode) {
1597 case Instruction::NOT_LONG:
1598 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
1599 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1600 // Check for destructive overlap
1601 if (rl_result.low_reg == rl_src2.high_reg) {
1602 int t_reg = AllocTemp();
1603 OpRegCopy(t_reg, rl_src2.high_reg);
1604 OpRegReg(kOpMvn, rl_result.low_reg, rl_src2.low_reg);
1605 OpRegReg(kOpMvn, rl_result.high_reg, t_reg);
1606 FreeTemp(t_reg);
1607 } else {
1608 OpRegReg(kOpMvn, rl_result.low_reg, rl_src2.low_reg);
1609 OpRegReg(kOpMvn, rl_result.high_reg, rl_src2.high_reg);
1610 }
1611 StoreValueWide(rl_dest, rl_result);
1612 return;
1613 case Instruction::ADD_LONG:
1614 case Instruction::ADD_LONG_2ADDR:
1615 if (cu_->instruction_set != kThumb2) {
1616 GenAddLong(rl_dest, rl_src1, rl_src2);
1617 return;
1618 }
1619 first_op = kOpAdd;
1620 second_op = kOpAdc;
1621 break;
1622 case Instruction::SUB_LONG:
1623 case Instruction::SUB_LONG_2ADDR:
1624 if (cu_->instruction_set != kThumb2) {
1625 GenSubLong(rl_dest, rl_src1, rl_src2);
1626 return;
1627 }
1628 first_op = kOpSub;
1629 second_op = kOpSbc;
1630 break;
1631 case Instruction::MUL_LONG:
1632 case Instruction::MUL_LONG_2ADDR:
1633 if (cu_->instruction_set == kThumb2) {
1634 GenMulLong(rl_dest, rl_src1, rl_src2);
1635 return;
1636 } else {
1637 call_out = true;
1638 ret_reg = TargetReg(kRet0);
Ian Rogers7655f292013-07-29 11:07:13 -07001639 func_offset = QUICK_ENTRYPOINT_OFFSET(pLmul);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001640 }
1641 break;
1642 case Instruction::DIV_LONG:
1643 case Instruction::DIV_LONG_2ADDR:
1644 call_out = true;
1645 check_zero = true;
1646 ret_reg = TargetReg(kRet0);
Ian Rogers7655f292013-07-29 11:07:13 -07001647 func_offset = QUICK_ENTRYPOINT_OFFSET(pLdiv);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001648 break;
1649 case Instruction::REM_LONG:
1650 case Instruction::REM_LONG_2ADDR:
1651 call_out = true;
1652 check_zero = true;
Ian Rogers7655f292013-07-29 11:07:13 -07001653 func_offset = QUICK_ENTRYPOINT_OFFSET(pLdivmod);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001654 /* NOTE - for Arm, result is in kArg2/kArg3 instead of kRet0/kRet1 */
1655 ret_reg = (cu_->instruction_set == kThumb2) ? TargetReg(kArg2) : TargetReg(kRet0);
1656 break;
1657 case Instruction::AND_LONG_2ADDR:
1658 case Instruction::AND_LONG:
1659 if (cu_->instruction_set == kX86) {
1660 return GenAndLong(rl_dest, rl_src1, rl_src2);
1661 }
1662 first_op = kOpAnd;
1663 second_op = kOpAnd;
1664 break;
1665 case Instruction::OR_LONG:
1666 case Instruction::OR_LONG_2ADDR:
1667 if (cu_->instruction_set == kX86) {
1668 GenOrLong(rl_dest, rl_src1, rl_src2);
1669 return;
1670 }
1671 first_op = kOpOr;
1672 second_op = kOpOr;
1673 break;
1674 case Instruction::XOR_LONG:
1675 case Instruction::XOR_LONG_2ADDR:
1676 if (cu_->instruction_set == kX86) {
1677 GenXorLong(rl_dest, rl_src1, rl_src2);
1678 return;
1679 }
1680 first_op = kOpXor;
1681 second_op = kOpXor;
1682 break;
1683 case Instruction::NEG_LONG: {
1684 GenNegLong(rl_dest, rl_src2);
1685 return;
1686 }
1687 default:
1688 LOG(FATAL) << "Invalid long arith op";
1689 }
1690 if (!call_out) {
1691 GenLong3Addr(first_op, second_op, rl_dest, rl_src1, rl_src2);
1692 } else {
1693 FlushAllRegs(); /* Send everything to home location */
1694 if (check_zero) {
1695 LoadValueDirectWideFixed(rl_src2, TargetReg(kArg2), TargetReg(kArg3));
1696 int r_tgt = CallHelperSetup(func_offset);
1697 GenDivZeroCheck(TargetReg(kArg2), TargetReg(kArg3));
1698 LoadValueDirectWideFixed(rl_src1, TargetReg(kArg0), TargetReg(kArg1));
1699 // NOTE: callout here is not a safepoint
1700 CallHelper(r_tgt, func_offset, false /* not safepoint */);
1701 } else {
1702 CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_src2, false);
1703 }
1704 // Adjust return regs in to handle case of rem returning kArg2/kArg3
1705 if (ret_reg == TargetReg(kRet0))
1706 rl_result = GetReturnWide(false);
1707 else
1708 rl_result = GetReturnWideAlt();
1709 StoreValueWide(rl_dest, rl_result);
1710 }
1711}
1712
Ian Rogers848871b2013-08-05 10:56:33 -07001713void Mir2Lir::GenConversionCall(ThreadOffset func_offset,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001714 RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001715 /*
1716 * Don't optimize the register usage since it calls out to support
1717 * functions
1718 */
1719 FlushAllRegs(); /* Send everything to home location */
1720 if (rl_src.wide) {
1721 LoadValueDirectWideFixed(rl_src, rl_src.fp ? TargetReg(kFArg0) : TargetReg(kArg0),
1722 rl_src.fp ? TargetReg(kFArg1) : TargetReg(kArg1));
1723 } else {
1724 LoadValueDirectFixed(rl_src, rl_src.fp ? TargetReg(kFArg0) : TargetReg(kArg0));
1725 }
1726 CallRuntimeHelperRegLocation(func_offset, rl_src, false);
1727 if (rl_dest.wide) {
1728 RegLocation rl_result;
1729 rl_result = GetReturnWide(rl_dest.fp);
1730 StoreValueWide(rl_dest, rl_result);
1731 } else {
1732 RegLocation rl_result;
1733 rl_result = GetReturn(rl_dest.fp);
1734 StoreValue(rl_dest, rl_result);
1735 }
1736}
1737
1738/* Check if we need to check for pending suspend request */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001739void Mir2Lir::GenSuspendTest(int opt_flags) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001740 if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) {
1741 return;
1742 }
1743 FlushAllRegs();
1744 LIR* branch = OpTestSuspend(NULL);
1745 LIR* ret_lab = NewLIR0(kPseudoTargetLabel);
1746 LIR* target = RawLIR(current_dalvik_offset_, kPseudoSuspendTarget,
1747 reinterpret_cast<uintptr_t>(ret_lab), current_dalvik_offset_);
1748 branch->target = target;
1749 suspend_launchpads_.Insert(target);
1750}
1751
1752/* Check if we need to check for pending suspend request */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001753void Mir2Lir::GenSuspendTestAndBranch(int opt_flags, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001754 if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) {
1755 OpUnconditionalBranch(target);
1756 return;
1757 }
1758 OpTestSuspend(target);
1759 LIR* launch_pad =
1760 RawLIR(current_dalvik_offset_, kPseudoSuspendTarget,
1761 reinterpret_cast<uintptr_t>(target), current_dalvik_offset_);
1762 FlushAllRegs();
1763 OpUnconditionalBranch(launch_pad);
1764 suspend_launchpads_.Insert(launch_pad);
1765}
1766
1767} // namespace art