blob: 959a0f199108d64a53314ae0de3f73419ca44c7a [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 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 "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Vladimir Marko58155012015-08-19 12:49:41 +000022#include "compiled_method.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070023#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010024#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080025#include "intrinsics.h"
26#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070027#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070029#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010030#include "utils/arm/assembler_arm.h"
31#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000032#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010033#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010036
Roland Levillain3b359c72015-11-17 19:35:12 +000037template<class MirrorType>
38class GcRoot;
39
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000040namespace arm {
41
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000042static bool ExpectedPairLayout(Location location) {
43 // We expected this for both core and fpu register pairs.
44 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
45}
46
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010047static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010048static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010049
David Brazdil58282f42016-01-14 12:45:10 +000050static constexpr Register kCoreAlwaysSpillRegister = R5;
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000051static constexpr Register kCoreCalleeSaves[] =
Andreas Gampe501fd632015-09-10 16:11:06 -070052 { R5, R6, R7, R8, R10, R11, LR };
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000053static constexpr SRegister kFpuCalleeSaves[] =
54 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010055
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000056// D31 cannot be split into two S registers, and the register allocator only works on
57// S registers. Therefore there is no need to block it.
58static constexpr DRegister DTMP = D31;
59
Vladimir Markof3e0ee22015-12-17 15:23:13 +000060static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7;
Andreas Gampe7cffc3b2015-10-19 21:31:53 -070061
Roland Levillain7cbd27f2016-08-11 23:53:33 +010062// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
63#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -070064#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065
Artem Serovf4d6aee2016-07-11 10:41:45 +010066static constexpr int kRegListThreshold = 4;
67
Artem Serovd300d8f2016-07-15 14:00:56 +010068// SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers,
69// for each live D registers they treat two corresponding S registers as live ones.
70//
71// Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build
72// from a list of contiguous S registers a list of contiguous D registers (processing first/last
73// S registers corner cases) and save/restore this new list treating them as D registers.
74// - decreasing code size
75// - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is
76// restored and then used in regular non SlowPath code as D register.
77//
78// For the following example (v means the S register is live):
79// D names: | D0 | D1 | D2 | D4 | ...
80// S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ...
81// Live? | | v | v | v | v | v | v | | ...
82//
83// S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed
84// as D registers.
85static size_t SaveContiguousSRegisterList(size_t first,
86 size_t last,
87 CodeGenerator* codegen,
88 size_t stack_offset) {
89 DCHECK_LE(first, last);
90 if ((first == last) && (first == 0)) {
91 stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first);
92 return stack_offset;
93 }
94 if (first % 2 == 1) {
95 stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++);
96 }
97
98 bool save_last = false;
99 if (last % 2 == 0) {
100 save_last = true;
101 --last;
102 }
103
104 if (first < last) {
105 DRegister d_reg = static_cast<DRegister>(first / 2);
106 DCHECK_EQ((last - first + 1) % 2, 0u);
107 size_t number_of_d_regs = (last - first + 1) / 2;
108
109 if (number_of_d_regs == 1) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100110 __ StoreDToOffset(d_reg, SP, stack_offset);
Artem Serovd300d8f2016-07-15 14:00:56 +0100111 } else if (number_of_d_regs > 1) {
112 __ add(IP, SP, ShifterOperand(stack_offset));
113 __ vstmiad(IP, d_reg, number_of_d_regs);
114 }
115 stack_offset += number_of_d_regs * kArmWordSize * 2;
116 }
117
118 if (save_last) {
119 stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1);
120 }
121
122 return stack_offset;
123}
124
125static size_t RestoreContiguousSRegisterList(size_t first,
126 size_t last,
127 CodeGenerator* codegen,
128 size_t stack_offset) {
129 DCHECK_LE(first, last);
130 if ((first == last) && (first == 0)) {
131 stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first);
132 return stack_offset;
133 }
134 if (first % 2 == 1) {
135 stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++);
136 }
137
138 bool restore_last = false;
139 if (last % 2 == 0) {
140 restore_last = true;
141 --last;
142 }
143
144 if (first < last) {
145 DRegister d_reg = static_cast<DRegister>(first / 2);
146 DCHECK_EQ((last - first + 1) % 2, 0u);
147 size_t number_of_d_regs = (last - first + 1) / 2;
148 if (number_of_d_regs == 1) {
149 __ LoadDFromOffset(d_reg, SP, stack_offset);
150 } else if (number_of_d_regs > 1) {
151 __ add(IP, SP, ShifterOperand(stack_offset));
152 __ vldmiad(IP, d_reg, number_of_d_regs);
153 }
154 stack_offset += number_of_d_regs * kArmWordSize * 2;
155 }
156
157 if (restore_last) {
158 stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1);
159 }
160
161 return stack_offset;
162}
163
Artem Serovf4d6aee2016-07-11 10:41:45 +0100164void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
165 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
166 size_t orig_offset = stack_offset;
167
168 const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true);
169 for (uint32_t i : LowToHighBits(core_spills)) {
170 // If the register holds an object, update the stack mask.
171 if (locations->RegisterContainsObject(i)) {
172 locations->SetStackBit(stack_offset / kVRegSize);
173 }
174 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
175 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
176 saved_core_stack_offsets_[i] = stack_offset;
177 stack_offset += kArmWordSize;
178 }
179
180 int reg_num = POPCOUNT(core_spills);
181 if (reg_num != 0) {
182 if (reg_num > kRegListThreshold) {
183 __ StoreList(RegList(core_spills), orig_offset);
184 } else {
185 stack_offset = orig_offset;
186 for (uint32_t i : LowToHighBits(core_spills)) {
187 stack_offset += codegen->SaveCoreRegister(stack_offset, i);
188 }
189 }
190 }
191
Artem Serovd300d8f2016-07-15 14:00:56 +0100192 uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false);
193 orig_offset = stack_offset;
Vladimir Marko804b03f2016-09-14 16:26:36 +0100194 for (uint32_t i : LowToHighBits(fp_spills)) {
Artem Serovf4d6aee2016-07-11 10:41:45 +0100195 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
196 saved_fpu_stack_offsets_[i] = stack_offset;
Artem Serovd300d8f2016-07-15 14:00:56 +0100197 stack_offset += kArmWordSize;
Artem Serovf4d6aee2016-07-11 10:41:45 +0100198 }
Artem Serovd300d8f2016-07-15 14:00:56 +0100199
200 stack_offset = orig_offset;
201 while (fp_spills != 0u) {
202 uint32_t begin = CTZ(fp_spills);
203 uint32_t tmp = fp_spills + (1u << begin);
204 fp_spills &= tmp; // Clear the contiguous range of 1s.
205 uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined.
206 stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset);
207 }
208 DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Artem Serovf4d6aee2016-07-11 10:41:45 +0100209}
210
211void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
212 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
213 size_t orig_offset = stack_offset;
214
215 const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true);
216 for (uint32_t i : LowToHighBits(core_spills)) {
217 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
218 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
219 stack_offset += kArmWordSize;
220 }
221
222 int reg_num = POPCOUNT(core_spills);
223 if (reg_num != 0) {
224 if (reg_num > kRegListThreshold) {
225 __ LoadList(RegList(core_spills), orig_offset);
226 } else {
227 stack_offset = orig_offset;
228 for (uint32_t i : LowToHighBits(core_spills)) {
229 stack_offset += codegen->RestoreCoreRegister(stack_offset, i);
230 }
231 }
232 }
233
Artem Serovd300d8f2016-07-15 14:00:56 +0100234 uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false);
235 while (fp_spills != 0u) {
236 uint32_t begin = CTZ(fp_spills);
237 uint32_t tmp = fp_spills + (1u << begin);
238 fp_spills &= tmp; // Clear the contiguous range of 1s.
239 uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined.
240 stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset);
Artem Serovf4d6aee2016-07-11 10:41:45 +0100241 }
Artem Serovd300d8f2016-07-15 14:00:56 +0100242 DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Artem Serovf4d6aee2016-07-11 10:41:45 +0100243}
244
245class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100246 public:
Artem Serovf4d6aee2016-07-11 10:41:45 +0100247 explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100248
Alexandre Rames67555f72014-11-18 10:55:16 +0000249 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100250 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100251 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000252 if (instruction_->CanThrowIntoCatchBlock()) {
253 // Live registers will be restored in the catch block if caught.
254 SaveLiveRegisters(codegen, instruction_->GetLocations());
255 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100256 arm_codegen->InvokeRuntime(kQuickThrowNullPointer,
257 instruction_,
258 instruction_->GetDexPc(),
259 this);
Roland Levillain888d0672015-11-23 18:53:50 +0000260 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100261 }
262
Alexandre Rames8158f282015-08-07 10:26:17 +0100263 bool IsFatal() const OVERRIDE { return true; }
264
Alexandre Rames9931f312015-06-19 14:47:01 +0100265 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
266
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100267 private:
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100268 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
269};
270
Artem Serovf4d6aee2016-07-11 10:41:45 +0100271class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
Calin Juravled0d48522014-11-04 16:40:20 +0000272 public:
Artem Serovf4d6aee2016-07-11 10:41:45 +0100273 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {}
Calin Juravled0d48522014-11-04 16:40:20 +0000274
Alexandre Rames67555f72014-11-18 10:55:16 +0000275 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000276 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
277 __ Bind(GetEntryLabel());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100278 arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000279 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Calin Juravled0d48522014-11-04 16:40:20 +0000280 }
281
Alexandre Rames8158f282015-08-07 10:26:17 +0100282 bool IsFatal() const OVERRIDE { return true; }
283
Alexandre Rames9931f312015-06-19 14:47:01 +0100284 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
285
Calin Juravled0d48522014-11-04 16:40:20 +0000286 private:
Calin Juravled0d48522014-11-04 16:40:20 +0000287 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
288};
289
Artem Serovf4d6aee2016-07-11 10:41:45 +0100290class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000291 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000292 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Artem Serovf4d6aee2016-07-11 10:41:45 +0100293 : SlowPathCodeARM(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000294
Alexandre Rames67555f72014-11-18 10:55:16 +0000295 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100296 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000297 __ Bind(GetEntryLabel());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100298 arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000299 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100300 if (successor_ == nullptr) {
301 __ b(GetReturnLabel());
302 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100303 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100304 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000305 }
306
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100307 Label* GetReturnLabel() {
308 DCHECK(successor_ == nullptr);
309 return &return_label_;
310 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000311
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100312 HBasicBlock* GetSuccessor() const {
313 return successor_;
314 }
315
Alexandre Rames9931f312015-06-19 14:47:01 +0100316 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
317
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000318 private:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100319 // If not null, the block to branch to after the suspend check.
320 HBasicBlock* const successor_;
321
322 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000323 Label return_label_;
324
325 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
326};
327
Artem Serovf4d6aee2016-07-11 10:41:45 +0100328class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100329 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100330 explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction)
Artem Serovf4d6aee2016-07-11 10:41:45 +0100331 : SlowPathCodeARM(instruction) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100332
Alexandre Rames67555f72014-11-18 10:55:16 +0000333 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100334 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100335 LocationSummary* locations = instruction_->GetLocations();
336
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100337 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000338 if (instruction_->CanThrowIntoCatchBlock()) {
339 // Live registers will be restored in the catch block if caught.
340 SaveLiveRegisters(codegen, instruction_->GetLocations());
341 }
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000342 // We're moving two locations to locations that could overlap, so we need a parallel
343 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100344 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000345 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100346 locations->InAt(0),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000347 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100348 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100349 locations->InAt(1),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100350 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
351 Primitive::kPrimInt);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100352 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
353 ? kQuickThrowStringBounds
354 : kQuickThrowArrayBounds;
355 arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100356 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Roland Levillain888d0672015-11-23 18:53:50 +0000357 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100358 }
359
Alexandre Rames8158f282015-08-07 10:26:17 +0100360 bool IsFatal() const OVERRIDE { return true; }
361
Alexandre Rames9931f312015-06-19 14:47:01 +0100362 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
363
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100364 private:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100365 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
366};
367
Artem Serovf4d6aee2016-07-11 10:41:45 +0100368class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100369 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000370 LoadClassSlowPathARM(HLoadClass* cls,
371 HInstruction* at,
372 uint32_t dex_pc,
373 bool do_clinit)
Artem Serovf4d6aee2016-07-11 10:41:45 +0100374 : SlowPathCodeARM(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000375 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
376 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100377
Alexandre Rames67555f72014-11-18 10:55:16 +0000378 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000379 LocationSummary* locations = at_->GetLocations();
380
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100381 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
382 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000383 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100384
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100385 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000386 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100387 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
388 : kQuickInitializeType;
389 arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this);
Roland Levillain888d0672015-11-23 18:53:50 +0000390 if (do_clinit_) {
391 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
392 } else {
393 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
394 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000395
396 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000397 Location out = locations->Out();
398 if (out.IsValid()) {
399 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000400 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
401 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000402 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100403 __ b(GetExitLabel());
404 }
405
Alexandre Rames9931f312015-06-19 14:47:01 +0100406 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
407
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100408 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000409 // The class this slow path will load.
410 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100411
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000412 // The instruction where this slow path is happening.
413 // (Might be the load class or an initialization check).
414 HInstruction* const at_;
415
416 // The dex PC of `at_`.
417 const uint32_t dex_pc_;
418
419 // Whether to initialize the class.
420 const bool do_clinit_;
421
422 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100423};
424
Vladimir Markoaad75c62016-10-03 08:46:48 +0000425class LoadStringSlowPathARM : public SlowPathCodeARM {
426 public:
427 explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {}
428
429 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
430 LocationSummary* locations = instruction_->GetLocations();
431 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100432 HLoadString* load = instruction_->AsLoadString();
433 const uint32_t string_index = load->GetStringIndex();
434 Register out = locations->Out().AsRegister<Register>();
435 Register temp = locations->GetTemp(0).AsRegister<Register>();
436 constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000437
438 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
439 __ Bind(GetEntryLabel());
440 SaveLiveRegisters(codegen, locations);
441
442 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100443 // In the unlucky case that the `temp` is R0, we preserve the address in `out` across
444 // the kSaveEverything call (or use `out` for the address after non-kSaveEverything call).
445 bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0));
446 Register entry_address = temp_is_r0 ? out : temp;
447 DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0));
448 if (call_saves_everything_except_r0 && temp_is_r0) {
449 __ mov(entry_address, ShifterOperand(temp));
450 }
451
Vladimir Markoaad75c62016-10-03 08:46:48 +0000452 __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index);
453 arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
454 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100455
456 // Store the resolved String to the .bss entry.
457 if (call_saves_everything_except_r0) {
458 // The string entry address was preserved in `entry_address` thanks to kSaveEverything.
459 __ str(R0, Address(entry_address));
460 } else {
461 // For non-Baker read barrier, we need to re-calculate the address of the string entry.
462 CodeGeneratorARM::PcRelativePatchInfo* labels =
463 arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index);
464 __ BindTrackedLabel(&labels->movw_label);
465 __ movw(entry_address, /* placeholder */ 0u);
466 __ BindTrackedLabel(&labels->movt_label);
467 __ movt(entry_address, /* placeholder */ 0u);
468 __ BindTrackedLabel(&labels->add_pc_label);
469 __ add(entry_address, entry_address, ShifterOperand(PC));
470 __ str(R0, Address(entry_address));
471 }
472
Vladimir Markoaad75c62016-10-03 08:46:48 +0000473 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
Vladimir Markoaad75c62016-10-03 08:46:48 +0000474 RestoreLiveRegisters(codegen, locations);
475
Vladimir Markoaad75c62016-10-03 08:46:48 +0000476 __ b(GetExitLabel());
477 }
478
479 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
480
481 private:
482 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
483};
484
Artem Serovf4d6aee2016-07-11 10:41:45 +0100485class TypeCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000486 public:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000487 TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal)
Artem Serovf4d6aee2016-07-11 10:41:45 +0100488 : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000489
Alexandre Rames67555f72014-11-18 10:55:16 +0000490 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000491 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100492 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
493 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000494 DCHECK(instruction_->IsCheckCast()
495 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000496
497 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
498 __ Bind(GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000499
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000500 if (!is_fatal_) {
501 SaveLiveRegisters(codegen, locations);
502 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000503
504 // We're moving two locations to locations that could overlap, so we need a parallel
505 // move resolver.
506 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000507 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100508 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000509 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100510 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100511 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100512 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
513 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000514
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000515 if (instruction_->IsInstanceOf()) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100516 arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100517 instruction_,
518 instruction_->GetDexPc(),
519 this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000520 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700521 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000522 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
523 } else {
524 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100525 arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000526 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000527 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000528
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000529 if (!is_fatal_) {
530 RestoreLiveRegisters(codegen, locations);
531 __ b(GetExitLabel());
532 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000533 }
534
Alexandre Rames9931f312015-06-19 14:47:01 +0100535 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
536
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000537 bool IsFatal() const OVERRIDE { return is_fatal_; }
538
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000539 private:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000540 const bool is_fatal_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000541
542 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
543};
544
Artem Serovf4d6aee2016-07-11 10:41:45 +0100545class DeoptimizationSlowPathARM : public SlowPathCodeARM {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700546 public:
Aart Bik42249c32016-01-07 15:33:50 -0800547 explicit DeoptimizationSlowPathARM(HDeoptimize* instruction)
Artem Serovf4d6aee2016-07-11 10:41:45 +0100548 : SlowPathCodeARM(instruction) {}
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700549
550 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800551 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700552 __ Bind(GetEntryLabel());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100553 arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000554 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700555 }
556
Alexandre Rames9931f312015-06-19 14:47:01 +0100557 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
558
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700559 private:
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700560 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
561};
562
Artem Serovf4d6aee2016-07-11 10:41:45 +0100563class ArraySetSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100564 public:
Artem Serovf4d6aee2016-07-11 10:41:45 +0100565 explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {}
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100566
567 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
568 LocationSummary* locations = instruction_->GetLocations();
569 __ Bind(GetEntryLabel());
570 SaveLiveRegisters(codegen, locations);
571
572 InvokeRuntimeCallingConvention calling_convention;
573 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
574 parallel_move.AddMove(
575 locations->InAt(0),
576 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
577 Primitive::kPrimNot,
578 nullptr);
579 parallel_move.AddMove(
580 locations->InAt(1),
581 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
582 Primitive::kPrimInt,
583 nullptr);
584 parallel_move.AddMove(
585 locations->InAt(2),
586 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
587 Primitive::kPrimNot,
588 nullptr);
589 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
590
591 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100592 arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000593 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100594 RestoreLiveRegisters(codegen, locations);
595 __ b(GetExitLabel());
596 }
597
598 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; }
599
600 private:
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100601 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM);
602};
603
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100604// Slow path marking an object reference `ref` during a read
605// barrier. The field `obj.field` in the object `obj` holding this
606// reference does not get updated by this slow path after marking (see
607// ReadBarrierMarkAndUpdateFieldSlowPathARM below for that).
608//
609// This means that after the execution of this slow path, `ref` will
610// always be up-to-date, but `obj.field` may not; i.e., after the
611// flip, `ref` will be a to-space reference, but `obj.field` will
612// probably still be a from-space reference (unless it gets updated by
613// another thread, or if another thread installed another object
614// reference (different from `ref`) in `obj.field`).
Artem Serovf4d6aee2016-07-11 10:41:45 +0100615class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM {
Roland Levillainc9285912015-12-18 10:38:42 +0000616 public:
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100617 ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location ref)
618 : SlowPathCodeARM(instruction), ref_(ref) {
Roland Levillainc9285912015-12-18 10:38:42 +0000619 DCHECK(kEmitCompilerReadBarrier);
620 }
621
622 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; }
623
624 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
625 LocationSummary* locations = instruction_->GetLocations();
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100626 Register ref_reg = ref_.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +0000627 DCHECK(locations->CanCall());
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100628 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
Roland Levillainc9285912015-12-18 10:38:42 +0000629 DCHECK(instruction_->IsInstanceFieldGet() ||
630 instruction_->IsStaticFieldGet() ||
631 instruction_->IsArrayGet() ||
Roland Levillain16d9f942016-08-25 17:27:56 +0100632 instruction_->IsArraySet() ||
Roland Levillainc9285912015-12-18 10:38:42 +0000633 instruction_->IsLoadClass() ||
634 instruction_->IsLoadString() ||
635 instruction_->IsInstanceOf() ||
Roland Levillain3d312422016-06-23 13:53:42 +0100636 instruction_->IsCheckCast() ||
Roland Levillain0b671c02016-08-19 12:02:34 +0100637 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
638 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
Roland Levillainc9285912015-12-18 10:38:42 +0000639 << "Unexpected instruction in read barrier marking slow path: "
640 << instruction_->DebugName();
641
642 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100643 // No need to save live registers; it's taken care of by the
644 // entrypoint. Also, there is no need to update the stack mask,
645 // as this runtime call will not trigger a garbage collection.
Roland Levillainc9285912015-12-18 10:38:42 +0000646 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100647 DCHECK_NE(ref_reg, SP);
648 DCHECK_NE(ref_reg, LR);
649 DCHECK_NE(ref_reg, PC);
Roland Levillain0b671c02016-08-19 12:02:34 +0100650 // IP is used internally by the ReadBarrierMarkRegX entry point
651 // as a temporary, it cannot be the entry point's input/output.
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100652 DCHECK_NE(ref_reg, IP);
653 DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg;
Roland Levillain02b75802016-07-13 11:54:35 +0100654 // "Compact" slow path, saving two moves.
655 //
656 // Instead of using the standard runtime calling convention (input
657 // and output in R0):
658 //
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100659 // R0 <- ref
Roland Levillain02b75802016-07-13 11:54:35 +0100660 // R0 <- ReadBarrierMark(R0)
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100661 // ref <- R0
Roland Levillain02b75802016-07-13 11:54:35 +0100662 //
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100663 // we just use rX (the register containing `ref`) as input and output
Roland Levillain02b75802016-07-13 11:54:35 +0100664 // of a dedicated entrypoint:
665 //
666 // rX <- ReadBarrierMarkRegX(rX)
667 //
668 int32_t entry_point_offset =
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100669 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg);
Roland Levillaindec8f632016-07-22 17:10:06 +0100670 // This runtime call does not require a stack map.
671 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
Roland Levillainc9285912015-12-18 10:38:42 +0000672 __ b(GetExitLabel());
673 }
674
675 private:
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100676 // The location (register) of the marked object reference.
677 const Location ref_;
Roland Levillainc9285912015-12-18 10:38:42 +0000678
679 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM);
680};
681
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100682// Slow path marking an object reference `ref` during a read barrier,
683// and if needed, atomically updating the field `obj.field` in the
684// object `obj` holding this reference after marking (contrary to
685// ReadBarrierMarkSlowPathARM above, which never tries to update
686// `obj.field`).
687//
688// This means that after the execution of this slow path, both `ref`
689// and `obj.field` will be up-to-date; i.e., after the flip, both will
690// hold the same to-space reference (unless another thread installed
691// another object reference (different from `ref`) in `obj.field`).
692class ReadBarrierMarkAndUpdateFieldSlowPathARM : public SlowPathCodeARM {
693 public:
694 ReadBarrierMarkAndUpdateFieldSlowPathARM(HInstruction* instruction,
695 Location ref,
696 Register obj,
697 Location field_offset,
698 Register temp1,
699 Register temp2)
700 : SlowPathCodeARM(instruction),
701 ref_(ref),
702 obj_(obj),
703 field_offset_(field_offset),
704 temp1_(temp1),
705 temp2_(temp2) {
706 DCHECK(kEmitCompilerReadBarrier);
707 }
708
709 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathARM"; }
710
711 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
712 LocationSummary* locations = instruction_->GetLocations();
713 Register ref_reg = ref_.AsRegister<Register>();
714 DCHECK(locations->CanCall());
715 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg;
716 // This slow path is only used by the UnsafeCASObject intrinsic.
717 DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
718 << "Unexpected instruction in read barrier marking and field updating slow path: "
719 << instruction_->DebugName();
720 DCHECK(instruction_->GetLocations()->Intrinsified());
721 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject);
722 DCHECK(field_offset_.IsRegisterPair()) << field_offset_;
723
724 __ Bind(GetEntryLabel());
725
726 // Save the old reference.
727 // Note that we cannot use IP to save the old reference, as IP is
728 // used internally by the ReadBarrierMarkRegX entry point, and we
729 // need the old reference after the call to that entry point.
730 DCHECK_NE(temp1_, IP);
731 __ Mov(temp1_, ref_reg);
732
733 // No need to save live registers; it's taken care of by the
734 // entrypoint. Also, there is no need to update the stack mask,
735 // as this runtime call will not trigger a garbage collection.
736 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
737 DCHECK_NE(ref_reg, SP);
738 DCHECK_NE(ref_reg, LR);
739 DCHECK_NE(ref_reg, PC);
740 // IP is used internally by the ReadBarrierMarkRegX entry point
741 // as a temporary, it cannot be the entry point's input/output.
742 DCHECK_NE(ref_reg, IP);
743 DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg;
744 // "Compact" slow path, saving two moves.
745 //
746 // Instead of using the standard runtime calling convention (input
747 // and output in R0):
748 //
749 // R0 <- ref
750 // R0 <- ReadBarrierMark(R0)
751 // ref <- R0
752 //
753 // we just use rX (the register containing `ref`) as input and output
754 // of a dedicated entrypoint:
755 //
756 // rX <- ReadBarrierMarkRegX(rX)
757 //
758 int32_t entry_point_offset =
759 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg);
760 // This runtime call does not require a stack map.
761 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
762
763 // If the new reference is different from the old reference,
764 // update the field in the holder (`*(obj_ + field_offset_)`).
765 //
766 // Note that this field could also hold a different object, if
767 // another thread had concurrently changed it. In that case, the
768 // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set
769 // (CAS) operation below would abort the CAS, leaving the field
770 // as-is.
771 Label done;
772 __ cmp(temp1_, ShifterOperand(ref_reg));
773 __ b(&done, EQ);
774
775 // Update the the holder's field atomically. This may fail if
776 // mutator updates before us, but it's OK. This is achieved
777 // using a strong compare-and-set (CAS) operation with relaxed
778 // memory synchronization ordering, where the expected value is
779 // the old reference and the desired value is the new reference.
780
781 // Convenience aliases.
782 Register base = obj_;
783 // The UnsafeCASObject intrinsic uses a register pair as field
784 // offset ("long offset"), of which only the low part contains
785 // data.
786 Register offset = field_offset_.AsRegisterPairLow<Register>();
787 Register expected = temp1_;
788 Register value = ref_reg;
789 Register tmp_ptr = IP; // Pointer to actual memory.
790 Register tmp = temp2_; // Value in memory.
791
792 __ add(tmp_ptr, base, ShifterOperand(offset));
793
794 if (kPoisonHeapReferences) {
795 __ PoisonHeapReference(expected);
796 if (value == expected) {
797 // Do not poison `value`, as it is the same register as
798 // `expected`, which has just been poisoned.
799 } else {
800 __ PoisonHeapReference(value);
801 }
802 }
803
804 // do {
805 // tmp = [r_ptr] - expected;
806 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
807
808 Label loop_head;
809 __ Bind(&loop_head);
810
811 __ ldrex(tmp, tmp_ptr);
812
813 __ subs(tmp, tmp, ShifterOperand(expected));
814
815 __ it(EQ, ItState::kItT);
816 __ strex(tmp, value, tmp_ptr, EQ);
817 __ cmp(tmp, ShifterOperand(1), EQ);
818
819 __ b(&loop_head, EQ);
820
821 if (kPoisonHeapReferences) {
822 __ UnpoisonHeapReference(expected);
823 if (value == expected) {
824 // Do not unpoison `value`, as it is the same register as
825 // `expected`, which has just been unpoisoned.
826 } else {
827 __ UnpoisonHeapReference(value);
828 }
829 }
830
831 __ Bind(&done);
832 __ b(GetExitLabel());
833 }
834
835 private:
836 // The location (register) of the marked object reference.
837 const Location ref_;
838 // The register containing the object holding the marked object reference field.
839 const Register obj_;
840 // The location of the offset of the marked reference field within `obj_`.
841 Location field_offset_;
842
843 const Register temp1_;
844 const Register temp2_;
845
846 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM);
847};
848
Roland Levillain3b359c72015-11-17 19:35:12 +0000849// Slow path generating a read barrier for a heap reference.
Artem Serovf4d6aee2016-07-11 10:41:45 +0100850class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM {
Roland Levillain3b359c72015-11-17 19:35:12 +0000851 public:
852 ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction,
853 Location out,
854 Location ref,
855 Location obj,
856 uint32_t offset,
857 Location index)
Artem Serovf4d6aee2016-07-11 10:41:45 +0100858 : SlowPathCodeARM(instruction),
Roland Levillain3b359c72015-11-17 19:35:12 +0000859 out_(out),
860 ref_(ref),
861 obj_(obj),
862 offset_(offset),
863 index_(index) {
864 DCHECK(kEmitCompilerReadBarrier);
865 // If `obj` is equal to `out` or `ref`, it means the initial object
866 // has been overwritten by (or after) the heap object reference load
867 // to be instrumented, e.g.:
868 //
869 // __ LoadFromOffset(kLoadWord, out, out, offset);
Roland Levillainc9285912015-12-18 10:38:42 +0000870 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
Roland Levillain3b359c72015-11-17 19:35:12 +0000871 //
872 // In that case, we have lost the information about the original
873 // object, and the emitted read barrier cannot work properly.
874 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
875 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
876 }
877
878 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
879 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
880 LocationSummary* locations = instruction_->GetLocations();
881 Register reg_out = out_.AsRegister<Register>();
882 DCHECK(locations->CanCall());
883 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillain3d312422016-06-23 13:53:42 +0100884 DCHECK(instruction_->IsInstanceFieldGet() ||
885 instruction_->IsStaticFieldGet() ||
886 instruction_->IsArrayGet() ||
887 instruction_->IsInstanceOf() ||
888 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100889 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillainc9285912015-12-18 10:38:42 +0000890 << "Unexpected instruction in read barrier for heap reference slow path: "
891 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000892
893 __ Bind(GetEntryLabel());
894 SaveLiveRegisters(codegen, locations);
895
896 // We may have to change the index's value, but as `index_` is a
897 // constant member (like other "inputs" of this slow path),
898 // introduce a copy of it, `index`.
899 Location index = index_;
900 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100901 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain3b359c72015-11-17 19:35:12 +0000902 if (instruction_->IsArrayGet()) {
903 // Compute the actual memory offset and store it in `index`.
904 Register index_reg = index_.AsRegister<Register>();
905 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
906 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
907 // We are about to change the value of `index_reg` (see the
908 // calls to art::arm::Thumb2Assembler::Lsl and
909 // art::arm::Thumb2Assembler::AddConstant below), but it has
910 // not been saved by the previous call to
911 // art::SlowPathCode::SaveLiveRegisters, as it is a
912 // callee-save register --
913 // art::SlowPathCode::SaveLiveRegisters does not consider
914 // callee-save registers, as it has been designed with the
915 // assumption that callee-save registers are supposed to be
916 // handled by the called function. So, as a callee-save
917 // register, `index_reg` _would_ eventually be saved onto
918 // the stack, but it would be too late: we would have
919 // changed its value earlier. Therefore, we manually save
920 // it here into another freely available register,
921 // `free_reg`, chosen of course among the caller-save
922 // registers (as a callee-save `free_reg` register would
923 // exhibit the same problem).
924 //
925 // Note we could have requested a temporary register from
926 // the register allocator instead; but we prefer not to, as
927 // this is a slow path, and we know we can find a
928 // caller-save register that is available.
929 Register free_reg = FindAvailableCallerSaveRegister(codegen);
930 __ Mov(free_reg, index_reg);
931 index_reg = free_reg;
932 index = Location::RegisterLocation(index_reg);
933 } else {
934 // The initial register stored in `index_` has already been
935 // saved in the call to art::SlowPathCode::SaveLiveRegisters
936 // (as it is not a callee-save register), so we can freely
937 // use it.
938 }
939 // Shifting the index value contained in `index_reg` by the scale
940 // factor (2) cannot overflow in practice, as the runtime is
941 // unable to allocate object arrays with a size larger than
942 // 2^26 - 1 (that is, 2^28 - 4 bytes).
943 __ Lsl(index_reg, index_reg, TIMES_4);
944 static_assert(
945 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
946 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
947 __ AddConstant(index_reg, index_reg, offset_);
948 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100949 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
950 // intrinsics, `index_` is not shifted by a scale factor of 2
951 // (as in the case of ArrayGet), as it is actually an offset
952 // to an object field within an object.
953 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000954 DCHECK(instruction_->GetLocations()->Intrinsified());
955 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
956 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
957 << instruction_->AsInvoke()->GetIntrinsic();
958 DCHECK_EQ(offset_, 0U);
959 DCHECK(index_.IsRegisterPair());
960 // UnsafeGet's offset location is a register pair, the low
961 // part contains the correct offset.
962 index = index_.ToLow();
963 }
964 }
965
966 // We're moving two or three locations to locations that could
967 // overlap, so we need a parallel move resolver.
968 InvokeRuntimeCallingConvention calling_convention;
969 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
970 parallel_move.AddMove(ref_,
971 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
972 Primitive::kPrimNot,
973 nullptr);
974 parallel_move.AddMove(obj_,
975 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
976 Primitive::kPrimNot,
977 nullptr);
978 if (index.IsValid()) {
979 parallel_move.AddMove(index,
980 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
981 Primitive::kPrimInt,
982 nullptr);
983 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
984 } else {
985 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
986 __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_);
987 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100988 arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000989 CheckEntrypointTypes<
990 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
991 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
992
993 RestoreLiveRegisters(codegen, locations);
994 __ b(GetExitLabel());
995 }
996
997 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; }
998
999 private:
1000 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
1001 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
1002 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
1003 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
1004 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
1005 return static_cast<Register>(i);
1006 }
1007 }
1008 // We shall never fail to find a free caller-save register, as
1009 // there are more than two core caller-save registers on ARM
1010 // (meaning it is possible to find one which is different from
1011 // `ref` and `obj`).
1012 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
1013 LOG(FATAL) << "Could not find a free caller-save register";
1014 UNREACHABLE();
1015 }
1016
Roland Levillain3b359c72015-11-17 19:35:12 +00001017 const Location out_;
1018 const Location ref_;
1019 const Location obj_;
1020 const uint32_t offset_;
1021 // An additional location containing an index to an array.
1022 // Only used for HArrayGet and the UnsafeGetObject &
1023 // UnsafeGetObjectVolatile intrinsics.
1024 const Location index_;
1025
1026 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM);
1027};
1028
1029// Slow path generating a read barrier for a GC root.
Artem Serovf4d6aee2016-07-11 10:41:45 +01001030class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM {
Roland Levillain3b359c72015-11-17 19:35:12 +00001031 public:
1032 ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root)
Artem Serovf4d6aee2016-07-11 10:41:45 +01001033 : SlowPathCodeARM(instruction), out_(out), root_(root) {
Roland Levillainc9285912015-12-18 10:38:42 +00001034 DCHECK(kEmitCompilerReadBarrier);
1035 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001036
1037 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
1038 LocationSummary* locations = instruction_->GetLocations();
1039 Register reg_out = out_.AsRegister<Register>();
1040 DCHECK(locations->CanCall());
1041 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillainc9285912015-12-18 10:38:42 +00001042 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
1043 << "Unexpected instruction in read barrier for GC root slow path: "
1044 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +00001045
1046 __ Bind(GetEntryLabel());
1047 SaveLiveRegisters(codegen, locations);
1048
1049 InvokeRuntimeCallingConvention calling_convention;
1050 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
1051 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001052 arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
Roland Levillain3b359c72015-11-17 19:35:12 +00001053 instruction_,
1054 instruction_->GetDexPc(),
1055 this);
1056 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
1057 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
1058
1059 RestoreLiveRegisters(codegen, locations);
1060 __ b(GetExitLabel());
1061 }
1062
1063 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; }
1064
1065 private:
Roland Levillain3b359c72015-11-17 19:35:12 +00001066 const Location out_;
1067 const Location root_;
1068
1069 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM);
1070};
1071
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00001072#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +01001073// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
1074#define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT
Dave Allison20dfc792014-06-16 20:44:29 -07001075
Aart Bike9f37602015-10-09 11:15:55 -07001076inline Condition ARMCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -07001077 switch (cond) {
1078 case kCondEQ: return EQ;
1079 case kCondNE: return NE;
1080 case kCondLT: return LT;
1081 case kCondLE: return LE;
1082 case kCondGT: return GT;
1083 case kCondGE: return GE;
Aart Bike9f37602015-10-09 11:15:55 -07001084 case kCondB: return LO;
1085 case kCondBE: return LS;
1086 case kCondA: return HI;
1087 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -07001088 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001089 LOG(FATAL) << "Unreachable";
1090 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -07001091}
1092
Aart Bike9f37602015-10-09 11:15:55 -07001093// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001094inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -07001095 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001096 case kCondEQ: return EQ;
1097 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -07001098 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001099 case kCondLT: return LO;
1100 case kCondLE: return LS;
1101 case kCondGT: return HI;
1102 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -07001103 // Unsigned remain unchanged.
1104 case kCondB: return LO;
1105 case kCondBE: return LS;
1106 case kCondA: return HI;
1107 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -07001108 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001109 LOG(FATAL) << "Unreachable";
1110 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -07001111}
1112
Vladimir Markod6e069b2016-01-18 11:11:01 +00001113inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) {
1114 // The ARM condition codes can express all the necessary branches, see the
1115 // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual.
1116 // There is no dex instruction or HIR that would need the missing conditions
1117 // "equal or unordered" or "not equal".
1118 switch (cond) {
1119 case kCondEQ: return EQ;
1120 case kCondNE: return NE /* unordered */;
1121 case kCondLT: return gt_bias ? CC : LT /* unordered */;
1122 case kCondLE: return gt_bias ? LS : LE /* unordered */;
1123 case kCondGT: return gt_bias ? HI /* unordered */ : GT;
1124 case kCondGE: return gt_bias ? CS /* unordered */ : GE;
1125 default:
1126 LOG(FATAL) << "UNREACHABLE";
1127 UNREACHABLE();
1128 }
1129}
1130
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001131void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +01001132 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001133}
1134
1135void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +01001136 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001137}
1138
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001139size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1140 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
1141 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +01001142}
1143
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001144size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1145 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
1146 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +01001147}
1148
Nicolas Geoffray840e5462015-01-07 16:01:24 +00001149size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1150 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
1151 return kArmWordSize;
1152}
1153
1154size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1155 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
1156 return kArmWordSize;
1157}
1158
Calin Juravle34166012014-12-19 17:22:29 +00001159CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +00001160 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +01001161 const CompilerOptions& compiler_options,
1162 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001163 : CodeGenerator(graph,
1164 kNumberOfCoreRegisters,
1165 kNumberOfSRegisters,
1166 kNumberOfRegisterPairs,
1167 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
1168 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +00001169 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
1170 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +01001171 compiler_options,
1172 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +01001173 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001174 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001175 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001176 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +01001177 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +00001178 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00001179 uint32_literals_(std::less<uint32_t>(),
1180 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +01001181 method_patches_(MethodReferenceComparator(),
1182 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1183 call_patches_(MethodReferenceComparator(),
1184 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markob4536b72015-11-24 13:45:23 +00001185 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00001186 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1187 boot_image_string_patches_(StringReferenceValueComparator(),
1188 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1189 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01001190 boot_image_type_patches_(TypeReferenceValueComparator(),
1191 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1192 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00001193 boot_image_address_patches_(std::less<uint32_t>(),
1194 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -07001195 // Always save the LR register to mimic Quick.
1196 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +01001197}
1198
Vladimir Markocf93a5c2015-06-16 11:33:24 +00001199void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
1200 // Ensure that we fix up branches and literal loads and emit the literal pool.
1201 __ FinalizeCode();
1202
1203 // Adjust native pc offsets in stack maps.
1204 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
1205 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
1206 uint32_t new_position = __ GetAdjustedPosition(old_position);
1207 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
1208 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +01001209 // Adjust pc offsets for the disassembly information.
1210 if (disasm_info_ != nullptr) {
1211 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
1212 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
1213 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
1214 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
1215 it.second.start = __ GetAdjustedPosition(it.second.start);
1216 it.second.end = __ GetAdjustedPosition(it.second.end);
1217 }
1218 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
1219 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
1220 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
1221 }
1222 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +00001223
1224 CodeGenerator::Finalize(allocator);
1225}
1226
David Brazdil58282f42016-01-14 12:45:10 +00001227void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001228 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +01001229 blocked_core_registers_[SP] = true;
1230 blocked_core_registers_[LR] = true;
1231 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001232
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001233 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +01001234 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001235
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001236 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +01001237 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001238
David Brazdil58282f42016-01-14 12:45:10 +00001239 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +01001240 // Stubs do not save callee-save floating point registers. If the graph
1241 // is debuggable, we need to deal with these registers differently. For
1242 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001243 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1244 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1245 }
1246 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001247}
1248
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001249InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001250 : InstructionCodeGenerator(graph, codegen),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001251 assembler_(codegen->GetAssembler()),
1252 codegen_(codegen) {}
1253
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001254void CodeGeneratorARM::ComputeSpillMask() {
1255 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
1256 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
David Brazdil58282f42016-01-14 12:45:10 +00001257 // There is no easy instruction to restore just the PC on thumb2. We spill and
1258 // restore another arbitrary register.
1259 core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001260 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
1261 // We use vpush and vpop for saving and restoring floating point registers, which take
1262 // a SRegister and the number of registers to save/restore after that SRegister. We
1263 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
1264 // but in the range.
1265 if (fpu_spill_mask_ != 0) {
1266 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
1267 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
1268 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
1269 fpu_spill_mask_ |= (1 << i);
1270 }
1271 }
1272}
1273
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001274static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +01001275 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001276}
1277
1278static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +01001279 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001280}
1281
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001282void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +00001283 bool skip_overflow_check =
1284 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +00001285 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001286 __ Bind(&frame_entry_label_);
1287
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001288 if (HasEmptyFrame()) {
1289 return;
1290 }
1291
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001292 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +00001293 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
1294 __ LoadFromOffset(kLoadWord, IP, IP, 0);
1295 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001296 }
1297
Andreas Gampe501fd632015-09-10 16:11:06 -07001298 __ PushList(core_spill_mask_);
1299 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
1300 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001301 if (fpu_spill_mask_ != 0) {
1302 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
1303 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001304 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +01001305 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001306 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001307 int adjust = GetFrameSize() - FrameEntrySpillSize();
1308 __ AddConstant(SP, -adjust);
1309 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001310
1311 // Save the current method if we need it. Note that we do not
1312 // do this in HCurrentMethod, as the instruction might have been removed
1313 // in the SSA graph.
1314 if (RequiresCurrentMethod()) {
1315 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
1316 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001317}
1318
1319void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001320 if (HasEmptyFrame()) {
1321 __ bx(LR);
1322 return;
1323 }
David Srbeckyc34dc932015-04-12 09:27:43 +01001324 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001325 int adjust = GetFrameSize() - FrameEntrySpillSize();
1326 __ AddConstant(SP, adjust);
1327 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001328 if (fpu_spill_mask_ != 0) {
1329 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
1330 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
Andreas Gampe542451c2016-07-26 09:02:02 -07001331 __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001332 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +00001333 }
Andreas Gampe501fd632015-09-10 16:11:06 -07001334 // Pop LR into PC to return.
1335 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
1336 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
1337 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +01001338 __ cfi().RestoreState();
1339 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001340}
1341
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001342void CodeGeneratorARM::Bind(HBasicBlock* block) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07001343 Label* label = GetLabelOf(block);
1344 __ BindTrackedLabel(label);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001345}
1346
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001347Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001348 switch (type) {
1349 case Primitive::kPrimBoolean:
1350 case Primitive::kPrimByte:
1351 case Primitive::kPrimChar:
1352 case Primitive::kPrimShort:
1353 case Primitive::kPrimInt:
1354 case Primitive::kPrimNot: {
1355 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001356 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001357 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001358 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001359 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001360 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001361 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001362 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001363
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001364 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001365 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001366 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001367 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001368 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001369 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001370 if (calling_convention.GetRegisterAt(index) == R1) {
1371 // Skip R1, and use R2_R3 instead.
1372 gp_index_++;
1373 index++;
1374 }
1375 }
1376 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
1377 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001378 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +01001379
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001380 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001381 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001382 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001383 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
1384 }
1385 }
1386
1387 case Primitive::kPrimFloat: {
1388 uint32_t stack_index = stack_index_++;
1389 if (float_index_ % 2 == 0) {
1390 float_index_ = std::max(double_index_, float_index_);
1391 }
1392 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
1393 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
1394 } else {
1395 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
1396 }
1397 }
1398
1399 case Primitive::kPrimDouble: {
1400 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
1401 uint32_t stack_index = stack_index_;
1402 stack_index_ += 2;
1403 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
1404 uint32_t index = double_index_;
1405 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001406 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001407 calling_convention.GetFpuRegisterAt(index),
1408 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001409 DCHECK(ExpectedPairLayout(result));
1410 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001411 } else {
1412 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001413 }
1414 }
1415
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001416 case Primitive::kPrimVoid:
1417 LOG(FATAL) << "Unexpected parameter type " << type;
1418 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001419 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001420 return Location::NoLocation();
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001421}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001422
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001423Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001424 switch (type) {
1425 case Primitive::kPrimBoolean:
1426 case Primitive::kPrimByte:
1427 case Primitive::kPrimChar:
1428 case Primitive::kPrimShort:
1429 case Primitive::kPrimInt:
1430 case Primitive::kPrimNot: {
1431 return Location::RegisterLocation(R0);
1432 }
1433
1434 case Primitive::kPrimFloat: {
1435 return Location::FpuRegisterLocation(S0);
1436 }
1437
1438 case Primitive::kPrimLong: {
1439 return Location::RegisterPairLocation(R0, R1);
1440 }
1441
1442 case Primitive::kPrimDouble: {
1443 return Location::FpuRegisterPairLocation(S0, S1);
1444 }
1445
1446 case Primitive::kPrimVoid:
Roland Levillain3b359c72015-11-17 19:35:12 +00001447 return Location::NoLocation();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001448 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +01001449
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001450 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001451}
1452
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001453Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
1454 return Location::RegisterLocation(kMethodRegisterArgument);
1455}
1456
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001457void CodeGeneratorARM::Move32(Location destination, Location source) {
1458 if (source.Equals(destination)) {
1459 return;
1460 }
1461 if (destination.IsRegister()) {
1462 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001463 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001464 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001465 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001466 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001467 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001468 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001469 } else if (destination.IsFpuRegister()) {
1470 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001471 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001472 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001473 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001474 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001475 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001476 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001477 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001478 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001479 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001480 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001481 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001482 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001483 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001484 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001485 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1486 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001487 }
1488 }
1489}
1490
1491void CodeGeneratorARM::Move64(Location destination, Location source) {
1492 if (source.Equals(destination)) {
1493 return;
1494 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001495 if (destination.IsRegisterPair()) {
1496 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001497 EmitParallelMoves(
1498 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
1499 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001500 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001501 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001502 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
1503 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001504 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001505 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001506 } else if (source.IsFpuRegisterPair()) {
1507 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
1508 destination.AsRegisterPairHigh<Register>(),
1509 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001510 } else {
1511 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001512 DCHECK(ExpectedPairLayout(destination));
1513 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
1514 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001515 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001516 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001517 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001518 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1519 SP,
1520 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001521 } else if (source.IsRegisterPair()) {
1522 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1523 source.AsRegisterPairLow<Register>(),
1524 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001525 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001526 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001527 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001528 } else {
1529 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001530 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001531 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001532 if (source.AsRegisterPairLow<Register>() == R1) {
1533 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001534 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
1535 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001536 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001537 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001538 SP, destination.GetStackIndex());
1539 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001540 } else if (source.IsFpuRegisterPair()) {
1541 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
1542 SP,
1543 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001544 } else {
1545 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001546 EmitParallelMoves(
1547 Location::StackSlot(source.GetStackIndex()),
1548 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001549 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001550 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001551 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
1552 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001553 }
1554 }
1555}
1556
Calin Juravle175dc732015-08-25 15:42:32 +01001557void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1558 DCHECK(location.IsRegister());
1559 __ LoadImmediate(location.AsRegister<Register>(), value);
1560}
1561
Calin Juravlee460d1d2015-09-29 04:52:17 +01001562void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001563 HParallelMove move(GetGraph()->GetArena());
1564 move.AddMove(src, dst, dst_type, nullptr);
1565 GetMoveResolver()->EmitNativeCode(&move);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001566}
1567
1568void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1569 if (location.IsRegister()) {
1570 locations->AddTemp(location);
1571 } else if (location.IsRegisterPair()) {
1572 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1573 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1574 } else {
1575 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1576 }
1577}
1578
Calin Juravle175dc732015-08-25 15:42:32 +01001579void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1580 HInstruction* instruction,
1581 uint32_t dex_pc,
1582 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001583 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001584 GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value());
Serban Constantinescuda8ffec2016-03-09 12:02:11 +00001585 if (EntrypointRequiresStackMap(entrypoint)) {
1586 RecordPcInfo(instruction, dex_pc, slow_path);
1587 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001588}
1589
Roland Levillaindec8f632016-07-22 17:10:06 +01001590void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1591 HInstruction* instruction,
1592 SlowPathCode* slow_path) {
1593 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001594 GenerateInvokeRuntime(entry_point_offset);
1595}
1596
1597void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) {
Roland Levillaindec8f632016-07-22 17:10:06 +01001598 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1599 __ blx(LR);
1600}
1601
David Brazdilfc6a86a2015-06-26 10:33:45 +00001602void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001603 DCHECK(!successor->IsExitBlock());
1604
1605 HBasicBlock* block = got->GetBlock();
1606 HInstruction* previous = got->GetPrevious();
1607
1608 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001609 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001610 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1611 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1612 return;
1613 }
1614
1615 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1616 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1617 }
1618 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001619 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001620 }
1621}
1622
David Brazdilfc6a86a2015-06-26 10:33:45 +00001623void LocationsBuilderARM::VisitGoto(HGoto* got) {
1624 got->SetLocations(nullptr);
1625}
1626
1627void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1628 HandleGoto(got, got->GetSuccessor());
1629}
1630
1631void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1632 try_boundary->SetLocations(nullptr);
1633}
1634
1635void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1636 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1637 if (!successor->IsExitBlock()) {
1638 HandleGoto(try_boundary, successor);
1639 }
1640}
1641
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001642void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001643 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001644}
1645
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001646void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001647}
1648
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001649void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1650 Primitive::Type type = instruction->InputAt(0)->GetType();
1651 Location lhs_loc = instruction->GetLocations()->InAt(0);
1652 Location rhs_loc = instruction->GetLocations()->InAt(1);
1653 if (rhs_loc.IsConstant()) {
1654 // 0.0 is the only immediate that can be encoded directly in
1655 // a VCMP instruction.
1656 //
1657 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1658 // specify that in a floating-point comparison, positive zero
1659 // and negative zero are considered equal, so we can use the
1660 // literal 0.0 for both cases here.
1661 //
1662 // Note however that some methods (Float.equal, Float.compare,
1663 // Float.compareTo, Double.equal, Double.compare,
1664 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1665 // StrictMath.min) consider 0.0 to be (strictly) greater than
1666 // -0.0. So if we ever translate calls to these methods into a
1667 // HCompare instruction, we must handle the -0.0 case with
1668 // care here.
1669 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1670 if (type == Primitive::kPrimFloat) {
1671 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1672 } else {
1673 DCHECK_EQ(type, Primitive::kPrimDouble);
1674 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1675 }
1676 } else {
1677 if (type == Primitive::kPrimFloat) {
1678 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1679 } else {
1680 DCHECK_EQ(type, Primitive::kPrimDouble);
1681 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1682 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1683 }
1684 }
1685}
1686
Roland Levillain4fa13f62015-07-06 18:11:54 +01001687void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1688 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001689 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001690 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001691 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001692}
1693
1694void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1695 Label* true_label,
1696 Label* false_label) {
1697 LocationSummary* locations = cond->GetLocations();
1698 Location left = locations->InAt(0);
1699 Location right = locations->InAt(1);
1700 IfCondition if_cond = cond->GetCondition();
1701
1702 Register left_high = left.AsRegisterPairHigh<Register>();
1703 Register left_low = left.AsRegisterPairLow<Register>();
1704 IfCondition true_high_cond = if_cond;
1705 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001706 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001707
1708 // Set the conditions for the test, remembering that == needs to be
1709 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001710 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001711 switch (if_cond) {
1712 case kCondEQ:
1713 case kCondNE:
1714 // Nothing to do.
1715 break;
1716 case kCondLT:
1717 false_high_cond = kCondGT;
1718 break;
1719 case kCondLE:
1720 true_high_cond = kCondLT;
1721 break;
1722 case kCondGT:
1723 false_high_cond = kCondLT;
1724 break;
1725 case kCondGE:
1726 true_high_cond = kCondGT;
1727 break;
Aart Bike9f37602015-10-09 11:15:55 -07001728 case kCondB:
1729 false_high_cond = kCondA;
1730 break;
1731 case kCondBE:
1732 true_high_cond = kCondB;
1733 break;
1734 case kCondA:
1735 false_high_cond = kCondB;
1736 break;
1737 case kCondAE:
1738 true_high_cond = kCondA;
1739 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001740 }
1741 if (right.IsConstant()) {
1742 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1743 int32_t val_low = Low32Bits(value);
1744 int32_t val_high = High32Bits(value);
1745
Vladimir Markoac6ac102015-12-17 12:14:00 +00001746 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001747 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001748 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001749 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001750 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001751 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001752 __ b(true_label, ARMCondition(true_high_cond));
1753 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001754 }
1755 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001756 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001757 } else {
1758 Register right_high = right.AsRegisterPairHigh<Register>();
1759 Register right_low = right.AsRegisterPairLow<Register>();
1760
1761 __ cmp(left_high, ShifterOperand(right_high));
1762 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001763 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001764 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001765 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001766 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001767 __ b(true_label, ARMCondition(true_high_cond));
1768 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001769 }
1770 // Must be equal high, so compare the lows.
1771 __ cmp(left_low, ShifterOperand(right_low));
1772 }
1773 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001774 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001775 __ b(true_label, final_condition);
1776}
1777
David Brazdil0debae72015-11-12 18:37:00 +00001778void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1779 Label* true_target_in,
1780 Label* false_target_in) {
1781 // Generated branching requires both targets to be explicit. If either of the
1782 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1783 Label fallthrough_target;
1784 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1785 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1786
Roland Levillain4fa13f62015-07-06 18:11:54 +01001787 Primitive::Type type = condition->InputAt(0)->GetType();
1788 switch (type) {
1789 case Primitive::kPrimLong:
1790 GenerateLongComparesAndJumps(condition, true_target, false_target);
1791 break;
1792 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001793 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001794 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001795 GenerateFPJumps(condition, true_target, false_target);
1796 break;
1797 default:
1798 LOG(FATAL) << "Unexpected compare type " << type;
1799 }
1800
David Brazdil0debae72015-11-12 18:37:00 +00001801 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001802 __ b(false_target);
1803 }
David Brazdil0debae72015-11-12 18:37:00 +00001804
1805 if (fallthrough_target.IsLinked()) {
1806 __ Bind(&fallthrough_target);
1807 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001808}
1809
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001810void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001811 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001812 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001813 Label* false_target) {
1814 HInstruction* cond = instruction->InputAt(condition_input_index);
1815
1816 if (true_target == nullptr && false_target == nullptr) {
1817 // Nothing to do. The code always falls through.
1818 return;
1819 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001820 // Constant condition, statically compared against "true" (integer value 1).
1821 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001822 if (true_target != nullptr) {
1823 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001824 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001825 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001826 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001827 if (false_target != nullptr) {
1828 __ b(false_target);
1829 }
1830 }
1831 return;
1832 }
1833
1834 // The following code generates these patterns:
1835 // (1) true_target == nullptr && false_target != nullptr
1836 // - opposite condition true => branch to false_target
1837 // (2) true_target != nullptr && false_target == nullptr
1838 // - condition true => branch to true_target
1839 // (3) true_target != nullptr && false_target != nullptr
1840 // - condition true => branch to true_target
1841 // - branch to false_target
1842 if (IsBooleanValueOrMaterializedCondition(cond)) {
1843 // Condition has been materialized, compare the output to 0.
1844 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1845 DCHECK(cond_val.IsRegister());
1846 if (true_target == nullptr) {
1847 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1848 } else {
1849 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001850 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001851 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001852 // Condition has not been materialized. Use its inputs as the comparison and
1853 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001854 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001855
1856 // If this is a long or FP comparison that has been folded into
1857 // the HCondition, generate the comparison directly.
1858 Primitive::Type type = condition->InputAt(0)->GetType();
1859 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1860 GenerateCompareTestAndBranch(condition, true_target, false_target);
1861 return;
1862 }
1863
1864 LocationSummary* locations = cond->GetLocations();
1865 DCHECK(locations->InAt(0).IsRegister());
1866 Register left = locations->InAt(0).AsRegister<Register>();
1867 Location right = locations->InAt(1);
1868 if (right.IsRegister()) {
1869 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001870 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001871 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001872 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001873 }
1874 if (true_target == nullptr) {
1875 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1876 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001877 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001878 }
Dave Allison20dfc792014-06-16 20:44:29 -07001879 }
David Brazdil0debae72015-11-12 18:37:00 +00001880
1881 // If neither branch falls through (case 3), the conditional branch to `true_target`
1882 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1883 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001884 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001885 }
1886}
1887
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001888void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001889 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1890 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001891 locations->SetInAt(0, Location::RequiresRegister());
1892 }
1893}
1894
1895void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001896 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1897 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1898 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1899 nullptr : codegen_->GetLabelOf(true_successor);
1900 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1901 nullptr : codegen_->GetLabelOf(false_successor);
1902 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001903}
1904
1905void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1906 LocationSummary* locations = new (GetGraph()->GetArena())
1907 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01001908 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
David Brazdil0debae72015-11-12 18:37:00 +00001909 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001910 locations->SetInAt(0, Location::RequiresRegister());
1911 }
1912}
1913
1914void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Artem Serovf4d6aee2016-07-11 10:41:45 +01001915 SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001916 GenerateTestAndBranch(deoptimize,
1917 /* condition_input_index */ 0,
1918 slow_path->GetEntryLabel(),
1919 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001920}
Dave Allison20dfc792014-06-16 20:44:29 -07001921
David Brazdil74eb1b22015-12-14 11:44:01 +00001922void LocationsBuilderARM::VisitSelect(HSelect* select) {
1923 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1924 if (Primitive::IsFloatingPointType(select->GetType())) {
1925 locations->SetInAt(0, Location::RequiresFpuRegister());
1926 locations->SetInAt(1, Location::RequiresFpuRegister());
1927 } else {
1928 locations->SetInAt(0, Location::RequiresRegister());
1929 locations->SetInAt(1, Location::RequiresRegister());
1930 }
1931 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1932 locations->SetInAt(2, Location::RequiresRegister());
1933 }
1934 locations->SetOut(Location::SameAsFirstInput());
1935}
1936
1937void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1938 LocationSummary* locations = select->GetLocations();
1939 Label false_target;
1940 GenerateTestAndBranch(select,
1941 /* condition_input_index */ 2,
1942 /* true_target */ nullptr,
1943 &false_target);
1944 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1945 __ Bind(&false_target);
1946}
1947
David Srbecky0cf44932015-12-09 14:09:59 +00001948void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1949 new (GetGraph()->GetArena()) LocationSummary(info);
1950}
1951
David Srbeckyd28f4a02016-03-14 17:14:24 +00001952void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1953 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001954}
1955
1956void CodeGeneratorARM::GenerateNop() {
1957 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001958}
1959
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001960void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001961 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001962 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001963 // Handle the long/FP comparisons made in instruction simplification.
1964 switch (cond->InputAt(0)->GetType()) {
1965 case Primitive::kPrimLong:
1966 locations->SetInAt(0, Location::RequiresRegister());
1967 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001968 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001969 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1970 }
1971 break;
1972
1973 case Primitive::kPrimFloat:
1974 case Primitive::kPrimDouble:
1975 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001976 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001977 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001978 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1979 }
1980 break;
1981
1982 default:
1983 locations->SetInAt(0, Location::RequiresRegister());
1984 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001985 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001986 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1987 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001988 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001989}
1990
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001991void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001992 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001993 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001994 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001995
1996 LocationSummary* locations = cond->GetLocations();
1997 Location left = locations->InAt(0);
1998 Location right = locations->InAt(1);
1999 Register out = locations->Out().AsRegister<Register>();
2000 Label true_label, false_label;
2001
2002 switch (cond->InputAt(0)->GetType()) {
2003 default: {
2004 // Integer case.
2005 if (right.IsRegister()) {
2006 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
2007 } else {
2008 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00002009 __ CmpConstant(left.AsRegister<Register>(),
2010 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01002011 }
Aart Bike9f37602015-10-09 11:15:55 -07002012 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01002013 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07002014 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01002015 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07002016 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01002017 return;
2018 }
2019 case Primitive::kPrimLong:
2020 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
2021 break;
2022 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01002023 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01002024 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01002025 GenerateFPJumps(cond, &true_label, &false_label);
2026 break;
2027 }
2028
2029 // Convert the jumps into the result.
2030 Label done_label;
2031
2032 // False case: result = 0.
2033 __ Bind(&false_label);
2034 __ LoadImmediate(out, 0);
2035 __ b(&done_label);
2036
2037 // True case: result = 1.
2038 __ Bind(&true_label);
2039 __ LoadImmediate(out, 1);
2040 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07002041}
2042
2043void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002044 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002045}
2046
2047void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002048 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002049}
2050
2051void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002052 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002053}
2054
2055void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002056 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002057}
2058
2059void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002060 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002061}
2062
2063void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002064 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002065}
2066
2067void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002068 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002069}
2070
2071void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002072 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002073}
2074
2075void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002076 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002077}
2078
2079void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002080 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002081}
2082
2083void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002084 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07002085}
2086
2087void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002088 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002089}
2090
Aart Bike9f37602015-10-09 11:15:55 -07002091void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002092 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002093}
2094
2095void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002096 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002097}
2098
2099void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002100 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002101}
2102
2103void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002104 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002105}
2106
2107void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002108 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002109}
2110
2111void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002112 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002113}
2114
2115void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002116 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002117}
2118
2119void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002120 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07002121}
2122
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002123void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002124 LocationSummary* locations =
2125 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002126 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002127}
2128
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01002129void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01002130 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002131}
2132
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00002133void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
2134 LocationSummary* locations =
2135 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2136 locations->SetOut(Location::ConstantLocation(constant));
2137}
2138
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01002139void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00002140 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00002141}
2142
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002143void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002144 LocationSummary* locations =
2145 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002146 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002147}
2148
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01002149void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002150 // Will be generated at use site.
2151}
2152
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002153void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
2154 LocationSummary* locations =
2155 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2156 locations->SetOut(Location::ConstantLocation(constant));
2157}
2158
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01002159void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002160 // Will be generated at use site.
2161}
2162
2163void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
2164 LocationSummary* locations =
2165 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2166 locations->SetOut(Location::ConstantLocation(constant));
2167}
2168
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01002169void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002170 // Will be generated at use site.
2171}
2172
Calin Juravle27df7582015-04-17 19:12:31 +01002173void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2174 memory_barrier->SetLocations(nullptr);
2175}
2176
2177void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00002178 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01002179}
2180
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002181void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00002182 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002183}
2184
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01002185void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00002186 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002187}
2188
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002189void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002190 LocationSummary* locations =
2191 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002192 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002193}
2194
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01002195void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00002196 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002197}
2198
Calin Juravle175dc732015-08-25 15:42:32 +01002199void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2200 // The trampoline uses the same calling convention as dex calling conventions,
2201 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
2202 // the method_idx.
2203 HandleInvoke(invoke);
2204}
2205
2206void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
2207 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
2208}
2209
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002210void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00002211 // Explicit clinit checks triggered by static invokes must have been pruned by
2212 // art::PrepareForRegisterAllocation.
2213 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01002214
Vladimir Marko68c981f2016-08-26 13:13:33 +01002215 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002216 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00002217 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
2218 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
2219 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002220 return;
2221 }
2222
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01002223 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00002224
2225 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
2226 if (invoke->HasPcRelativeDexCache()) {
2227 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
2228 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01002229}
2230
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002231static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
2232 if (invoke->GetLocations()->Intrinsified()) {
2233 IntrinsicCodeGeneratorARM intrinsic(codegen);
2234 intrinsic.Dispatch(invoke);
2235 return true;
2236 }
2237 return false;
2238}
2239
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002240void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00002241 // Explicit clinit checks triggered by static invokes must have been pruned by
2242 // art::PrepareForRegisterAllocation.
2243 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01002244
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002245 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2246 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002247 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01002248
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002249 LocationSummary* locations = invoke->GetLocations();
2250 codegen_->GenerateStaticOrDirectCall(
2251 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002252 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01002253}
2254
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01002255void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01002256 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01002257 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00002258}
2259
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002260void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Vladimir Marko68c981f2016-08-26 13:13:33 +01002261 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002262 if (intrinsic.TryDispatch(invoke)) {
2263 return;
2264 }
2265
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002266 HandleInvoke(invoke);
2267}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00002268
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01002269void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002270 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2271 return;
2272 }
2273
Andreas Gampebfb5ba92015-09-01 15:45:02 +00002274 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01002275 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01002276 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00002277}
2278
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002279void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
2280 HandleInvoke(invoke);
2281 // Add the hidden argument.
2282 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
2283}
2284
2285void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
2286 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00002287 LocationSummary* locations = invoke->GetLocations();
2288 Register temp = locations->GetTemp(0).AsRegister<Register>();
2289 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002290 Location receiver = locations->InAt(0);
2291 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2292
Roland Levillain3b359c72015-11-17 19:35:12 +00002293 // Set the hidden argument. This is safe to do this here, as R12
2294 // won't be modified thereafter, before the `blx` (call) instruction.
2295 DCHECK_EQ(R12, hidden_reg);
2296 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002297
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002298 if (receiver.IsStackSlot()) {
2299 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00002300 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002301 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
2302 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00002303 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00002304 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002305 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002306 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00002307 // Instead of simply (possibly) unpoisoning `temp` here, we should
2308 // emit a read barrier for the previous class reference load.
2309 // However this is not required in practice, as this is an
2310 // intermediate/temporary reference and because the current
2311 // concurrent copying collector keeps the from-space memory
2312 // intact/accessible until the end of the marking phase (the
2313 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01002314 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00002315 __ LoadFromOffset(kLoadWord, temp, temp,
2316 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
2317 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00002318 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002319 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00002320 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00002321 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07002322 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00002323 // LR = temp->GetEntryPoint();
2324 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
2325 // LR();
2326 __ blx(LR);
2327 DCHECK(!codegen_->IsLeafMethod());
2328 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2329}
2330
Roland Levillain88cb1752014-10-20 16:36:47 +01002331void LocationsBuilderARM::VisitNeg(HNeg* neg) {
2332 LocationSummary* locations =
2333 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2334 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002335 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01002336 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002337 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2338 break;
2339 }
2340 case Primitive::kPrimLong: {
2341 locations->SetInAt(0, Location::RequiresRegister());
2342 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01002343 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002344 }
Roland Levillain88cb1752014-10-20 16:36:47 +01002345
Roland Levillain88cb1752014-10-20 16:36:47 +01002346 case Primitive::kPrimFloat:
2347 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002348 locations->SetInAt(0, Location::RequiresFpuRegister());
2349 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01002350 break;
2351
2352 default:
2353 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2354 }
2355}
2356
2357void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
2358 LocationSummary* locations = neg->GetLocations();
2359 Location out = locations->Out();
2360 Location in = locations->InAt(0);
2361 switch (neg->GetResultType()) {
2362 case Primitive::kPrimInt:
2363 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002364 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01002365 break;
2366
2367 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002368 DCHECK(in.IsRegisterPair());
2369 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
2370 __ rsbs(out.AsRegisterPairLow<Register>(),
2371 in.AsRegisterPairLow<Register>(),
2372 ShifterOperand(0));
2373 // We cannot emit an RSC (Reverse Subtract with Carry)
2374 // instruction here, as it does not exist in the Thumb-2
2375 // instruction set. We use the following approach
2376 // using SBC and SUB instead.
2377 //
2378 // out.hi = -C
2379 __ sbc(out.AsRegisterPairHigh<Register>(),
2380 out.AsRegisterPairHigh<Register>(),
2381 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2382 // out.hi = out.hi - in.hi
2383 __ sub(out.AsRegisterPairHigh<Register>(),
2384 out.AsRegisterPairHigh<Register>(),
2385 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2386 break;
2387
Roland Levillain88cb1752014-10-20 16:36:47 +01002388 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002389 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002390 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002391 break;
2392
Roland Levillain88cb1752014-10-20 16:36:47 +01002393 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002394 DCHECK(in.IsFpuRegisterPair());
2395 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2396 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002397 break;
2398
2399 default:
2400 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2401 }
2402}
2403
Roland Levillaindff1f282014-11-05 14:15:05 +00002404void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002405 Primitive::Type result_type = conversion->GetResultType();
2406 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002407 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002408
Roland Levillain5b3ee562015-04-14 16:02:41 +01002409 // The float-to-long, double-to-long and long-to-float type conversions
2410 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002411 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002412 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2413 && result_type == Primitive::kPrimLong)
2414 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002415 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002416 : LocationSummary::kNoCall;
2417 LocationSummary* locations =
2418 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2419
David Brazdilb2bd1c52015-03-25 11:17:37 +00002420 // The Java language does not allow treating boolean as an integral type but
2421 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002422
Roland Levillaindff1f282014-11-05 14:15:05 +00002423 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002424 case Primitive::kPrimByte:
2425 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002426 case Primitive::kPrimLong:
2427 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002428 case Primitive::kPrimBoolean:
2429 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002430 case Primitive::kPrimShort:
2431 case Primitive::kPrimInt:
2432 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002433 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002434 locations->SetInAt(0, Location::RequiresRegister());
2435 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2436 break;
2437
2438 default:
2439 LOG(FATAL) << "Unexpected type conversion from " << input_type
2440 << " to " << result_type;
2441 }
2442 break;
2443
Roland Levillain01a8d712014-11-14 16:27:39 +00002444 case Primitive::kPrimShort:
2445 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002446 case Primitive::kPrimLong:
2447 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002448 case Primitive::kPrimBoolean:
2449 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002450 case Primitive::kPrimByte:
2451 case Primitive::kPrimInt:
2452 case Primitive::kPrimChar:
2453 // Processing a Dex `int-to-short' instruction.
2454 locations->SetInAt(0, Location::RequiresRegister());
2455 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2456 break;
2457
2458 default:
2459 LOG(FATAL) << "Unexpected type conversion from " << input_type
2460 << " to " << result_type;
2461 }
2462 break;
2463
Roland Levillain946e1432014-11-11 17:35:19 +00002464 case Primitive::kPrimInt:
2465 switch (input_type) {
2466 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002467 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002468 locations->SetInAt(0, Location::Any());
2469 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2470 break;
2471
2472 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002473 // Processing a Dex `float-to-int' instruction.
2474 locations->SetInAt(0, Location::RequiresFpuRegister());
2475 locations->SetOut(Location::RequiresRegister());
2476 locations->AddTemp(Location::RequiresFpuRegister());
2477 break;
2478
Roland Levillain946e1432014-11-11 17:35:19 +00002479 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002480 // Processing a Dex `double-to-int' instruction.
2481 locations->SetInAt(0, Location::RequiresFpuRegister());
2482 locations->SetOut(Location::RequiresRegister());
2483 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002484 break;
2485
2486 default:
2487 LOG(FATAL) << "Unexpected type conversion from " << input_type
2488 << " to " << result_type;
2489 }
2490 break;
2491
Roland Levillaindff1f282014-11-05 14:15:05 +00002492 case Primitive::kPrimLong:
2493 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002494 case Primitive::kPrimBoolean:
2495 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002496 case Primitive::kPrimByte:
2497 case Primitive::kPrimShort:
2498 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002499 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002500 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002501 locations->SetInAt(0, Location::RequiresRegister());
2502 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2503 break;
2504
Roland Levillain624279f2014-12-04 11:54:28 +00002505 case Primitive::kPrimFloat: {
2506 // Processing a Dex `float-to-long' instruction.
2507 InvokeRuntimeCallingConvention calling_convention;
2508 locations->SetInAt(0, Location::FpuRegisterLocation(
2509 calling_convention.GetFpuRegisterAt(0)));
2510 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2511 break;
2512 }
2513
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002514 case Primitive::kPrimDouble: {
2515 // Processing a Dex `double-to-long' instruction.
2516 InvokeRuntimeCallingConvention calling_convention;
2517 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2518 calling_convention.GetFpuRegisterAt(0),
2519 calling_convention.GetFpuRegisterAt(1)));
2520 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002521 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002522 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002523
2524 default:
2525 LOG(FATAL) << "Unexpected type conversion from " << input_type
2526 << " to " << result_type;
2527 }
2528 break;
2529
Roland Levillain981e4542014-11-14 11:47:14 +00002530 case Primitive::kPrimChar:
2531 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002532 case Primitive::kPrimLong:
2533 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002534 case Primitive::kPrimBoolean:
2535 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002536 case Primitive::kPrimByte:
2537 case Primitive::kPrimShort:
2538 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002539 // Processing a Dex `int-to-char' instruction.
2540 locations->SetInAt(0, Location::RequiresRegister());
2541 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2542 break;
2543
2544 default:
2545 LOG(FATAL) << "Unexpected type conversion from " << input_type
2546 << " to " << result_type;
2547 }
2548 break;
2549
Roland Levillaindff1f282014-11-05 14:15:05 +00002550 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002551 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002552 case Primitive::kPrimBoolean:
2553 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002554 case Primitive::kPrimByte:
2555 case Primitive::kPrimShort:
2556 case Primitive::kPrimInt:
2557 case Primitive::kPrimChar:
2558 // Processing a Dex `int-to-float' instruction.
2559 locations->SetInAt(0, Location::RequiresRegister());
2560 locations->SetOut(Location::RequiresFpuRegister());
2561 break;
2562
Roland Levillain5b3ee562015-04-14 16:02:41 +01002563 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002564 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002565 InvokeRuntimeCallingConvention calling_convention;
2566 locations->SetInAt(0, Location::RegisterPairLocation(
2567 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2568 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002569 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002570 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002571
Roland Levillaincff13742014-11-17 14:32:17 +00002572 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002573 // Processing a Dex `double-to-float' instruction.
2574 locations->SetInAt(0, Location::RequiresFpuRegister());
2575 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002576 break;
2577
2578 default:
2579 LOG(FATAL) << "Unexpected type conversion from " << input_type
2580 << " to " << result_type;
2581 };
2582 break;
2583
Roland Levillaindff1f282014-11-05 14:15:05 +00002584 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002585 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002586 case Primitive::kPrimBoolean:
2587 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002588 case Primitive::kPrimByte:
2589 case Primitive::kPrimShort:
2590 case Primitive::kPrimInt:
2591 case Primitive::kPrimChar:
2592 // Processing a Dex `int-to-double' instruction.
2593 locations->SetInAt(0, Location::RequiresRegister());
2594 locations->SetOut(Location::RequiresFpuRegister());
2595 break;
2596
2597 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002598 // Processing a Dex `long-to-double' instruction.
2599 locations->SetInAt(0, Location::RequiresRegister());
2600 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002601 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002602 locations->AddTemp(Location::RequiresFpuRegister());
2603 break;
2604
Roland Levillaincff13742014-11-17 14:32:17 +00002605 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002606 // Processing a Dex `float-to-double' instruction.
2607 locations->SetInAt(0, Location::RequiresFpuRegister());
2608 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002609 break;
2610
2611 default:
2612 LOG(FATAL) << "Unexpected type conversion from " << input_type
2613 << " to " << result_type;
2614 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002615 break;
2616
2617 default:
2618 LOG(FATAL) << "Unexpected type conversion from " << input_type
2619 << " to " << result_type;
2620 }
2621}
2622
2623void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2624 LocationSummary* locations = conversion->GetLocations();
2625 Location out = locations->Out();
2626 Location in = locations->InAt(0);
2627 Primitive::Type result_type = conversion->GetResultType();
2628 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002629 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002630 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002631 case Primitive::kPrimByte:
2632 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002633 case Primitive::kPrimLong:
2634 // Type conversion from long to byte is a result of code transformations.
2635 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2636 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002637 case Primitive::kPrimBoolean:
2638 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002639 case Primitive::kPrimShort:
2640 case Primitive::kPrimInt:
2641 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002642 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002643 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002644 break;
2645
2646 default:
2647 LOG(FATAL) << "Unexpected type conversion from " << input_type
2648 << " to " << result_type;
2649 }
2650 break;
2651
Roland Levillain01a8d712014-11-14 16:27:39 +00002652 case Primitive::kPrimShort:
2653 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002654 case Primitive::kPrimLong:
2655 // Type conversion from long to short is a result of code transformations.
2656 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2657 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002658 case Primitive::kPrimBoolean:
2659 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002660 case Primitive::kPrimByte:
2661 case Primitive::kPrimInt:
2662 case Primitive::kPrimChar:
2663 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002664 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002665 break;
2666
2667 default:
2668 LOG(FATAL) << "Unexpected type conversion from " << input_type
2669 << " to " << result_type;
2670 }
2671 break;
2672
Roland Levillain946e1432014-11-11 17:35:19 +00002673 case Primitive::kPrimInt:
2674 switch (input_type) {
2675 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002676 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002677 DCHECK(out.IsRegister());
2678 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002679 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002680 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002681 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002682 } else {
2683 DCHECK(in.IsConstant());
2684 DCHECK(in.GetConstant()->IsLongConstant());
2685 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002686 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002687 }
2688 break;
2689
Roland Levillain3f8f9362014-12-02 17:45:01 +00002690 case Primitive::kPrimFloat: {
2691 // Processing a Dex `float-to-int' instruction.
2692 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002693 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002694 __ vmovrs(out.AsRegister<Register>(), temp);
2695 break;
2696 }
2697
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002698 case Primitive::kPrimDouble: {
2699 // Processing a Dex `double-to-int' instruction.
2700 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002701 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002702 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002703 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002704 }
Roland Levillain946e1432014-11-11 17:35:19 +00002705
2706 default:
2707 LOG(FATAL) << "Unexpected type conversion from " << input_type
2708 << " to " << result_type;
2709 }
2710 break;
2711
Roland Levillaindff1f282014-11-05 14:15:05 +00002712 case Primitive::kPrimLong:
2713 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002714 case Primitive::kPrimBoolean:
2715 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002716 case Primitive::kPrimByte:
2717 case Primitive::kPrimShort:
2718 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002719 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002720 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002721 DCHECK(out.IsRegisterPair());
2722 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002723 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002724 // Sign extension.
2725 __ Asr(out.AsRegisterPairHigh<Register>(),
2726 out.AsRegisterPairLow<Register>(),
2727 31);
2728 break;
2729
2730 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002731 // Processing a Dex `float-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002732 codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002733 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002734 break;
2735
Roland Levillaindff1f282014-11-05 14:15:05 +00002736 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002737 // Processing a Dex `double-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002738 codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002739 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002740 break;
2741
2742 default:
2743 LOG(FATAL) << "Unexpected type conversion from " << input_type
2744 << " to " << result_type;
2745 }
2746 break;
2747
Roland Levillain981e4542014-11-14 11:47:14 +00002748 case Primitive::kPrimChar:
2749 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002750 case Primitive::kPrimLong:
2751 // Type conversion from long to char is a result of code transformations.
2752 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2753 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002754 case Primitive::kPrimBoolean:
2755 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002756 case Primitive::kPrimByte:
2757 case Primitive::kPrimShort:
2758 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002759 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002760 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002761 break;
2762
2763 default:
2764 LOG(FATAL) << "Unexpected type conversion from " << input_type
2765 << " to " << result_type;
2766 }
2767 break;
2768
Roland Levillaindff1f282014-11-05 14:15:05 +00002769 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002770 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002771 case Primitive::kPrimBoolean:
2772 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002773 case Primitive::kPrimByte:
2774 case Primitive::kPrimShort:
2775 case Primitive::kPrimInt:
2776 case Primitive::kPrimChar: {
2777 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002778 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2779 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002780 break;
2781 }
2782
Roland Levillain5b3ee562015-04-14 16:02:41 +01002783 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002784 // Processing a Dex `long-to-float' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002785 codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002786 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002787 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002788
Roland Levillaincff13742014-11-17 14:32:17 +00002789 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002790 // Processing a Dex `double-to-float' instruction.
2791 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2792 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002793 break;
2794
2795 default:
2796 LOG(FATAL) << "Unexpected type conversion from " << input_type
2797 << " to " << result_type;
2798 };
2799 break;
2800
Roland Levillaindff1f282014-11-05 14:15:05 +00002801 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002802 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002803 case Primitive::kPrimBoolean:
2804 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002805 case Primitive::kPrimByte:
2806 case Primitive::kPrimShort:
2807 case Primitive::kPrimInt:
2808 case Primitive::kPrimChar: {
2809 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002810 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002811 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2812 out.AsFpuRegisterPairLow<SRegister>());
2813 break;
2814 }
2815
Roland Levillain647b9ed2014-11-27 12:06:00 +00002816 case Primitive::kPrimLong: {
2817 // Processing a Dex `long-to-double' instruction.
2818 Register low = in.AsRegisterPairLow<Register>();
2819 Register high = in.AsRegisterPairHigh<Register>();
2820 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2821 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002822 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002823 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002824 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2825 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002826
Roland Levillain682393c2015-04-14 15:57:52 +01002827 // temp_d = int-to-double(high)
2828 __ vmovsr(temp_s, high);
2829 __ vcvtdi(temp_d, temp_s);
2830 // constant_d = k2Pow32EncodingForDouble
2831 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2832 // out_d = unsigned-to-double(low)
2833 __ vmovsr(out_s, low);
2834 __ vcvtdu(out_d, out_s);
2835 // out_d += temp_d * constant_d
2836 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002837 break;
2838 }
2839
Roland Levillaincff13742014-11-17 14:32:17 +00002840 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002841 // Processing a Dex `float-to-double' instruction.
2842 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2843 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002844 break;
2845
2846 default:
2847 LOG(FATAL) << "Unexpected type conversion from " << input_type
2848 << " to " << result_type;
2849 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002850 break;
2851
2852 default:
2853 LOG(FATAL) << "Unexpected type conversion from " << input_type
2854 << " to " << result_type;
2855 }
2856}
2857
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002858void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002859 LocationSummary* locations =
2860 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002861 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002862 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002863 locations->SetInAt(0, Location::RequiresRegister());
2864 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002865 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2866 break;
2867 }
2868
2869 case Primitive::kPrimLong: {
2870 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002871 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002872 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002873 break;
2874 }
2875
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002876 case Primitive::kPrimFloat:
2877 case Primitive::kPrimDouble: {
2878 locations->SetInAt(0, Location::RequiresFpuRegister());
2879 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002880 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002881 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002882 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002883
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002884 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002885 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002886 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002887}
2888
2889void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2890 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002891 Location out = locations->Out();
2892 Location first = locations->InAt(0);
2893 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002894 switch (add->GetResultType()) {
2895 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002896 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002897 __ add(out.AsRegister<Register>(),
2898 first.AsRegister<Register>(),
2899 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002900 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002901 __ AddConstant(out.AsRegister<Register>(),
2902 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002903 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002904 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002905 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002906
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002907 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002908 if (second.IsConstant()) {
2909 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2910 GenerateAddLongConst(out, first, value);
2911 } else {
2912 DCHECK(second.IsRegisterPair());
2913 __ adds(out.AsRegisterPairLow<Register>(),
2914 first.AsRegisterPairLow<Register>(),
2915 ShifterOperand(second.AsRegisterPairLow<Register>()));
2916 __ adc(out.AsRegisterPairHigh<Register>(),
2917 first.AsRegisterPairHigh<Register>(),
2918 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2919 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002920 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002921 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002922
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002923 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002924 __ vadds(out.AsFpuRegister<SRegister>(),
2925 first.AsFpuRegister<SRegister>(),
2926 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002927 break;
2928
2929 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002930 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2931 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2932 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002933 break;
2934
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002935 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002936 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002937 }
2938}
2939
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002940void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002941 LocationSummary* locations =
2942 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002943 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002944 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002945 locations->SetInAt(0, Location::RequiresRegister());
2946 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002947 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2948 break;
2949 }
2950
2951 case Primitive::kPrimLong: {
2952 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002953 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002954 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002955 break;
2956 }
Calin Juravle11351682014-10-23 15:38:15 +01002957 case Primitive::kPrimFloat:
2958 case Primitive::kPrimDouble: {
2959 locations->SetInAt(0, Location::RequiresFpuRegister());
2960 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002961 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002962 break;
Calin Juravle11351682014-10-23 15:38:15 +01002963 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002964 default:
Calin Juravle11351682014-10-23 15:38:15 +01002965 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002966 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002967}
2968
2969void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2970 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002971 Location out = locations->Out();
2972 Location first = locations->InAt(0);
2973 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002974 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002975 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002976 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002977 __ sub(out.AsRegister<Register>(),
2978 first.AsRegister<Register>(),
2979 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002980 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002981 __ AddConstant(out.AsRegister<Register>(),
2982 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002983 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002984 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002985 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002986 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002987
Calin Juravle11351682014-10-23 15:38:15 +01002988 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002989 if (second.IsConstant()) {
2990 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2991 GenerateAddLongConst(out, first, -value);
2992 } else {
2993 DCHECK(second.IsRegisterPair());
2994 __ subs(out.AsRegisterPairLow<Register>(),
2995 first.AsRegisterPairLow<Register>(),
2996 ShifterOperand(second.AsRegisterPairLow<Register>()));
2997 __ sbc(out.AsRegisterPairHigh<Register>(),
2998 first.AsRegisterPairHigh<Register>(),
2999 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3000 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003001 break;
Calin Juravle11351682014-10-23 15:38:15 +01003002 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003003
Calin Juravle11351682014-10-23 15:38:15 +01003004 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00003005 __ vsubs(out.AsFpuRegister<SRegister>(),
3006 first.AsFpuRegister<SRegister>(),
3007 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003008 break;
Calin Juravle11351682014-10-23 15:38:15 +01003009 }
3010
3011 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00003012 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
3013 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
3014 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01003015 break;
3016 }
3017
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003018
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003019 default:
Calin Juravle11351682014-10-23 15:38:15 +01003020 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003021 }
3022}
3023
Calin Juravle34bacdf2014-10-07 20:23:36 +01003024void LocationsBuilderARM::VisitMul(HMul* mul) {
3025 LocationSummary* locations =
3026 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
3027 switch (mul->GetResultType()) {
3028 case Primitive::kPrimInt:
3029 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003030 locations->SetInAt(0, Location::RequiresRegister());
3031 locations->SetInAt(1, Location::RequiresRegister());
3032 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01003033 break;
3034 }
3035
Calin Juravleb5bfa962014-10-21 18:02:24 +01003036 case Primitive::kPrimFloat:
3037 case Primitive::kPrimDouble: {
3038 locations->SetInAt(0, Location::RequiresFpuRegister());
3039 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00003040 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01003041 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01003042 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01003043
3044 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01003045 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01003046 }
3047}
3048
3049void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
3050 LocationSummary* locations = mul->GetLocations();
3051 Location out = locations->Out();
3052 Location first = locations->InAt(0);
3053 Location second = locations->InAt(1);
3054 switch (mul->GetResultType()) {
3055 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00003056 __ mul(out.AsRegister<Register>(),
3057 first.AsRegister<Register>(),
3058 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01003059 break;
3060 }
3061 case Primitive::kPrimLong: {
3062 Register out_hi = out.AsRegisterPairHigh<Register>();
3063 Register out_lo = out.AsRegisterPairLow<Register>();
3064 Register in1_hi = first.AsRegisterPairHigh<Register>();
3065 Register in1_lo = first.AsRegisterPairLow<Register>();
3066 Register in2_hi = second.AsRegisterPairHigh<Register>();
3067 Register in2_lo = second.AsRegisterPairLow<Register>();
3068
3069 // Extra checks to protect caused by the existence of R1_R2.
3070 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
3071 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
3072 DCHECK_NE(out_hi, in1_lo);
3073 DCHECK_NE(out_hi, in2_lo);
3074
3075 // input: in1 - 64 bits, in2 - 64 bits
3076 // output: out
3077 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
3078 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
3079 // parts: out.lo = (in1.lo * in2.lo)[31:0]
3080
3081 // IP <- in1.lo * in2.hi
3082 __ mul(IP, in1_lo, in2_hi);
3083 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
3084 __ mla(out_hi, in1_hi, in2_lo, IP);
3085 // out.lo <- (in1.lo * in2.lo)[31:0];
3086 __ umull(out_lo, IP, in1_lo, in2_lo);
3087 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
3088 __ add(out_hi, out_hi, ShifterOperand(IP));
3089 break;
3090 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01003091
3092 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00003093 __ vmuls(out.AsFpuRegister<SRegister>(),
3094 first.AsFpuRegister<SRegister>(),
3095 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01003096 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01003097 }
3098
3099 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00003100 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
3101 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
3102 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01003103 break;
3104 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01003105
3106 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01003107 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01003108 }
3109}
3110
Zheng Xuc6667102015-05-15 16:08:45 +08003111void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
3112 DCHECK(instruction->IsDiv() || instruction->IsRem());
3113 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
3114
3115 LocationSummary* locations = instruction->GetLocations();
3116 Location second = locations->InAt(1);
3117 DCHECK(second.IsConstant());
3118
3119 Register out = locations->Out().AsRegister<Register>();
3120 Register dividend = locations->InAt(0).AsRegister<Register>();
3121 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3122 DCHECK(imm == 1 || imm == -1);
3123
3124 if (instruction->IsRem()) {
3125 __ LoadImmediate(out, 0);
3126 } else {
3127 if (imm == 1) {
3128 __ Mov(out, dividend);
3129 } else {
3130 __ rsb(out, dividend, ShifterOperand(0));
3131 }
3132 }
3133}
3134
3135void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
3136 DCHECK(instruction->IsDiv() || instruction->IsRem());
3137 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
3138
3139 LocationSummary* locations = instruction->GetLocations();
3140 Location second = locations->InAt(1);
3141 DCHECK(second.IsConstant());
3142
3143 Register out = locations->Out().AsRegister<Register>();
3144 Register dividend = locations->InAt(0).AsRegister<Register>();
3145 Register temp = locations->GetTemp(0).AsRegister<Register>();
3146 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003147 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08003148 int ctz_imm = CTZ(abs_imm);
3149
3150 if (ctz_imm == 1) {
3151 __ Lsr(temp, dividend, 32 - ctz_imm);
3152 } else {
3153 __ Asr(temp, dividend, 31);
3154 __ Lsr(temp, temp, 32 - ctz_imm);
3155 }
3156 __ add(out, temp, ShifterOperand(dividend));
3157
3158 if (instruction->IsDiv()) {
3159 __ Asr(out, out, ctz_imm);
3160 if (imm < 0) {
3161 __ rsb(out, out, ShifterOperand(0));
3162 }
3163 } else {
3164 __ ubfx(out, out, 0, ctz_imm);
3165 __ sub(out, out, ShifterOperand(temp));
3166 }
3167}
3168
3169void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
3170 DCHECK(instruction->IsDiv() || instruction->IsRem());
3171 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
3172
3173 LocationSummary* locations = instruction->GetLocations();
3174 Location second = locations->InAt(1);
3175 DCHECK(second.IsConstant());
3176
3177 Register out = locations->Out().AsRegister<Register>();
3178 Register dividend = locations->InAt(0).AsRegister<Register>();
3179 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
3180 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
3181 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3182
3183 int64_t magic;
3184 int shift;
3185 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
3186
3187 __ LoadImmediate(temp1, magic);
3188 __ smull(temp2, temp1, dividend, temp1);
3189
3190 if (imm > 0 && magic < 0) {
3191 __ add(temp1, temp1, ShifterOperand(dividend));
3192 } else if (imm < 0 && magic > 0) {
3193 __ sub(temp1, temp1, ShifterOperand(dividend));
3194 }
3195
3196 if (shift != 0) {
3197 __ Asr(temp1, temp1, shift);
3198 }
3199
3200 if (instruction->IsDiv()) {
3201 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
3202 } else {
3203 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
3204 // TODO: Strength reduction for mls.
3205 __ LoadImmediate(temp2, imm);
3206 __ mls(out, temp1, temp2, dividend);
3207 }
3208}
3209
3210void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
3211 DCHECK(instruction->IsDiv() || instruction->IsRem());
3212 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
3213
3214 LocationSummary* locations = instruction->GetLocations();
3215 Location second = locations->InAt(1);
3216 DCHECK(second.IsConstant());
3217
3218 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
3219 if (imm == 0) {
3220 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
3221 } else if (imm == 1 || imm == -1) {
3222 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003223 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003224 DivRemByPowerOfTwo(instruction);
3225 } else {
3226 DCHECK(imm <= -2 || imm >= 2);
3227 GenerateDivRemWithAnyConstant(instruction);
3228 }
3229}
3230
Calin Juravle7c4954d2014-10-28 16:57:40 +00003231void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003232 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3233 if (div->GetResultType() == Primitive::kPrimLong) {
3234 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003235 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08003236 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
3237 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003238 } else if (div->GetResultType() == Primitive::kPrimInt &&
3239 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
3240 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003241 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003242 }
3243
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003244 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
3245
Calin Juravle7c4954d2014-10-28 16:57:40 +00003246 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00003247 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003248 if (div->InputAt(1)->IsConstant()) {
3249 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003250 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003251 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003252 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
3253 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003254 // No temp register required.
3255 } else {
3256 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003257 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003258 locations->AddTemp(Location::RequiresRegister());
3259 }
3260 }
3261 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003262 locations->SetInAt(0, Location::RequiresRegister());
3263 locations->SetInAt(1, Location::RequiresRegister());
3264 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3265 } else {
3266 InvokeRuntimeCallingConvention calling_convention;
3267 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3268 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3269 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3270 // we only need the former.
3271 locations->SetOut(Location::RegisterLocation(R0));
3272 }
Calin Juravled0d48522014-11-04 16:40:20 +00003273 break;
3274 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00003275 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003276 InvokeRuntimeCallingConvention calling_convention;
3277 locations->SetInAt(0, Location::RegisterPairLocation(
3278 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3279 locations->SetInAt(1, Location::RegisterPairLocation(
3280 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003281 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00003282 break;
3283 }
3284 case Primitive::kPrimFloat:
3285 case Primitive::kPrimDouble: {
3286 locations->SetInAt(0, Location::RequiresFpuRegister());
3287 locations->SetInAt(1, Location::RequiresFpuRegister());
3288 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3289 break;
3290 }
3291
3292 default:
3293 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3294 }
3295}
3296
3297void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
3298 LocationSummary* locations = div->GetLocations();
3299 Location out = locations->Out();
3300 Location first = locations->InAt(0);
3301 Location second = locations->InAt(1);
3302
3303 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00003304 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003305 if (second.IsConstant()) {
3306 GenerateDivRemConstantIntegral(div);
3307 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003308 __ sdiv(out.AsRegister<Register>(),
3309 first.AsRegister<Register>(),
3310 second.AsRegister<Register>());
3311 } else {
3312 InvokeRuntimeCallingConvention calling_convention;
3313 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3314 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3315 DCHECK_EQ(R0, out.AsRegister<Register>());
3316
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003317 codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003318 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003319 }
Calin Juravled0d48522014-11-04 16:40:20 +00003320 break;
3321 }
3322
Calin Juravle7c4954d2014-10-28 16:57:40 +00003323 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003324 InvokeRuntimeCallingConvention calling_convention;
3325 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
3326 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
3327 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
3328 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
3329 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003330 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003331
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003332 codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003333 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00003334 break;
3335 }
3336
3337 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00003338 __ vdivs(out.AsFpuRegister<SRegister>(),
3339 first.AsFpuRegister<SRegister>(),
3340 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00003341 break;
3342 }
3343
3344 case Primitive::kPrimDouble: {
3345 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
3346 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
3347 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
3348 break;
3349 }
3350
3351 default:
3352 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3353 }
3354}
3355
Calin Juravlebacfec32014-11-14 15:54:36 +00003356void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003357 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003358
3359 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003360 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08003361 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
3362 // sdiv will be replaced by other instruction sequence.
3363 call_kind = LocationSummary::kNoCall;
3364 } else if ((rem->GetResultType() == Primitive::kPrimInt)
3365 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003366 // Have hardware divide instruction for int, do it with three instructions.
3367 call_kind = LocationSummary::kNoCall;
3368 }
3369
Calin Juravlebacfec32014-11-14 15:54:36 +00003370 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3371
Calin Juravled2ec87d2014-12-08 14:24:46 +00003372 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003373 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003374 if (rem->InputAt(1)->IsConstant()) {
3375 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003376 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003377 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003378 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3379 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003380 // No temp register required.
3381 } else {
3382 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003383 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003384 locations->AddTemp(Location::RequiresRegister());
3385 }
3386 }
3387 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003388 locations->SetInAt(0, Location::RequiresRegister());
3389 locations->SetInAt(1, Location::RequiresRegister());
3390 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3391 locations->AddTemp(Location::RequiresRegister());
3392 } else {
3393 InvokeRuntimeCallingConvention calling_convention;
3394 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3395 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3396 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3397 // we only need the latter.
3398 locations->SetOut(Location::RegisterLocation(R1));
3399 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003400 break;
3401 }
3402 case Primitive::kPrimLong: {
3403 InvokeRuntimeCallingConvention calling_convention;
3404 locations->SetInAt(0, Location::RegisterPairLocation(
3405 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3406 locations->SetInAt(1, Location::RegisterPairLocation(
3407 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3408 // The runtime helper puts the output in R2,R3.
3409 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3410 break;
3411 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003412 case Primitive::kPrimFloat: {
3413 InvokeRuntimeCallingConvention calling_convention;
3414 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3415 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3416 locations->SetOut(Location::FpuRegisterLocation(S0));
3417 break;
3418 }
3419
Calin Juravlebacfec32014-11-14 15:54:36 +00003420 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003421 InvokeRuntimeCallingConvention calling_convention;
3422 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3423 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3424 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3425 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3426 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003427 break;
3428 }
3429
3430 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003431 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003432 }
3433}
3434
3435void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3436 LocationSummary* locations = rem->GetLocations();
3437 Location out = locations->Out();
3438 Location first = locations->InAt(0);
3439 Location second = locations->InAt(1);
3440
Calin Juravled2ec87d2014-12-08 14:24:46 +00003441 Primitive::Type type = rem->GetResultType();
3442 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003443 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003444 if (second.IsConstant()) {
3445 GenerateDivRemConstantIntegral(rem);
3446 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003447 Register reg1 = first.AsRegister<Register>();
3448 Register reg2 = second.AsRegister<Register>();
3449 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003450
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003451 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003452 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003453 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003454 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003455 } else {
3456 InvokeRuntimeCallingConvention calling_convention;
3457 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3458 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3459 DCHECK_EQ(R1, out.AsRegister<Register>());
3460
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003461 codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003462 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003463 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003464 break;
3465 }
3466
3467 case Primitive::kPrimLong: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003468 codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003469 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003470 break;
3471 }
3472
Calin Juravled2ec87d2014-12-08 14:24:46 +00003473 case Primitive::kPrimFloat: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003474 codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003475 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003476 break;
3477 }
3478
Calin Juravlebacfec32014-11-14 15:54:36 +00003479 case Primitive::kPrimDouble: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003480 codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003481 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003482 break;
3483 }
3484
3485 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003486 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003487 }
3488}
3489
Calin Juravled0d48522014-11-04 16:40:20 +00003490void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003491 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003492 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003493}
3494
3495void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Artem Serovf4d6aee2016-07-11 10:41:45 +01003496 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003497 codegen_->AddSlowPath(slow_path);
3498
3499 LocationSummary* locations = instruction->GetLocations();
3500 Location value = locations->InAt(0);
3501
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003502 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003503 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003504 case Primitive::kPrimByte:
3505 case Primitive::kPrimChar:
3506 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003507 case Primitive::kPrimInt: {
3508 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003509 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003510 } else {
3511 DCHECK(value.IsConstant()) << value;
3512 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3513 __ b(slow_path->GetEntryLabel());
3514 }
3515 }
3516 break;
3517 }
3518 case Primitive::kPrimLong: {
3519 if (value.IsRegisterPair()) {
3520 __ orrs(IP,
3521 value.AsRegisterPairLow<Register>(),
3522 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3523 __ b(slow_path->GetEntryLabel(), EQ);
3524 } else {
3525 DCHECK(value.IsConstant()) << value;
3526 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3527 __ b(slow_path->GetEntryLabel());
3528 }
3529 }
3530 break;
3531 default:
3532 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3533 }
3534 }
Calin Juravled0d48522014-11-04 16:40:20 +00003535}
3536
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003537void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3538 Register in = locations->InAt(0).AsRegister<Register>();
3539 Location rhs = locations->InAt(1);
3540 Register out = locations->Out().AsRegister<Register>();
3541
3542 if (rhs.IsConstant()) {
3543 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3544 // so map all rotations to a +ve. equivalent in that range.
3545 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3546 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3547 if (rot) {
3548 // Rotate, mapping left rotations to right equivalents if necessary.
3549 // (e.g. left by 2 bits == right by 30.)
3550 __ Ror(out, in, rot);
3551 } else if (out != in) {
3552 __ Mov(out, in);
3553 }
3554 } else {
3555 __ Ror(out, in, rhs.AsRegister<Register>());
3556 }
3557}
3558
3559// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3560// rotates by swapping input regs (effectively rotating by the first 32-bits of
3561// a larger rotation) or flipping direction (thus treating larger right/left
3562// rotations as sub-word sized rotations in the other direction) as appropriate.
3563void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3564 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3565 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3566 Location rhs = locations->InAt(1);
3567 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3568 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3569
3570 if (rhs.IsConstant()) {
3571 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3572 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003573 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003574 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3575 // logic below to a simple pair of binary orr.
3576 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3577 if (rot >= kArmBitsPerWord) {
3578 rot -= kArmBitsPerWord;
3579 std::swap(in_reg_hi, in_reg_lo);
3580 }
3581 // Rotate, or mov to out for zero or word size rotations.
3582 if (rot != 0u) {
3583 __ Lsr(out_reg_hi, in_reg_hi, rot);
3584 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3585 __ Lsr(out_reg_lo, in_reg_lo, rot);
3586 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3587 } else {
3588 __ Mov(out_reg_lo, in_reg_lo);
3589 __ Mov(out_reg_hi, in_reg_hi);
3590 }
3591 } else {
3592 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3593 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3594 Label end;
3595 Label shift_by_32_plus_shift_right;
3596
3597 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3598 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3599 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3600 __ b(&shift_by_32_plus_shift_right, CC);
3601
3602 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3603 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3604 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3605 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3606 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3607 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3608 __ Lsr(shift_left, in_reg_hi, shift_right);
3609 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3610 __ b(&end);
3611
3612 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3613 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3614 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3615 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3616 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3617 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3618 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3619 __ Lsl(shift_right, in_reg_hi, shift_left);
3620 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3621
3622 __ Bind(&end);
3623 }
3624}
Roland Levillain22c49222016-03-18 14:04:28 +00003625
3626void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003627 LocationSummary* locations =
3628 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3629 switch (ror->GetResultType()) {
3630 case Primitive::kPrimInt: {
3631 locations->SetInAt(0, Location::RequiresRegister());
3632 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3633 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3634 break;
3635 }
3636 case Primitive::kPrimLong: {
3637 locations->SetInAt(0, Location::RequiresRegister());
3638 if (ror->InputAt(1)->IsConstant()) {
3639 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3640 } else {
3641 locations->SetInAt(1, Location::RequiresRegister());
3642 locations->AddTemp(Location::RequiresRegister());
3643 locations->AddTemp(Location::RequiresRegister());
3644 }
3645 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3646 break;
3647 }
3648 default:
3649 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3650 }
3651}
3652
Roland Levillain22c49222016-03-18 14:04:28 +00003653void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003654 LocationSummary* locations = ror->GetLocations();
3655 Primitive::Type type = ror->GetResultType();
3656 switch (type) {
3657 case Primitive::kPrimInt: {
3658 HandleIntegerRotate(locations);
3659 break;
3660 }
3661 case Primitive::kPrimLong: {
3662 HandleLongRotate(locations);
3663 break;
3664 }
3665 default:
3666 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003667 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003668 }
3669}
3670
Calin Juravle9aec02f2014-11-18 23:06:35 +00003671void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3672 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3673
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003674 LocationSummary* locations =
3675 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003676
3677 switch (op->GetResultType()) {
3678 case Primitive::kPrimInt: {
3679 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003680 if (op->InputAt(1)->IsConstant()) {
3681 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3682 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3683 } else {
3684 locations->SetInAt(1, Location::RequiresRegister());
3685 // Make the output overlap, as it will be used to hold the masked
3686 // second input.
3687 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3688 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003689 break;
3690 }
3691 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003692 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003693 if (op->InputAt(1)->IsConstant()) {
3694 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3695 // For simplicity, use kOutputOverlap even though we only require that low registers
3696 // don't clash with high registers which the register allocator currently guarantees.
3697 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3698 } else {
3699 locations->SetInAt(1, Location::RequiresRegister());
3700 locations->AddTemp(Location::RequiresRegister());
3701 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3702 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003703 break;
3704 }
3705 default:
3706 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3707 }
3708}
3709
3710void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3711 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3712
3713 LocationSummary* locations = op->GetLocations();
3714 Location out = locations->Out();
3715 Location first = locations->InAt(0);
3716 Location second = locations->InAt(1);
3717
3718 Primitive::Type type = op->GetResultType();
3719 switch (type) {
3720 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003721 Register out_reg = out.AsRegister<Register>();
3722 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003723 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003724 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003725 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003726 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003727 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003728 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003729 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003730 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003731 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003732 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003733 }
3734 } else {
3735 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003736 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003737 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003738 __ Mov(out_reg, first_reg);
3739 } else if (op->IsShl()) {
3740 __ Lsl(out_reg, first_reg, shift_value);
3741 } else if (op->IsShr()) {
3742 __ Asr(out_reg, first_reg, shift_value);
3743 } else {
3744 __ Lsr(out_reg, first_reg, shift_value);
3745 }
3746 }
3747 break;
3748 }
3749 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003750 Register o_h = out.AsRegisterPairHigh<Register>();
3751 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003752
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003753 Register high = first.AsRegisterPairHigh<Register>();
3754 Register low = first.AsRegisterPairLow<Register>();
3755
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003756 if (second.IsRegister()) {
3757 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003758
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003759 Register second_reg = second.AsRegister<Register>();
3760
3761 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003762 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003763 // Shift the high part
3764 __ Lsl(o_h, high, o_l);
3765 // Shift the low part and `or` what overflew on the high part
3766 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3767 __ Lsr(temp, low, temp);
3768 __ orr(o_h, o_h, ShifterOperand(temp));
3769 // If the shift is > 32 bits, override the high part
3770 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3771 __ it(PL);
3772 __ Lsl(o_h, low, temp, PL);
3773 // Shift the low part
3774 __ Lsl(o_l, low, o_l);
3775 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003776 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003777 // Shift the low part
3778 __ Lsr(o_l, low, o_h);
3779 // Shift the high part and `or` what underflew on the low part
3780 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3781 __ Lsl(temp, high, temp);
3782 __ orr(o_l, o_l, ShifterOperand(temp));
3783 // If the shift is > 32 bits, override the low part
3784 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3785 __ it(PL);
3786 __ Asr(o_l, high, temp, PL);
3787 // Shift the high part
3788 __ Asr(o_h, high, o_h);
3789 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003790 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003791 // same as Shr except we use `Lsr`s and not `Asr`s
3792 __ Lsr(o_l, low, o_h);
3793 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3794 __ Lsl(temp, high, temp);
3795 __ orr(o_l, o_l, ShifterOperand(temp));
3796 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3797 __ it(PL);
3798 __ Lsr(o_l, high, temp, PL);
3799 __ Lsr(o_h, high, o_h);
3800 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003801 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003802 // Register allocator doesn't create partial overlap.
3803 DCHECK_NE(o_l, high);
3804 DCHECK_NE(o_h, low);
3805 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003806 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003807 if (shift_value > 32) {
3808 if (op->IsShl()) {
3809 __ Lsl(o_h, low, shift_value - 32);
3810 __ LoadImmediate(o_l, 0);
3811 } else if (op->IsShr()) {
3812 __ Asr(o_l, high, shift_value - 32);
3813 __ Asr(o_h, high, 31);
3814 } else {
3815 __ Lsr(o_l, high, shift_value - 32);
3816 __ LoadImmediate(o_h, 0);
3817 }
3818 } else if (shift_value == 32) {
3819 if (op->IsShl()) {
3820 __ mov(o_h, ShifterOperand(low));
3821 __ LoadImmediate(o_l, 0);
3822 } else if (op->IsShr()) {
3823 __ mov(o_l, ShifterOperand(high));
3824 __ Asr(o_h, high, 31);
3825 } else {
3826 __ mov(o_l, ShifterOperand(high));
3827 __ LoadImmediate(o_h, 0);
3828 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003829 } else if (shift_value == 1) {
3830 if (op->IsShl()) {
3831 __ Lsls(o_l, low, 1);
3832 __ adc(o_h, high, ShifterOperand(high));
3833 } else if (op->IsShr()) {
3834 __ Asrs(o_h, high, 1);
3835 __ Rrx(o_l, low);
3836 } else {
3837 __ Lsrs(o_h, high, 1);
3838 __ Rrx(o_l, low);
3839 }
3840 } else {
3841 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003842 if (op->IsShl()) {
3843 __ Lsl(o_h, high, shift_value);
3844 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3845 __ Lsl(o_l, low, shift_value);
3846 } else if (op->IsShr()) {
3847 __ Lsr(o_l, low, shift_value);
3848 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3849 __ Asr(o_h, high, shift_value);
3850 } else {
3851 __ Lsr(o_l, low, shift_value);
3852 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3853 __ Lsr(o_h, high, shift_value);
3854 }
3855 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003856 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003857 break;
3858 }
3859 default:
3860 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003861 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003862 }
3863}
3864
3865void LocationsBuilderARM::VisitShl(HShl* shl) {
3866 HandleShift(shl);
3867}
3868
3869void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3870 HandleShift(shl);
3871}
3872
3873void LocationsBuilderARM::VisitShr(HShr* shr) {
3874 HandleShift(shr);
3875}
3876
3877void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3878 HandleShift(shr);
3879}
3880
3881void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3882 HandleShift(ushr);
3883}
3884
3885void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3886 HandleShift(ushr);
3887}
3888
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003889void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003890 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003891 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003892 if (instruction->IsStringAlloc()) {
3893 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3894 } else {
3895 InvokeRuntimeCallingConvention calling_convention;
3896 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3897 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3898 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003899 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003900}
3901
3902void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003903 // Note: if heap poisoning is enabled, the entry point takes cares
3904 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003905 if (instruction->IsStringAlloc()) {
3906 // String is allocated through StringFactory. Call NewEmptyString entry point.
3907 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003908 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003909 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3910 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3911 __ blx(LR);
3912 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3913 } else {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003914 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
David Brazdil6de19382016-01-08 17:37:10 +00003915 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3916 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003917}
3918
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003919void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3920 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003921 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003922 InvokeRuntimeCallingConvention calling_convention;
3923 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003924 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003925 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003926 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003927}
3928
3929void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3930 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003931 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003932 // Note: if heap poisoning is enabled, the entry point takes cares
3933 // of poisoning the reference.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003934 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003935 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003936}
3937
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003938void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003939 LocationSummary* locations =
3940 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003941 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3942 if (location.IsStackSlot()) {
3943 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3944 } else if (location.IsDoubleStackSlot()) {
3945 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003946 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003947 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003948}
3949
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003950void InstructionCodeGeneratorARM::VisitParameterValue(
3951 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003952 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003953}
3954
3955void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3956 LocationSummary* locations =
3957 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3958 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3959}
3960
3961void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3962 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003963}
3964
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003965void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003966 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003967 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003968 locations->SetInAt(0, Location::RequiresRegister());
3969 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003970}
3971
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003972void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3973 LocationSummary* locations = not_->GetLocations();
3974 Location out = locations->Out();
3975 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003976 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003977 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003978 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003979 break;
3980
3981 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003982 __ mvn(out.AsRegisterPairLow<Register>(),
3983 ShifterOperand(in.AsRegisterPairLow<Register>()));
3984 __ mvn(out.AsRegisterPairHigh<Register>(),
3985 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003986 break;
3987
3988 default:
3989 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3990 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003991}
3992
David Brazdil66d126e2015-04-03 16:02:44 +01003993void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3994 LocationSummary* locations =
3995 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3996 locations->SetInAt(0, Location::RequiresRegister());
3997 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3998}
3999
4000void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01004001 LocationSummary* locations = bool_not->GetLocations();
4002 Location out = locations->Out();
4003 Location in = locations->InAt(0);
4004 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
4005}
4006
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004007void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004008 LocationSummary* locations =
4009 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00004010 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00004011 case Primitive::kPrimBoolean:
4012 case Primitive::kPrimByte:
4013 case Primitive::kPrimShort:
4014 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08004015 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00004016 case Primitive::kPrimLong: {
4017 locations->SetInAt(0, Location::RequiresRegister());
4018 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004019 // Output overlaps because it is written before doing the low comparison.
4020 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00004021 break;
4022 }
4023 case Primitive::kPrimFloat:
4024 case Primitive::kPrimDouble: {
4025 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004026 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00004027 locations->SetOut(Location::RequiresRegister());
4028 break;
4029 }
4030 default:
4031 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
4032 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004033}
4034
4035void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004036 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004037 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00004038 Location left = locations->InAt(0);
4039 Location right = locations->InAt(1);
4040
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004041 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00004042 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00004043 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00004044 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00004045 case Primitive::kPrimBoolean:
4046 case Primitive::kPrimByte:
4047 case Primitive::kPrimShort:
4048 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08004049 case Primitive::kPrimInt: {
4050 __ LoadImmediate(out, 0);
4051 __ cmp(left.AsRegister<Register>(),
4052 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
4053 less_cond = LT;
4054 break;
4055 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004056 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004057 __ cmp(left.AsRegisterPairHigh<Register>(),
4058 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004059 __ b(&less, LT);
4060 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01004061 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00004062 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004063 __ cmp(left.AsRegisterPairLow<Register>(),
4064 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00004065 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00004066 break;
4067 }
4068 case Primitive::kPrimFloat:
4069 case Primitive::kPrimDouble: {
4070 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004071 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00004072 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00004073 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004074 break;
4075 }
4076 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00004077 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00004078 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004079 }
Aart Bika19616e2016-02-01 18:57:58 -08004080
Calin Juravleddb7df22014-11-25 20:56:51 +00004081 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00004082 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00004083
4084 __ Bind(&greater);
4085 __ LoadImmediate(out, 1);
4086 __ b(&done);
4087
4088 __ Bind(&less);
4089 __ LoadImmediate(out, -1);
4090
4091 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01004092}
4093
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01004094void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004095 LocationSummary* locations =
4096 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01004097 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01004098 locations->SetInAt(i, Location::Any());
4099 }
4100 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01004101}
4102
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01004103void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004104 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01004105}
4106
Roland Levillainc9285912015-12-18 10:38:42 +00004107void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
4108 // TODO (ported from quick): revisit ARM barrier kinds.
4109 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00004110 switch (kind) {
4111 case MemBarrierKind::kAnyStore:
4112 case MemBarrierKind::kLoadAny:
4113 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07004114 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00004115 break;
4116 }
4117 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07004118 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00004119 break;
4120 }
4121 default:
4122 LOG(FATAL) << "Unexpected memory barrier " << kind;
4123 }
Kenny Root1d8199d2015-06-02 11:01:10 -07004124 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00004125}
4126
4127void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
4128 uint32_t offset,
4129 Register out_lo,
4130 Register out_hi) {
4131 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004132 // Ensure `out_lo` is different from `addr`, so that loading
4133 // `offset` into `out_lo` does not clutter `addr`.
4134 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00004135 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00004136 __ add(IP, addr, ShifterOperand(out_lo));
4137 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00004138 }
4139 __ ldrexd(out_lo, out_hi, addr);
4140}
4141
4142void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
4143 uint32_t offset,
4144 Register value_lo,
4145 Register value_hi,
4146 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00004147 Register temp2,
4148 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004149 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00004150 if (offset != 0) {
4151 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00004152 __ add(IP, addr, ShifterOperand(temp1));
4153 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00004154 }
4155 __ Bind(&fail);
4156 // We need a load followed by store. (The address used in a STREX instruction must
4157 // be the same as the address in the most recently executed LDREX instruction.)
4158 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00004159 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004160 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004161 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00004162}
4163
4164void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
4165 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
4166
Nicolas Geoffray39468442014-09-02 15:17:15 +01004167 LocationSummary* locations =
4168 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004169 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00004170
Calin Juravle52c48962014-12-16 17:02:57 +00004171 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004172 if (Primitive::IsFloatingPointType(field_type)) {
4173 locations->SetInAt(1, Location::RequiresFpuRegister());
4174 } else {
4175 locations->SetInAt(1, Location::RequiresRegister());
4176 }
4177
Calin Juravle52c48962014-12-16 17:02:57 +00004178 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00004179 bool generate_volatile = field_info.IsVolatile()
4180 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004181 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01004182 bool needs_write_barrier =
4183 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01004184 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00004185 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01004186 if (needs_write_barrier) {
4187 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01004188 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00004189 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004190 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00004191 // - registers need to be consecutive
4192 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00004193 // We don't test for ARM yet, and the assertion makes sure that we
4194 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00004195 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
4196
4197 locations->AddTemp(Location::RequiresRegister());
4198 locations->AddTemp(Location::RequiresRegister());
4199 if (field_type == Primitive::kPrimDouble) {
4200 // For doubles we need two more registers to copy the value.
4201 locations->AddTemp(Location::RegisterLocation(R2));
4202 locations->AddTemp(Location::RegisterLocation(R3));
4203 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01004204 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004205}
4206
Calin Juravle52c48962014-12-16 17:02:57 +00004207void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004208 const FieldInfo& field_info,
4209 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00004210 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
4211
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004212 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00004213 Register base = locations->InAt(0).AsRegister<Register>();
4214 Location value = locations->InAt(1);
4215
4216 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004217 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004218 Primitive::Type field_type = field_info.GetFieldType();
4219 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01004220 bool needs_write_barrier =
4221 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00004222
4223 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004224 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00004225 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004226
4227 switch (field_type) {
4228 case Primitive::kPrimBoolean:
4229 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00004230 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004231 break;
4232 }
4233
4234 case Primitive::kPrimShort:
4235 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00004236 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004237 break;
4238 }
4239
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004240 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004241 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01004242 if (kPoisonHeapReferences && needs_write_barrier) {
4243 // Note that in the case where `value` is a null reference,
4244 // we do not enter this block, as a null reference does not
4245 // need poisoning.
4246 DCHECK_EQ(field_type, Primitive::kPrimNot);
4247 Register temp = locations->GetTemp(0).AsRegister<Register>();
4248 __ Mov(temp, value.AsRegister<Register>());
4249 __ PoisonHeapReference(temp);
4250 __ StoreToOffset(kStoreWord, temp, base, offset);
4251 } else {
4252 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
4253 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004254 break;
4255 }
4256
4257 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00004258 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004259 GenerateWideAtomicStore(base, offset,
4260 value.AsRegisterPairLow<Register>(),
4261 value.AsRegisterPairHigh<Register>(),
4262 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00004263 locations->GetTemp(1).AsRegister<Register>(),
4264 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004265 } else {
4266 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004267 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004268 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004269 break;
4270 }
4271
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004272 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00004273 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004274 break;
4275 }
4276
4277 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004278 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004279 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004280 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
4281 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
4282
4283 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
4284
4285 GenerateWideAtomicStore(base, offset,
4286 value_reg_lo,
4287 value_reg_hi,
4288 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00004289 locations->GetTemp(3).AsRegister<Register>(),
4290 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004291 } else {
4292 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004293 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004294 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004295 break;
4296 }
4297
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004298 case Primitive::kPrimVoid:
4299 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004300 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004301 }
Calin Juravle52c48962014-12-16 17:02:57 +00004302
Calin Juravle77520bc2015-01-12 18:45:46 +00004303 // Longs and doubles are handled in the switch.
4304 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
4305 codegen_->MaybeRecordImplicitNullCheck(instruction);
4306 }
4307
4308 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
4309 Register temp = locations->GetTemp(0).AsRegister<Register>();
4310 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004311 codegen_->MarkGCCard(
4312 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00004313 }
4314
Calin Juravle52c48962014-12-16 17:02:57 +00004315 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004316 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00004317 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004318}
4319
Calin Juravle52c48962014-12-16 17:02:57 +00004320void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
4321 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00004322
4323 bool object_field_get_with_read_barrier =
4324 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004325 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004326 new (GetGraph()->GetArena()) LocationSummary(instruction,
4327 object_field_get_with_read_barrier ?
4328 LocationSummary::kCallOnSlowPath :
4329 LocationSummary::kNoCall);
Vladimir Marko70e97462016-08-09 11:04:26 +01004330 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01004331 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01004332 }
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004333 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004334
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004335 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00004336 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004337 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00004338 // The output overlaps in case of volatile long: we don't want the
4339 // code generated by GenerateWideAtomicLoad to overwrite the
4340 // object's location. Likewise, in the case of an object field get
4341 // with read barriers enabled, we do not want the load to overwrite
4342 // the object's location, as we need it to emit the read barrier.
4343 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
4344 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01004345
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004346 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4347 locations->SetOut(Location::RequiresFpuRegister());
4348 } else {
4349 locations->SetOut(Location::RequiresRegister(),
4350 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
4351 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004352 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00004353 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00004354 // - registers need to be consecutive
4355 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00004356 // We don't test for ARM yet, and the assertion makes sure that we
4357 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00004358 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
4359 locations->AddTemp(Location::RequiresRegister());
4360 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00004361 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4362 // We need a temporary register for the read barrier marking slow
4363 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4364 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004365 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004366}
4367
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004368Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
4369 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
4370 << input->GetType();
4371 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
4372 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4373 return Location::ConstantLocation(input->AsConstant());
4374 } else {
4375 return Location::RequiresFpuRegister();
4376 }
4377}
4378
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004379Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4380 Opcode opcode) {
4381 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4382 if (constant->IsConstant() &&
4383 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4384 return Location::ConstantLocation(constant->AsConstant());
4385 }
4386 return Location::RequiresRegister();
4387}
4388
4389bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4390 Opcode opcode) {
4391 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4392 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004393 Opcode high_opcode = opcode;
4394 SetCc low_set_cc = kCcDontCare;
4395 switch (opcode) {
4396 case SUB:
4397 // Flip the operation to an ADD.
4398 value = -value;
4399 opcode = ADD;
4400 FALLTHROUGH_INTENDED;
4401 case ADD:
4402 if (Low32Bits(value) == 0u) {
4403 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4404 }
4405 high_opcode = ADC;
4406 low_set_cc = kCcSet;
4407 break;
4408 default:
4409 break;
4410 }
4411 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4412 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004413 } else {
4414 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4415 }
4416}
4417
Vladimir Marko59751a72016-08-05 14:37:27 +01004418bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4419 Opcode opcode,
4420 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004421 ShifterOperand so;
4422 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004423 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004424 return true;
4425 }
4426 Opcode neg_opcode = kNoOperand;
4427 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004428 case AND: neg_opcode = BIC; value = ~value; break;
4429 case ORR: neg_opcode = ORN; value = ~value; break;
4430 case ADD: neg_opcode = SUB; value = -value; break;
4431 case ADC: neg_opcode = SBC; value = ~value; break;
4432 case SUB: neg_opcode = ADD; value = -value; break;
4433 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004434 default:
4435 return false;
4436 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004437 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004438}
4439
Calin Juravle52c48962014-12-16 17:02:57 +00004440void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4441 const FieldInfo& field_info) {
4442 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004443
Calin Juravle52c48962014-12-16 17:02:57 +00004444 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004445 Location base_loc = locations->InAt(0);
4446 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004447 Location out = locations->Out();
4448 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004449 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004450 Primitive::Type field_type = field_info.GetFieldType();
4451 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4452
4453 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004454 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004455 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004456 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004457
Roland Levillainc9285912015-12-18 10:38:42 +00004458 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004459 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004460 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004461
Roland Levillainc9285912015-12-18 10:38:42 +00004462 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004463 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004464 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004465
Roland Levillainc9285912015-12-18 10:38:42 +00004466 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004467 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004468 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004469
4470 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004471 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004472 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004473
4474 case Primitive::kPrimNot: {
4475 // /* HeapReference<Object> */ out = *(base + offset)
4476 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4477 Location temp_loc = locations->GetTemp(0);
4478 // Note that a potential implicit null check is handled in this
4479 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4480 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4481 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4482 if (is_volatile) {
4483 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4484 }
4485 } else {
4486 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4487 codegen_->MaybeRecordImplicitNullCheck(instruction);
4488 if (is_volatile) {
4489 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4490 }
4491 // If read barriers are enabled, emit read barriers other than
4492 // Baker's using a slow path (and also unpoison the loaded
4493 // reference, if heap poisoning is enabled).
4494 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4495 }
4496 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004497 }
4498
Roland Levillainc9285912015-12-18 10:38:42 +00004499 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004500 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004501 GenerateWideAtomicLoad(base, offset,
4502 out.AsRegisterPairLow<Register>(),
4503 out.AsRegisterPairHigh<Register>());
4504 } else {
4505 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4506 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004507 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004508
Roland Levillainc9285912015-12-18 10:38:42 +00004509 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004510 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004511 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004512
4513 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004514 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004515 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004516 Register lo = locations->GetTemp(0).AsRegister<Register>();
4517 Register hi = locations->GetTemp(1).AsRegister<Register>();
4518 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004519 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004520 __ vmovdrr(out_reg, lo, hi);
4521 } else {
4522 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004523 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004524 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004525 break;
4526 }
4527
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004528 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004529 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004530 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004531 }
Calin Juravle52c48962014-12-16 17:02:57 +00004532
Roland Levillainc9285912015-12-18 10:38:42 +00004533 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4534 // Potential implicit null checks, in the case of reference or
4535 // double fields, are handled in the previous switch statement.
4536 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004537 codegen_->MaybeRecordImplicitNullCheck(instruction);
4538 }
4539
Calin Juravle52c48962014-12-16 17:02:57 +00004540 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004541 if (field_type == Primitive::kPrimNot) {
4542 // Memory barriers, in the case of references, are also handled
4543 // in the previous switch statement.
4544 } else {
4545 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4546 }
Roland Levillain4d027112015-07-01 15:41:14 +01004547 }
Calin Juravle52c48962014-12-16 17:02:57 +00004548}
4549
4550void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4551 HandleFieldSet(instruction, instruction->GetFieldInfo());
4552}
4553
4554void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004555 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004556}
4557
4558void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4559 HandleFieldGet(instruction, instruction->GetFieldInfo());
4560}
4561
4562void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4563 HandleFieldGet(instruction, instruction->GetFieldInfo());
4564}
4565
4566void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4567 HandleFieldGet(instruction, instruction->GetFieldInfo());
4568}
4569
4570void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4571 HandleFieldGet(instruction, instruction->GetFieldInfo());
4572}
4573
4574void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4575 HandleFieldSet(instruction, instruction->GetFieldInfo());
4576}
4577
4578void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004579 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004580}
4581
Calin Juravlee460d1d2015-09-29 04:52:17 +01004582void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4583 HUnresolvedInstanceFieldGet* instruction) {
4584 FieldAccessCallingConventionARM calling_convention;
4585 codegen_->CreateUnresolvedFieldLocationSummary(
4586 instruction, instruction->GetFieldType(), calling_convention);
4587}
4588
4589void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4590 HUnresolvedInstanceFieldGet* instruction) {
4591 FieldAccessCallingConventionARM calling_convention;
4592 codegen_->GenerateUnresolvedFieldAccess(instruction,
4593 instruction->GetFieldType(),
4594 instruction->GetFieldIndex(),
4595 instruction->GetDexPc(),
4596 calling_convention);
4597}
4598
4599void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4600 HUnresolvedInstanceFieldSet* instruction) {
4601 FieldAccessCallingConventionARM calling_convention;
4602 codegen_->CreateUnresolvedFieldLocationSummary(
4603 instruction, instruction->GetFieldType(), calling_convention);
4604}
4605
4606void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4607 HUnresolvedInstanceFieldSet* instruction) {
4608 FieldAccessCallingConventionARM calling_convention;
4609 codegen_->GenerateUnresolvedFieldAccess(instruction,
4610 instruction->GetFieldType(),
4611 instruction->GetFieldIndex(),
4612 instruction->GetDexPc(),
4613 calling_convention);
4614}
4615
4616void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4617 HUnresolvedStaticFieldGet* instruction) {
4618 FieldAccessCallingConventionARM calling_convention;
4619 codegen_->CreateUnresolvedFieldLocationSummary(
4620 instruction, instruction->GetFieldType(), calling_convention);
4621}
4622
4623void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4624 HUnresolvedStaticFieldGet* instruction) {
4625 FieldAccessCallingConventionARM calling_convention;
4626 codegen_->GenerateUnresolvedFieldAccess(instruction,
4627 instruction->GetFieldType(),
4628 instruction->GetFieldIndex(),
4629 instruction->GetDexPc(),
4630 calling_convention);
4631}
4632
4633void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4634 HUnresolvedStaticFieldSet* instruction) {
4635 FieldAccessCallingConventionARM calling_convention;
4636 codegen_->CreateUnresolvedFieldLocationSummary(
4637 instruction, instruction->GetFieldType(), calling_convention);
4638}
4639
4640void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4641 HUnresolvedStaticFieldSet* instruction) {
4642 FieldAccessCallingConventionARM calling_convention;
4643 codegen_->GenerateUnresolvedFieldAccess(instruction,
4644 instruction->GetFieldType(),
4645 instruction->GetFieldIndex(),
4646 instruction->GetDexPc(),
4647 calling_convention);
4648}
4649
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004650void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01004651 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
4652 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004653}
4654
Calin Juravle2ae48182016-03-16 14:05:09 +00004655void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4656 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004657 return;
4658 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004659 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004660
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004661 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004662 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004663}
4664
Calin Juravle2ae48182016-03-16 14:05:09 +00004665void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Artem Serovf4d6aee2016-07-11 10:41:45 +01004666 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004667 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004668
4669 LocationSummary* locations = instruction->GetLocations();
4670 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004671
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004672 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004673}
4674
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004675void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004676 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004677}
4678
Artem Serov6c916792016-07-11 14:02:34 +01004679static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4680 switch (type) {
4681 case Primitive::kPrimNot:
4682 return kLoadWord;
4683 case Primitive::kPrimBoolean:
4684 return kLoadUnsignedByte;
4685 case Primitive::kPrimByte:
4686 return kLoadSignedByte;
4687 case Primitive::kPrimChar:
4688 return kLoadUnsignedHalfword;
4689 case Primitive::kPrimShort:
4690 return kLoadSignedHalfword;
4691 case Primitive::kPrimInt:
4692 return kLoadWord;
4693 case Primitive::kPrimLong:
4694 return kLoadWordPair;
4695 case Primitive::kPrimFloat:
4696 return kLoadSWord;
4697 case Primitive::kPrimDouble:
4698 return kLoadDWord;
4699 default:
4700 LOG(FATAL) << "Unreachable type " << type;
4701 UNREACHABLE();
4702 }
4703}
4704
4705static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4706 switch (type) {
4707 case Primitive::kPrimNot:
4708 return kStoreWord;
4709 case Primitive::kPrimBoolean:
4710 case Primitive::kPrimByte:
4711 return kStoreByte;
4712 case Primitive::kPrimChar:
4713 case Primitive::kPrimShort:
4714 return kStoreHalfword;
4715 case Primitive::kPrimInt:
4716 return kStoreWord;
4717 case Primitive::kPrimLong:
4718 return kStoreWordPair;
4719 case Primitive::kPrimFloat:
4720 return kStoreSWord;
4721 case Primitive::kPrimDouble:
4722 return kStoreDWord;
4723 default:
4724 LOG(FATAL) << "Unreachable type " << type;
4725 UNREACHABLE();
4726 }
4727}
4728
4729void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4730 Location out_loc,
4731 Register base,
4732 Register reg_offset,
4733 Condition cond) {
4734 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4735 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4736
4737 switch (type) {
4738 case Primitive::kPrimByte:
4739 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4740 break;
4741 case Primitive::kPrimBoolean:
4742 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4743 break;
4744 case Primitive::kPrimShort:
4745 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4746 break;
4747 case Primitive::kPrimChar:
4748 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4749 break;
4750 case Primitive::kPrimNot:
4751 case Primitive::kPrimInt:
4752 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4753 break;
4754 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4755 case Primitive::kPrimLong:
4756 case Primitive::kPrimFloat:
4757 case Primitive::kPrimDouble:
4758 default:
4759 LOG(FATAL) << "Unreachable type " << type;
4760 UNREACHABLE();
4761 }
4762}
4763
4764void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4765 Location loc,
4766 Register base,
4767 Register reg_offset,
4768 Condition cond) {
4769 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4770 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4771
4772 switch (type) {
4773 case Primitive::kPrimByte:
4774 case Primitive::kPrimBoolean:
4775 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4776 break;
4777 case Primitive::kPrimShort:
4778 case Primitive::kPrimChar:
4779 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4780 break;
4781 case Primitive::kPrimNot:
4782 case Primitive::kPrimInt:
4783 __ str(loc.AsRegister<Register>(), mem_address, cond);
4784 break;
4785 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4786 case Primitive::kPrimLong:
4787 case Primitive::kPrimFloat:
4788 case Primitive::kPrimDouble:
4789 default:
4790 LOG(FATAL) << "Unreachable type " << type;
4791 UNREACHABLE();
4792 }
4793}
4794
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004795void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004796 bool object_array_get_with_read_barrier =
4797 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004798 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004799 new (GetGraph()->GetArena()) LocationSummary(instruction,
4800 object_array_get_with_read_barrier ?
4801 LocationSummary::kCallOnSlowPath :
4802 LocationSummary::kNoCall);
Vladimir Marko70e97462016-08-09 11:04:26 +01004803 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01004804 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01004805 }
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004806 locations->SetInAt(0, Location::RequiresRegister());
4807 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004808 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4809 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4810 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004811 // The output overlaps in the case of an object array get with
4812 // read barriers enabled: we do not want the move to overwrite the
4813 // array's location, as we need it to emit the read barrier.
4814 locations->SetOut(
4815 Location::RequiresRegister(),
4816 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004817 }
Roland Levillainc9285912015-12-18 10:38:42 +00004818 // We need a temporary register for the read barrier marking slow
4819 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
jessicahandojo05765752016-09-09 19:01:32 -07004820 // Also need for String compression feature.
4821 if ((object_array_get_with_read_barrier && kUseBakerReadBarrier)
4822 || (mirror::kUseStringCompression && instruction->IsStringCharAt())) {
Roland Levillainc9285912015-12-18 10:38:42 +00004823 locations->AddTemp(Location::RequiresRegister());
4824 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004825}
4826
4827void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4828 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004829 Location obj_loc = locations->InAt(0);
4830 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004831 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004832 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004833 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004834 Primitive::Type type = instruction->GetType();
jessicahandojo05765752016-09-09 19:01:32 -07004835 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
4836 instruction->IsStringCharAt();
Artem Serov328429f2016-07-06 16:23:04 +01004837 HInstruction* array_instr = instruction->GetArray();
4838 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004839 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4840 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Artem Serov6c916792016-07-11 14:02:34 +01004841
Roland Levillain4d027112015-07-01 15:41:14 +01004842 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004843 case Primitive::kPrimBoolean:
4844 case Primitive::kPrimByte:
4845 case Primitive::kPrimShort:
4846 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004847 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004848 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004849 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
jessicahandojo05765752016-09-09 19:01:32 -07004850 if (maybe_compressed_char_at) {
4851 Register length = IP;
4852 Label uncompressed_load, done;
4853 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
4854 __ LoadFromOffset(kLoadWord, length, obj, count_offset);
4855 codegen_->MaybeRecordImplicitNullCheck(instruction);
4856 __ cmp(length, ShifterOperand(0));
4857 __ b(&uncompressed_load, GE);
4858 __ LoadFromOffset(kLoadUnsignedByte,
4859 out_loc.AsRegister<Register>(),
4860 obj,
4861 data_offset + const_index);
4862 __ b(&done);
4863 __ Bind(&uncompressed_load);
4864 __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar),
4865 out_loc.AsRegister<Register>(),
4866 obj,
4867 data_offset + (const_index << 1));
4868 __ Bind(&done);
4869 } else {
4870 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
Artem Serov6c916792016-07-11 14:02:34 +01004871
jessicahandojo05765752016-09-09 19:01:32 -07004872 LoadOperandType load_type = GetLoadOperandType(type);
4873 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
4874 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004875 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004876 Register temp = IP;
4877
4878 if (has_intermediate_address) {
4879 // We do not need to compute the intermediate address from the array: the
4880 // input instruction has done it already. See the comment in
4881 // `TryExtractArrayAccessAddress()`.
4882 if (kIsDebugBuild) {
4883 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4884 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4885 }
4886 temp = obj;
4887 } else {
4888 __ add(temp, obj, ShifterOperand(data_offset));
4889 }
jessicahandojo05765752016-09-09 19:01:32 -07004890 if (maybe_compressed_char_at) {
4891 Label uncompressed_load, done;
4892 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
4893 Register length = locations->GetTemp(0).AsRegister<Register>();
4894 __ LoadFromOffset(kLoadWord, length, obj, count_offset);
4895 codegen_->MaybeRecordImplicitNullCheck(instruction);
4896 __ cmp(length, ShifterOperand(0));
4897 __ b(&uncompressed_load, GE);
4898 __ ldrb(out_loc.AsRegister<Register>(),
4899 Address(temp, index.AsRegister<Register>(), Shift::LSL, 0));
4900 __ b(&done);
4901 __ Bind(&uncompressed_load);
4902 __ ldrh(out_loc.AsRegister<Register>(),
4903 Address(temp, index.AsRegister<Register>(), Shift::LSL, 1));
4904 __ Bind(&done);
4905 } else {
4906 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
4907 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004908 }
4909 break;
4910 }
4911
Roland Levillainc9285912015-12-18 10:38:42 +00004912 case Primitive::kPrimNot: {
4913 static_assert(
4914 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4915 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004916 // /* HeapReference<Object> */ out =
4917 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4918 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4919 Location temp = locations->GetTemp(0);
4920 // Note that a potential implicit null check is handled in this
4921 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4922 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4923 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4924 } else {
4925 Register out = out_loc.AsRegister<Register>();
4926 if (index.IsConstant()) {
4927 size_t offset =
4928 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4929 __ LoadFromOffset(kLoadWord, out, obj, offset);
4930 codegen_->MaybeRecordImplicitNullCheck(instruction);
4931 // If read barriers are enabled, emit read barriers other than
4932 // Baker's using a slow path (and also unpoison the loaded
4933 // reference, if heap poisoning is enabled).
4934 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4935 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004936 Register temp = IP;
4937
4938 if (has_intermediate_address) {
4939 // We do not need to compute the intermediate address from the array: the
4940 // input instruction has done it already. See the comment in
4941 // `TryExtractArrayAccessAddress()`.
4942 if (kIsDebugBuild) {
4943 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4944 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4945 }
4946 temp = obj;
4947 } else {
4948 __ add(temp, obj, ShifterOperand(data_offset));
4949 }
4950 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004951
Roland Levillainc9285912015-12-18 10:38:42 +00004952 codegen_->MaybeRecordImplicitNullCheck(instruction);
4953 // If read barriers are enabled, emit read barriers other than
4954 // Baker's using a slow path (and also unpoison the loaded
4955 // reference, if heap poisoning is enabled).
4956 codegen_->MaybeGenerateReadBarrierSlow(
4957 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4958 }
4959 }
4960 break;
4961 }
4962
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004963 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004964 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004965 size_t offset =
4966 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004967 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004968 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004969 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004970 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004971 }
4972 break;
4973 }
4974
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004975 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004976 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004977 if (index.IsConstant()) {
4978 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004979 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004980 } else {
4981 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004982 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004983 }
4984 break;
4985 }
4986
4987 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004988 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004989 if (index.IsConstant()) {
4990 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004991 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004992 } else {
4993 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004994 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004995 }
4996 break;
4997 }
4998
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004999 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01005000 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07005001 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005002 }
Roland Levillain4d027112015-07-01 15:41:14 +01005003
5004 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00005005 // Potential implicit null checks, in the case of reference
5006 // arrays, are handled in the previous switch statement.
jessicahandojo05765752016-09-09 19:01:32 -07005007 } else if (!maybe_compressed_char_at) {
Roland Levillainc9285912015-12-18 10:38:42 +00005008 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01005009 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005010}
5011
5012void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01005013 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00005014
5015 bool needs_write_barrier =
5016 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00005017 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00005018
Nicolas Geoffray39468442014-09-02 15:17:15 +01005019 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005020 instruction,
Vladimir Marko8d49fd72016-08-25 15:20:47 +01005021 may_need_runtime_call_for_type_check ?
Roland Levillain3b359c72015-11-17 19:35:12 +00005022 LocationSummary::kCallOnSlowPath :
5023 LocationSummary::kNoCall);
5024
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005025 locations->SetInAt(0, Location::RequiresRegister());
5026 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
5027 if (Primitive::IsFloatingPointType(value_type)) {
5028 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005029 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005030 locations->SetInAt(2, Location::RequiresRegister());
5031 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005032 if (needs_write_barrier) {
5033 // Temporary registers for the write barrier.
5034 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00005035 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005036 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005037}
5038
5039void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
5040 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005041 Location array_loc = locations->InAt(0);
5042 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005043 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01005044 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00005045 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00005046 bool needs_write_barrier =
5047 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01005048 uint32_t data_offset =
5049 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
5050 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01005051 HInstruction* array_instr = instruction->GetArray();
5052 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00005053 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
5054 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005055
5056 switch (value_type) {
5057 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01005058 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005059 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01005060 case Primitive::kPrimChar:
5061 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005062 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01005063 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
5064 uint32_t full_offset =
5065 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
5066 StoreOperandType store_type = GetStoreOperandType(value_type);
5067 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005068 } else {
Artem Serov328429f2016-07-06 16:23:04 +01005069 Register temp = IP;
5070
5071 if (has_intermediate_address) {
5072 // We do not need to compute the intermediate address from the array: the
5073 // input instruction has done it already. See the comment in
5074 // `TryExtractArrayAccessAddress()`.
5075 if (kIsDebugBuild) {
5076 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
5077 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
5078 }
5079 temp = array;
5080 } else {
5081 __ add(temp, array, ShifterOperand(data_offset));
5082 }
Artem Serov6c916792016-07-11 14:02:34 +01005083 codegen_->StoreToShiftedRegOffset(value_type,
5084 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01005085 temp,
Artem Serov6c916792016-07-11 14:02:34 +01005086 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005087 }
5088 break;
5089 }
5090
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005091 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00005092 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01005093 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
5094 // See the comment in instruction_simplifier_shared.cc.
5095 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005096
5097 if (instruction->InputAt(2)->IsNullConstant()) {
5098 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00005099 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00005100 size_t offset =
5101 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01005102 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00005103 } else {
5104 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01005105 __ add(IP, array, ShifterOperand(data_offset));
5106 codegen_->StoreToShiftedRegOffset(value_type,
5107 value_loc,
5108 IP,
5109 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00005110 }
Roland Levillain1407ee72016-01-08 15:56:19 +00005111 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00005112 DCHECK(!needs_write_barrier);
5113 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005114 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00005115 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005116
5117 DCHECK(needs_write_barrier);
Roland Levillain16d9f942016-08-25 17:27:56 +01005118 Location temp1_loc = locations->GetTemp(0);
5119 Register temp1 = temp1_loc.AsRegister<Register>();
5120 Location temp2_loc = locations->GetTemp(1);
5121 Register temp2 = temp2_loc.AsRegister<Register>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005122 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
5123 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5124 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5125 Label done;
Artem Serovf4d6aee2016-07-11 10:41:45 +01005126 SlowPathCodeARM* slow_path = nullptr;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005127
Roland Levillain3b359c72015-11-17 19:35:12 +00005128 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005129 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
5130 codegen_->AddSlowPath(slow_path);
5131 if (instruction->GetValueCanBeNull()) {
5132 Label non_zero;
5133 __ CompareAndBranchIfNonZero(value, &non_zero);
5134 if (index.IsConstant()) {
5135 size_t offset =
5136 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
5137 __ StoreToOffset(kStoreWord, value, array, offset);
5138 } else {
5139 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01005140 __ add(IP, array, ShifterOperand(data_offset));
5141 codegen_->StoreToShiftedRegOffset(value_type,
5142 value_loc,
5143 IP,
5144 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005145 }
5146 codegen_->MaybeRecordImplicitNullCheck(instruction);
5147 __ b(&done);
5148 __ Bind(&non_zero);
5149 }
5150
Roland Levillain9d6e1f82016-09-05 15:57:33 +01005151 // Note that when read barriers are enabled, the type checks
5152 // are performed without read barriers. This is fine, even in
5153 // the case where a class object is in the from-space after
5154 // the flip, as a comparison involving such a type would not
5155 // produce a false positive; it may of course produce a false
5156 // negative, in which case we would take the ArraySet slow
5157 // path.
Roland Levillain16d9f942016-08-25 17:27:56 +01005158
Roland Levillain9d6e1f82016-09-05 15:57:33 +01005159 // /* HeapReference<Class> */ temp1 = array->klass_
5160 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
5161 codegen_->MaybeRecordImplicitNullCheck(instruction);
5162 __ MaybeUnpoisonHeapReference(temp1);
Roland Levillain16d9f942016-08-25 17:27:56 +01005163
Roland Levillain9d6e1f82016-09-05 15:57:33 +01005164 // /* HeapReference<Class> */ temp1 = temp1->component_type_
5165 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
5166 // /* HeapReference<Class> */ temp2 = value->klass_
5167 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
5168 // If heap poisoning is enabled, no need to unpoison `temp1`
5169 // nor `temp2`, as we are comparing two poisoned references.
5170 __ cmp(temp1, ShifterOperand(temp2));
Roland Levillain16d9f942016-08-25 17:27:56 +01005171
Roland Levillain9d6e1f82016-09-05 15:57:33 +01005172 if (instruction->StaticTypeOfArrayIsObjectArray()) {
5173 Label do_put;
5174 __ b(&do_put, EQ);
5175 // If heap poisoning is enabled, the `temp1` reference has
5176 // not been unpoisoned yet; unpoison it now.
Roland Levillain3b359c72015-11-17 19:35:12 +00005177 __ MaybeUnpoisonHeapReference(temp1);
5178
Roland Levillain9d6e1f82016-09-05 15:57:33 +01005179 // /* HeapReference<Class> */ temp1 = temp1->super_class_
5180 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
5181 // If heap poisoning is enabled, no need to unpoison
5182 // `temp1`, as we are comparing against null below.
5183 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
5184 __ Bind(&do_put);
5185 } else {
5186 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005187 }
5188 }
5189
Artem Serov6c916792016-07-11 14:02:34 +01005190 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005191 if (kPoisonHeapReferences) {
5192 // Note that in the case where `value` is a null reference,
5193 // we do not enter this block, as a null reference does not
5194 // need poisoning.
5195 DCHECK_EQ(value_type, Primitive::kPrimNot);
5196 __ Mov(temp1, value);
5197 __ PoisonHeapReference(temp1);
5198 source = temp1;
5199 }
5200
5201 if (index.IsConstant()) {
5202 size_t offset =
5203 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
5204 __ StoreToOffset(kStoreWord, source, array, offset);
5205 } else {
5206 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01005207
5208 __ add(IP, array, ShifterOperand(data_offset));
5209 codegen_->StoreToShiftedRegOffset(value_type,
5210 Location::RegisterLocation(source),
5211 IP,
5212 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005213 }
5214
Roland Levillain3b359c72015-11-17 19:35:12 +00005215 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005216 codegen_->MaybeRecordImplicitNullCheck(instruction);
5217 }
5218
5219 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
5220
5221 if (done.IsLinked()) {
5222 __ Bind(&done);
5223 }
5224
5225 if (slow_path != nullptr) {
5226 __ Bind(slow_path->GetExitLabel());
5227 }
5228
5229 break;
5230 }
5231
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005232 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01005233 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005234 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00005235 size_t offset =
5236 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005237 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005238 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005239 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01005240 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005241 }
5242 break;
5243 }
5244
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005245 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005246 Location value = locations->InAt(2);
5247 DCHECK(value.IsFpuRegister());
5248 if (index.IsConstant()) {
5249 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005250 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005251 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005252 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005253 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
5254 }
5255 break;
5256 }
5257
5258 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005259 Location value = locations->InAt(2);
5260 DCHECK(value.IsFpuRegisterPair());
5261 if (index.IsConstant()) {
5262 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005263 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005264 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01005265 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005266 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
5267 }
Calin Juravle77520bc2015-01-12 18:45:46 +00005268
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005269 break;
5270 }
5271
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005272 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005273 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07005274 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005275 }
Calin Juravle77520bc2015-01-12 18:45:46 +00005276
Roland Levillain80e67092016-01-08 16:04:55 +00005277 // Objects are handled in the switch.
5278 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00005279 codegen_->MaybeRecordImplicitNullCheck(instruction);
5280 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005281}
5282
5283void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01005284 LocationSummary* locations =
5285 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01005286 locations->SetInAt(0, Location::RequiresRegister());
5287 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005288}
5289
5290void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
5291 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01005292 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00005293 Register obj = locations->InAt(0).AsRegister<Register>();
5294 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005295 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00005296 codegen_->MaybeRecordImplicitNullCheck(instruction);
jessicahandojo05765752016-09-09 19:01:32 -07005297 // Mask out compression flag from String's array length.
5298 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
5299 __ bic(out, out, ShifterOperand(1u << 31));
5300 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005301}
5302
Artem Serov328429f2016-07-06 16:23:04 +01005303void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Roland Levillain4a3aa572016-08-15 13:17:06 +00005304 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
5305 DCHECK(!kEmitCompilerReadBarrier);
Artem Serov328429f2016-07-06 16:23:04 +01005306 LocationSummary* locations =
5307 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5308
5309 locations->SetInAt(0, Location::RequiresRegister());
5310 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
5311 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5312}
5313
5314void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
5315 LocationSummary* locations = instruction->GetLocations();
5316 Location out = locations->Out();
5317 Location first = locations->InAt(0);
5318 Location second = locations->InAt(1);
5319
Roland Levillain4a3aa572016-08-15 13:17:06 +00005320 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
5321 DCHECK(!kEmitCompilerReadBarrier);
5322
Artem Serov328429f2016-07-06 16:23:04 +01005323 if (second.IsRegister()) {
5324 __ add(out.AsRegister<Register>(),
5325 first.AsRegister<Register>(),
5326 ShifterOperand(second.AsRegister<Register>()));
5327 } else {
5328 __ AddConstant(out.AsRegister<Register>(),
5329 first.AsRegister<Register>(),
5330 second.GetConstant()->AsIntConstant()->GetValue());
5331 }
5332}
5333
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005334void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01005335 RegisterSet caller_saves = RegisterSet::Empty();
5336 InvokeRuntimeCallingConvention calling_convention;
5337 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5338 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
5339 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005340 locations->SetInAt(0, Location::RequiresRegister());
5341 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005342}
5343
5344void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
5345 LocationSummary* locations = instruction->GetLocations();
Artem Serovf4d6aee2016-07-11 10:41:45 +01005346 SlowPathCodeARM* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005347 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005348 codegen_->AddSlowPath(slow_path);
5349
Roland Levillain271ab9c2014-11-27 15:23:57 +00005350 Register index = locations->InAt(0).AsRegister<Register>();
5351 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005352
5353 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01005354 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005355}
5356
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005357void CodeGeneratorARM::MarkGCCard(Register temp,
5358 Register card,
5359 Register object,
5360 Register value,
5361 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005362 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005363 if (can_be_null) {
5364 __ CompareAndBranchIfZero(value, &is_null);
5365 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005366 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005367 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5368 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005369 if (can_be_null) {
5370 __ Bind(&is_null);
5371 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005372}
5373
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005374void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005375 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005376}
5377
5378void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005379 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5380}
5381
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005382void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01005383 LocationSummary* locations =
5384 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01005385 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005386}
5387
5388void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005389 HBasicBlock* block = instruction->GetBlock();
5390 if (block->GetLoopInformation() != nullptr) {
5391 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5392 // The back edge will generate the suspend check.
5393 return;
5394 }
5395 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5396 // The goto will generate the suspend check.
5397 return;
5398 }
5399 GenerateSuspendCheck(instruction, nullptr);
5400}
5401
5402void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5403 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005404 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005405 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5406 if (slow_path == nullptr) {
5407 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5408 instruction->SetSlowPath(slow_path);
5409 codegen_->AddSlowPath(slow_path);
5410 if (successor != nullptr) {
5411 DCHECK(successor->IsLoopHeader());
5412 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5413 }
5414 } else {
5415 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5416 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005417
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005418 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005419 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005420 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005421 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005422 __ Bind(slow_path->GetReturnLabel());
5423 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005424 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005425 __ b(slow_path->GetEntryLabel());
5426 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005427}
5428
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005429ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5430 return codegen_->GetAssembler();
5431}
5432
5433void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005434 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005435 Location source = move->GetSource();
5436 Location destination = move->GetDestination();
5437
5438 if (source.IsRegister()) {
5439 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005440 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005441 } else if (destination.IsFpuRegister()) {
5442 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005443 } else {
5444 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005445 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005446 SP, destination.GetStackIndex());
5447 }
5448 } else if (source.IsStackSlot()) {
5449 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005450 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005451 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005452 } else if (destination.IsFpuRegister()) {
5453 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005454 } else {
5455 DCHECK(destination.IsStackSlot());
5456 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5457 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5458 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005459 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005460 if (destination.IsRegister()) {
5461 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5462 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005463 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005464 } else {
5465 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005466 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5467 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005468 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005469 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005470 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5471 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005472 } else if (destination.IsRegisterPair()) {
5473 DCHECK(ExpectedPairLayout(destination));
5474 __ LoadFromOffset(
5475 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5476 } else {
5477 DCHECK(destination.IsFpuRegisterPair()) << destination;
5478 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5479 SP,
5480 source.GetStackIndex());
5481 }
5482 } else if (source.IsRegisterPair()) {
5483 if (destination.IsRegisterPair()) {
5484 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5485 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005486 } else if (destination.IsFpuRegisterPair()) {
5487 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5488 source.AsRegisterPairLow<Register>(),
5489 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005490 } else {
5491 DCHECK(destination.IsDoubleStackSlot()) << destination;
5492 DCHECK(ExpectedPairLayout(source));
5493 __ StoreToOffset(
5494 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5495 }
5496 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005497 if (destination.IsRegisterPair()) {
5498 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5499 destination.AsRegisterPairHigh<Register>(),
5500 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5501 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005502 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5503 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5504 } else {
5505 DCHECK(destination.IsDoubleStackSlot()) << destination;
5506 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5507 SP,
5508 destination.GetStackIndex());
5509 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005510 } else {
5511 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005512 HConstant* constant = source.GetConstant();
5513 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5514 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005515 if (destination.IsRegister()) {
5516 __ LoadImmediate(destination.AsRegister<Register>(), value);
5517 } else {
5518 DCHECK(destination.IsStackSlot());
5519 __ LoadImmediate(IP, value);
5520 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5521 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005522 } else if (constant->IsLongConstant()) {
5523 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005524 if (destination.IsRegisterPair()) {
5525 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5526 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005527 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005528 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005529 __ LoadImmediate(IP, Low32Bits(value));
5530 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5531 __ LoadImmediate(IP, High32Bits(value));
5532 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5533 }
5534 } else if (constant->IsDoubleConstant()) {
5535 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005536 if (destination.IsFpuRegisterPair()) {
5537 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005538 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005539 DCHECK(destination.IsDoubleStackSlot()) << destination;
5540 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005541 __ LoadImmediate(IP, Low32Bits(int_value));
5542 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5543 __ LoadImmediate(IP, High32Bits(int_value));
5544 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5545 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005546 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005547 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005548 float value = constant->AsFloatConstant()->GetValue();
5549 if (destination.IsFpuRegister()) {
5550 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5551 } else {
5552 DCHECK(destination.IsStackSlot());
5553 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5554 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5555 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005556 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005557 }
5558}
5559
5560void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5561 __ Mov(IP, reg);
5562 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5563 __ StoreToOffset(kStoreWord, IP, SP, mem);
5564}
5565
5566void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5567 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5568 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5569 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5570 SP, mem1 + stack_offset);
5571 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5572 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5573 SP, mem2 + stack_offset);
5574 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5575}
5576
5577void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005578 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005579 Location source = move->GetSource();
5580 Location destination = move->GetDestination();
5581
5582 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005583 DCHECK_NE(source.AsRegister<Register>(), IP);
5584 DCHECK_NE(destination.AsRegister<Register>(), IP);
5585 __ Mov(IP, source.AsRegister<Register>());
5586 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5587 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005588 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005589 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005590 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005591 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005592 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5593 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005594 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005595 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005596 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005597 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005598 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005599 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005600 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005601 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005602 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5603 destination.AsRegisterPairHigh<Register>(),
5604 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005605 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005606 Register low_reg = source.IsRegisterPair()
5607 ? source.AsRegisterPairLow<Register>()
5608 : destination.AsRegisterPairLow<Register>();
5609 int mem = source.IsRegisterPair()
5610 ? destination.GetStackIndex()
5611 : source.GetStackIndex();
5612 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005613 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005614 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005615 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005616 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005617 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5618 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005619 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005620 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005621 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005622 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5623 DRegister reg = source.IsFpuRegisterPair()
5624 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5625 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5626 int mem = source.IsFpuRegisterPair()
5627 ? destination.GetStackIndex()
5628 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005629 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005630 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005631 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005632 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5633 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5634 : destination.AsFpuRegister<SRegister>();
5635 int mem = source.IsFpuRegister()
5636 ? destination.GetStackIndex()
5637 : source.GetStackIndex();
5638
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005639 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005640 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005641 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005642 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005643 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5644 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005645 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005646 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005647 }
5648}
5649
5650void ParallelMoveResolverARM::SpillScratch(int reg) {
5651 __ Push(static_cast<Register>(reg));
5652}
5653
5654void ParallelMoveResolverARM::RestoreScratch(int reg) {
5655 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005656}
5657
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005658HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5659 HLoadClass::LoadKind desired_class_load_kind) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005660 switch (desired_class_load_kind) {
5661 case HLoadClass::LoadKind::kReferrersClass:
5662 break;
5663 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5664 DCHECK(!GetCompilerOptions().GetCompilePic());
5665 break;
5666 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5667 DCHECK(GetCompilerOptions().GetCompilePic());
5668 break;
5669 case HLoadClass::LoadKind::kBootImageAddress:
5670 break;
5671 case HLoadClass::LoadKind::kDexCacheAddress:
5672 DCHECK(Runtime::Current()->UseJitCompilation());
5673 break;
5674 case HLoadClass::LoadKind::kDexCachePcRelative:
5675 DCHECK(!Runtime::Current()->UseJitCompilation());
5676 // We disable pc-relative load when there is an irreducible loop, as the optimization
5677 // is incompatible with it.
5678 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5679 // with irreducible loops.
5680 if (GetGraph()->HasIrreducibleLoops()) {
5681 return HLoadClass::LoadKind::kDexCacheViaMethod;
5682 }
5683 break;
5684 case HLoadClass::LoadKind::kDexCacheViaMethod:
5685 break;
5686 }
5687 return desired_class_load_kind;
5688}
5689
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005690void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005691 if (cls->NeedsAccessCheck()) {
5692 InvokeRuntimeCallingConvention calling_convention;
5693 CodeGenerator::CreateLoadClassLocationSummary(
5694 cls,
5695 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5696 Location::RegisterLocation(R0),
5697 /* code_generator_supports_read_barrier */ true);
5698 return;
5699 }
5700
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005701 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
5702 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005703 ? LocationSummary::kCallOnSlowPath
5704 : LocationSummary::kNoCall;
5705 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005706 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01005707 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01005708 }
5709
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005710 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5711 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5712 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5713 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5714 locations->SetInAt(0, Location::RequiresRegister());
5715 }
5716 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005717}
5718
5719void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005720 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005721 if (cls->NeedsAccessCheck()) {
5722 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01005723 codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005724 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005725 return;
5726 }
5727
Roland Levillain3b359c72015-11-17 19:35:12 +00005728 Location out_loc = locations->Out();
5729 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005730
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005731 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005732 bool generate_null_check = false;
5733 switch (cls->GetLoadKind()) {
5734 case HLoadClass::LoadKind::kReferrersClass: {
5735 DCHECK(!cls->CanCallRuntime());
5736 DCHECK(!cls->MustGenerateClinitCheck());
5737 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5738 Register current_method = locations->InAt(0).AsRegister<Register>();
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005739 GenerateGcRootFieldLoad(cls,
5740 out_loc,
5741 current_method,
5742 ArtMethod::DeclaringClassOffset().Int32Value(),
5743 requires_read_barrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005744 break;
5745 }
5746 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005747 DCHECK(!requires_read_barrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005748 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5749 cls->GetTypeIndex()));
5750 break;
5751 }
5752 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005753 DCHECK(!requires_read_barrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005754 CodeGeneratorARM::PcRelativePatchInfo* labels =
5755 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5756 __ BindTrackedLabel(&labels->movw_label);
5757 __ movw(out, /* placeholder */ 0u);
5758 __ BindTrackedLabel(&labels->movt_label);
5759 __ movt(out, /* placeholder */ 0u);
5760 __ BindTrackedLabel(&labels->add_pc_label);
5761 __ add(out, out, ShifterOperand(PC));
5762 break;
5763 }
5764 case HLoadClass::LoadKind::kBootImageAddress: {
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005765 DCHECK(!requires_read_barrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005766 DCHECK_NE(cls->GetAddress(), 0u);
5767 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5768 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5769 break;
5770 }
5771 case HLoadClass::LoadKind::kDexCacheAddress: {
5772 DCHECK_NE(cls->GetAddress(), 0u);
5773 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5774 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5775 // a 128B range. To try and reduce the number of literals if we load multiple types,
5776 // simply split the dex cache address to a 128B aligned base loaded from a literal
5777 // and the remaining offset embedded in the load.
5778 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5779 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5780 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5781 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5782 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5783 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5784 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005785 GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005786 generate_null_check = !cls->IsInDexCache();
5787 break;
5788 }
5789 case HLoadClass::LoadKind::kDexCachePcRelative: {
5790 Register base_reg = locations->InAt(0).AsRegister<Register>();
5791 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5792 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5793 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005794 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset, requires_read_barrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005795 generate_null_check = !cls->IsInDexCache();
5796 break;
5797 }
5798 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5799 // /* GcRoot<mirror::Class>[] */ out =
5800 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5801 Register current_method = locations->InAt(0).AsRegister<Register>();
5802 __ LoadFromOffset(kLoadWord,
5803 out,
5804 current_method,
5805 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5806 // /* GcRoot<mirror::Class> */ out = out[type_index]
5807 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005808 GenerateGcRootFieldLoad(cls, out_loc, out, offset, requires_read_barrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005809 generate_null_check = !cls->IsInDexCache();
5810 }
5811 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005812
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005813 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5814 DCHECK(cls->CanCallRuntime());
Artem Serovf4d6aee2016-07-11 10:41:45 +01005815 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005816 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5817 codegen_->AddSlowPath(slow_path);
5818 if (generate_null_check) {
5819 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5820 }
5821 if (cls->MustGenerateClinitCheck()) {
5822 GenerateClassInitializationCheck(slow_path, out);
5823 } else {
5824 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005825 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005826 }
5827}
5828
5829void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5830 LocationSummary* locations =
5831 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5832 locations->SetInAt(0, Location::RequiresRegister());
5833 if (check->HasUses()) {
5834 locations->SetOut(Location::SameAsFirstInput());
5835 }
5836}
5837
5838void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005839 // We assume the class is not null.
Artem Serovf4d6aee2016-07-11 10:41:45 +01005840 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005841 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005842 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005843 GenerateClassInitializationCheck(slow_path,
5844 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005845}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005846
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005847void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Artem Serovf4d6aee2016-07-11 10:41:45 +01005848 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005849 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5850 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5851 __ b(slow_path->GetEntryLabel(), LT);
5852 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5853 // properly. Therefore, we do a memory fence.
5854 __ dmb(ISH);
5855 __ Bind(slow_path->GetExitLabel());
5856}
5857
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005858HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5859 HLoadString::LoadKind desired_string_load_kind) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005860 switch (desired_string_load_kind) {
5861 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5862 DCHECK(!GetCompilerOptions().GetCompilePic());
5863 break;
5864 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5865 DCHECK(GetCompilerOptions().GetCompilePic());
5866 break;
5867 case HLoadString::LoadKind::kBootImageAddress:
5868 break;
5869 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005870 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005871 break;
Vladimir Markoaad75c62016-10-03 08:46:48 +00005872 case HLoadString::LoadKind::kBssEntry:
Calin Juravleffc87072016-04-20 14:22:09 +01005873 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005874 break;
5875 case HLoadString::LoadKind::kDexCacheViaMethod:
5876 break;
5877 }
5878 return desired_string_load_kind;
5879}
5880
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005881void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Christina Wadsworthd8ec6db2016-08-30 17:19:14 -07005882 LocationSummary::CallKind call_kind = load->NeedsEnvironment()
Vladimir Markoaad75c62016-10-03 08:46:48 +00005883 ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod)
5884 ? LocationSummary::kCallOnMainOnly
5885 : LocationSummary::kCallOnSlowPath)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005886 : LocationSummary::kNoCall;
5887 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Marko70e97462016-08-09 11:04:26 +01005888
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005889 HLoadString::LoadKind load_kind = load->GetLoadKind();
Christina Wadsworthd8ec6db2016-08-30 17:19:14 -07005890 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) {
Christina Wadsworthd8ec6db2016-08-30 17:19:14 -07005891 locations->SetOut(Location::RegisterLocation(R0));
5892 } else {
5893 locations->SetOut(Location::RequiresRegister());
Vladimir Marko94ce9c22016-09-30 14:50:51 +01005894 if (load_kind == HLoadString::LoadKind::kBssEntry) {
5895 if (!kUseReadBarrier || kUseBakerReadBarrier) {
5896 // Rely on the pResolveString and/or marking to save everything, including temps.
5897 // Note that IP may theoretically be clobbered by saving/restoring the live register
5898 // (only one thanks to the custom calling convention), so we request a different temp.
5899 locations->AddTemp(Location::RequiresRegister());
5900 RegisterSet caller_saves = RegisterSet::Empty();
5901 InvokeRuntimeCallingConvention calling_convention;
5902 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5903 // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK()
5904 // that the the kPrimNot result register is the same as the first argument register.
5905 locations->SetCustomSlowPathCallerSaves(caller_saves);
5906 } else {
5907 // For non-Baker read barrier we have a temp-clobbering call.
5908 }
5909 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005910 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005911}
5912
5913void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005914 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005915 Location out_loc = locations->Out();
5916 Register out = out_loc.AsRegister<Register>();
Christina Wadsworthd8ec6db2016-08-30 17:19:14 -07005917 HLoadString::LoadKind load_kind = load->GetLoadKind();
Roland Levillain3b359c72015-11-17 19:35:12 +00005918
Christina Wadsworthd8ec6db2016-08-30 17:19:14 -07005919 switch (load_kind) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005920 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005921 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5922 load->GetStringIndex()));
5923 return; // No dex cache slow path.
5924 }
5925 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00005926 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005927 CodeGeneratorARM::PcRelativePatchInfo* labels =
5928 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5929 __ BindTrackedLabel(&labels->movw_label);
5930 __ movw(out, /* placeholder */ 0u);
5931 __ BindTrackedLabel(&labels->movt_label);
5932 __ movt(out, /* placeholder */ 0u);
5933 __ BindTrackedLabel(&labels->add_pc_label);
5934 __ add(out, out, ShifterOperand(PC));
5935 return; // No dex cache slow path.
5936 }
5937 case HLoadString::LoadKind::kBootImageAddress: {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005938 DCHECK_NE(load->GetAddress(), 0u);
5939 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5940 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5941 return; // No dex cache slow path.
5942 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00005943 case HLoadString::LoadKind::kBssEntry: {
5944 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Marko94ce9c22016-09-30 14:50:51 +01005945 Register temp = locations->GetTemp(0).AsRegister<Register>();
Vladimir Markoaad75c62016-10-03 08:46:48 +00005946 CodeGeneratorARM::PcRelativePatchInfo* labels =
5947 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5948 __ BindTrackedLabel(&labels->movw_label);
Vladimir Marko94ce9c22016-09-30 14:50:51 +01005949 __ movw(temp, /* placeholder */ 0u);
Vladimir Markoaad75c62016-10-03 08:46:48 +00005950 __ BindTrackedLabel(&labels->movt_label);
Vladimir Marko94ce9c22016-09-30 14:50:51 +01005951 __ movt(temp, /* placeholder */ 0u);
Vladimir Markoaad75c62016-10-03 08:46:48 +00005952 __ BindTrackedLabel(&labels->add_pc_label);
Vladimir Marko94ce9c22016-09-30 14:50:51 +01005953 __ add(temp, temp, ShifterOperand(PC));
5954 GenerateGcRootFieldLoad(load, out_loc, temp, 0);
Vladimir Markoaad75c62016-10-03 08:46:48 +00005955 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5956 codegen_->AddSlowPath(slow_path);
5957 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5958 __ Bind(slow_path->GetExitLabel());
5959 return;
5960 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005961 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005962 break;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005963 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005964
Christina Wadsworthd8ec6db2016-08-30 17:19:14 -07005965 // TODO: Consider re-adding the compiler code to do string dex cache lookup again.
5966 DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod);
5967 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko94ce9c22016-09-30 14:50:51 +01005968 DCHECK_EQ(calling_convention.GetRegisterAt(0), out);
Christina Wadsworthd8ec6db2016-08-30 17:19:14 -07005969 __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex());
5970 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
5971 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005972}
5973
David Brazdilcb1c0552015-08-04 16:22:25 +01005974static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005975 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005976}
5977
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005978void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5979 LocationSummary* locations =
5980 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5981 locations->SetOut(Location::RequiresRegister());
5982}
5983
5984void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005985 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005986 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5987}
5988
5989void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5990 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5991}
5992
5993void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005994 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005995 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005996}
5997
5998void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5999 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006000 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00006001 InvokeRuntimeCallingConvention calling_convention;
6002 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6003}
6004
6005void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01006006 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006007 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00006008}
6009
Roland Levillainc9285912015-12-18 10:38:42 +00006010static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
6011 return kEmitCompilerReadBarrier &&
6012 (kUseBakerReadBarrier ||
6013 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
6014 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
6015 type_check_kind == TypeCheckKind::kArrayObjectCheck);
6016}
6017
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006018void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006019 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00006020 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Vladimir Marko70e97462016-08-09 11:04:26 +01006021 bool baker_read_barrier_slow_path = false;
Roland Levillain3b359c72015-11-17 19:35:12 +00006022 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006023 case TypeCheckKind::kExactCheck:
6024 case TypeCheckKind::kAbstractClassCheck:
6025 case TypeCheckKind::kClassHierarchyCheck:
6026 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00006027 call_kind =
6028 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Vladimir Marko70e97462016-08-09 11:04:26 +01006029 baker_read_barrier_slow_path = kUseBakerReadBarrier;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006030 break;
6031 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00006032 case TypeCheckKind::kUnresolvedCheck:
6033 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006034 call_kind = LocationSummary::kCallOnSlowPath;
6035 break;
6036 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006037
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006038 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Vladimir Marko70e97462016-08-09 11:04:26 +01006039 if (baker_read_barrier_slow_path) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01006040 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01006041 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006042 locations->SetInAt(0, Location::RequiresRegister());
6043 locations->SetInAt(1, Location::RequiresRegister());
6044 // The "out" register is used as a temporary, so it overlaps with the inputs.
6045 // Note that TypeCheckSlowPathARM uses this register too.
6046 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
6047 // When read barriers are enabled, we need a temporary register for
6048 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00006049 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006050 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006051 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006052}
6053
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006054void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00006055 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006056 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00006057 Location obj_loc = locations->InAt(0);
6058 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00006059 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00006060 Location out_loc = locations->Out();
6061 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006062 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00006063 locations->GetTemp(0) :
6064 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006065 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006066 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
6067 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
6068 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00006069 Label done, zero;
Artem Serovf4d6aee2016-07-11 10:41:45 +01006070 SlowPathCodeARM* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006071
6072 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01006073 // avoid null check if we know obj is not null.
6074 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00006075 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01006076 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006077
Roland Levillain3b359c72015-11-17 19:35:12 +00006078 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006079 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006080
Roland Levillainc9285912015-12-18 10:38:42 +00006081 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006082 case TypeCheckKind::kExactCheck: {
6083 __ cmp(out, ShifterOperand(cls));
6084 // Classes must be equal for the instanceof to succeed.
6085 __ b(&zero, NE);
6086 __ LoadImmediate(out, 1);
6087 __ b(&done);
6088 break;
6089 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006090
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006091 case TypeCheckKind::kAbstractClassCheck: {
6092 // If the class is abstract, we eagerly fetch the super class of the
6093 // object to avoid doing a comparison we know will fail.
6094 Label loop;
6095 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00006096 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006097 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006098 // If `out` is null, we use it for the result, and jump to `done`.
6099 __ CompareAndBranchIfZero(out, &done);
6100 __ cmp(out, ShifterOperand(cls));
6101 __ b(&loop, NE);
6102 __ LoadImmediate(out, 1);
6103 if (zero.IsLinked()) {
6104 __ b(&done);
6105 }
6106 break;
6107 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006108
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006109 case TypeCheckKind::kClassHierarchyCheck: {
6110 // Walk over the class hierarchy to find a match.
6111 Label loop, success;
6112 __ Bind(&loop);
6113 __ cmp(out, ShifterOperand(cls));
6114 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006115 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006116 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006117 __ CompareAndBranchIfNonZero(out, &loop);
6118 // If `out` is null, we use it for the result, and jump to `done`.
6119 __ b(&done);
6120 __ Bind(&success);
6121 __ LoadImmediate(out, 1);
6122 if (zero.IsLinked()) {
6123 __ b(&done);
6124 }
6125 break;
6126 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006127
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006128 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006129 // Do an exact check.
6130 Label exact_check;
6131 __ cmp(out, ShifterOperand(cls));
6132 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006133 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00006134 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006135 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006136 // If `out` is null, we use it for the result, and jump to `done`.
6137 __ CompareAndBranchIfZero(out, &done);
6138 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
6139 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
6140 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006141 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006142 __ LoadImmediate(out, 1);
6143 __ b(&done);
6144 break;
6145 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006146
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006147 case TypeCheckKind::kArrayCheck: {
6148 __ cmp(out, ShifterOperand(cls));
6149 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00006150 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
6151 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006152 codegen_->AddSlowPath(slow_path);
6153 __ b(slow_path->GetEntryLabel(), NE);
6154 __ LoadImmediate(out, 1);
6155 if (zero.IsLinked()) {
6156 __ b(&done);
6157 }
6158 break;
6159 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006160
Calin Juravle98893e12015-10-02 21:05:03 +01006161 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00006162 case TypeCheckKind::kInterfaceCheck: {
6163 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006164 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00006165 // cases.
6166 //
6167 // We cannot directly call the InstanceofNonTrivial runtime
6168 // entry point without resorting to a type checking slow path
6169 // here (i.e. by calling InvokeRuntime directly), as it would
6170 // require to assign fixed registers for the inputs of this
6171 // HInstanceOf instruction (following the runtime calling
6172 // convention), which might be cluttered by the potential first
6173 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006174 //
6175 // TODO: Introduce a new runtime entry point taking the object
6176 // to test (instead of its class) as argument, and let it deal
6177 // with the read barrier issues. This will let us refactor this
6178 // case of the `switch` code as it was previously (with a direct
6179 // call to the runtime not using a type checking slow path).
6180 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006181 DCHECK(locations->OnlyCallsOnSlowPath());
6182 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
6183 /* is_fatal */ false);
6184 codegen_->AddSlowPath(slow_path);
6185 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006186 if (zero.IsLinked()) {
6187 __ b(&done);
6188 }
6189 break;
6190 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006191 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01006192
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006193 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01006194 __ Bind(&zero);
6195 __ LoadImmediate(out, 0);
6196 }
6197
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006198 if (done.IsLinked()) {
6199 __ Bind(&done);
6200 }
6201
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006202 if (slow_path != nullptr) {
6203 __ Bind(slow_path->GetExitLabel());
6204 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00006205}
6206
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006207void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006208 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
6209 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
6210
Roland Levillain3b359c72015-11-17 19:35:12 +00006211 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
6212 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006213 case TypeCheckKind::kExactCheck:
6214 case TypeCheckKind::kAbstractClassCheck:
6215 case TypeCheckKind::kClassHierarchyCheck:
6216 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00006217 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
6218 LocationSummary::kCallOnSlowPath :
6219 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006220 break;
6221 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00006222 case TypeCheckKind::kUnresolvedCheck:
6223 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006224 call_kind = LocationSummary::kCallOnSlowPath;
6225 break;
6226 }
6227
Roland Levillain3b359c72015-11-17 19:35:12 +00006228 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
6229 locations->SetInAt(0, Location::RequiresRegister());
6230 locations->SetInAt(1, Location::RequiresRegister());
6231 // Note that TypeCheckSlowPathARM uses this "temp" register too.
6232 locations->AddTemp(Location::RequiresRegister());
6233 // When read barriers are enabled, we need an additional temporary
6234 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00006235 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006236 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006237 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006238}
6239
6240void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00006241 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006242 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00006243 Location obj_loc = locations->InAt(0);
6244 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00006245 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00006246 Location temp_loc = locations->GetTemp(0);
6247 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006248 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00006249 locations->GetTemp(1) :
6250 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006251 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006252 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
6253 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
6254 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006255
Roland Levillain3b359c72015-11-17 19:35:12 +00006256 bool is_type_check_slow_path_fatal =
6257 (type_check_kind == TypeCheckKind::kExactCheck ||
6258 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
6259 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
6260 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
6261 !instruction->CanThrowIntoCatchBlock();
Artem Serovf4d6aee2016-07-11 10:41:45 +01006262 SlowPathCodeARM* type_check_slow_path =
Roland Levillain3b359c72015-11-17 19:35:12 +00006263 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
6264 is_type_check_slow_path_fatal);
6265 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006266
6267 Label done;
6268 // Avoid null check if we know obj is not null.
6269 if (instruction->MustDoNullCheck()) {
6270 __ CompareAndBranchIfZero(obj, &done);
6271 }
6272
Roland Levillain3b359c72015-11-17 19:35:12 +00006273 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006274 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006275
Roland Levillain3b359c72015-11-17 19:35:12 +00006276 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006277 case TypeCheckKind::kExactCheck:
6278 case TypeCheckKind::kArrayCheck: {
6279 __ cmp(temp, ShifterOperand(cls));
6280 // Jump to slow path for throwing the exception or doing a
6281 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00006282 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006283 break;
6284 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006285
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006286 case TypeCheckKind::kAbstractClassCheck: {
6287 // If the class is abstract, we eagerly fetch the super class of the
6288 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00006289 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006290 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00006291 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006292 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006293
6294 // If the class reference currently in `temp` is not null, jump
6295 // to the `compare_classes` label to compare it with the checked
6296 // class.
6297 __ CompareAndBranchIfNonZero(temp, &compare_classes);
6298 // Otherwise, jump to the slow path to throw the exception.
6299 //
6300 // But before, move back the object's class into `temp` before
6301 // going into the slow path, as it has been overwritten in the
6302 // meantime.
6303 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006304 GenerateReferenceLoadTwoRegisters(
6305 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006306 __ b(type_check_slow_path->GetEntryLabel());
6307
6308 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006309 __ cmp(temp, ShifterOperand(cls));
6310 __ b(&loop, NE);
6311 break;
6312 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006313
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006314 case TypeCheckKind::kClassHierarchyCheck: {
6315 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006316 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006317 __ Bind(&loop);
6318 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006319 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006320
Roland Levillain3b359c72015-11-17 19:35:12 +00006321 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006322 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006323
6324 // If the class reference currently in `temp` is not null, jump
6325 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006326 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00006327 // Otherwise, jump to the slow path to throw the exception.
6328 //
6329 // But before, move back the object's class into `temp` before
6330 // going into the slow path, as it has been overwritten in the
6331 // meantime.
6332 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006333 GenerateReferenceLoadTwoRegisters(
6334 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006335 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006336 break;
6337 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006338
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006339 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006340 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00006341 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006342 __ cmp(temp, ShifterOperand(cls));
6343 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006344
6345 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00006346 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006347 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006348
6349 // If the component type is not null (i.e. the object is indeed
6350 // an array), jump to label `check_non_primitive_component_type`
6351 // to further check that this component type is not a primitive
6352 // type.
6353 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6354 // Otherwise, jump to the slow path to throw the exception.
6355 //
6356 // But before, move back the object's class into `temp` before
6357 // going into the slow path, as it has been overwritten in the
6358 // meantime.
6359 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006360 GenerateReferenceLoadTwoRegisters(
6361 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006362 __ b(type_check_slow_path->GetEntryLabel());
6363
6364 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006365 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006366 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6367 __ CompareAndBranchIfZero(temp, &done);
6368 // Same comment as above regarding `temp` and the slow path.
6369 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006370 GenerateReferenceLoadTwoRegisters(
6371 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006372 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006373 break;
6374 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006375
Calin Juravle98893e12015-10-02 21:05:03 +01006376 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006377 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006378 // We always go into the type check slow path for the unresolved
6379 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006380 //
6381 // We cannot directly call the CheckCast runtime entry point
6382 // without resorting to a type checking slow path here (i.e. by
6383 // calling InvokeRuntime directly), as it would require to
6384 // assign fixed registers for the inputs of this HInstanceOf
6385 // instruction (following the runtime calling convention), which
6386 // might be cluttered by the potential first read barrier
6387 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006388 //
6389 // TODO: Introduce a new runtime entry point taking the object
6390 // to test (instead of its class) as argument, and let it deal
6391 // with the read barrier issues. This will let us refactor this
6392 // case of the `switch` code as it was previously (with a direct
6393 // call to the runtime not using a type checking slow path).
6394 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006395 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006396 break;
6397 }
6398 __ Bind(&done);
6399
Roland Levillain3b359c72015-11-17 19:35:12 +00006400 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006401}
6402
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006403void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6404 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006405 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006406 InvokeRuntimeCallingConvention calling_convention;
6407 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6408}
6409
6410void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01006411 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
6412 instruction,
6413 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006414 if (instruction->IsEnter()) {
6415 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6416 } else {
6417 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6418 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006419}
6420
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006421void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6422void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6423void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006424
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006425void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006426 LocationSummary* locations =
6427 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6428 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6429 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006430 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006431 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006432 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006433 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006434}
6435
6436void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6437 HandleBitwiseOperation(instruction);
6438}
6439
6440void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6441 HandleBitwiseOperation(instruction);
6442}
6443
6444void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6445 HandleBitwiseOperation(instruction);
6446}
6447
Artem Serov7fc63502016-02-09 17:15:29 +00006448
6449void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6450 LocationSummary* locations =
6451 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6452 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6453 || instruction->GetResultType() == Primitive::kPrimLong);
6454
6455 locations->SetInAt(0, Location::RequiresRegister());
6456 locations->SetInAt(1, Location::RequiresRegister());
6457 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6458}
6459
6460void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6461 LocationSummary* locations = instruction->GetLocations();
6462 Location first = locations->InAt(0);
6463 Location second = locations->InAt(1);
6464 Location out = locations->Out();
6465
6466 if (instruction->GetResultType() == Primitive::kPrimInt) {
6467 Register first_reg = first.AsRegister<Register>();
6468 ShifterOperand second_reg(second.AsRegister<Register>());
6469 Register out_reg = out.AsRegister<Register>();
6470
6471 switch (instruction->GetOpKind()) {
6472 case HInstruction::kAnd:
6473 __ bic(out_reg, first_reg, second_reg);
6474 break;
6475 case HInstruction::kOr:
6476 __ orn(out_reg, first_reg, second_reg);
6477 break;
6478 // There is no EON on arm.
6479 case HInstruction::kXor:
6480 default:
6481 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6482 UNREACHABLE();
6483 }
6484 return;
6485
6486 } else {
6487 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6488 Register first_low = first.AsRegisterPairLow<Register>();
6489 Register first_high = first.AsRegisterPairHigh<Register>();
6490 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6491 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6492 Register out_low = out.AsRegisterPairLow<Register>();
6493 Register out_high = out.AsRegisterPairHigh<Register>();
6494
6495 switch (instruction->GetOpKind()) {
6496 case HInstruction::kAnd:
6497 __ bic(out_low, first_low, second_low);
6498 __ bic(out_high, first_high, second_high);
6499 break;
6500 case HInstruction::kOr:
6501 __ orn(out_low, first_low, second_low);
6502 __ orn(out_high, first_high, second_high);
6503 break;
6504 // There is no EON on arm.
6505 case HInstruction::kXor:
6506 default:
6507 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6508 UNREACHABLE();
6509 }
6510 }
6511}
6512
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006513void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6514 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6515 if (value == 0xffffffffu) {
6516 if (out != first) {
6517 __ mov(out, ShifterOperand(first));
6518 }
6519 return;
6520 }
6521 if (value == 0u) {
6522 __ mov(out, ShifterOperand(0));
6523 return;
6524 }
6525 ShifterOperand so;
6526 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6527 __ and_(out, first, so);
6528 } else {
6529 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6530 __ bic(out, first, ShifterOperand(~value));
6531 }
6532}
6533
6534void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6535 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6536 if (value == 0u) {
6537 if (out != first) {
6538 __ mov(out, ShifterOperand(first));
6539 }
6540 return;
6541 }
6542 if (value == 0xffffffffu) {
6543 __ mvn(out, ShifterOperand(0));
6544 return;
6545 }
6546 ShifterOperand so;
6547 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6548 __ orr(out, first, so);
6549 } else {
6550 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6551 __ orn(out, first, ShifterOperand(~value));
6552 }
6553}
6554
6555void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6556 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6557 if (value == 0u) {
6558 if (out != first) {
6559 __ mov(out, ShifterOperand(first));
6560 }
6561 return;
6562 }
6563 __ eor(out, first, ShifterOperand(value));
6564}
6565
Vladimir Marko59751a72016-08-05 14:37:27 +01006566void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6567 Location first,
6568 uint64_t value) {
6569 Register out_low = out.AsRegisterPairLow<Register>();
6570 Register out_high = out.AsRegisterPairHigh<Register>();
6571 Register first_low = first.AsRegisterPairLow<Register>();
6572 Register first_high = first.AsRegisterPairHigh<Register>();
6573 uint32_t value_low = Low32Bits(value);
6574 uint32_t value_high = High32Bits(value);
6575 if (value_low == 0u) {
6576 if (out_low != first_low) {
6577 __ mov(out_low, ShifterOperand(first_low));
6578 }
6579 __ AddConstant(out_high, first_high, value_high);
6580 return;
6581 }
6582 __ AddConstantSetFlags(out_low, first_low, value_low);
6583 ShifterOperand so;
6584 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6585 __ adc(out_high, first_high, so);
6586 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6587 __ sbc(out_high, first_high, so);
6588 } else {
6589 LOG(FATAL) << "Unexpected constant " << value_high;
6590 UNREACHABLE();
6591 }
6592}
6593
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006594void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6595 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006596 Location first = locations->InAt(0);
6597 Location second = locations->InAt(1);
6598 Location out = locations->Out();
6599
6600 if (second.IsConstant()) {
6601 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6602 uint32_t value_low = Low32Bits(value);
6603 if (instruction->GetResultType() == Primitive::kPrimInt) {
6604 Register first_reg = first.AsRegister<Register>();
6605 Register out_reg = out.AsRegister<Register>();
6606 if (instruction->IsAnd()) {
6607 GenerateAndConst(out_reg, first_reg, value_low);
6608 } else if (instruction->IsOr()) {
6609 GenerateOrrConst(out_reg, first_reg, value_low);
6610 } else {
6611 DCHECK(instruction->IsXor());
6612 GenerateEorConst(out_reg, first_reg, value_low);
6613 }
6614 } else {
6615 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6616 uint32_t value_high = High32Bits(value);
6617 Register first_low = first.AsRegisterPairLow<Register>();
6618 Register first_high = first.AsRegisterPairHigh<Register>();
6619 Register out_low = out.AsRegisterPairLow<Register>();
6620 Register out_high = out.AsRegisterPairHigh<Register>();
6621 if (instruction->IsAnd()) {
6622 GenerateAndConst(out_low, first_low, value_low);
6623 GenerateAndConst(out_high, first_high, value_high);
6624 } else if (instruction->IsOr()) {
6625 GenerateOrrConst(out_low, first_low, value_low);
6626 GenerateOrrConst(out_high, first_high, value_high);
6627 } else {
6628 DCHECK(instruction->IsXor());
6629 GenerateEorConst(out_low, first_low, value_low);
6630 GenerateEorConst(out_high, first_high, value_high);
6631 }
6632 }
6633 return;
6634 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006635
6636 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006637 Register first_reg = first.AsRegister<Register>();
6638 ShifterOperand second_reg(second.AsRegister<Register>());
6639 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006640 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006641 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006642 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006643 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006644 } else {
6645 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006646 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006647 }
6648 } else {
6649 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006650 Register first_low = first.AsRegisterPairLow<Register>();
6651 Register first_high = first.AsRegisterPairHigh<Register>();
6652 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6653 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6654 Register out_low = out.AsRegisterPairLow<Register>();
6655 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006656 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006657 __ and_(out_low, first_low, second_low);
6658 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006659 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006660 __ orr(out_low, first_low, second_low);
6661 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006662 } else {
6663 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006664 __ eor(out_low, first_low, second_low);
6665 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006666 }
6667 }
6668}
6669
Roland Levillainc9285912015-12-18 10:38:42 +00006670void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6671 Location out,
6672 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006673 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006674 Register out_reg = out.AsRegister<Register>();
6675 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006676 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006677 if (kUseBakerReadBarrier) {
6678 // Load with fast path based Baker's read barrier.
6679 // /* HeapReference<Object> */ out = *(out + offset)
6680 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006681 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006682 } else {
6683 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006684 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006685 // in the following move operation, as we will need it for the
6686 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006687 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006688 // /* HeapReference<Object> */ out = *(out + offset)
6689 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006690 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006691 }
6692 } else {
6693 // Plain load with no read barrier.
6694 // /* HeapReference<Object> */ out = *(out + offset)
6695 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6696 __ MaybeUnpoisonHeapReference(out_reg);
6697 }
6698}
6699
6700void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6701 Location out,
6702 Location obj,
6703 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006704 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006705 Register out_reg = out.AsRegister<Register>();
6706 Register obj_reg = obj.AsRegister<Register>();
6707 if (kEmitCompilerReadBarrier) {
6708 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006709 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006710 // Load with fast path based Baker's read barrier.
6711 // /* HeapReference<Object> */ out = *(obj + offset)
6712 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006713 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006714 } else {
6715 // Load with slow path based read barrier.
6716 // /* HeapReference<Object> */ out = *(obj + offset)
6717 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6718 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6719 }
6720 } else {
6721 // Plain load with no read barrier.
6722 // /* HeapReference<Object> */ out = *(obj + offset)
6723 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6724 __ MaybeUnpoisonHeapReference(out_reg);
6725 }
6726}
6727
6728void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6729 Location root,
6730 Register obj,
Mathieu Chartier31b12e32016-09-02 17:11:57 -07006731 uint32_t offset,
6732 bool requires_read_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006733 Register root_reg = root.AsRegister<Register>();
Mathieu Chartier31b12e32016-09-02 17:11:57 -07006734 if (requires_read_barrier) {
6735 DCHECK(kEmitCompilerReadBarrier);
Roland Levillainc9285912015-12-18 10:38:42 +00006736 if (kUseBakerReadBarrier) {
6737 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6738 // Baker's read barrier are used:
6739 //
6740 // root = obj.field;
6741 // if (Thread::Current()->GetIsGcMarking()) {
6742 // root = ReadBarrier::Mark(root)
6743 // }
6744
6745 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6746 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6747 static_assert(
6748 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6749 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6750 "have different sizes.");
6751 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6752 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6753 "have different sizes.");
6754
Vladimir Marko953437b2016-08-24 08:30:46 +00006755 // Slow path marking the GC root `root`.
Artem Serovf4d6aee2016-07-11 10:41:45 +01006756 SlowPathCodeARM* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006757 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006758 codegen_->AddSlowPath(slow_path);
6759
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006760 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006761 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006762 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006763 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6764 __ Bind(slow_path->GetExitLabel());
6765 } else {
6766 // GC root loaded through a slow path for read barriers other
6767 // than Baker's.
6768 // /* GcRoot<mirror::Object>* */ root = obj + offset
6769 __ AddConstant(root_reg, obj, offset);
6770 // /* mirror::Object* */ root = root->Read()
6771 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6772 }
6773 } else {
6774 // Plain GC root load with no read barrier.
6775 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6776 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6777 // Note that GC roots are not affected by heap poisoning, thus we
6778 // do not have to unpoison `root_reg` here.
6779 }
6780}
6781
6782void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6783 Location ref,
6784 Register obj,
6785 uint32_t offset,
6786 Location temp,
6787 bool needs_null_check) {
6788 DCHECK(kEmitCompilerReadBarrier);
6789 DCHECK(kUseBakerReadBarrier);
6790
6791 // /* HeapReference<Object> */ ref = *(obj + offset)
6792 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006793 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006794 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006795 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006796}
6797
6798void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6799 Location ref,
6800 Register obj,
6801 uint32_t data_offset,
6802 Location index,
6803 Location temp,
6804 bool needs_null_check) {
6805 DCHECK(kEmitCompilerReadBarrier);
6806 DCHECK(kUseBakerReadBarrier);
6807
Roland Levillainbfea3352016-06-23 13:48:47 +01006808 static_assert(
6809 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6810 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006811 // /* HeapReference<Object> */ ref =
6812 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006813 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006814 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006815 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006816}
6817
6818void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6819 Location ref,
6820 Register obj,
6821 uint32_t offset,
6822 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006823 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006824 Location temp,
Roland Levillaina1aa3b12016-10-26 13:03:38 +01006825 bool needs_null_check,
6826 bool always_update_field,
6827 Register* temp2) {
Roland Levillainc9285912015-12-18 10:38:42 +00006828 DCHECK(kEmitCompilerReadBarrier);
6829 DCHECK(kUseBakerReadBarrier);
6830
6831 // In slow path based read barriers, the read barrier call is
6832 // inserted after the original load. However, in fast path based
6833 // Baker's read barriers, we need to perform the load of
6834 // mirror::Object::monitor_ *before* the original reference load.
6835 // This load-load ordering is required by the read barrier.
6836 // The fast path/slow path (for Baker's algorithm) should look like:
6837 //
6838 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6839 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6840 // HeapReference<Object> ref = *src; // Original reference load.
6841 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6842 // if (is_gray) {
6843 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6844 // }
6845 //
6846 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006847 // slightly more complex as it performs additional checks that we do
6848 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006849
6850 Register ref_reg = ref.AsRegister<Register>();
6851 Register temp_reg = temp.AsRegister<Register>();
6852 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6853
6854 // /* int32_t */ monitor = obj->monitor_
6855 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6856 if (needs_null_check) {
6857 MaybeRecordImplicitNullCheck(instruction);
6858 }
6859 // /* LockWord */ lock_word = LockWord(monitor)
6860 static_assert(sizeof(LockWord) == sizeof(int32_t),
6861 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006862
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006863 // Introduce a dependency on the lock_word including the rb_state,
6864 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006865 // a memory barrier (which would be more expensive).
Roland Levillain0b671c02016-08-19 12:02:34 +01006866 // `obj` is unchanged by this operation, but its value now depends
6867 // on `temp_reg`.
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006868 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006869
6870 // The actual reference load.
6871 if (index.IsValid()) {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01006872 // Load types involving an "index": ArrayGet,
6873 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
6874 // intrinsics.
Roland Levillainbfea3352016-06-23 13:48:47 +01006875 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006876 if (index.IsConstant()) {
6877 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006878 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006879 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6880 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006881 // Handle the special case of the
Roland Levillaina1aa3b12016-10-26 13:03:38 +01006882 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
6883 // intrinsics, which use a register pair as index ("long
6884 // offset"), of which only the low part contains data.
Roland Levillainbfea3352016-06-23 13:48:47 +01006885 Register index_reg = index.IsRegisterPair()
6886 ? index.AsRegisterPairLow<Register>()
6887 : index.AsRegister<Register>();
6888 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006889 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6890 }
6891 } else {
6892 // /* HeapReference<Object> */ ref = *(obj + offset)
6893 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6894 }
6895
6896 // Object* ref = ref_addr->AsMirrorPtr()
6897 __ MaybeUnpoisonHeapReference(ref_reg);
6898
Vladimir Marko953437b2016-08-24 08:30:46 +00006899 // Slow path marking the object `ref` when it is gray.
Roland Levillaina1aa3b12016-10-26 13:03:38 +01006900 SlowPathCodeARM* slow_path;
6901 if (always_update_field) {
6902 DCHECK(temp2 != nullptr);
6903 // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address
6904 // of the form `obj + field_offset`, where `obj` is a register and
6905 // `field_offset` is a register pair (of which only the lower half
6906 // is used). Thus `offset` and `scale_factor` above are expected
6907 // to be null in this code path.
6908 DCHECK_EQ(offset, 0u);
6909 DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1);
6910 slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM(
6911 instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2);
6912 } else {
6913 slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
6914 }
Roland Levillainc9285912015-12-18 10:38:42 +00006915 AddSlowPath(slow_path);
6916
6917 // if (rb_state == ReadBarrier::gray_ptr_)
6918 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006919 // Given the numeric representation, it's enough to check the low bit of the
6920 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6921 // which can be a 16-bit instruction unlike the TST immediate.
6922 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6923 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6924 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6925 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6926 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006927 __ Bind(slow_path->GetExitLabel());
6928}
6929
6930void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6931 Location out,
6932 Location ref,
6933 Location obj,
6934 uint32_t offset,
6935 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006936 DCHECK(kEmitCompilerReadBarrier);
6937
Roland Levillainc9285912015-12-18 10:38:42 +00006938 // Insert a slow path based read barrier *after* the reference load.
6939 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006940 // If heap poisoning is enabled, the unpoisoning of the loaded
6941 // reference will be carried out by the runtime within the slow
6942 // path.
6943 //
6944 // Note that `ref` currently does not get unpoisoned (when heap
6945 // poisoning is enabled), which is alright as the `ref` argument is
6946 // not used by the artReadBarrierSlow entry point.
6947 //
6948 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
Artem Serovf4d6aee2016-07-11 10:41:45 +01006949 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
Roland Levillain3b359c72015-11-17 19:35:12 +00006950 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6951 AddSlowPath(slow_path);
6952
Roland Levillain3b359c72015-11-17 19:35:12 +00006953 __ b(slow_path->GetEntryLabel());
6954 __ Bind(slow_path->GetExitLabel());
6955}
6956
Roland Levillainc9285912015-12-18 10:38:42 +00006957void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6958 Location out,
6959 Location ref,
6960 Location obj,
6961 uint32_t offset,
6962 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006963 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006964 // Baker's read barriers shall be handled by the fast path
6965 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6966 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006967 // If heap poisoning is enabled, unpoisoning will be taken care of
6968 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006969 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006970 } else if (kPoisonHeapReferences) {
6971 __ UnpoisonHeapReference(out.AsRegister<Register>());
6972 }
6973}
6974
Roland Levillainc9285912015-12-18 10:38:42 +00006975void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6976 Location out,
6977 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006978 DCHECK(kEmitCompilerReadBarrier);
6979
Roland Levillainc9285912015-12-18 10:38:42 +00006980 // Insert a slow path based read barrier *after* the GC root load.
6981 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006982 // Note that GC roots are not affected by heap poisoning, so we do
6983 // not need to do anything special for this here.
Artem Serovf4d6aee2016-07-11 10:41:45 +01006984 SlowPathCodeARM* slow_path =
Roland Levillain3b359c72015-11-17 19:35:12 +00006985 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6986 AddSlowPath(slow_path);
6987
Roland Levillain3b359c72015-11-17 19:35:12 +00006988 __ b(slow_path->GetEntryLabel());
6989 __ Bind(slow_path->GetExitLabel());
6990}
6991
Vladimir Markodc151b22015-10-15 18:02:30 +01006992HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6993 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01006994 HInvokeStaticOrDirect* invoke) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006995 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6996 // We disable pc-relative load when there is an irreducible loop, as the optimization
6997 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006998 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6999 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00007000 if (GetGraph()->HasIrreducibleLoops() &&
7001 (dispatch_info.method_load_kind ==
7002 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
7003 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
7004 }
7005
7006 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01007007 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01007008 if (&outer_dex_file != invoke->GetTargetMethod().dex_file) {
Vladimir Markodc151b22015-10-15 18:02:30 +01007009 // Calls across dex files are more likely to exceed the available BL range,
7010 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
7011 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
7012 (desired_dispatch_info.method_load_kind ==
7013 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
7014 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
7015 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
7016 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00007017 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01007018 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00007019 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01007020 0u
7021 };
7022 }
7023 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00007024 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01007025}
7026
Vladimir Markob4536b72015-11-24 13:45:23 +00007027Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
7028 Register temp) {
7029 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
7030 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
7031 if (!invoke->GetLocations()->Intrinsified()) {
7032 return location.AsRegister<Register>();
7033 }
7034 // For intrinsics we allow any location, so it may be on the stack.
7035 if (!location.IsRegister()) {
7036 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
7037 return temp;
7038 }
7039 // For register locations, check if the register was saved. If so, get it from the stack.
7040 // Note: There is a chance that the register was saved but not overwritten, so we could
7041 // save one load. However, since this is just an intrinsic slow path we prefer this
7042 // simple and more robust approach rather that trying to determine if that's the case.
7043 SlowPathCode* slow_path = GetCurrentSlowPath();
7044 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
7045 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
7046 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
7047 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
7048 return temp;
7049 }
7050 return location.AsRegister<Register>();
7051}
7052
Nicolas Geoffray38207af2015-06-01 15:46:22 +01007053void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00007054 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00007055 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00007056 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
7057 // LR = code address from literal pool with link-time patch.
7058 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00007059 break;
7060 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
7061 // LR = invoke->GetDirectCodePtr();
7062 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00007063 break;
7064 default:
7065 break;
7066 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08007067
Vladimir Marko58155012015-08-19 12:49:41 +00007068 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
7069 switch (invoke->GetMethodLoadKind()) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007070 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
7071 uint32_t offset =
7072 GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Vladimir Marko58155012015-08-19 12:49:41 +00007073 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007074 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset);
Vladimir Marko58155012015-08-19 12:49:41 +00007075 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01007076 }
Vladimir Marko58155012015-08-19 12:49:41 +00007077 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00007078 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00007079 break;
7080 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
7081 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
7082 break;
7083 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
7084 __ LoadLiteral(temp.AsRegister<Register>(),
7085 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
7086 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00007087 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
7088 HArmDexCacheArraysBase* base =
7089 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
7090 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
7091 temp.AsRegister<Register>());
7092 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
7093 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
7094 break;
7095 }
Vladimir Marko58155012015-08-19 12:49:41 +00007096 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00007097 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00007098 Register method_reg;
7099 Register reg = temp.AsRegister<Register>();
7100 if (current_method.IsRegister()) {
7101 method_reg = current_method.AsRegister<Register>();
7102 } else {
7103 DCHECK(invoke->GetLocations()->Intrinsified());
7104 DCHECK(!current_method.IsValid());
7105 method_reg = reg;
7106 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
7107 }
Roland Levillain3b359c72015-11-17 19:35:12 +00007108 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
7109 __ LoadFromOffset(kLoadWord,
7110 reg,
7111 method_reg,
7112 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01007113 // temp = temp[index_in_cache];
7114 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
7115 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00007116 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
7117 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01007118 }
Vladimir Marko58155012015-08-19 12:49:41 +00007119 }
7120
7121 switch (invoke->GetCodePtrLocation()) {
7122 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
7123 __ bl(GetFrameEntryLabel());
7124 break;
7125 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markoaad75c62016-10-03 08:46:48 +00007126 relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file,
7127 invoke->GetTargetMethod().dex_method_index);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007128 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01007129 // Arbitrarily branch to the BL itself, override at link time.
7130 __ bl(&relative_call_patches_.back().label);
7131 break;
Vladimir Marko58155012015-08-19 12:49:41 +00007132 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
7133 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
7134 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00007135 // LR()
7136 __ blx(LR);
7137 break;
7138 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
7139 // LR = callee_method->entry_point_from_quick_compiled_code_
7140 __ LoadFromOffset(
7141 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07007142 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00007143 // LR()
7144 __ blx(LR);
7145 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08007146 }
7147
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08007148 DCHECK(!IsLeafMethod());
7149}
7150
Andreas Gampebfb5ba92015-09-01 15:45:02 +00007151void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
7152 Register temp = temp_location.AsRegister<Register>();
7153 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
7154 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00007155
7156 // Use the calling convention instead of the location of the receiver, as
7157 // intrinsics may have put the receiver in a different register. In the intrinsics
7158 // slow path, the arguments have been moved to the right place, so here we are
7159 // guaranteed that the receiver is the first register of the calling convention.
7160 InvokeDexCallingConvention calling_convention;
7161 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00007162 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00007163 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00007164 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00007165 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00007166 // Instead of simply (possibly) unpoisoning `temp` here, we should
7167 // emit a read barrier for the previous class reference load.
7168 // However this is not required in practice, as this is an
7169 // intermediate/temporary reference and because the current
7170 // concurrent copying collector keeps the from-space memory
7171 // intact/accessible until the end of the marking phase (the
7172 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00007173 __ MaybeUnpoisonHeapReference(temp);
7174 // temp = temp->GetMethodAt(method_offset);
7175 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07007176 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00007177 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
7178 // LR = temp->GetEntryPoint();
7179 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
7180 // LR();
7181 __ blx(LR);
7182}
7183
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007184CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
7185 const DexFile& dex_file, uint32_t string_index) {
7186 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
7187}
7188
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007189CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
7190 const DexFile& dex_file, uint32_t type_index) {
7191 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
7192}
7193
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007194CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
7195 const DexFile& dex_file, uint32_t element_offset) {
7196 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
7197}
7198
7199CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
7200 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
7201 patches->emplace_back(dex_file, offset_or_index);
7202 return &patches->back();
7203}
7204
7205Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
7206 uint32_t string_index) {
7207 return boot_image_string_patches_.GetOrCreate(
7208 StringReference(&dex_file, string_index),
7209 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
7210}
7211
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007212Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
7213 uint32_t type_index) {
7214 return boot_image_type_patches_.GetOrCreate(
7215 TypeReference(&dex_file, type_index),
7216 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
7217}
7218
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007219Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
7220 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
7221 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
7222 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
7223}
7224
7225Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
7226 return DeduplicateUint32Literal(address, &uint32_literals_);
7227}
7228
Vladimir Markoaad75c62016-10-03 08:46:48 +00007229template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
7230inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches(
7231 const ArenaDeque<PcRelativePatchInfo>& infos,
7232 ArenaVector<LinkerPatch>* linker_patches) {
7233 for (const PcRelativePatchInfo& info : infos) {
7234 const DexFile& dex_file = info.target_dex_file;
7235 size_t offset_or_index = info.offset_or_index;
7236 DCHECK(info.add_pc_label.IsBound());
7237 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
7238 // Add MOVW patch.
7239 DCHECK(info.movw_label.IsBound());
7240 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
7241 linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index));
7242 // Add MOVT patch.
7243 DCHECK(info.movt_label.IsBound());
7244 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
7245 linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index));
7246 }
7247}
7248
Vladimir Marko58155012015-08-19 12:49:41 +00007249void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
7250 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00007251 size_t size =
7252 method_patches_.size() +
7253 call_patches_.size() +
7254 relative_call_patches_.size() +
Vladimir Markoaad75c62016-10-03 08:46:48 +00007255 /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007256 boot_image_string_patches_.size() +
Vladimir Markoaad75c62016-10-03 08:46:48 +00007257 /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007258 boot_image_type_patches_.size() +
Vladimir Markoaad75c62016-10-03 08:46:48 +00007259 /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007260 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00007261 linker_patches->reserve(size);
7262 for (const auto& entry : method_patches_) {
7263 const MethodReference& target_method = entry.first;
7264 Literal* literal = entry.second;
7265 DCHECK(literal->GetLabel()->IsBound());
7266 uint32_t literal_offset = literal->GetLabel()->Position();
7267 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
7268 target_method.dex_file,
7269 target_method.dex_method_index));
7270 }
7271 for (const auto& entry : call_patches_) {
7272 const MethodReference& target_method = entry.first;
7273 Literal* literal = entry.second;
7274 DCHECK(literal->GetLabel()->IsBound());
7275 uint32_t literal_offset = literal->GetLabel()->Position();
7276 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
7277 target_method.dex_file,
7278 target_method.dex_method_index));
7279 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00007280 for (const PatchInfo<Label>& info : relative_call_patches_) {
Vladimir Marko58155012015-08-19 12:49:41 +00007281 uint32_t literal_offset = info.label.Position();
Vladimir Markoaad75c62016-10-03 08:46:48 +00007282 linker_patches->push_back(
7283 LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index));
Vladimir Marko58155012015-08-19 12:49:41 +00007284 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00007285 EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_,
7286 linker_patches);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007287 for (const auto& entry : boot_image_string_patches_) {
7288 const StringReference& target_string = entry.first;
7289 Literal* literal = entry.second;
7290 DCHECK(literal->GetLabel()->IsBound());
7291 uint32_t literal_offset = literal->GetLabel()->Position();
7292 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
7293 target_string.dex_file,
7294 target_string.string_index));
7295 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00007296 if (!GetCompilerOptions().IsBootImage()) {
7297 EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_,
7298 linker_patches);
7299 } else {
7300 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_,
7301 linker_patches);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007302 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01007303 for (const auto& entry : boot_image_type_patches_) {
7304 const TypeReference& target_type = entry.first;
7305 Literal* literal = entry.second;
7306 DCHECK(literal->GetLabel()->IsBound());
7307 uint32_t literal_offset = literal->GetLabel()->Position();
7308 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
7309 target_type.dex_file,
7310 target_type.type_index));
7311 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00007312 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_,
7313 linker_patches);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007314 for (const auto& entry : boot_image_address_patches_) {
7315 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
7316 Literal* literal = entry.second;
7317 DCHECK(literal->GetLabel()->IsBound());
7318 uint32_t literal_offset = literal->GetLabel()->Position();
7319 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
7320 }
7321}
7322
7323Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
7324 return map->GetOrCreate(
7325 value,
7326 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00007327}
7328
7329Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
7330 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007331 return map->GetOrCreate(
7332 target_method,
7333 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00007334}
7335
7336Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
7337 return DeduplicateMethodLiteral(target_method, &method_patches_);
7338}
7339
7340Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
7341 return DeduplicateMethodLiteral(target_method, &call_patches_);
7342}
7343
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03007344void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7345 LocationSummary* locations =
7346 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7347 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7348 Location::RequiresRegister());
7349 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7350 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7351 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7352}
7353
7354void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7355 LocationSummary* locations = instr->GetLocations();
7356 Register res = locations->Out().AsRegister<Register>();
7357 Register accumulator =
7358 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7359 Register mul_left =
7360 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7361 Register mul_right =
7362 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7363
7364 if (instr->GetOpKind() == HInstruction::kAdd) {
7365 __ mla(res, mul_left, mul_right, accumulator);
7366 } else {
7367 __ mls(res, mul_left, mul_right, accumulator);
7368 }
7369}
7370
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007371void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007372 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007373 LOG(FATAL) << "Unreachable";
7374}
7375
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007376void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007377 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007378 LOG(FATAL) << "Unreachable";
7379}
7380
Mark Mendellfe57faa2015-09-18 09:26:15 -04007381// Simple implementation of packed switch - generate cascaded compare/jumps.
7382void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7383 LocationSummary* locations =
7384 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7385 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007386 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007387 codegen_->GetAssembler()->IsThumb()) {
7388 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7389 if (switch_instr->GetStartValue() != 0) {
7390 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7391 }
7392 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007393}
7394
7395void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7396 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007397 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007398 LocationSummary* locations = switch_instr->GetLocations();
7399 Register value_reg = locations->InAt(0).AsRegister<Register>();
7400 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7401
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007402 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007403 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007404 Register temp_reg = IP;
7405 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7406 // the immediate, because IP is used as the destination register. For the other
7407 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7408 // and they can be encoded in the instruction without making use of IP register.
7409 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7410
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007411 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007412 // Jump to successors[0] if value == lower_bound.
7413 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7414 int32_t last_index = 0;
7415 for (; num_entries - last_index > 2; last_index += 2) {
7416 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7417 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7418 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7419 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7420 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7421 }
7422 if (num_entries - last_index == 2) {
7423 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007424 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007425 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007426 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007427
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007428 // And the default for any other value.
7429 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7430 __ b(codegen_->GetLabelOf(default_block));
7431 }
7432 } else {
7433 // Create a table lookup.
7434 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7435
7436 // Materialize a pointer to the switch table
7437 std::vector<Label*> labels(num_entries);
7438 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7439 for (uint32_t i = 0; i < num_entries; i++) {
7440 labels[i] = codegen_->GetLabelOf(successors[i]);
7441 }
7442 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7443
7444 // Remove the bias.
7445 Register key_reg;
7446 if (lower_bound != 0) {
7447 key_reg = locations->GetTemp(1).AsRegister<Register>();
7448 __ AddConstant(key_reg, value_reg, -lower_bound);
7449 } else {
7450 key_reg = value_reg;
7451 }
7452
7453 // Check whether the value is in the table, jump to default block if not.
7454 __ CmpConstant(key_reg, num_entries - 1);
7455 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7456
7457 // Load the displacement from the table.
7458 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7459
7460 // Dispatch is a direct add to the PC (for Thumb2).
7461 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007462 }
7463}
7464
Vladimir Markob4536b72015-11-24 13:45:23 +00007465void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7466 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7467 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007468}
7469
7470void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7471 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007472 CodeGeneratorARM::PcRelativePatchInfo* labels =
7473 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007474 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007475 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007476 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007477 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007478 __ BindTrackedLabel(&labels->add_pc_label);
7479 __ add(base_reg, base_reg, ShifterOperand(PC));
7480}
7481
Andreas Gampe85b62f22015-09-09 13:15:38 -07007482void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7483 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007484 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007485 return;
7486 }
7487
7488 DCHECK_NE(type, Primitive::kPrimVoid);
7489
7490 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7491 if (return_loc.Equals(trg)) {
7492 return;
7493 }
7494
7495 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7496 // with the last branch.
7497 if (type == Primitive::kPrimLong) {
7498 HParallelMove parallel_move(GetGraph()->GetArena());
7499 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7500 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7501 GetMoveResolver()->EmitNativeCode(&parallel_move);
7502 } else if (type == Primitive::kPrimDouble) {
7503 HParallelMove parallel_move(GetGraph()->GetArena());
7504 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7505 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7506 GetMoveResolver()->EmitNativeCode(&parallel_move);
7507 } else {
7508 // Let the parallel move resolver take care of all of this.
7509 HParallelMove parallel_move(GetGraph()->GetArena());
7510 parallel_move.AddMove(return_loc, trg, type, nullptr);
7511 GetMoveResolver()->EmitNativeCode(&parallel_move);
7512 }
7513}
7514
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007515void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7516 LocationSummary* locations =
7517 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7518 locations->SetInAt(0, Location::RequiresRegister());
7519 locations->SetOut(Location::RequiresRegister());
7520}
7521
7522void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7523 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007524 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007525 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007526 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007527 __ LoadFromOffset(kLoadWord,
7528 locations->Out().AsRegister<Register>(),
7529 locations->InAt(0).AsRegister<Register>(),
7530 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007531 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007532 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007533 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007534 __ LoadFromOffset(kLoadWord,
7535 locations->Out().AsRegister<Register>(),
7536 locations->InAt(0).AsRegister<Register>(),
7537 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7538 __ LoadFromOffset(kLoadWord,
7539 locations->Out().AsRegister<Register>(),
7540 locations->Out().AsRegister<Register>(),
7541 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007542 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007543}
7544
Roland Levillain4d027112015-07-01 15:41:14 +01007545#undef __
7546#undef QUICK_ENTRY_POINT
7547
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007548} // namespace arm
7549} // namespace art