blob: 1a9dbeae0f1a798cb147370e296150d74f63f411 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 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/* This file contains codegen for the Thumb2 ISA. */
18
Brian Carlstrom7940e442013-07-12 13:46:57 -070019#include "codegen_arm.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080020
21#include "arm_lir.h"
22#include "base/logging.h"
23#include "dex/mir_graph.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070024#include "dex/quick/mir_to_lir-inl.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080025#include "driver/compiler_driver.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070026#include "gc/accounting/card_table.h"
Vladimir Markof4da6752014-08-01 19:04:18 +010027#include "mirror/art_method.h"
28#include "mirror/object_array-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070029#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe7e499922015-01-06 08:28:12 -080030#include "utils.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070031
32namespace art {
33
Brian Carlstrom7940e442013-07-12 13:46:57 -070034/*
35 * The sparse table in the literal pool is an array of <key,displacement>
36 * pairs. For each set, we'll load them as a pair using ldmia.
37 * This means that the register number of the temp we use for the key
38 * must be lower than the reg for the displacement.
39 *
40 * The test loop will look something like:
41 *
buzbee2700f7e2014-03-07 09:46:20 -080042 * adr r_base, <table>
Brian Carlstrom7940e442013-07-12 13:46:57 -070043 * ldr r_val, [rARM_SP, v_reg_off]
44 * mov r_idx, #table_size
45 * lp:
buzbee2700f7e2014-03-07 09:46:20 -080046 * ldmia r_base!, {r_key, r_disp}
Brian Carlstrom7940e442013-07-12 13:46:57 -070047 * sub r_idx, #1
48 * cmp r_val, r_key
49 * ifeq
50 * add rARM_PC, r_disp ; This is the branch from which we compute displacement
51 * cbnz r_idx, lp
52 */
Andreas Gampe48971b32014-08-06 10:09:01 -070053void ArmMir2Lir::GenLargeSparseSwitch(MIR* mir, uint32_t table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -070054 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -070055 // Add the table to the list - we'll process it later
56 SwitchTable *tab_rec =
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000057 static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData));
Chao-ying Fu72f53af2014-11-11 16:48:40 -080058 tab_rec->switch_mir = mir;
Brian Carlstrom7940e442013-07-12 13:46:57 -070059 tab_rec->table = table;
60 tab_rec->vaddr = current_dalvik_offset_;
buzbee0d829482013-10-11 15:24:55 -070061 uint32_t size = table[1];
Vladimir Markoe39c54e2014-09-22 14:50:02 +010062 switch_tables_.push_back(tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -070063
64 // Get the switch value
65 rl_src = LoadValue(rl_src, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -080066 RegStorage r_base = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070067 /* Allocate key and disp temps */
buzbee2700f7e2014-03-07 09:46:20 -080068 RegStorage r_key = AllocTemp();
69 RegStorage r_disp = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070070 // Make sure r_key's register number is less than r_disp's number for ldmia
buzbee2700f7e2014-03-07 09:46:20 -080071 if (r_key.GetReg() > r_disp.GetReg()) {
72 RegStorage tmp = r_disp;
Brian Carlstrom7940e442013-07-12 13:46:57 -070073 r_disp = r_key;
74 r_key = tmp;
75 }
76 // Materialize a pointer to the switch table
buzbee2700f7e2014-03-07 09:46:20 -080077 NewLIR3(kThumb2Adr, r_base.GetReg(), 0, WrapPointer(tab_rec));
Brian Carlstrom7940e442013-07-12 13:46:57 -070078 // Set up r_idx
buzbee2700f7e2014-03-07 09:46:20 -080079 RegStorage r_idx = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070080 LoadConstant(r_idx, size);
81 // Establish loop branch target
82 LIR* target = NewLIR0(kPseudoTargetLabel);
83 // Load next key/disp
buzbee091cc402014-03-31 10:14:40 -070084 NewLIR2(kThumb2LdmiaWB, r_base.GetReg(), (1 << r_key.GetRegNum()) | (1 << r_disp.GetRegNum()));
buzbee2700f7e2014-03-07 09:46:20 -080085 OpRegReg(kOpCmp, r_key, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070086 // Go if match. NOTE: No instruction set switch here - must stay Thumb2
Dave Allison3da67a52014-04-02 17:03:45 -070087 LIR* it = OpIT(kCondEq, "");
buzbee2700f7e2014-03-07 09:46:20 -080088 LIR* switch_branch = NewLIR1(kThumb2AddPCR, r_disp.GetReg());
Dave Allison3da67a52014-04-02 17:03:45 -070089 OpEndIT(it);
Brian Carlstrom7940e442013-07-12 13:46:57 -070090 tab_rec->anchor = switch_branch;
91 // Needs to use setflags encoding here
Vladimir Markodbb8c492014-02-28 17:36:39 +000092 OpRegRegImm(kOpSub, r_idx, r_idx, 1); // For value == 1, this should set flags.
Vladimir Marko8dea81c2014-06-06 14:50:36 +010093 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 OpCondBranch(kCondNe, target);
95}
96
97
Andreas Gampe48971b32014-08-06 10:09:01 -070098void ArmMir2Lir::GenLargePackedSwitch(MIR* mir, uint32_t table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -070099 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700100 // Add the table to the list - we'll process it later
101 SwitchTable *tab_rec =
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000102 static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData));
Chao-ying Fu72f53af2014-11-11 16:48:40 -0800103 tab_rec->switch_mir = mir;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104 tab_rec->table = table;
105 tab_rec->vaddr = current_dalvik_offset_;
buzbee0d829482013-10-11 15:24:55 -0700106 uint32_t size = table[1];
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100107 switch_tables_.push_back(tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700108
109 // Get the switch value
110 rl_src = LoadValue(rl_src, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800111 RegStorage table_base = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700112 // Materialize a pointer to the switch table
buzbee2700f7e2014-03-07 09:46:20 -0800113 NewLIR3(kThumb2Adr, table_base.GetReg(), 0, WrapPointer(tab_rec));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114 int low_key = s4FromSwitchData(&table[2]);
buzbee2700f7e2014-03-07 09:46:20 -0800115 RegStorage keyReg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700116 // Remove the bias, if necessary
117 if (low_key == 0) {
buzbee2700f7e2014-03-07 09:46:20 -0800118 keyReg = rl_src.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700119 } else {
120 keyReg = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -0800121 OpRegRegImm(kOpSub, keyReg, rl_src.reg, low_key);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700122 }
123 // Bounds check - if < 0 or >= size continue following switch
124 OpRegImm(kOpCmp, keyReg, size-1);
125 LIR* branch_over = OpCondBranch(kCondHi, NULL);
126
127 // Load the displacement from the switch table
buzbee2700f7e2014-03-07 09:46:20 -0800128 RegStorage disp_reg = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -0700129 LoadBaseIndexed(table_base, keyReg, disp_reg, 2, k32);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700130
131 // ..and go! NOTE: No instruction set switch here - must stay Thumb2
buzbee2700f7e2014-03-07 09:46:20 -0800132 LIR* switch_branch = NewLIR1(kThumb2AddPCR, disp_reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700133 tab_rec->anchor = switch_branch;
134
135 /* branch_over target here */
136 LIR* target = NewLIR0(kPseudoTargetLabel);
137 branch_over->target = target;
138}
139
140/*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700141 * Handle unlocked -> thin locked transition inline or else call out to quick entrypoint. For more
142 * details see monitor.cc.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700143 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700144void ArmMir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700145 FlushAllRegs();
buzbee695d13a2014-04-19 13:32:20 -0700146 // FIXME: need separate LoadValues for object references.
buzbee2700f7e2014-03-07 09:46:20 -0800147 LoadValueDirectFixed(rl_src, rs_r0); // Get obj
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 LockCallTemps(); // Prepare for explicit register usage
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700149 constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15.
150 if (kArchVariantHasGoodBranchPredictor) {
Dave Allisonf9439142014-03-27 15:10:22 -0700151 LIR* null_check_branch = nullptr;
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700152 if ((opt_flags & MIR_IGNORE_NULL_CHECK) && !(cu_->disable_opt & (1 << kNullCheckElimination))) {
153 null_check_branch = nullptr; // No null check.
154 } else {
155 // If the null-check fails its handled by the slow-path to reduce exception related meta-data.
Dave Allison69dfe512014-07-11 17:11:58 +0000156 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Dave Allisonf9439142014-03-27 15:10:22 -0700157 null_check_branch = OpCmpImmBranch(kCondEq, rs_r0, 0, NULL);
158 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700159 }
buzbee695d13a2014-04-19 13:32:20 -0700160 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
buzbee091cc402014-03-31 10:14:40 -0700161 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
162 mirror::Object::MonitorOffset().Int32Value() >> 2);
Dave Allisonf9439142014-03-27 15:10:22 -0700163 MarkPossibleNullPointerException(opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800164 // Zero out the read barrier bits.
165 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
166 LIR* not_unlocked_branch = OpCmpImmBranch(kCondNe, rs_r3, 0, NULL);
167 // r1 is zero except for the rb bits here. Copy the read barrier bits into r2.
168 OpRegRegReg(kOpOr, rs_r2, rs_r2, rs_r1);
buzbee091cc402014-03-31 10:14:40 -0700169 NewLIR4(kThumb2Strex, rs_r1.GetReg(), rs_r2.GetReg(), rs_r0.GetReg(),
170 mirror::Object::MonitorOffset().Int32Value() >> 2);
buzbee2700f7e2014-03-07 09:46:20 -0800171 LIR* lock_success_branch = OpCmpImmBranch(kCondEq, rs_r1, 0, NULL);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700172
173
174 LIR* slow_path_target = NewLIR0(kPseudoTargetLabel);
175 not_unlocked_branch->target = slow_path_target;
176 if (null_check_branch != nullptr) {
177 null_check_branch->target = slow_path_target;
178 }
179 // TODO: move to a slow path.
180 // Go expensive route - artLockObjectFromCode(obj);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700181 LoadWordDisp(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pLockObject).Int32Value(), rs_rARM_LR);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000182 ClobberCallerSave();
buzbee2700f7e2014-03-07 09:46:20 -0800183 LIR* call_inst = OpReg(kOpBlx, rs_rARM_LR);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700184 MarkSafepointPC(call_inst);
185
186 LIR* success_target = NewLIR0(kPseudoTargetLabel);
187 lock_success_branch->target = success_target;
Hans Boehm48f5c472014-06-27 14:50:10 -0700188 GenMemBarrier(kLoadAny);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700189 } else {
190 // Explicit null-check as slow-path is entered using an IT.
buzbee2700f7e2014-03-07 09:46:20 -0800191 GenNullCheck(rs_r0, opt_flags);
buzbee695d13a2014-04-19 13:32:20 -0700192 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
buzbee091cc402014-03-31 10:14:40 -0700193 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
194 mirror::Object::MonitorOffset().Int32Value() >> 2);
Dave Allisonf9439142014-03-27 15:10:22 -0700195 MarkPossibleNullPointerException(opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800196 // Zero out the read barrier bits.
197 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
198 // r1 will be zero except for the rb bits if the following
199 // cmp-and-branch branches to eq where r2 will be used. Copy the
200 // read barrier bits into r2.
201 OpRegRegReg(kOpOr, rs_r2, rs_r2, rs_r1);
202 OpRegImm(kOpCmp, rs_r3, 0);
203
Dave Allison3da67a52014-04-02 17:03:45 -0700204 LIR* it = OpIT(kCondEq, "");
buzbee091cc402014-03-31 10:14:40 -0700205 NewLIR4(kThumb2Strex/*eq*/, rs_r1.GetReg(), rs_r2.GetReg(), rs_r0.GetReg(),
206 mirror::Object::MonitorOffset().Int32Value() >> 2);
Dave Allison3da67a52014-04-02 17:03:45 -0700207 OpEndIT(it);
buzbee2700f7e2014-03-07 09:46:20 -0800208 OpRegImm(kOpCmp, rs_r1, 0);
Dave Allison3da67a52014-04-02 17:03:45 -0700209 it = OpIT(kCondNe, "T");
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700210 // Go expensive route - artLockObjectFromCode(self, obj);
buzbee091cc402014-03-31 10:14:40 -0700211 LoadWordDisp/*ne*/(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pLockObject).Int32Value(),
212 rs_rARM_LR);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000213 ClobberCallerSave();
buzbee2700f7e2014-03-07 09:46:20 -0800214 LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rARM_LR);
Dave Allison3da67a52014-04-02 17:03:45 -0700215 OpEndIT(it);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700216 MarkSafepointPC(call_inst);
Hans Boehm48f5c472014-06-27 14:50:10 -0700217 GenMemBarrier(kLoadAny);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700218 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700219}
220
221/*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700222 * Handle thin locked -> unlocked transition inline or else call out to quick entrypoint. For more
223 * details see monitor.cc. Note the code below doesn't use ldrex/strex as the code holds the lock
224 * and can only give away ownership if its suspended.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700225 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700226void ArmMir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700227 FlushAllRegs();
buzbee2700f7e2014-03-07 09:46:20 -0800228 LoadValueDirectFixed(rl_src, rs_r0); // Get obj
Brian Carlstrom7940e442013-07-12 13:46:57 -0700229 LockCallTemps(); // Prepare for explicit register usage
Dave Allisonf9439142014-03-27 15:10:22 -0700230 LIR* null_check_branch = nullptr;
buzbee695d13a2014-04-19 13:32:20 -0700231 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700232 constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15.
233 if (kArchVariantHasGoodBranchPredictor) {
234 if ((opt_flags & MIR_IGNORE_NULL_CHECK) && !(cu_->disable_opt & (1 << kNullCheckElimination))) {
235 null_check_branch = nullptr; // No null check.
236 } else {
237 // If the null-check fails its handled by the slow-path to reduce exception related meta-data.
Dave Allison69dfe512014-07-11 17:11:58 +0000238 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Dave Allisonf9439142014-03-27 15:10:22 -0700239 null_check_branch = OpCmpImmBranch(kCondEq, rs_r0, 0, NULL);
240 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700241 }
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800242 if (!kUseReadBarrier) {
243 Load32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); // Get lock
244 } else {
245 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
246 mirror::Object::MonitorOffset().Int32Value() >> 2);
247 }
Dave Allisonf9439142014-03-27 15:10:22 -0700248 MarkPossibleNullPointerException(opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800249 // Zero out the read barrier bits.
250 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
251 // Zero out except the read barrier bits.
252 OpRegRegImm(kOpAnd, rs_r1, rs_r1, LockWord::kReadBarrierStateMaskShifted);
253 LIR* slow_unlock_branch = OpCmpBranch(kCondNe, rs_r3, rs_r2, NULL);
Hans Boehm48f5c472014-06-27 14:50:10 -0700254 GenMemBarrier(kAnyStore);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800255 LIR* unlock_success_branch;
256 if (!kUseReadBarrier) {
257 Store32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1);
258 unlock_success_branch = OpUnconditionalBranch(NULL);
259 } else {
260 NewLIR4(kThumb2Strex, rs_r2.GetReg(), rs_r1.GetReg(), rs_r0.GetReg(),
261 mirror::Object::MonitorOffset().Int32Value() >> 2);
262 unlock_success_branch = OpCmpImmBranch(kCondEq, rs_r2, 0, NULL);
263 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700264 LIR* slow_path_target = NewLIR0(kPseudoTargetLabel);
265 slow_unlock_branch->target = slow_path_target;
266 if (null_check_branch != nullptr) {
267 null_check_branch->target = slow_path_target;
268 }
269 // TODO: move to a slow path.
270 // Go expensive route - artUnlockObjectFromCode(obj);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700271 LoadWordDisp(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject).Int32Value(), rs_rARM_LR);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000272 ClobberCallerSave();
buzbee2700f7e2014-03-07 09:46:20 -0800273 LIR* call_inst = OpReg(kOpBlx, rs_rARM_LR);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700274 MarkSafepointPC(call_inst);
275
276 LIR* success_target = NewLIR0(kPseudoTargetLabel);
277 unlock_success_branch->target = success_target;
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700278 } else {
279 // Explicit null-check as slow-path is entered using an IT.
buzbee2700f7e2014-03-07 09:46:20 -0800280 GenNullCheck(rs_r0, opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800281 if (!kUseReadBarrier) {
282 Load32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); // Get lock
283 } else {
284 // If we use read barriers, we need to use atomic instructions.
285 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
286 mirror::Object::MonitorOffset().Int32Value() >> 2);
287 }
Dave Allisonb373e092014-02-20 16:06:36 -0800288 MarkPossibleNullPointerException(opt_flags);
buzbee695d13a2014-04-19 13:32:20 -0700289 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800290 // Zero out the read barrier bits.
291 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
292 // Zero out except the read barrier bits.
293 OpRegRegImm(kOpAnd, rs_r1, rs_r1, LockWord::kReadBarrierStateMaskShifted);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700294 // Is lock unheld on lock or held by us (==thread_id) on unlock?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800295 OpRegReg(kOpCmp, rs_r3, rs_r2);
296 if (!kUseReadBarrier) {
297 LIR* it = OpIT(kCondEq, "EE");
298 if (GenMemBarrier(kAnyStore)) {
299 UpdateIT(it, "TEE");
300 }
301 Store32Disp/*eq*/(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1);
302 // Go expensive route - UnlockObjectFromCode(obj);
303 LoadWordDisp/*ne*/(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject).Int32Value(),
304 rs_rARM_LR);
305 ClobberCallerSave();
306 LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rARM_LR);
307 OpEndIT(it);
308 MarkSafepointPC(call_inst);
309 } else {
310 // If we use read barriers, we need to use atomic instructions.
311 LIR* it = OpIT(kCondEq, "");
312 if (GenMemBarrier(kAnyStore)) {
313 UpdateIT(it, "T");
314 }
315 NewLIR4/*eq*/(kThumb2Strex, rs_r2.GetReg(), rs_r1.GetReg(), rs_r0.GetReg(),
316 mirror::Object::MonitorOffset().Int32Value() >> 2);
317 OpEndIT(it);
318 // Since we know r2 wasn't zero before the above it instruction,
319 // if r2 is zero here, we know r3 was equal to r2 and the strex
320 // suceeded (we're done). Otherwise (either r3 wasn't equal to r2
321 // or the strex failed), call the entrypoint.
322 OpRegImm(kOpCmp, rs_r2, 0);
323 LIR* it2 = OpIT(kCondNe, "T");
324 // Go expensive route - UnlockObjectFromCode(obj);
325 LoadWordDisp/*ne*/(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject).Int32Value(),
326 rs_rARM_LR);
327 ClobberCallerSave();
328 LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rARM_LR);
329 OpEndIT(it2);
330 MarkSafepointPC(call_inst);
Andreas Gampeb14329f2014-05-15 11:16:06 -0700331 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700332 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700333}
334
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700335void ArmMir2Lir::GenMoveException(RegLocation rl_dest) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700336 int ex_offset = Thread::ExceptionOffset<4>().Int32Value();
buzbeea0cd2d72014-06-01 09:33:49 -0700337 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
338 RegStorage reset_reg = AllocTempRef();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000339 LoadRefDisp(rs_rARM_SELF, ex_offset, rl_result.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700340 LoadConstant(reset_reg, 0);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000341 StoreRefDisp(rs_rARM_SELF, ex_offset, reset_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700342 FreeTemp(reset_reg);
343 StoreValue(rl_dest, rl_result);
344}
345
Vladimir Markobf535be2014-11-19 18:52:35 +0000346void ArmMir2Lir::UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800347 RegStorage reg_card_base = AllocTemp();
348 RegStorage reg_card_no = AllocTemp();
Ian Rogersdd7624d2014-03-14 17:43:00 -0700349 LoadWordDisp(rs_rARM_SELF, Thread::CardTableOffset<4>().Int32Value(), reg_card_base);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700350 OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift);
buzbee2700f7e2014-03-07 09:46:20 -0800351 StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700352 FreeTemp(reg_card_base);
353 FreeTemp(reg_card_no);
354}
355
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700356void ArmMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700357 int spill_count = num_core_spills_ + num_fp_spills_;
358 /*
359 * On entry, r0, r1, r2 & r3 are live. Let the register allocation
360 * mechanism know so it doesn't try to use any of them when
361 * expanding the frame or flushing. This leaves the utility
362 * code with a single temp: r12. This should be enough.
363 */
buzbee091cc402014-03-31 10:14:40 -0700364 LockTemp(rs_r0);
365 LockTemp(rs_r1);
366 LockTemp(rs_r2);
367 LockTemp(rs_r3);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700368
369 /*
370 * We can safely skip the stack overflow check if we're
371 * a leaf *and* our frame size < fudge factor.
372 */
Dave Allison648d7112014-07-25 16:15:27 -0700373 bool skip_overflow_check = mir_graph_->MethodIsLeaf() && !FrameNeedsStackCheck(frame_size_, kArm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700374 NewLIR0(kPseudoMethodEntry);
Dave Allison648d7112014-07-25 16:15:27 -0700375 const size_t kStackOverflowReservedUsableBytes = GetStackOverflowReservedBytes(kArm);
Andreas Gampe7cd26f32014-06-18 17:01:15 -0700376 bool large_frame = (static_cast<size_t>(frame_size_) > kStackOverflowReservedUsableBytes);
Dave Allison648d7112014-07-25 16:15:27 -0700377 bool generate_explicit_stack_overflow_check = large_frame ||
378 !cu_->compiler_driver->GetCompilerOptions().GetImplicitStackOverflowChecks();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700379 if (!skip_overflow_check) {
Dave Allison648d7112014-07-25 16:15:27 -0700380 if (generate_explicit_stack_overflow_check) {
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000381 if (!large_frame) {
382 /* Load stack limit */
383 LockTemp(rs_r12);
384 Load32Disp(rs_rARM_SELF, Thread::StackEndOffset<4>().Int32Value(), rs_r12);
385 }
Dave Allison5cd33752014-04-15 15:57:58 -0700386 } else {
387 // Implicit stack overflow check.
388 // Generate a load from [sp, #-overflowsize]. If this is in the stack
389 // redzone we will get a segmentation fault.
390 //
391 // Caveat coder: if someone changes the kStackOverflowReservedBytes value
392 // we need to make sure that it's loadable in an immediate field of
393 // a sub instruction. Otherwise we will get a temp allocation and the
394 // code size will increase.
395 //
396 // This is done before the callee save instructions to avoid any possibility
397 // of these overflowing. This uses r12 and that's never saved in a callee
398 // save.
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700399 OpRegRegImm(kOpSub, rs_r12, rs_rARM_SP, GetStackOverflowReservedBytes(kArm));
Dave Allison5cd33752014-04-15 15:57:58 -0700400 Load32Disp(rs_r12, 0, rs_r12);
401 MarkPossibleStackOverflowException();
Dave Allisonb373e092014-02-20 16:06:36 -0800402 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700403 }
404 /* Spill core callee saves */
Vladimir Marko9d5c25a2014-11-26 15:42:32 +0000405 if (core_spill_mask_ == 0u) {
406 // Nothing to spill.
407 } else if ((core_spill_mask_ & ~(0xffu | (1u << rs_rARM_LR.GetRegNum()))) == 0u) {
408 // Spilling only low regs and/or LR, use 16-bit PUSH.
409 constexpr int lr_bit_shift = rs_rARM_LR.GetRegNum() - 8;
410 NewLIR1(kThumbPush,
411 (core_spill_mask_ & ~(1u << rs_rARM_LR.GetRegNum())) |
412 ((core_spill_mask_ & (1u << rs_rARM_LR.GetRegNum())) >> lr_bit_shift));
413 } else if (IsPowerOfTwo(core_spill_mask_)) {
414 // kThumb2Push cannot be used to spill a single register.
415 NewLIR1(kThumb2Push1, CTZ(core_spill_mask_));
416 } else {
417 NewLIR1(kThumb2Push, core_spill_mask_);
418 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700419 /* Need to spill any FP regs? */
420 if (num_fp_spills_) {
421 /*
422 * NOTE: fp spills are a little different from core spills in that
423 * they are pushed as a contiguous block. When promoting from
424 * the fp set, we must allocate all singles from s16..highest-promoted
425 */
426 NewLIR1(kThumb2VPushCS, num_fp_spills_);
427 }
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700428
Mathieu Chartier05a48b12014-03-31 16:11:41 -0700429 const int spill_size = spill_count * 4;
430 const int frame_size_without_spills = frame_size_ - spill_size;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700431 if (!skip_overflow_check) {
Dave Allison648d7112014-07-25 16:15:27 -0700432 if (generate_explicit_stack_overflow_check) {
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700433 class StackOverflowSlowPath : public LIRSlowPath {
434 public:
435 StackOverflowSlowPath(Mir2Lir* m2l, LIR* branch, bool restore_lr, size_t sp_displace)
436 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch, nullptr), restore_lr_(restore_lr),
437 sp_displace_(sp_displace) {
438 }
439 void Compile() OVERRIDE {
440 m2l_->ResetRegPool();
441 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -0700442 GenerateTargetLabel(kPseudoThrowTarget);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700443 if (restore_lr_) {
buzbee2700f7e2014-03-07 09:46:20 -0800444 m2l_->LoadWordDisp(rs_rARM_SP, sp_displace_ - 4, rs_rARM_LR);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700445 }
buzbee2700f7e2014-03-07 09:46:20 -0800446 m2l_->OpRegImm(kOpAdd, rs_rARM_SP, sp_displace_);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700447 m2l_->ClobberCallerSave();
Ian Rogersdd7624d2014-03-14 17:43:00 -0700448 ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pThrowStackOverflow);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700449 // Load the entrypoint directly into the pc instead of doing a load + branch. Assumes
450 // codegen and target are in thumb2 mode.
buzbee695d13a2014-04-19 13:32:20 -0700451 // NOTE: native pointer.
buzbee2700f7e2014-03-07 09:46:20 -0800452 m2l_->LoadWordDisp(rs_rARM_SELF, func_offset.Int32Value(), rs_rARM_PC);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700453 }
454
455 private:
456 const bool restore_lr_;
457 const size_t sp_displace_;
458 };
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000459 if (large_frame) {
460 // Note: may need a temp reg, and we only have r12 free at this point.
buzbee2700f7e2014-03-07 09:46:20 -0800461 OpRegRegImm(kOpSub, rs_rARM_LR, rs_rARM_SP, frame_size_without_spills);
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000462 Load32Disp(rs_rARM_SELF, Thread::StackEndOffset<4>().Int32Value(), rs_r12);
buzbee2700f7e2014-03-07 09:46:20 -0800463 LIR* branch = OpCmpBranch(kCondUlt, rs_rARM_LR, rs_r12, nullptr);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700464 // Need to restore LR since we used it as a temp.
Mathieu Chartier05a48b12014-03-31 16:11:41 -0700465 AddSlowPath(new(arena_)StackOverflowSlowPath(this, branch, true, spill_size));
buzbee2700f7e2014-03-07 09:46:20 -0800466 OpRegCopy(rs_rARM_SP, rs_rARM_LR); // Establish stack
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700467 } else {
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000468 /*
469 * If the frame is small enough we are guaranteed to have enough space that remains to
470 * handle signals on the user stack. However, we may not have any free temp
471 * registers at this point, so we'll temporarily add LR to the temp pool.
472 */
473 DCHECK(!GetRegInfo(rs_rARM_LR)->IsTemp());
474 MarkTemp(rs_rARM_LR);
475 FreeTemp(rs_rARM_LR);
buzbee2700f7e2014-03-07 09:46:20 -0800476 OpRegRegImm(kOpSub, rs_rARM_SP, rs_rARM_SP, frame_size_without_spills);
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000477 Clobber(rs_rARM_LR);
478 UnmarkTemp(rs_rARM_LR);
buzbee2700f7e2014-03-07 09:46:20 -0800479 LIR* branch = OpCmpBranch(kCondUlt, rs_rARM_SP, rs_r12, nullptr);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700480 AddSlowPath(new(arena_)StackOverflowSlowPath(this, branch, false, frame_size_));
481 }
Dave Allisonb373e092014-02-20 16:06:36 -0800482 } else {
Dave Allison5cd33752014-04-15 15:57:58 -0700483 // Implicit stack overflow check has already been done. Just make room on the
484 // stack for the frame now.
Dave Allisonf9439142014-03-27 15:10:22 -0700485 OpRegImm(kOpSub, rs_rARM_SP, frame_size_without_spills);
Dave Allisonb373e092014-02-20 16:06:36 -0800486 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700487 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800488 OpRegImm(kOpSub, rs_rARM_SP, frame_size_without_spills);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700489 }
490
491 FlushIns(ArgLocs, rl_method);
492
buzbee091cc402014-03-31 10:14:40 -0700493 FreeTemp(rs_r0);
494 FreeTemp(rs_r1);
495 FreeTemp(rs_r2);
496 FreeTemp(rs_r3);
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000497 FreeTemp(rs_r12);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700498}
499
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700500void ArmMir2Lir::GenExitSequence() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700501 int spill_count = num_core_spills_ + num_fp_spills_;
502 /*
503 * In the exit path, r0/r1 are live - make sure they aren't
504 * allocated by the register utilities as temps.
505 */
buzbee091cc402014-03-31 10:14:40 -0700506 LockTemp(rs_r0);
507 LockTemp(rs_r1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700508
509 NewLIR0(kPseudoMethodExit);
buzbee2700f7e2014-03-07 09:46:20 -0800510 OpRegImm(kOpAdd, rs_rARM_SP, frame_size_ - (spill_count * 4));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700511 /* Need to restore any FP callee saves? */
512 if (num_fp_spills_) {
513 NewLIR1(kThumb2VPopCS, num_fp_spills_);
514 }
Vladimir Marko9d5c25a2014-11-26 15:42:32 +0000515 if ((core_spill_mask_ & (1 << rs_rARM_LR.GetRegNum())) != 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700516 /* Unspill rARM_LR to rARM_PC */
buzbee091cc402014-03-31 10:14:40 -0700517 core_spill_mask_ &= ~(1 << rs_rARM_LR.GetRegNum());
518 core_spill_mask_ |= (1 << rs_rARM_PC.GetRegNum());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700519 }
Vladimir Marko9d5c25a2014-11-26 15:42:32 +0000520 if (core_spill_mask_ == 0u) {
521 // Nothing to unspill.
522 } else if ((core_spill_mask_ & ~(0xffu | (1u << rs_rARM_PC.GetRegNum()))) == 0u) {
523 // Unspilling only low regs and/or PC, use 16-bit POP.
524 constexpr int pc_bit_shift = rs_rARM_PC.GetRegNum() - 8;
525 NewLIR1(kThumbPop,
526 (core_spill_mask_ & ~(1u << rs_rARM_PC.GetRegNum())) |
527 ((core_spill_mask_ & (1u << rs_rARM_PC.GetRegNum())) >> pc_bit_shift));
528 } else if (IsPowerOfTwo(core_spill_mask_)) {
529 // kThumb2Pop cannot be used to unspill a single register.
530 NewLIR1(kThumb2Pop1, CTZ(core_spill_mask_));
531 } else {
532 NewLIR1(kThumb2Pop, core_spill_mask_);
533 }
534 if ((core_spill_mask_ & (1 << rs_rARM_PC.GetRegNum())) == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700535 /* We didn't pop to rARM_PC, so must do a bv rARM_LR */
buzbee091cc402014-03-31 10:14:40 -0700536 NewLIR1(kThumbBx, rs_rARM_LR.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700537 }
538}
539
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800540void ArmMir2Lir::GenSpecialExitSequence() {
buzbee091cc402014-03-31 10:14:40 -0700541 NewLIR1(kThumbBx, rs_rARM_LR.GetReg());
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800542}
543
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000544void ArmMir2Lir::GenSpecialEntryForSuspend() {
545 // Keep 16-byte stack alignment - push r0, i.e. ArtMethod*, r5, r6, lr.
546 DCHECK(!IsTemp(rs_r5));
547 DCHECK(!IsTemp(rs_r6));
548 core_spill_mask_ =
549 (1u << rs_r5.GetRegNum()) | (1u << rs_r6.GetRegNum()) | (1u << rs_rARM_LR.GetRegNum());
550 num_core_spills_ = 3u;
551 fp_spill_mask_ = 0u;
552 num_fp_spills_ = 0u;
553 frame_size_ = 16u;
554 core_vmap_table_.clear();
555 fp_vmap_table_.clear();
556 NewLIR1(kThumbPush, (1u << rs_r0.GetRegNum()) | // ArtMethod*
557 (core_spill_mask_ & ~(1u << rs_rARM_LR.GetRegNum())) | // Spills other than LR.
558 (1u << 8)); // LR encoded for 16-bit push.
559}
560
561void ArmMir2Lir::GenSpecialExitForSuspend() {
562 // Pop the frame. (ArtMethod* no longer needed but restore it anyway.)
563 NewLIR1(kThumb2Pop, (1u << rs_r0.GetRegNum()) | core_spill_mask_); // 32-bit because of LR.
564}
565
Vladimir Markof4da6752014-08-01 19:04:18 +0100566static bool ArmUseRelativeCall(CompilationUnit* cu, const MethodReference& target_method) {
567 // Emit relative calls only within a dex file due to the limited range of the BL insn.
568 return cu->dex_file == target_method.dex_file;
569}
570
571/*
572 * Bit of a hack here - in the absence of a real scheduling pass,
573 * emit the next instruction in static & direct invoke sequences.
574 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700575static int ArmNextSDCallInsn(CompilationUnit* cu, CallInfo* info ATTRIBUTE_UNUSED,
Vladimir Markof4da6752014-08-01 19:04:18 +0100576 int state, const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700577 uint32_t unused_idx ATTRIBUTE_UNUSED,
Vladimir Markof4da6752014-08-01 19:04:18 +0100578 uintptr_t direct_code, uintptr_t direct_method,
579 InvokeType type) {
580 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
581 if (direct_code != 0 && direct_method != 0) {
582 switch (state) {
583 case 0: // Get the current Method* [sets kArg0]
584 if (direct_code != static_cast<uintptr_t>(-1)) {
585 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
586 } else if (ArmUseRelativeCall(cu, target_method)) {
587 // Defer to linker patch.
588 } else {
589 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
590 }
591 if (direct_method != static_cast<uintptr_t>(-1)) {
592 cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method);
593 } else {
594 cg->LoadMethodAddress(target_method, type, kArg0);
595 }
596 break;
597 default:
598 return -1;
599 }
600 } else {
601 RegStorage arg0_ref = cg->TargetReg(kArg0, kRef);
602 switch (state) {
603 case 0: // Get the current Method* [sets kArg0]
604 // TUNING: we can save a reg copy if Method* has been promoted.
605 cg->LoadCurrMethodDirect(arg0_ref);
606 break;
607 case 1: // Get method->dex_cache_resolved_methods_
608 cg->LoadRefDisp(arg0_ref,
609 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
610 arg0_ref,
611 kNotVolatile);
612 // Set up direct code if known.
613 if (direct_code != 0) {
614 if (direct_code != static_cast<uintptr_t>(-1)) {
615 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
616 } else if (ArmUseRelativeCall(cu, target_method)) {
617 // Defer to linker patch.
618 } else {
619 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
620 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
621 }
622 }
623 break;
624 case 2: // Grab target method*
625 CHECK_EQ(cu->dex_file, target_method.dex_file);
626 cg->LoadRefDisp(arg0_ref,
627 mirror::ObjectArray<mirror::Object>::OffsetOfElement(
628 target_method.dex_method_index).Int32Value(),
629 arg0_ref,
630 kNotVolatile);
631 break;
632 case 3: // Grab the code from the method*
633 if (direct_code == 0) {
634 // kInvokeTgt := arg0_ref->entrypoint
635 cg->LoadWordDisp(arg0_ref,
Mathieu Chartier2d721012014-11-10 11:08:06 -0800636 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
637 kArmPointerSize).Int32Value(), cg->TargetPtrReg(kInvokeTgt));
Vladimir Markof4da6752014-08-01 19:04:18 +0100638 }
639 break;
640 default:
641 return -1;
642 }
643 }
644 return state + 1;
645}
646
647NextCallInsn ArmMir2Lir::GetNextSDCallInsn() {
648 return ArmNextSDCallInsn;
649}
650
651LIR* ArmMir2Lir::CallWithLinkerFixup(const MethodReference& target_method, InvokeType type) {
652 // For ARM, just generate a relative BL instruction that will be filled in at 'link time'.
653 // If the target turns out to be too far, the linker will generate a thunk for dispatch.
654 int target_method_idx = target_method.dex_method_index;
655 const DexFile* target_dex_file = target_method.dex_file;
656
657 // Generate the call instruction and save index, dex_file, and type.
658 // NOTE: Method deduplication takes linker patches into account, so we can just pass 0
659 // as a placeholder for the offset.
660 LIR* call = RawLIR(current_dalvik_offset_, kThumb2Bl, 0,
661 target_method_idx, WrapPointer(const_cast<DexFile*>(target_dex_file)), type);
662 AppendLIR(call);
663 call_method_insns_.push_back(call);
664 return call;
665}
666
667LIR* ArmMir2Lir::GenCallInsn(const MirMethodLoweringInfo& method_info) {
668 LIR* call_insn;
669 if (method_info.FastPath() && ArmUseRelativeCall(cu_, method_info.GetTargetMethod()) &&
670 (method_info.GetSharpType() == kDirect || method_info.GetSharpType() == kStatic) &&
671 method_info.DirectCode() == static_cast<uintptr_t>(-1)) {
672 call_insn = CallWithLinkerFixup(method_info.GetTargetMethod(), method_info.GetSharpType());
673 } else {
674 call_insn = OpReg(kOpBlx, TargetPtrReg(kInvokeTgt));
675 }
676 return call_insn;
677}
678
Brian Carlstrom7940e442013-07-12 13:46:57 -0700679} // namespace art