blob: 3081c9e7525b272d214380bf902868afdd7f1722 [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"
Vladimir Marko20f85592015-03-19 10:07:02 +000026#include "driver/compiler_options.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070027#include "gc/accounting/card_table.h"
Vladimir Markof4da6752014-08-01 19:04:18 +010028#include "mirror/art_method.h"
29#include "mirror/object_array-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070030#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe7e499922015-01-06 08:28:12 -080031#include "utils.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070032
33namespace art {
34
Brian Carlstrom7940e442013-07-12 13:46:57 -070035/*
36 * The sparse table in the literal pool is an array of <key,displacement>
37 * pairs. For each set, we'll load them as a pair using ldmia.
38 * This means that the register number of the temp we use for the key
39 * must be lower than the reg for the displacement.
40 *
41 * The test loop will look something like:
42 *
buzbee2700f7e2014-03-07 09:46:20 -080043 * adr r_base, <table>
Brian Carlstrom7940e442013-07-12 13:46:57 -070044 * ldr r_val, [rARM_SP, v_reg_off]
45 * mov r_idx, #table_size
46 * lp:
buzbee2700f7e2014-03-07 09:46:20 -080047 * ldmia r_base!, {r_key, r_disp}
Brian Carlstrom7940e442013-07-12 13:46:57 -070048 * sub r_idx, #1
49 * cmp r_val, r_key
50 * ifeq
51 * add rARM_PC, r_disp ; This is the branch from which we compute displacement
52 * cbnz r_idx, lp
53 */
Andreas Gampe48971b32014-08-06 10:09:01 -070054void ArmMir2Lir::GenLargeSparseSwitch(MIR* mir, uint32_t table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -070055 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -070056 // Add the table to the list - we'll process it later
57 SwitchTable *tab_rec =
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000058 static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData));
Chao-ying Fu72f53af2014-11-11 16:48:40 -080059 tab_rec->switch_mir = mir;
Brian Carlstrom7940e442013-07-12 13:46:57 -070060 tab_rec->table = table;
61 tab_rec->vaddr = current_dalvik_offset_;
buzbee0d829482013-10-11 15:24:55 -070062 uint32_t size = table[1];
Vladimir Markoe39c54e2014-09-22 14:50:02 +010063 switch_tables_.push_back(tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -070064
65 // Get the switch value
66 rl_src = LoadValue(rl_src, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -080067 RegStorage r_base = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070068 /* Allocate key and disp temps */
buzbee2700f7e2014-03-07 09:46:20 -080069 RegStorage r_key = AllocTemp();
70 RegStorage r_disp = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070071 // Make sure r_key's register number is less than r_disp's number for ldmia
buzbee2700f7e2014-03-07 09:46:20 -080072 if (r_key.GetReg() > r_disp.GetReg()) {
73 RegStorage tmp = r_disp;
Brian Carlstrom7940e442013-07-12 13:46:57 -070074 r_disp = r_key;
75 r_key = tmp;
76 }
77 // Materialize a pointer to the switch table
buzbee2700f7e2014-03-07 09:46:20 -080078 NewLIR3(kThumb2Adr, r_base.GetReg(), 0, WrapPointer(tab_rec));
Brian Carlstrom7940e442013-07-12 13:46:57 -070079 // Set up r_idx
buzbee2700f7e2014-03-07 09:46:20 -080080 RegStorage r_idx = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 LoadConstant(r_idx, size);
82 // Establish loop branch target
83 LIR* target = NewLIR0(kPseudoTargetLabel);
84 // Load next key/disp
buzbee091cc402014-03-31 10:14:40 -070085 NewLIR2(kThumb2LdmiaWB, r_base.GetReg(), (1 << r_key.GetRegNum()) | (1 << r_disp.GetRegNum()));
buzbee2700f7e2014-03-07 09:46:20 -080086 OpRegReg(kOpCmp, r_key, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070087 // Go if match. NOTE: No instruction set switch here - must stay Thumb2
Dave Allison3da67a52014-04-02 17:03:45 -070088 LIR* it = OpIT(kCondEq, "");
buzbee2700f7e2014-03-07 09:46:20 -080089 LIR* switch_branch = NewLIR1(kThumb2AddPCR, r_disp.GetReg());
Dave Allison3da67a52014-04-02 17:03:45 -070090 OpEndIT(it);
Brian Carlstrom7940e442013-07-12 13:46:57 -070091 tab_rec->anchor = switch_branch;
92 // Needs to use setflags encoding here
Vladimir Markodbb8c492014-02-28 17:36:39 +000093 OpRegRegImm(kOpSub, r_idx, r_idx, 1); // For value == 1, this should set flags.
Vladimir Marko8dea81c2014-06-06 14:50:36 +010094 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Brian Carlstrom7940e442013-07-12 13:46:57 -070095 OpCondBranch(kCondNe, target);
96}
97
98
Andreas Gampe48971b32014-08-06 10:09:01 -070099void ArmMir2Lir::GenLargePackedSwitch(MIR* mir, uint32_t table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700100 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700101 // Add the table to the list - we'll process it later
102 SwitchTable *tab_rec =
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000103 static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData));
Chao-ying Fu72f53af2014-11-11 16:48:40 -0800104 tab_rec->switch_mir = mir;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700105 tab_rec->table = table;
106 tab_rec->vaddr = current_dalvik_offset_;
buzbee0d829482013-10-11 15:24:55 -0700107 uint32_t size = table[1];
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100108 switch_tables_.push_back(tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700109
110 // Get the switch value
111 rl_src = LoadValue(rl_src, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800112 RegStorage table_base = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700113 // Materialize a pointer to the switch table
buzbee2700f7e2014-03-07 09:46:20 -0800114 NewLIR3(kThumb2Adr, table_base.GetReg(), 0, WrapPointer(tab_rec));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700115 int low_key = s4FromSwitchData(&table[2]);
buzbee2700f7e2014-03-07 09:46:20 -0800116 RegStorage keyReg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117 // Remove the bias, if necessary
118 if (low_key == 0) {
buzbee2700f7e2014-03-07 09:46:20 -0800119 keyReg = rl_src.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700120 } else {
121 keyReg = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -0800122 OpRegRegImm(kOpSub, keyReg, rl_src.reg, low_key);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123 }
124 // Bounds check - if < 0 or >= size continue following switch
125 OpRegImm(kOpCmp, keyReg, size-1);
126 LIR* branch_over = OpCondBranch(kCondHi, NULL);
127
128 // Load the displacement from the switch table
buzbee2700f7e2014-03-07 09:46:20 -0800129 RegStorage disp_reg = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -0700130 LoadBaseIndexed(table_base, keyReg, disp_reg, 2, k32);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700131
132 // ..and go! NOTE: No instruction set switch here - must stay Thumb2
buzbee2700f7e2014-03-07 09:46:20 -0800133 LIR* switch_branch = NewLIR1(kThumb2AddPCR, disp_reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700134 tab_rec->anchor = switch_branch;
135
136 /* branch_over target here */
137 LIR* target = NewLIR0(kPseudoTargetLabel);
138 branch_over->target = target;
139}
140
141/*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700142 * Handle unlocked -> thin locked transition inline or else call out to quick entrypoint. For more
143 * details see monitor.cc.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700144 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700145void ArmMir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700146 FlushAllRegs();
buzbee695d13a2014-04-19 13:32:20 -0700147 // FIXME: need separate LoadValues for object references.
buzbee2700f7e2014-03-07 09:46:20 -0800148 LoadValueDirectFixed(rl_src, rs_r0); // Get obj
Brian Carlstrom7940e442013-07-12 13:46:57 -0700149 LockCallTemps(); // Prepare for explicit register usage
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700150 constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15.
151 if (kArchVariantHasGoodBranchPredictor) {
Dave Allisonf9439142014-03-27 15:10:22 -0700152 LIR* null_check_branch = nullptr;
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700153 if ((opt_flags & MIR_IGNORE_NULL_CHECK) && !(cu_->disable_opt & (1 << kNullCheckElimination))) {
154 null_check_branch = nullptr; // No null check.
155 } else {
156 // If the null-check fails its handled by the slow-path to reduce exception related meta-data.
Dave Allison69dfe512014-07-11 17:11:58 +0000157 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Dave Allisonf9439142014-03-27 15:10:22 -0700158 null_check_branch = OpCmpImmBranch(kCondEq, rs_r0, 0, NULL);
159 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700160 }
buzbee695d13a2014-04-19 13:32:20 -0700161 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
buzbee091cc402014-03-31 10:14:40 -0700162 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
163 mirror::Object::MonitorOffset().Int32Value() >> 2);
Dave Allisonf9439142014-03-27 15:10:22 -0700164 MarkPossibleNullPointerException(opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800165 // Zero out the read barrier bits.
166 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
167 LIR* not_unlocked_branch = OpCmpImmBranch(kCondNe, rs_r3, 0, NULL);
168 // r1 is zero except for the rb bits here. Copy the read barrier bits into r2.
169 OpRegRegReg(kOpOr, rs_r2, rs_r2, rs_r1);
buzbee091cc402014-03-31 10:14:40 -0700170 NewLIR4(kThumb2Strex, rs_r1.GetReg(), rs_r2.GetReg(), rs_r0.GetReg(),
171 mirror::Object::MonitorOffset().Int32Value() >> 2);
buzbee2700f7e2014-03-07 09:46:20 -0800172 LIR* lock_success_branch = OpCmpImmBranch(kCondEq, rs_r1, 0, NULL);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700173
174
175 LIR* slow_path_target = NewLIR0(kPseudoTargetLabel);
176 not_unlocked_branch->target = slow_path_target;
177 if (null_check_branch != nullptr) {
178 null_check_branch->target = slow_path_target;
179 }
180 // TODO: move to a slow path.
181 // Go expensive route - artLockObjectFromCode(obj);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700182 LoadWordDisp(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pLockObject).Int32Value(), rs_rARM_LR);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000183 ClobberCallerSave();
buzbee2700f7e2014-03-07 09:46:20 -0800184 LIR* call_inst = OpReg(kOpBlx, rs_rARM_LR);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700185 MarkSafepointPC(call_inst);
186
187 LIR* success_target = NewLIR0(kPseudoTargetLabel);
188 lock_success_branch->target = success_target;
Hans Boehm48f5c472014-06-27 14:50:10 -0700189 GenMemBarrier(kLoadAny);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700190 } else {
191 // Explicit null-check as slow-path is entered using an IT.
buzbee2700f7e2014-03-07 09:46:20 -0800192 GenNullCheck(rs_r0, opt_flags);
buzbee695d13a2014-04-19 13:32:20 -0700193 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
buzbee091cc402014-03-31 10:14:40 -0700194 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
195 mirror::Object::MonitorOffset().Int32Value() >> 2);
Dave Allisonf9439142014-03-27 15:10:22 -0700196 MarkPossibleNullPointerException(opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800197 // Zero out the read barrier bits.
198 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
199 // r1 will be zero except for the rb bits if the following
200 // cmp-and-branch branches to eq where r2 will be used. Copy the
201 // read barrier bits into r2.
202 OpRegRegReg(kOpOr, rs_r2, rs_r2, rs_r1);
203 OpRegImm(kOpCmp, rs_r3, 0);
204
Dave Allison3da67a52014-04-02 17:03:45 -0700205 LIR* it = OpIT(kCondEq, "");
buzbee091cc402014-03-31 10:14:40 -0700206 NewLIR4(kThumb2Strex/*eq*/, rs_r1.GetReg(), rs_r2.GetReg(), rs_r0.GetReg(),
207 mirror::Object::MonitorOffset().Int32Value() >> 2);
Dave Allison3da67a52014-04-02 17:03:45 -0700208 OpEndIT(it);
buzbee2700f7e2014-03-07 09:46:20 -0800209 OpRegImm(kOpCmp, rs_r1, 0);
Dave Allison3da67a52014-04-02 17:03:45 -0700210 it = OpIT(kCondNe, "T");
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700211 // Go expensive route - artLockObjectFromCode(self, obj);
buzbee091cc402014-03-31 10:14:40 -0700212 LoadWordDisp/*ne*/(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pLockObject).Int32Value(),
213 rs_rARM_LR);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000214 ClobberCallerSave();
buzbee2700f7e2014-03-07 09:46:20 -0800215 LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rARM_LR);
Dave Allison3da67a52014-04-02 17:03:45 -0700216 OpEndIT(it);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700217 MarkSafepointPC(call_inst);
Hans Boehm48f5c472014-06-27 14:50:10 -0700218 GenMemBarrier(kLoadAny);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700219 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700220}
221
222/*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700223 * Handle thin locked -> unlocked transition inline or else call out to quick entrypoint. For more
224 * details see monitor.cc. Note the code below doesn't use ldrex/strex as the code holds the lock
225 * and can only give away ownership if its suspended.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700226 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700227void ArmMir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228 FlushAllRegs();
buzbee2700f7e2014-03-07 09:46:20 -0800229 LoadValueDirectFixed(rl_src, rs_r0); // Get obj
Brian Carlstrom7940e442013-07-12 13:46:57 -0700230 LockCallTemps(); // Prepare for explicit register usage
Dave Allisonf9439142014-03-27 15:10:22 -0700231 LIR* null_check_branch = nullptr;
buzbee695d13a2014-04-19 13:32:20 -0700232 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700233 constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15.
234 if (kArchVariantHasGoodBranchPredictor) {
235 if ((opt_flags & MIR_IGNORE_NULL_CHECK) && !(cu_->disable_opt & (1 << kNullCheckElimination))) {
236 null_check_branch = nullptr; // No null check.
237 } else {
238 // If the null-check fails its handled by the slow-path to reduce exception related meta-data.
Dave Allison69dfe512014-07-11 17:11:58 +0000239 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Dave Allisonf9439142014-03-27 15:10:22 -0700240 null_check_branch = OpCmpImmBranch(kCondEq, rs_r0, 0, NULL);
241 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700242 }
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800243 if (!kUseReadBarrier) {
244 Load32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); // Get lock
245 } else {
246 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
247 mirror::Object::MonitorOffset().Int32Value() >> 2);
248 }
Dave Allisonf9439142014-03-27 15:10:22 -0700249 MarkPossibleNullPointerException(opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800250 // Zero out the read barrier bits.
251 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
252 // Zero out except the read barrier bits.
253 OpRegRegImm(kOpAnd, rs_r1, rs_r1, LockWord::kReadBarrierStateMaskShifted);
254 LIR* slow_unlock_branch = OpCmpBranch(kCondNe, rs_r3, rs_r2, NULL);
Hans Boehm48f5c472014-06-27 14:50:10 -0700255 GenMemBarrier(kAnyStore);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800256 LIR* unlock_success_branch;
257 if (!kUseReadBarrier) {
258 Store32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1);
259 unlock_success_branch = OpUnconditionalBranch(NULL);
260 } else {
261 NewLIR4(kThumb2Strex, rs_r2.GetReg(), rs_r1.GetReg(), rs_r0.GetReg(),
262 mirror::Object::MonitorOffset().Int32Value() >> 2);
263 unlock_success_branch = OpCmpImmBranch(kCondEq, rs_r2, 0, NULL);
264 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700265 LIR* slow_path_target = NewLIR0(kPseudoTargetLabel);
266 slow_unlock_branch->target = slow_path_target;
267 if (null_check_branch != nullptr) {
268 null_check_branch->target = slow_path_target;
269 }
270 // TODO: move to a slow path.
271 // Go expensive route - artUnlockObjectFromCode(obj);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700272 LoadWordDisp(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject).Int32Value(), rs_rARM_LR);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000273 ClobberCallerSave();
buzbee2700f7e2014-03-07 09:46:20 -0800274 LIR* call_inst = OpReg(kOpBlx, rs_rARM_LR);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700275 MarkSafepointPC(call_inst);
276
277 LIR* success_target = NewLIR0(kPseudoTargetLabel);
278 unlock_success_branch->target = success_target;
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700279 } else {
280 // Explicit null-check as slow-path is entered using an IT.
buzbee2700f7e2014-03-07 09:46:20 -0800281 GenNullCheck(rs_r0, opt_flags);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800282 if (!kUseReadBarrier) {
283 Load32Disp(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1); // Get lock
284 } else {
285 // If we use read barriers, we need to use atomic instructions.
286 NewLIR3(kThumb2Ldrex, rs_r1.GetReg(), rs_r0.GetReg(),
287 mirror::Object::MonitorOffset().Int32Value() >> 2);
288 }
Dave Allisonb373e092014-02-20 16:06:36 -0800289 MarkPossibleNullPointerException(opt_flags);
buzbee695d13a2014-04-19 13:32:20 -0700290 Load32Disp(rs_rARM_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_r2);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800291 // Zero out the read barrier bits.
292 OpRegRegImm(kOpAnd, rs_r3, rs_r1, LockWord::kReadBarrierStateMaskShiftedToggled);
293 // Zero out except the read barrier bits.
294 OpRegRegImm(kOpAnd, rs_r1, rs_r1, LockWord::kReadBarrierStateMaskShifted);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700295 // Is lock unheld on lock or held by us (==thread_id) on unlock?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800296 OpRegReg(kOpCmp, rs_r3, rs_r2);
297 if (!kUseReadBarrier) {
298 LIR* it = OpIT(kCondEq, "EE");
299 if (GenMemBarrier(kAnyStore)) {
300 UpdateIT(it, "TEE");
301 }
302 Store32Disp/*eq*/(rs_r0, mirror::Object::MonitorOffset().Int32Value(), rs_r1);
303 // Go expensive route - UnlockObjectFromCode(obj);
304 LoadWordDisp/*ne*/(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject).Int32Value(),
305 rs_rARM_LR);
306 ClobberCallerSave();
307 LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rARM_LR);
308 OpEndIT(it);
309 MarkSafepointPC(call_inst);
310 } else {
311 // If we use read barriers, we need to use atomic instructions.
312 LIR* it = OpIT(kCondEq, "");
313 if (GenMemBarrier(kAnyStore)) {
314 UpdateIT(it, "T");
315 }
316 NewLIR4/*eq*/(kThumb2Strex, rs_r2.GetReg(), rs_r1.GetReg(), rs_r0.GetReg(),
317 mirror::Object::MonitorOffset().Int32Value() >> 2);
318 OpEndIT(it);
319 // Since we know r2 wasn't zero before the above it instruction,
320 // if r2 is zero here, we know r3 was equal to r2 and the strex
321 // suceeded (we're done). Otherwise (either r3 wasn't equal to r2
322 // or the strex failed), call the entrypoint.
323 OpRegImm(kOpCmp, rs_r2, 0);
324 LIR* it2 = OpIT(kCondNe, "T");
325 // Go expensive route - UnlockObjectFromCode(obj);
326 LoadWordDisp/*ne*/(rs_rARM_SELF, QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject).Int32Value(),
327 rs_rARM_LR);
328 ClobberCallerSave();
329 LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rARM_LR);
330 OpEndIT(it2);
331 MarkSafepointPC(call_inst);
Andreas Gampeb14329f2014-05-15 11:16:06 -0700332 }
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700333 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700334}
335
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700336void ArmMir2Lir::GenMoveException(RegLocation rl_dest) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700337 int ex_offset = Thread::ExceptionOffset<4>().Int32Value();
buzbeea0cd2d72014-06-01 09:33:49 -0700338 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
339 RegStorage reset_reg = AllocTempRef();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000340 LoadRefDisp(rs_rARM_SELF, ex_offset, rl_result.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700341 LoadConstant(reset_reg, 0);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000342 StoreRefDisp(rs_rARM_SELF, ex_offset, reset_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700343 FreeTemp(reset_reg);
344 StoreValue(rl_dest, rl_result);
345}
346
Vladimir Markobf535be2014-11-19 18:52:35 +0000347void ArmMir2Lir::UnconditionallyMarkGCCard(RegStorage tgt_addr_reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800348 RegStorage reg_card_base = AllocTemp();
349 RegStorage reg_card_no = AllocTemp();
Ian Rogersdd7624d2014-03-14 17:43:00 -0700350 LoadWordDisp(rs_rARM_SELF, Thread::CardTableOffset<4>().Int32Value(), reg_card_base);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700351 OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift);
buzbee2700f7e2014-03-07 09:46:20 -0800352 StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700353 FreeTemp(reg_card_base);
354 FreeTemp(reg_card_no);
355}
356
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700357void ArmMir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700358 int spill_count = num_core_spills_ + num_fp_spills_;
359 /*
360 * On entry, r0, r1, r2 & r3 are live. Let the register allocation
361 * mechanism know so it doesn't try to use any of them when
362 * expanding the frame or flushing. This leaves the utility
363 * code with a single temp: r12. This should be enough.
364 */
buzbee091cc402014-03-31 10:14:40 -0700365 LockTemp(rs_r0);
366 LockTemp(rs_r1);
367 LockTemp(rs_r2);
368 LockTemp(rs_r3);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700369
370 /*
371 * We can safely skip the stack overflow check if we're
372 * a leaf *and* our frame size < fudge factor.
373 */
Dave Allison648d7112014-07-25 16:15:27 -0700374 bool skip_overflow_check = mir_graph_->MethodIsLeaf() && !FrameNeedsStackCheck(frame_size_, kArm);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700375 NewLIR0(kPseudoMethodEntry);
Dave Allison648d7112014-07-25 16:15:27 -0700376 const size_t kStackOverflowReservedUsableBytes = GetStackOverflowReservedBytes(kArm);
Andreas Gampe7cd26f32014-06-18 17:01:15 -0700377 bool large_frame = (static_cast<size_t>(frame_size_) > kStackOverflowReservedUsableBytes);
Dave Allison648d7112014-07-25 16:15:27 -0700378 bool generate_explicit_stack_overflow_check = large_frame ||
379 !cu_->compiler_driver->GetCompilerOptions().GetImplicitStackOverflowChecks();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700380 if (!skip_overflow_check) {
Dave Allison648d7112014-07-25 16:15:27 -0700381 if (generate_explicit_stack_overflow_check) {
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000382 if (!large_frame) {
383 /* Load stack limit */
384 LockTemp(rs_r12);
385 Load32Disp(rs_rARM_SELF, Thread::StackEndOffset<4>().Int32Value(), rs_r12);
386 }
Dave Allison5cd33752014-04-15 15:57:58 -0700387 } else {
388 // Implicit stack overflow check.
389 // Generate a load from [sp, #-overflowsize]. If this is in the stack
390 // redzone we will get a segmentation fault.
391 //
392 // Caveat coder: if someone changes the kStackOverflowReservedBytes value
393 // we need to make sure that it's loadable in an immediate field of
394 // a sub instruction. Otherwise we will get a temp allocation and the
395 // code size will increase.
396 //
397 // This is done before the callee save instructions to avoid any possibility
398 // of these overflowing. This uses r12 and that's never saved in a callee
399 // save.
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700400 OpRegRegImm(kOpSub, rs_r12, rs_rARM_SP, GetStackOverflowReservedBytes(kArm));
Dave Allison5cd33752014-04-15 15:57:58 -0700401 Load32Disp(rs_r12, 0, rs_r12);
402 MarkPossibleStackOverflowException();
Dave Allisonb373e092014-02-20 16:06:36 -0800403 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700404 }
405 /* Spill core callee saves */
Vladimir Marko9d5c25a2014-11-26 15:42:32 +0000406 if (core_spill_mask_ == 0u) {
407 // Nothing to spill.
408 } else if ((core_spill_mask_ & ~(0xffu | (1u << rs_rARM_LR.GetRegNum()))) == 0u) {
409 // Spilling only low regs and/or LR, use 16-bit PUSH.
410 constexpr int lr_bit_shift = rs_rARM_LR.GetRegNum() - 8;
411 NewLIR1(kThumbPush,
412 (core_spill_mask_ & ~(1u << rs_rARM_LR.GetRegNum())) |
413 ((core_spill_mask_ & (1u << rs_rARM_LR.GetRegNum())) >> lr_bit_shift));
414 } else if (IsPowerOfTwo(core_spill_mask_)) {
415 // kThumb2Push cannot be used to spill a single register.
416 NewLIR1(kThumb2Push1, CTZ(core_spill_mask_));
417 } else {
418 NewLIR1(kThumb2Push, core_spill_mask_);
419 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700420 /* Need to spill any FP regs? */
421 if (num_fp_spills_) {
422 /*
423 * NOTE: fp spills are a little different from core spills in that
424 * they are pushed as a contiguous block. When promoting from
425 * the fp set, we must allocate all singles from s16..highest-promoted
426 */
427 NewLIR1(kThumb2VPushCS, num_fp_spills_);
428 }
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700429
Mathieu Chartier05a48b12014-03-31 16:11:41 -0700430 const int spill_size = spill_count * 4;
431 const int frame_size_without_spills = frame_size_ - spill_size;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700432 if (!skip_overflow_check) {
Dave Allison648d7112014-07-25 16:15:27 -0700433 if (generate_explicit_stack_overflow_check) {
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700434 class StackOverflowSlowPath : public LIRSlowPath {
435 public:
436 StackOverflowSlowPath(Mir2Lir* m2l, LIR* branch, bool restore_lr, size_t sp_displace)
Vladimir Marko0b40ecf2015-03-20 12:08:03 +0000437 : LIRSlowPath(m2l, branch), restore_lr_(restore_lr),
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700438 sp_displace_(sp_displace) {
439 }
440 void Compile() OVERRIDE {
441 m2l_->ResetRegPool();
442 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -0700443 GenerateTargetLabel(kPseudoThrowTarget);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700444 if (restore_lr_) {
buzbee2700f7e2014-03-07 09:46:20 -0800445 m2l_->LoadWordDisp(rs_rARM_SP, sp_displace_ - 4, rs_rARM_LR);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700446 }
buzbee2700f7e2014-03-07 09:46:20 -0800447 m2l_->OpRegImm(kOpAdd, rs_rARM_SP, sp_displace_);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700448 m2l_->ClobberCallerSave();
Ian Rogersdd7624d2014-03-14 17:43:00 -0700449 ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pThrowStackOverflow);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700450 // Load the entrypoint directly into the pc instead of doing a load + branch. Assumes
451 // codegen and target are in thumb2 mode.
buzbee695d13a2014-04-19 13:32:20 -0700452 // NOTE: native pointer.
buzbee2700f7e2014-03-07 09:46:20 -0800453 m2l_->LoadWordDisp(rs_rARM_SELF, func_offset.Int32Value(), rs_rARM_PC);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700454 }
455
456 private:
457 const bool restore_lr_;
458 const size_t sp_displace_;
459 };
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000460 if (large_frame) {
461 // Note: may need a temp reg, and we only have r12 free at this point.
buzbee2700f7e2014-03-07 09:46:20 -0800462 OpRegRegImm(kOpSub, rs_rARM_LR, rs_rARM_SP, frame_size_without_spills);
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000463 Load32Disp(rs_rARM_SELF, Thread::StackEndOffset<4>().Int32Value(), rs_r12);
buzbee2700f7e2014-03-07 09:46:20 -0800464 LIR* branch = OpCmpBranch(kCondUlt, rs_rARM_LR, rs_r12, nullptr);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700465 // Need to restore LR since we used it as a temp.
Mathieu Chartier05a48b12014-03-31 16:11:41 -0700466 AddSlowPath(new(arena_)StackOverflowSlowPath(this, branch, true, spill_size));
buzbee2700f7e2014-03-07 09:46:20 -0800467 OpRegCopy(rs_rARM_SP, rs_rARM_LR); // Establish stack
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700468 } else {
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000469 /*
470 * If the frame is small enough we are guaranteed to have enough space that remains to
471 * handle signals on the user stack. However, we may not have any free temp
472 * registers at this point, so we'll temporarily add LR to the temp pool.
473 */
474 DCHECK(!GetRegInfo(rs_rARM_LR)->IsTemp());
475 MarkTemp(rs_rARM_LR);
476 FreeTemp(rs_rARM_LR);
buzbee2700f7e2014-03-07 09:46:20 -0800477 OpRegRegImm(kOpSub, rs_rARM_SP, rs_rARM_SP, frame_size_without_spills);
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000478 Clobber(rs_rARM_LR);
479 UnmarkTemp(rs_rARM_LR);
buzbee2700f7e2014-03-07 09:46:20 -0800480 LIR* branch = OpCmpBranch(kCondUlt, rs_rARM_SP, rs_r12, nullptr);
Mathieu Chartier0d507d12014-03-19 10:17:28 -0700481 AddSlowPath(new(arena_)StackOverflowSlowPath(this, branch, false, frame_size_));
482 }
Dave Allisonb373e092014-02-20 16:06:36 -0800483 } else {
Dave Allison5cd33752014-04-15 15:57:58 -0700484 // Implicit stack overflow check has already been done. Just make room on the
485 // stack for the frame now.
Dave Allisonf9439142014-03-27 15:10:22 -0700486 OpRegImm(kOpSub, rs_rARM_SP, frame_size_without_spills);
Dave Allisonb373e092014-02-20 16:06:36 -0800487 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700488 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800489 OpRegImm(kOpSub, rs_rARM_SP, frame_size_without_spills);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700490 }
491
492 FlushIns(ArgLocs, rl_method);
493
buzbee091cc402014-03-31 10:14:40 -0700494 FreeTemp(rs_r0);
495 FreeTemp(rs_r1);
496 FreeTemp(rs_r2);
497 FreeTemp(rs_r3);
Bill Buzbeefe8cf8b2014-05-15 13:57:54 +0000498 FreeTemp(rs_r12);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700499}
500
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700501void ArmMir2Lir::GenExitSequence() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700502 int spill_count = num_core_spills_ + num_fp_spills_;
503 /*
504 * In the exit path, r0/r1 are live - make sure they aren't
505 * allocated by the register utilities as temps.
506 */
buzbee091cc402014-03-31 10:14:40 -0700507 LockTemp(rs_r0);
508 LockTemp(rs_r1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700509
510 NewLIR0(kPseudoMethodExit);
buzbee2700f7e2014-03-07 09:46:20 -0800511 OpRegImm(kOpAdd, rs_rARM_SP, frame_size_ - (spill_count * 4));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700512 /* Need to restore any FP callee saves? */
513 if (num_fp_spills_) {
514 NewLIR1(kThumb2VPopCS, num_fp_spills_);
515 }
Vladimir Marko9d5c25a2014-11-26 15:42:32 +0000516 if ((core_spill_mask_ & (1 << rs_rARM_LR.GetRegNum())) != 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700517 /* Unspill rARM_LR to rARM_PC */
buzbee091cc402014-03-31 10:14:40 -0700518 core_spill_mask_ &= ~(1 << rs_rARM_LR.GetRegNum());
519 core_spill_mask_ |= (1 << rs_rARM_PC.GetRegNum());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700520 }
Vladimir Marko9d5c25a2014-11-26 15:42:32 +0000521 if (core_spill_mask_ == 0u) {
522 // Nothing to unspill.
523 } else if ((core_spill_mask_ & ~(0xffu | (1u << rs_rARM_PC.GetRegNum()))) == 0u) {
524 // Unspilling only low regs and/or PC, use 16-bit POP.
525 constexpr int pc_bit_shift = rs_rARM_PC.GetRegNum() - 8;
526 NewLIR1(kThumbPop,
527 (core_spill_mask_ & ~(1u << rs_rARM_PC.GetRegNum())) |
528 ((core_spill_mask_ & (1u << rs_rARM_PC.GetRegNum())) >> pc_bit_shift));
529 } else if (IsPowerOfTwo(core_spill_mask_)) {
530 // kThumb2Pop cannot be used to unspill a single register.
531 NewLIR1(kThumb2Pop1, CTZ(core_spill_mask_));
532 } else {
533 NewLIR1(kThumb2Pop, core_spill_mask_);
534 }
535 if ((core_spill_mask_ & (1 << rs_rARM_PC.GetRegNum())) == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700536 /* We didn't pop to rARM_PC, so must do a bv rARM_LR */
buzbee091cc402014-03-31 10:14:40 -0700537 NewLIR1(kThumbBx, rs_rARM_LR.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700538 }
539}
540
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800541void ArmMir2Lir::GenSpecialExitSequence() {
buzbee091cc402014-03-31 10:14:40 -0700542 NewLIR1(kThumbBx, rs_rARM_LR.GetReg());
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800543}
544
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000545void ArmMir2Lir::GenSpecialEntryForSuspend() {
546 // Keep 16-byte stack alignment - push r0, i.e. ArtMethod*, r5, r6, lr.
547 DCHECK(!IsTemp(rs_r5));
548 DCHECK(!IsTemp(rs_r6));
549 core_spill_mask_ =
550 (1u << rs_r5.GetRegNum()) | (1u << rs_r6.GetRegNum()) | (1u << rs_rARM_LR.GetRegNum());
551 num_core_spills_ = 3u;
552 fp_spill_mask_ = 0u;
553 num_fp_spills_ = 0u;
554 frame_size_ = 16u;
555 core_vmap_table_.clear();
556 fp_vmap_table_.clear();
557 NewLIR1(kThumbPush, (1u << rs_r0.GetRegNum()) | // ArtMethod*
558 (core_spill_mask_ & ~(1u << rs_rARM_LR.GetRegNum())) | // Spills other than LR.
559 (1u << 8)); // LR encoded for 16-bit push.
560}
561
562void ArmMir2Lir::GenSpecialExitForSuspend() {
563 // Pop the frame. (ArtMethod* no longer needed but restore it anyway.)
564 NewLIR1(kThumb2Pop, (1u << rs_r0.GetRegNum()) | core_spill_mask_); // 32-bit because of LR.
565}
566
Vladimir Markof4da6752014-08-01 19:04:18 +0100567static bool ArmUseRelativeCall(CompilationUnit* cu, const MethodReference& target_method) {
568 // Emit relative calls only within a dex file due to the limited range of the BL insn.
569 return cu->dex_file == target_method.dex_file;
570}
571
572/*
573 * Bit of a hack here - in the absence of a real scheduling pass,
574 * emit the next instruction in static & direct invoke sequences.
575 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700576static int ArmNextSDCallInsn(CompilationUnit* cu, CallInfo* info ATTRIBUTE_UNUSED,
Vladimir Markof4da6752014-08-01 19:04:18 +0100577 int state, const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700578 uint32_t unused_idx ATTRIBUTE_UNUSED,
Vladimir Markof4da6752014-08-01 19:04:18 +0100579 uintptr_t direct_code, uintptr_t direct_method,
580 InvokeType type) {
581 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
582 if (direct_code != 0 && direct_method != 0) {
583 switch (state) {
584 case 0: // Get the current Method* [sets kArg0]
585 if (direct_code != static_cast<uintptr_t>(-1)) {
586 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
587 } else if (ArmUseRelativeCall(cu, target_method)) {
588 // Defer to linker patch.
589 } else {
590 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
591 }
592 if (direct_method != static_cast<uintptr_t>(-1)) {
593 cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method);
594 } else {
595 cg->LoadMethodAddress(target_method, type, kArg0);
596 }
597 break;
598 default:
599 return -1;
600 }
601 } else {
602 RegStorage arg0_ref = cg->TargetReg(kArg0, kRef);
603 switch (state) {
604 case 0: // Get the current Method* [sets kArg0]
605 // TUNING: we can save a reg copy if Method* has been promoted.
606 cg->LoadCurrMethodDirect(arg0_ref);
607 break;
608 case 1: // Get method->dex_cache_resolved_methods_
609 cg->LoadRefDisp(arg0_ref,
610 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
611 arg0_ref,
612 kNotVolatile);
613 // Set up direct code if known.
614 if (direct_code != 0) {
615 if (direct_code != static_cast<uintptr_t>(-1)) {
616 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
617 } else if (ArmUseRelativeCall(cu, target_method)) {
618 // Defer to linker patch.
619 } else {
620 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
621 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
622 }
623 }
624 break;
625 case 2: // Grab target method*
626 CHECK_EQ(cu->dex_file, target_method.dex_file);
627 cg->LoadRefDisp(arg0_ref,
628 mirror::ObjectArray<mirror::Object>::OffsetOfElement(
629 target_method.dex_method_index).Int32Value(),
630 arg0_ref,
631 kNotVolatile);
632 break;
633 case 3: // Grab the code from the method*
634 if (direct_code == 0) {
635 // kInvokeTgt := arg0_ref->entrypoint
636 cg->LoadWordDisp(arg0_ref,
Mathieu Chartier2d721012014-11-10 11:08:06 -0800637 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
638 kArmPointerSize).Int32Value(), cg->TargetPtrReg(kInvokeTgt));
Vladimir Markof4da6752014-08-01 19:04:18 +0100639 }
640 break;
641 default:
642 return -1;
643 }
644 }
645 return state + 1;
646}
647
648NextCallInsn ArmMir2Lir::GetNextSDCallInsn() {
649 return ArmNextSDCallInsn;
650}
651
652LIR* ArmMir2Lir::CallWithLinkerFixup(const MethodReference& target_method, InvokeType type) {
653 // For ARM, just generate a relative BL instruction that will be filled in at 'link time'.
654 // If the target turns out to be too far, the linker will generate a thunk for dispatch.
655 int target_method_idx = target_method.dex_method_index;
656 const DexFile* target_dex_file = target_method.dex_file;
657
658 // Generate the call instruction and save index, dex_file, and type.
659 // NOTE: Method deduplication takes linker patches into account, so we can just pass 0
660 // as a placeholder for the offset.
661 LIR* call = RawLIR(current_dalvik_offset_, kThumb2Bl, 0,
Vladimir Markof6737f72015-03-23 17:05:14 +0000662 target_method_idx, WrapPointer(target_dex_file), type);
Vladimir Markof4da6752014-08-01 19:04:18 +0100663 AppendLIR(call);
664 call_method_insns_.push_back(call);
665 return call;
666}
667
668LIR* ArmMir2Lir::GenCallInsn(const MirMethodLoweringInfo& method_info) {
669 LIR* call_insn;
670 if (method_info.FastPath() && ArmUseRelativeCall(cu_, method_info.GetTargetMethod()) &&
671 (method_info.GetSharpType() == kDirect || method_info.GetSharpType() == kStatic) &&
672 method_info.DirectCode() == static_cast<uintptr_t>(-1)) {
673 call_insn = CallWithLinkerFixup(method_info.GetTargetMethod(), method_info.GetSharpType());
674 } else {
675 call_insn = OpReg(kOpBlx, TargetPtrReg(kInvokeTgt));
676 }
677 return call_insn;
678}
679
Brian Carlstrom7940e442013-07-12 13:46:57 -0700680} // namespace art