blob: 16072d9c2566c2f9e3f57f24f83ef99c6a141740 [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
Andreas Gampe85b62f22015-09-09 13:15:38 -070066class NullCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 public:
David Srbecky9cd6d372016-02-09 15:24:47 +000068 explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010069
Alexandre Rames67555f72014-11-18 10:55:16 +000070 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010071 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010072 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000073 if (instruction_->CanThrowIntoCatchBlock()) {
74 // Live registers will be restored in the catch block if caught.
75 SaveLiveRegisters(codegen, instruction_->GetLocations());
76 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +010077 arm_codegen->InvokeRuntime(kQuickThrowNullPointer,
78 instruction_,
79 instruction_->GetDexPc(),
80 this);
Roland Levillain888d0672015-11-23 18:53:50 +000081 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082 }
83
Alexandre Rames8158f282015-08-07 10:26:17 +010084 bool IsFatal() const OVERRIDE { return true; }
85
Alexandre Rames9931f312015-06-19 14:47:01 +010086 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
87
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 private:
Nicolas Geoffraye5038322014-07-04 09:41:32 +010089 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
90};
91
Andreas Gampe85b62f22015-09-09 13:15:38 -070092class DivZeroCheckSlowPathARM : public SlowPathCode {
Calin Juravled0d48522014-11-04 16:40:20 +000093 public:
David Srbecky9cd6d372016-02-09 15:24:47 +000094 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {}
Calin Juravled0d48522014-11-04 16:40:20 +000095
Alexandre Rames67555f72014-11-18 10:55:16 +000096 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000097 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
98 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000099 if (instruction_->CanThrowIntoCatchBlock()) {
100 // Live registers will be restored in the catch block if caught.
101 SaveLiveRegisters(codegen, instruction_->GetLocations());
102 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100103 arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000104 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Calin Juravled0d48522014-11-04 16:40:20 +0000105 }
106
Alexandre Rames8158f282015-08-07 10:26:17 +0100107 bool IsFatal() const OVERRIDE { return true; }
108
Alexandre Rames9931f312015-06-19 14:47:01 +0100109 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
110
Calin Juravled0d48522014-11-04 16:40:20 +0000111 private:
Calin Juravled0d48522014-11-04 16:40:20 +0000112 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
113};
114
Andreas Gampe85b62f22015-09-09 13:15:38 -0700115class SuspendCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000117 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000118 : SlowPathCode(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000119
Alexandre Rames67555f72014-11-18 10:55:16 +0000120 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100121 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000122 __ Bind(GetEntryLabel());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100123 arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000124 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 if (successor_ == nullptr) {
126 __ b(GetReturnLabel());
127 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100128 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000130 }
131
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100132 Label* GetReturnLabel() {
133 DCHECK(successor_ == nullptr);
134 return &return_label_;
135 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000136
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100137 HBasicBlock* GetSuccessor() const {
138 return successor_;
139 }
140
Alexandre Rames9931f312015-06-19 14:47:01 +0100141 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
142
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000143 private:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100144 // If not null, the block to branch to after the suspend check.
145 HBasicBlock* const successor_;
146
147 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000148 Label return_label_;
149
150 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
151};
152
Andreas Gampe85b62f22015-09-09 13:15:38 -0700153class BoundsCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100154 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100155 explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000156 : SlowPathCode(instruction) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100157
Alexandre Rames67555f72014-11-18 10:55:16 +0000158 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100159 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100160 LocationSummary* locations = instruction_->GetLocations();
161
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000163 if (instruction_->CanThrowIntoCatchBlock()) {
164 // Live registers will be restored in the catch block if caught.
165 SaveLiveRegisters(codegen, instruction_->GetLocations());
166 }
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000167 // We're moving two locations to locations that could overlap, so we need a parallel
168 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100169 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000170 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100171 locations->InAt(0),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000172 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100173 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100174 locations->InAt(1),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100175 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
176 Primitive::kPrimInt);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100177 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
178 ? kQuickThrowStringBounds
179 : kQuickThrowArrayBounds;
180 arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100181 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Roland Levillain888d0672015-11-23 18:53:50 +0000182 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 }
184
Alexandre Rames8158f282015-08-07 10:26:17 +0100185 bool IsFatal() const OVERRIDE { return true; }
186
Alexandre Rames9931f312015-06-19 14:47:01 +0100187 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
188
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100189 private:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100190 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
191};
192
Andreas Gampe85b62f22015-09-09 13:15:38 -0700193class LoadClassSlowPathARM : public SlowPathCode {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100194 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000195 LoadClassSlowPathARM(HLoadClass* cls,
196 HInstruction* at,
197 uint32_t dex_pc,
198 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000199 : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
201 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202
Alexandre Rames67555f72014-11-18 10:55:16 +0000203 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 LocationSummary* locations = at_->GetLocations();
205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
207 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000208 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100212 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
213 : kQuickInitializeType;
214 arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this);
Roland Levillain888d0672015-11-23 18:53:50 +0000215 if (do_clinit_) {
216 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
217 } else {
218 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
219 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000220
221 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000222 Location out = locations->Out();
223 if (out.IsValid()) {
224 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000225 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
226 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000227 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100228 __ b(GetExitLabel());
229 }
230
Alexandre Rames9931f312015-06-19 14:47:01 +0100231 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
232
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100233 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000234 // The class this slow path will load.
235 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100236
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000237 // The instruction where this slow path is happening.
238 // (Might be the load class or an initialization check).
239 HInstruction* const at_;
240
241 // The dex PC of `at_`.
242 const uint32_t dex_pc_;
243
244 // Whether to initialize the class.
245 const bool do_clinit_;
246
247 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100248};
249
Andreas Gampe85b62f22015-09-09 13:15:38 -0700250class LoadStringSlowPathARM : public SlowPathCode {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000251 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000252 explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000253
Alexandre Rames67555f72014-11-18 10:55:16 +0000254 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000255 LocationSummary* locations = instruction_->GetLocations();
256 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
257
258 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
259 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000260 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000261
262 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000263 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
264 __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100265 arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000266 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000267 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
268
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000269 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000270 __ b(GetExitLabel());
271 }
272
Alexandre Rames9931f312015-06-19 14:47:01 +0100273 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
274
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000275 private:
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000276 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
277};
278
Andreas Gampe85b62f22015-09-09 13:15:38 -0700279class TypeCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000280 public:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000281 TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal)
David Srbecky9cd6d372016-02-09 15:24:47 +0000282 : SlowPathCode(instruction), is_fatal_(is_fatal) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000283
Alexandre Rames67555f72014-11-18 10:55:16 +0000284 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100286 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
287 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 DCHECK(instruction_->IsCheckCast()
289 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000290
291 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
292 __ Bind(GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000293
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000294 if (!is_fatal_) {
295 SaveLiveRegisters(codegen, locations);
296 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000297
298 // We're moving two locations to locations that could overlap, so we need a parallel
299 // move resolver.
300 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000301 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100302 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000303 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100304 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100305 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100306 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
307 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000308
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000309 if (instruction_->IsInstanceOf()) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100310 arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100311 instruction_,
312 instruction_->GetDexPc(),
313 this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000314 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700315 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000316 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
317 } else {
318 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100319 arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000320 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000321 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000322
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000323 if (!is_fatal_) {
324 RestoreLiveRegisters(codegen, locations);
325 __ b(GetExitLabel());
326 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000327 }
328
Alexandre Rames9931f312015-06-19 14:47:01 +0100329 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
330
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000331 bool IsFatal() const OVERRIDE { return is_fatal_; }
332
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000333 private:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000334 const bool is_fatal_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000335
336 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
337};
338
Andreas Gampe85b62f22015-09-09 13:15:38 -0700339class DeoptimizationSlowPathARM : public SlowPathCode {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700340 public:
Aart Bik42249c32016-01-07 15:33:50 -0800341 explicit DeoptimizationSlowPathARM(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000342 : SlowPathCode(instruction) {}
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700343
344 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800345 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700346 __ Bind(GetEntryLabel());
347 SaveLiveRegisters(codegen, instruction_->GetLocations());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100348 arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000349 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700350 }
351
Alexandre Rames9931f312015-06-19 14:47:01 +0100352 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
353
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700354 private:
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700355 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
356};
357
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100358class ArraySetSlowPathARM : public SlowPathCode {
359 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000360 explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100361
362 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
363 LocationSummary* locations = instruction_->GetLocations();
364 __ Bind(GetEntryLabel());
365 SaveLiveRegisters(codegen, locations);
366
367 InvokeRuntimeCallingConvention calling_convention;
368 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
369 parallel_move.AddMove(
370 locations->InAt(0),
371 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
372 Primitive::kPrimNot,
373 nullptr);
374 parallel_move.AddMove(
375 locations->InAt(1),
376 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
377 Primitive::kPrimInt,
378 nullptr);
379 parallel_move.AddMove(
380 locations->InAt(2),
381 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
382 Primitive::kPrimNot,
383 nullptr);
384 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
385
386 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100387 arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000388 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100389 RestoreLiveRegisters(codegen, locations);
390 __ b(GetExitLabel());
391 }
392
393 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; }
394
395 private:
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100396 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM);
397};
398
Roland Levillainc9285912015-12-18 10:38:42 +0000399// Slow path marking an object during a read barrier.
400class ReadBarrierMarkSlowPathARM : public SlowPathCode {
401 public:
Roland Levillain02b75802016-07-13 11:54:35 +0100402 ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj)
403 : SlowPathCode(instruction), obj_(obj) {
Roland Levillainc9285912015-12-18 10:38:42 +0000404 DCHECK(kEmitCompilerReadBarrier);
405 }
406
407 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; }
408
409 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
410 LocationSummary* locations = instruction_->GetLocations();
Roland Levillain02b75802016-07-13 11:54:35 +0100411 Register reg = obj_.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +0000412 DCHECK(locations->CanCall());
Roland Levillain02b75802016-07-13 11:54:35 +0100413 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg));
Roland Levillainc9285912015-12-18 10:38:42 +0000414 DCHECK(instruction_->IsInstanceFieldGet() ||
415 instruction_->IsStaticFieldGet() ||
416 instruction_->IsArrayGet() ||
Roland Levillain16d9f942016-08-25 17:27:56 +0100417 instruction_->IsArraySet() ||
Roland Levillainc9285912015-12-18 10:38:42 +0000418 instruction_->IsLoadClass() ||
419 instruction_->IsLoadString() ||
420 instruction_->IsInstanceOf() ||
Roland Levillain3d312422016-06-23 13:53:42 +0100421 instruction_->IsCheckCast() ||
Roland Levillain0b671c02016-08-19 12:02:34 +0100422 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
423 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
Roland Levillainc9285912015-12-18 10:38:42 +0000424 << "Unexpected instruction in read barrier marking slow path: "
425 << instruction_->DebugName();
426
427 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100428 // No need to save live registers; it's taken care of by the
429 // entrypoint. Also, there is no need to update the stack mask,
430 // as this runtime call will not trigger a garbage collection.
Roland Levillainc9285912015-12-18 10:38:42 +0000431 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Roland Levillain02b75802016-07-13 11:54:35 +0100432 DCHECK_NE(reg, SP);
433 DCHECK_NE(reg, LR);
434 DCHECK_NE(reg, PC);
Roland Levillain0b671c02016-08-19 12:02:34 +0100435 // IP is used internally by the ReadBarrierMarkRegX entry point
436 // as a temporary, it cannot be the entry point's input/output.
437 DCHECK_NE(reg, IP);
Roland Levillain02b75802016-07-13 11:54:35 +0100438 DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg;
439 // "Compact" slow path, saving two moves.
440 //
441 // Instead of using the standard runtime calling convention (input
442 // and output in R0):
443 //
444 // R0 <- obj
445 // R0 <- ReadBarrierMark(R0)
446 // obj <- R0
447 //
448 // we just use rX (the register holding `obj`) as input and output
449 // of a dedicated entrypoint:
450 //
451 // rX <- ReadBarrierMarkRegX(rX)
452 //
453 int32_t entry_point_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -0700454 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg);
Roland Levillaindec8f632016-07-22 17:10:06 +0100455 // This runtime call does not require a stack map.
456 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
Roland Levillainc9285912015-12-18 10:38:42 +0000457 __ b(GetExitLabel());
458 }
459
460 private:
Roland Levillainc9285912015-12-18 10:38:42 +0000461 const Location obj_;
462
463 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM);
464};
465
Roland Levillain3b359c72015-11-17 19:35:12 +0000466// Slow path generating a read barrier for a heap reference.
467class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode {
468 public:
469 ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction,
470 Location out,
471 Location ref,
472 Location obj,
473 uint32_t offset,
474 Location index)
David Srbecky9cd6d372016-02-09 15:24:47 +0000475 : SlowPathCode(instruction),
Roland Levillain3b359c72015-11-17 19:35:12 +0000476 out_(out),
477 ref_(ref),
478 obj_(obj),
479 offset_(offset),
480 index_(index) {
481 DCHECK(kEmitCompilerReadBarrier);
482 // If `obj` is equal to `out` or `ref`, it means the initial object
483 // has been overwritten by (or after) the heap object reference load
484 // to be instrumented, e.g.:
485 //
486 // __ LoadFromOffset(kLoadWord, out, out, offset);
Roland Levillainc9285912015-12-18 10:38:42 +0000487 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
Roland Levillain3b359c72015-11-17 19:35:12 +0000488 //
489 // In that case, we have lost the information about the original
490 // object, and the emitted read barrier cannot work properly.
491 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
492 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
493 }
494
495 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
496 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
497 LocationSummary* locations = instruction_->GetLocations();
498 Register reg_out = out_.AsRegister<Register>();
499 DCHECK(locations->CanCall());
500 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillain3d312422016-06-23 13:53:42 +0100501 DCHECK(instruction_->IsInstanceFieldGet() ||
502 instruction_->IsStaticFieldGet() ||
503 instruction_->IsArrayGet() ||
504 instruction_->IsInstanceOf() ||
505 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100506 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillainc9285912015-12-18 10:38:42 +0000507 << "Unexpected instruction in read barrier for heap reference slow path: "
508 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000509
510 __ Bind(GetEntryLabel());
511 SaveLiveRegisters(codegen, locations);
512
513 // We may have to change the index's value, but as `index_` is a
514 // constant member (like other "inputs" of this slow path),
515 // introduce a copy of it, `index`.
516 Location index = index_;
517 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100518 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain3b359c72015-11-17 19:35:12 +0000519 if (instruction_->IsArrayGet()) {
520 // Compute the actual memory offset and store it in `index`.
521 Register index_reg = index_.AsRegister<Register>();
522 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
523 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
524 // We are about to change the value of `index_reg` (see the
525 // calls to art::arm::Thumb2Assembler::Lsl and
526 // art::arm::Thumb2Assembler::AddConstant below), but it has
527 // not been saved by the previous call to
528 // art::SlowPathCode::SaveLiveRegisters, as it is a
529 // callee-save register --
530 // art::SlowPathCode::SaveLiveRegisters does not consider
531 // callee-save registers, as it has been designed with the
532 // assumption that callee-save registers are supposed to be
533 // handled by the called function. So, as a callee-save
534 // register, `index_reg` _would_ eventually be saved onto
535 // the stack, but it would be too late: we would have
536 // changed its value earlier. Therefore, we manually save
537 // it here into another freely available register,
538 // `free_reg`, chosen of course among the caller-save
539 // registers (as a callee-save `free_reg` register would
540 // exhibit the same problem).
541 //
542 // Note we could have requested a temporary register from
543 // the register allocator instead; but we prefer not to, as
544 // this is a slow path, and we know we can find a
545 // caller-save register that is available.
546 Register free_reg = FindAvailableCallerSaveRegister(codegen);
547 __ Mov(free_reg, index_reg);
548 index_reg = free_reg;
549 index = Location::RegisterLocation(index_reg);
550 } else {
551 // The initial register stored in `index_` has already been
552 // saved in the call to art::SlowPathCode::SaveLiveRegisters
553 // (as it is not a callee-save register), so we can freely
554 // use it.
555 }
556 // Shifting the index value contained in `index_reg` by the scale
557 // factor (2) cannot overflow in practice, as the runtime is
558 // unable to allocate object arrays with a size larger than
559 // 2^26 - 1 (that is, 2^28 - 4 bytes).
560 __ Lsl(index_reg, index_reg, TIMES_4);
561 static_assert(
562 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
563 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
564 __ AddConstant(index_reg, index_reg, offset_);
565 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100566 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
567 // intrinsics, `index_` is not shifted by a scale factor of 2
568 // (as in the case of ArrayGet), as it is actually an offset
569 // to an object field within an object.
570 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000571 DCHECK(instruction_->GetLocations()->Intrinsified());
572 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
573 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
574 << instruction_->AsInvoke()->GetIntrinsic();
575 DCHECK_EQ(offset_, 0U);
576 DCHECK(index_.IsRegisterPair());
577 // UnsafeGet's offset location is a register pair, the low
578 // part contains the correct offset.
579 index = index_.ToLow();
580 }
581 }
582
583 // We're moving two or three locations to locations that could
584 // overlap, so we need a parallel move resolver.
585 InvokeRuntimeCallingConvention calling_convention;
586 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
587 parallel_move.AddMove(ref_,
588 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
589 Primitive::kPrimNot,
590 nullptr);
591 parallel_move.AddMove(obj_,
592 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
593 Primitive::kPrimNot,
594 nullptr);
595 if (index.IsValid()) {
596 parallel_move.AddMove(index,
597 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
598 Primitive::kPrimInt,
599 nullptr);
600 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
601 } else {
602 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
603 __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_);
604 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100605 arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000606 CheckEntrypointTypes<
607 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
608 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
609
610 RestoreLiveRegisters(codegen, locations);
611 __ b(GetExitLabel());
612 }
613
614 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; }
615
616 private:
617 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
618 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
619 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
620 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
621 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
622 return static_cast<Register>(i);
623 }
624 }
625 // We shall never fail to find a free caller-save register, as
626 // there are more than two core caller-save registers on ARM
627 // (meaning it is possible to find one which is different from
628 // `ref` and `obj`).
629 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
630 LOG(FATAL) << "Could not find a free caller-save register";
631 UNREACHABLE();
632 }
633
Roland Levillain3b359c72015-11-17 19:35:12 +0000634 const Location out_;
635 const Location ref_;
636 const Location obj_;
637 const uint32_t offset_;
638 // An additional location containing an index to an array.
639 // Only used for HArrayGet and the UnsafeGetObject &
640 // UnsafeGetObjectVolatile intrinsics.
641 const Location index_;
642
643 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM);
644};
645
646// Slow path generating a read barrier for a GC root.
647class ReadBarrierForRootSlowPathARM : public SlowPathCode {
648 public:
649 ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root)
David Srbecky9cd6d372016-02-09 15:24:47 +0000650 : SlowPathCode(instruction), out_(out), root_(root) {
Roland Levillainc9285912015-12-18 10:38:42 +0000651 DCHECK(kEmitCompilerReadBarrier);
652 }
Roland Levillain3b359c72015-11-17 19:35:12 +0000653
654 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
655 LocationSummary* locations = instruction_->GetLocations();
656 Register reg_out = out_.AsRegister<Register>();
657 DCHECK(locations->CanCall());
658 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillainc9285912015-12-18 10:38:42 +0000659 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
660 << "Unexpected instruction in read barrier for GC root slow path: "
661 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000662
663 __ Bind(GetEntryLabel());
664 SaveLiveRegisters(codegen, locations);
665
666 InvokeRuntimeCallingConvention calling_convention;
667 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
668 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100669 arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
Roland Levillain3b359c72015-11-17 19:35:12 +0000670 instruction_,
671 instruction_->GetDexPc(),
672 this);
673 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
674 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
675
676 RestoreLiveRegisters(codegen, locations);
677 __ b(GetExitLabel());
678 }
679
680 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; }
681
682 private:
Roland Levillain3b359c72015-11-17 19:35:12 +0000683 const Location out_;
684 const Location root_;
685
686 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM);
687};
688
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000689#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100690// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
691#define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT
Dave Allison20dfc792014-06-16 20:44:29 -0700692
Aart Bike9f37602015-10-09 11:15:55 -0700693inline Condition ARMCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700694 switch (cond) {
695 case kCondEQ: return EQ;
696 case kCondNE: return NE;
697 case kCondLT: return LT;
698 case kCondLE: return LE;
699 case kCondGT: return GT;
700 case kCondGE: return GE;
Aart Bike9f37602015-10-09 11:15:55 -0700701 case kCondB: return LO;
702 case kCondBE: return LS;
703 case kCondA: return HI;
704 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700705 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100706 LOG(FATAL) << "Unreachable";
707 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700708}
709
Aart Bike9f37602015-10-09 11:15:55 -0700710// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100711inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700712 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100713 case kCondEQ: return EQ;
714 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -0700715 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100716 case kCondLT: return LO;
717 case kCondLE: return LS;
718 case kCondGT: return HI;
719 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -0700720 // Unsigned remain unchanged.
721 case kCondB: return LO;
722 case kCondBE: return LS;
723 case kCondA: return HI;
724 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700725 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100726 LOG(FATAL) << "Unreachable";
727 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700728}
729
Vladimir Markod6e069b2016-01-18 11:11:01 +0000730inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) {
731 // The ARM condition codes can express all the necessary branches, see the
732 // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual.
733 // There is no dex instruction or HIR that would need the missing conditions
734 // "equal or unordered" or "not equal".
735 switch (cond) {
736 case kCondEQ: return EQ;
737 case kCondNE: return NE /* unordered */;
738 case kCondLT: return gt_bias ? CC : LT /* unordered */;
739 case kCondLE: return gt_bias ? LS : LE /* unordered */;
740 case kCondGT: return gt_bias ? HI /* unordered */ : GT;
741 case kCondGE: return gt_bias ? CS /* unordered */ : GE;
742 default:
743 LOG(FATAL) << "UNREACHABLE";
744 UNREACHABLE();
745 }
746}
747
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100748void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100749 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100750}
751
752void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100753 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100754}
755
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100756size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
757 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
758 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100759}
760
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100761size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
762 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
763 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100764}
765
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000766size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
767 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
768 return kArmWordSize;
769}
770
771size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
772 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
773 return kArmWordSize;
774}
775
Calin Juravle34166012014-12-19 17:22:29 +0000776CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000777 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100778 const CompilerOptions& compiler_options,
779 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000780 : CodeGenerator(graph,
781 kNumberOfCoreRegisters,
782 kNumberOfSRegisters,
783 kNumberOfRegisterPairs,
784 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
785 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +0000786 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
787 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100788 compiler_options,
789 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100790 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100791 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100792 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100793 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100794 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +0000795 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000796 uint32_literals_(std::less<uint32_t>(),
797 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +0100798 method_patches_(MethodReferenceComparator(),
799 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
800 call_patches_(MethodReferenceComparator(),
801 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markob4536b72015-11-24 13:45:23 +0000802 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000803 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
804 boot_image_string_patches_(StringReferenceValueComparator(),
805 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
806 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100807 boot_image_type_patches_(TypeReferenceValueComparator(),
808 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
809 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000810 boot_image_address_patches_(std::less<uint32_t>(),
811 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700812 // Always save the LR register to mimic Quick.
813 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100814}
815
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000816void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
817 // Ensure that we fix up branches and literal loads and emit the literal pool.
818 __ FinalizeCode();
819
820 // Adjust native pc offsets in stack maps.
821 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
822 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
823 uint32_t new_position = __ GetAdjustedPosition(old_position);
824 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
825 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100826 // Adjust pc offsets for the disassembly information.
827 if (disasm_info_ != nullptr) {
828 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
829 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
830 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
831 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
832 it.second.start = __ GetAdjustedPosition(it.second.start);
833 it.second.end = __ GetAdjustedPosition(it.second.end);
834 }
835 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
836 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
837 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
838 }
839 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000840
841 CodeGenerator::Finalize(allocator);
842}
843
David Brazdil58282f42016-01-14 12:45:10 +0000844void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100845 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100846 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100847
848 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100849 blocked_core_registers_[SP] = true;
850 blocked_core_registers_[LR] = true;
851 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100852
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100853 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100854 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100855
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100856 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100857 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100858
David Brazdil58282f42016-01-14 12:45:10 +0000859 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100860 // Stubs do not save callee-save floating point registers. If the graph
861 // is debuggable, we need to deal with these registers differently. For
862 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000863 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
864 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
865 }
866 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100867
868 UpdateBlockedPairRegisters();
869}
870
871void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
872 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
873 ArmManagedRegister current =
874 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
875 if (blocked_core_registers_[current.AsRegisterPairLow()]
876 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
877 blocked_register_pairs_[i] = true;
878 }
879 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100880}
881
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100882InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
Aart Bik42249c32016-01-07 15:33:50 -0800883 : InstructionCodeGenerator(graph, codegen),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100884 assembler_(codegen->GetAssembler()),
885 codegen_(codegen) {}
886
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000887void CodeGeneratorARM::ComputeSpillMask() {
888 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
889 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
David Brazdil58282f42016-01-14 12:45:10 +0000890 // There is no easy instruction to restore just the PC on thumb2. We spill and
891 // restore another arbitrary register.
892 core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000893 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
894 // We use vpush and vpop for saving and restoring floating point registers, which take
895 // a SRegister and the number of registers to save/restore after that SRegister. We
896 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
897 // but in the range.
898 if (fpu_spill_mask_ != 0) {
899 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
900 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
901 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
902 fpu_spill_mask_ |= (1 << i);
903 }
904 }
905}
906
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100907static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100908 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100909}
910
911static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100912 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100913}
914
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000915void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000916 bool skip_overflow_check =
917 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000918 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000919 __ Bind(&frame_entry_label_);
920
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000921 if (HasEmptyFrame()) {
922 return;
923 }
924
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100925 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000926 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
927 __ LoadFromOffset(kLoadWord, IP, IP, 0);
928 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100929 }
930
Andreas Gampe501fd632015-09-10 16:11:06 -0700931 __ PushList(core_spill_mask_);
932 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
933 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000934 if (fpu_spill_mask_ != 0) {
935 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
936 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100937 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100938 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000939 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100940 int adjust = GetFrameSize() - FrameEntrySpillSize();
941 __ AddConstant(SP, -adjust);
942 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100943 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000944}
945
946void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000947 if (HasEmptyFrame()) {
948 __ bx(LR);
949 return;
950 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100951 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100952 int adjust = GetFrameSize() - FrameEntrySpillSize();
953 __ AddConstant(SP, adjust);
954 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000955 if (fpu_spill_mask_ != 0) {
956 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
957 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
Andreas Gampe542451c2016-07-26 09:02:02 -0700958 __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100959 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000960 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700961 // Pop LR into PC to return.
962 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
963 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
964 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100965 __ cfi().RestoreState();
966 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000967}
968
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100969void CodeGeneratorARM::Bind(HBasicBlock* block) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700970 Label* label = GetLabelOf(block);
971 __ BindTrackedLabel(label);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000972}
973
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100974Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100975 switch (type) {
976 case Primitive::kPrimBoolean:
977 case Primitive::kPrimByte:
978 case Primitive::kPrimChar:
979 case Primitive::kPrimShort:
980 case Primitive::kPrimInt:
981 case Primitive::kPrimNot: {
982 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000983 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100984 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100985 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100986 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000987 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100988 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100989 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100990
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000991 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100992 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000993 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100994 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000995 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100996 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000997 if (calling_convention.GetRegisterAt(index) == R1) {
998 // Skip R1, and use R2_R3 instead.
999 gp_index_++;
1000 index++;
1001 }
1002 }
1003 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
1004 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001005 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +01001006
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001007 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001008 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001009 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001010 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
1011 }
1012 }
1013
1014 case Primitive::kPrimFloat: {
1015 uint32_t stack_index = stack_index_++;
1016 if (float_index_ % 2 == 0) {
1017 float_index_ = std::max(double_index_, float_index_);
1018 }
1019 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
1020 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
1021 } else {
1022 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
1023 }
1024 }
1025
1026 case Primitive::kPrimDouble: {
1027 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
1028 uint32_t stack_index = stack_index_;
1029 stack_index_ += 2;
1030 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
1031 uint32_t index = double_index_;
1032 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001033 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001034 calling_convention.GetFpuRegisterAt(index),
1035 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001036 DCHECK(ExpectedPairLayout(result));
1037 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001038 } else {
1039 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001040 }
1041 }
1042
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001043 case Primitive::kPrimVoid:
1044 LOG(FATAL) << "Unexpected parameter type " << type;
1045 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001046 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001047 return Location::NoLocation();
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001048}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001049
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001050Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001051 switch (type) {
1052 case Primitive::kPrimBoolean:
1053 case Primitive::kPrimByte:
1054 case Primitive::kPrimChar:
1055 case Primitive::kPrimShort:
1056 case Primitive::kPrimInt:
1057 case Primitive::kPrimNot: {
1058 return Location::RegisterLocation(R0);
1059 }
1060
1061 case Primitive::kPrimFloat: {
1062 return Location::FpuRegisterLocation(S0);
1063 }
1064
1065 case Primitive::kPrimLong: {
1066 return Location::RegisterPairLocation(R0, R1);
1067 }
1068
1069 case Primitive::kPrimDouble: {
1070 return Location::FpuRegisterPairLocation(S0, S1);
1071 }
1072
1073 case Primitive::kPrimVoid:
Roland Levillain3b359c72015-11-17 19:35:12 +00001074 return Location::NoLocation();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001075 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +01001076
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001077 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001078}
1079
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001080Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
1081 return Location::RegisterLocation(kMethodRegisterArgument);
1082}
1083
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001084void CodeGeneratorARM::Move32(Location destination, Location source) {
1085 if (source.Equals(destination)) {
1086 return;
1087 }
1088 if (destination.IsRegister()) {
1089 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001090 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001091 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001092 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001093 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001094 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001095 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001096 } else if (destination.IsFpuRegister()) {
1097 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001098 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001099 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001100 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001101 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001102 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001103 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001104 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001105 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001106 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001107 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001108 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001109 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001110 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001111 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001112 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1113 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001114 }
1115 }
1116}
1117
1118void CodeGeneratorARM::Move64(Location destination, Location source) {
1119 if (source.Equals(destination)) {
1120 return;
1121 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001122 if (destination.IsRegisterPair()) {
1123 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001124 EmitParallelMoves(
1125 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
1126 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001127 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001128 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001129 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
1130 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001131 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001132 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001133 } else if (source.IsFpuRegisterPair()) {
1134 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
1135 destination.AsRegisterPairHigh<Register>(),
1136 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001137 } else {
1138 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001139 DCHECK(ExpectedPairLayout(destination));
1140 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
1141 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001142 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001143 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001144 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001145 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1146 SP,
1147 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001148 } else if (source.IsRegisterPair()) {
1149 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1150 source.AsRegisterPairLow<Register>(),
1151 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001152 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001153 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001154 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001155 } else {
1156 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001157 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001158 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001159 if (source.AsRegisterPairLow<Register>() == R1) {
1160 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001161 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
1162 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001163 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001164 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001165 SP, destination.GetStackIndex());
1166 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001167 } else if (source.IsFpuRegisterPair()) {
1168 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
1169 SP,
1170 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001171 } else {
1172 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001173 EmitParallelMoves(
1174 Location::StackSlot(source.GetStackIndex()),
1175 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001176 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001177 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001178 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
1179 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001180 }
1181 }
1182}
1183
Calin Juravle175dc732015-08-25 15:42:32 +01001184void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1185 DCHECK(location.IsRegister());
1186 __ LoadImmediate(location.AsRegister<Register>(), value);
1187}
1188
Calin Juravlee460d1d2015-09-29 04:52:17 +01001189void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001190 HParallelMove move(GetGraph()->GetArena());
1191 move.AddMove(src, dst, dst_type, nullptr);
1192 GetMoveResolver()->EmitNativeCode(&move);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001193}
1194
1195void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1196 if (location.IsRegister()) {
1197 locations->AddTemp(location);
1198 } else if (location.IsRegisterPair()) {
1199 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1200 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1201 } else {
1202 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1203 }
1204}
1205
Calin Juravle175dc732015-08-25 15:42:32 +01001206void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1207 HInstruction* instruction,
1208 uint32_t dex_pc,
1209 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001210 ValidateInvokeRuntime(instruction, slow_path);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001211 GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value());
Serban Constantinescuda8ffec2016-03-09 12:02:11 +00001212 if (EntrypointRequiresStackMap(entrypoint)) {
1213 RecordPcInfo(instruction, dex_pc, slow_path);
1214 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001215}
1216
Roland Levillaindec8f632016-07-22 17:10:06 +01001217void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1218 HInstruction* instruction,
1219 SlowPathCode* slow_path) {
1220 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001221 GenerateInvokeRuntime(entry_point_offset);
1222}
1223
1224void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) {
Roland Levillaindec8f632016-07-22 17:10:06 +01001225 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1226 __ blx(LR);
1227}
1228
David Brazdilfc6a86a2015-06-26 10:33:45 +00001229void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001230 DCHECK(!successor->IsExitBlock());
1231
1232 HBasicBlock* block = got->GetBlock();
1233 HInstruction* previous = got->GetPrevious();
1234
1235 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001236 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001237 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1238 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1239 return;
1240 }
1241
1242 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1243 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1244 }
1245 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001246 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001247 }
1248}
1249
David Brazdilfc6a86a2015-06-26 10:33:45 +00001250void LocationsBuilderARM::VisitGoto(HGoto* got) {
1251 got->SetLocations(nullptr);
1252}
1253
1254void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1255 HandleGoto(got, got->GetSuccessor());
1256}
1257
1258void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1259 try_boundary->SetLocations(nullptr);
1260}
1261
1262void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1263 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1264 if (!successor->IsExitBlock()) {
1265 HandleGoto(try_boundary, successor);
1266 }
1267}
1268
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001269void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001270 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001271}
1272
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001273void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001274}
1275
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001276void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1277 Primitive::Type type = instruction->InputAt(0)->GetType();
1278 Location lhs_loc = instruction->GetLocations()->InAt(0);
1279 Location rhs_loc = instruction->GetLocations()->InAt(1);
1280 if (rhs_loc.IsConstant()) {
1281 // 0.0 is the only immediate that can be encoded directly in
1282 // a VCMP instruction.
1283 //
1284 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1285 // specify that in a floating-point comparison, positive zero
1286 // and negative zero are considered equal, so we can use the
1287 // literal 0.0 for both cases here.
1288 //
1289 // Note however that some methods (Float.equal, Float.compare,
1290 // Float.compareTo, Double.equal, Double.compare,
1291 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1292 // StrictMath.min) consider 0.0 to be (strictly) greater than
1293 // -0.0. So if we ever translate calls to these methods into a
1294 // HCompare instruction, we must handle the -0.0 case with
1295 // care here.
1296 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1297 if (type == Primitive::kPrimFloat) {
1298 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1299 } else {
1300 DCHECK_EQ(type, Primitive::kPrimDouble);
1301 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1302 }
1303 } else {
1304 if (type == Primitive::kPrimFloat) {
1305 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1306 } else {
1307 DCHECK_EQ(type, Primitive::kPrimDouble);
1308 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1309 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1310 }
1311 }
1312}
1313
Roland Levillain4fa13f62015-07-06 18:11:54 +01001314void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1315 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001316 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001317 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001318 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001319}
1320
1321void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1322 Label* true_label,
1323 Label* false_label) {
1324 LocationSummary* locations = cond->GetLocations();
1325 Location left = locations->InAt(0);
1326 Location right = locations->InAt(1);
1327 IfCondition if_cond = cond->GetCondition();
1328
1329 Register left_high = left.AsRegisterPairHigh<Register>();
1330 Register left_low = left.AsRegisterPairLow<Register>();
1331 IfCondition true_high_cond = if_cond;
1332 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001333 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001334
1335 // Set the conditions for the test, remembering that == needs to be
1336 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001337 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001338 switch (if_cond) {
1339 case kCondEQ:
1340 case kCondNE:
1341 // Nothing to do.
1342 break;
1343 case kCondLT:
1344 false_high_cond = kCondGT;
1345 break;
1346 case kCondLE:
1347 true_high_cond = kCondLT;
1348 break;
1349 case kCondGT:
1350 false_high_cond = kCondLT;
1351 break;
1352 case kCondGE:
1353 true_high_cond = kCondGT;
1354 break;
Aart Bike9f37602015-10-09 11:15:55 -07001355 case kCondB:
1356 false_high_cond = kCondA;
1357 break;
1358 case kCondBE:
1359 true_high_cond = kCondB;
1360 break;
1361 case kCondA:
1362 false_high_cond = kCondB;
1363 break;
1364 case kCondAE:
1365 true_high_cond = kCondA;
1366 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001367 }
1368 if (right.IsConstant()) {
1369 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1370 int32_t val_low = Low32Bits(value);
1371 int32_t val_high = High32Bits(value);
1372
Vladimir Markoac6ac102015-12-17 12:14:00 +00001373 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001374 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001375 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001376 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001377 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001378 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001379 __ b(true_label, ARMCondition(true_high_cond));
1380 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001381 }
1382 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001383 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001384 } else {
1385 Register right_high = right.AsRegisterPairHigh<Register>();
1386 Register right_low = right.AsRegisterPairLow<Register>();
1387
1388 __ cmp(left_high, ShifterOperand(right_high));
1389 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001390 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001391 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001392 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001393 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001394 __ b(true_label, ARMCondition(true_high_cond));
1395 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001396 }
1397 // Must be equal high, so compare the lows.
1398 __ cmp(left_low, ShifterOperand(right_low));
1399 }
1400 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001401 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001402 __ b(true_label, final_condition);
1403}
1404
David Brazdil0debae72015-11-12 18:37:00 +00001405void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1406 Label* true_target_in,
1407 Label* false_target_in) {
1408 // Generated branching requires both targets to be explicit. If either of the
1409 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1410 Label fallthrough_target;
1411 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1412 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1413
Roland Levillain4fa13f62015-07-06 18:11:54 +01001414 Primitive::Type type = condition->InputAt(0)->GetType();
1415 switch (type) {
1416 case Primitive::kPrimLong:
1417 GenerateLongComparesAndJumps(condition, true_target, false_target);
1418 break;
1419 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001420 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001421 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001422 GenerateFPJumps(condition, true_target, false_target);
1423 break;
1424 default:
1425 LOG(FATAL) << "Unexpected compare type " << type;
1426 }
1427
David Brazdil0debae72015-11-12 18:37:00 +00001428 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001429 __ b(false_target);
1430 }
David Brazdil0debae72015-11-12 18:37:00 +00001431
1432 if (fallthrough_target.IsLinked()) {
1433 __ Bind(&fallthrough_target);
1434 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001435}
1436
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001437void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001438 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001439 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001440 Label* false_target) {
1441 HInstruction* cond = instruction->InputAt(condition_input_index);
1442
1443 if (true_target == nullptr && false_target == nullptr) {
1444 // Nothing to do. The code always falls through.
1445 return;
1446 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001447 // Constant condition, statically compared against "true" (integer value 1).
1448 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001449 if (true_target != nullptr) {
1450 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001451 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001452 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001453 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001454 if (false_target != nullptr) {
1455 __ b(false_target);
1456 }
1457 }
1458 return;
1459 }
1460
1461 // The following code generates these patterns:
1462 // (1) true_target == nullptr && false_target != nullptr
1463 // - opposite condition true => branch to false_target
1464 // (2) true_target != nullptr && false_target == nullptr
1465 // - condition true => branch to true_target
1466 // (3) true_target != nullptr && false_target != nullptr
1467 // - condition true => branch to true_target
1468 // - branch to false_target
1469 if (IsBooleanValueOrMaterializedCondition(cond)) {
1470 // Condition has been materialized, compare the output to 0.
1471 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1472 DCHECK(cond_val.IsRegister());
1473 if (true_target == nullptr) {
1474 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1475 } else {
1476 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001477 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001478 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001479 // Condition has not been materialized. Use its inputs as the comparison and
1480 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001481 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001482
1483 // If this is a long or FP comparison that has been folded into
1484 // the HCondition, generate the comparison directly.
1485 Primitive::Type type = condition->InputAt(0)->GetType();
1486 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1487 GenerateCompareTestAndBranch(condition, true_target, false_target);
1488 return;
1489 }
1490
1491 LocationSummary* locations = cond->GetLocations();
1492 DCHECK(locations->InAt(0).IsRegister());
1493 Register left = locations->InAt(0).AsRegister<Register>();
1494 Location right = locations->InAt(1);
1495 if (right.IsRegister()) {
1496 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001497 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001498 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001499 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001500 }
1501 if (true_target == nullptr) {
1502 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1503 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001504 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001505 }
Dave Allison20dfc792014-06-16 20:44:29 -07001506 }
David Brazdil0debae72015-11-12 18:37:00 +00001507
1508 // If neither branch falls through (case 3), the conditional branch to `true_target`
1509 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1510 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001511 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001512 }
1513}
1514
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001515void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001516 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1517 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001518 locations->SetInAt(0, Location::RequiresRegister());
1519 }
1520}
1521
1522void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001523 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1524 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1525 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1526 nullptr : codegen_->GetLabelOf(true_successor);
1527 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1528 nullptr : codegen_->GetLabelOf(false_successor);
1529 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001530}
1531
1532void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1533 LocationSummary* locations = new (GetGraph()->GetArena())
1534 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00001535 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001536 locations->SetInAt(0, Location::RequiresRegister());
1537 }
1538}
1539
1540void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08001541 SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001542 GenerateTestAndBranch(deoptimize,
1543 /* condition_input_index */ 0,
1544 slow_path->GetEntryLabel(),
1545 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001546}
Dave Allison20dfc792014-06-16 20:44:29 -07001547
David Brazdil74eb1b22015-12-14 11:44:01 +00001548void LocationsBuilderARM::VisitSelect(HSelect* select) {
1549 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1550 if (Primitive::IsFloatingPointType(select->GetType())) {
1551 locations->SetInAt(0, Location::RequiresFpuRegister());
1552 locations->SetInAt(1, Location::RequiresFpuRegister());
1553 } else {
1554 locations->SetInAt(0, Location::RequiresRegister());
1555 locations->SetInAt(1, Location::RequiresRegister());
1556 }
1557 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1558 locations->SetInAt(2, Location::RequiresRegister());
1559 }
1560 locations->SetOut(Location::SameAsFirstInput());
1561}
1562
1563void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1564 LocationSummary* locations = select->GetLocations();
1565 Label false_target;
1566 GenerateTestAndBranch(select,
1567 /* condition_input_index */ 2,
1568 /* true_target */ nullptr,
1569 &false_target);
1570 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1571 __ Bind(&false_target);
1572}
1573
David Srbecky0cf44932015-12-09 14:09:59 +00001574void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1575 new (GetGraph()->GetArena()) LocationSummary(info);
1576}
1577
David Srbeckyd28f4a02016-03-14 17:14:24 +00001578void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1579 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001580}
1581
1582void CodeGeneratorARM::GenerateNop() {
1583 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001584}
1585
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001586void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001587 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001588 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001589 // Handle the long/FP comparisons made in instruction simplification.
1590 switch (cond->InputAt(0)->GetType()) {
1591 case Primitive::kPrimLong:
1592 locations->SetInAt(0, Location::RequiresRegister());
1593 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001594 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001595 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1596 }
1597 break;
1598
1599 case Primitive::kPrimFloat:
1600 case Primitive::kPrimDouble:
1601 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001602 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001603 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001604 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1605 }
1606 break;
1607
1608 default:
1609 locations->SetInAt(0, Location::RequiresRegister());
1610 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001611 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001612 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1613 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001614 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001615}
1616
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001617void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001618 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001619 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001620 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001621
1622 LocationSummary* locations = cond->GetLocations();
1623 Location left = locations->InAt(0);
1624 Location right = locations->InAt(1);
1625 Register out = locations->Out().AsRegister<Register>();
1626 Label true_label, false_label;
1627
1628 switch (cond->InputAt(0)->GetType()) {
1629 default: {
1630 // Integer case.
1631 if (right.IsRegister()) {
1632 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1633 } else {
1634 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001635 __ CmpConstant(left.AsRegister<Register>(),
1636 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001637 }
Aart Bike9f37602015-10-09 11:15:55 -07001638 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001639 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001640 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001641 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001642 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001643 return;
1644 }
1645 case Primitive::kPrimLong:
1646 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1647 break;
1648 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001649 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001650 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001651 GenerateFPJumps(cond, &true_label, &false_label);
1652 break;
1653 }
1654
1655 // Convert the jumps into the result.
1656 Label done_label;
1657
1658 // False case: result = 0.
1659 __ Bind(&false_label);
1660 __ LoadImmediate(out, 0);
1661 __ b(&done_label);
1662
1663 // True case: result = 1.
1664 __ Bind(&true_label);
1665 __ LoadImmediate(out, 1);
1666 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001667}
1668
1669void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001670 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001671}
1672
1673void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001674 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001675}
1676
1677void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001678 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001679}
1680
1681void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001682 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001683}
1684
1685void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001686 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001687}
1688
1689void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001690 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001691}
1692
1693void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001694 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001695}
1696
1697void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001698 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001699}
1700
1701void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001702 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001703}
1704
1705void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001706 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001707}
1708
1709void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001710 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001711}
1712
1713void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001714 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001715}
1716
Aart Bike9f37602015-10-09 11:15:55 -07001717void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001718 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001719}
1720
1721void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001722 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001723}
1724
1725void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001726 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001727}
1728
1729void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001730 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001731}
1732
1733void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001734 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001735}
1736
1737void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001738 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001739}
1740
1741void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001742 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001743}
1744
1745void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001746 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001747}
1748
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001749void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001750 LocationSummary* locations =
1751 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001752 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001753}
1754
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001755void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001756 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001757}
1758
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001759void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1760 LocationSummary* locations =
1761 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1762 locations->SetOut(Location::ConstantLocation(constant));
1763}
1764
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001765void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001766 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001767}
1768
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001769void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001770 LocationSummary* locations =
1771 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001772 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001773}
1774
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001775void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001776 // Will be generated at use site.
1777}
1778
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001779void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1780 LocationSummary* locations =
1781 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1782 locations->SetOut(Location::ConstantLocation(constant));
1783}
1784
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001785void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001786 // Will be generated at use site.
1787}
1788
1789void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1790 LocationSummary* locations =
1791 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1792 locations->SetOut(Location::ConstantLocation(constant));
1793}
1794
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001795void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001796 // Will be generated at use site.
1797}
1798
Calin Juravle27df7582015-04-17 19:12:31 +01001799void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1800 memory_barrier->SetLocations(nullptr);
1801}
1802
1803void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00001804 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01001805}
1806
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001807void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001808 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001809}
1810
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001811void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001812 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001813}
1814
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001815void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001816 LocationSummary* locations =
1817 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001818 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001819}
1820
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001821void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001822 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001823}
1824
Calin Juravle175dc732015-08-25 15:42:32 +01001825void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1826 // The trampoline uses the same calling convention as dex calling conventions,
1827 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1828 // the method_idx.
1829 HandleInvoke(invoke);
1830}
1831
1832void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1833 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1834}
1835
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001836void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001837 // Explicit clinit checks triggered by static invokes must have been pruned by
1838 // art::PrepareForRegisterAllocation.
1839 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001840
Vladimir Marko68c981f2016-08-26 13:13:33 +01001841 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001842 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00001843 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
1844 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
1845 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001846 return;
1847 }
1848
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001849 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00001850
1851 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
1852 if (invoke->HasPcRelativeDexCache()) {
1853 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
1854 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001855}
1856
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001857static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1858 if (invoke->GetLocations()->Intrinsified()) {
1859 IntrinsicCodeGeneratorARM intrinsic(codegen);
1860 intrinsic.Dispatch(invoke);
1861 return true;
1862 }
1863 return false;
1864}
1865
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001866void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001867 // Explicit clinit checks triggered by static invokes must have been pruned by
1868 // art::PrepareForRegisterAllocation.
1869 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001870
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001871 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1872 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001873 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001874
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001875 LocationSummary* locations = invoke->GetLocations();
1876 codegen_->GenerateStaticOrDirectCall(
1877 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001878 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001879}
1880
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001881void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001882 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001883 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001884}
1885
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001886void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Vladimir Marko68c981f2016-08-26 13:13:33 +01001887 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001888 if (intrinsic.TryDispatch(invoke)) {
1889 return;
1890 }
1891
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001892 HandleInvoke(invoke);
1893}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001894
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001895void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001896 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1897 return;
1898 }
1899
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001900 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001901 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001902 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001903}
1904
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001905void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1906 HandleInvoke(invoke);
1907 // Add the hidden argument.
1908 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1909}
1910
1911void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1912 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00001913 LocationSummary* locations = invoke->GetLocations();
1914 Register temp = locations->GetTemp(0).AsRegister<Register>();
1915 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001916 Location receiver = locations->InAt(0);
1917 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1918
Roland Levillain3b359c72015-11-17 19:35:12 +00001919 // Set the hidden argument. This is safe to do this here, as R12
1920 // won't be modified thereafter, before the `blx` (call) instruction.
1921 DCHECK_EQ(R12, hidden_reg);
1922 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001923
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001924 if (receiver.IsStackSlot()) {
1925 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00001926 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001927 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1928 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00001929 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00001930 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001931 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001932 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00001933 // Instead of simply (possibly) unpoisoning `temp` here, we should
1934 // emit a read barrier for the previous class reference load.
1935 // However this is not required in practice, as this is an
1936 // intermediate/temporary reference and because the current
1937 // concurrent copying collector keeps the from-space memory
1938 // intact/accessible until the end of the marking phase (the
1939 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01001940 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001941 __ LoadFromOffset(kLoadWord, temp, temp,
1942 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
1943 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00001944 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001945 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001946 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00001947 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07001948 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001949 // LR = temp->GetEntryPoint();
1950 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1951 // LR();
1952 __ blx(LR);
1953 DCHECK(!codegen_->IsLeafMethod());
1954 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1955}
1956
Roland Levillain88cb1752014-10-20 16:36:47 +01001957void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1958 LocationSummary* locations =
1959 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1960 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001961 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001962 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001963 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1964 break;
1965 }
1966 case Primitive::kPrimLong: {
1967 locations->SetInAt(0, Location::RequiresRegister());
1968 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001969 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001970 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001971
Roland Levillain88cb1752014-10-20 16:36:47 +01001972 case Primitive::kPrimFloat:
1973 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001974 locations->SetInAt(0, Location::RequiresFpuRegister());
1975 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001976 break;
1977
1978 default:
1979 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1980 }
1981}
1982
1983void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1984 LocationSummary* locations = neg->GetLocations();
1985 Location out = locations->Out();
1986 Location in = locations->InAt(0);
1987 switch (neg->GetResultType()) {
1988 case Primitive::kPrimInt:
1989 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001990 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001991 break;
1992
1993 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001994 DCHECK(in.IsRegisterPair());
1995 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1996 __ rsbs(out.AsRegisterPairLow<Register>(),
1997 in.AsRegisterPairLow<Register>(),
1998 ShifterOperand(0));
1999 // We cannot emit an RSC (Reverse Subtract with Carry)
2000 // instruction here, as it does not exist in the Thumb-2
2001 // instruction set. We use the following approach
2002 // using SBC and SUB instead.
2003 //
2004 // out.hi = -C
2005 __ sbc(out.AsRegisterPairHigh<Register>(),
2006 out.AsRegisterPairHigh<Register>(),
2007 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2008 // out.hi = out.hi - in.hi
2009 __ sub(out.AsRegisterPairHigh<Register>(),
2010 out.AsRegisterPairHigh<Register>(),
2011 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2012 break;
2013
Roland Levillain88cb1752014-10-20 16:36:47 +01002014 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002015 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002016 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002017 break;
2018
Roland Levillain88cb1752014-10-20 16:36:47 +01002019 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002020 DCHECK(in.IsFpuRegisterPair());
2021 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2022 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002023 break;
2024
2025 default:
2026 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2027 }
2028}
2029
Roland Levillaindff1f282014-11-05 14:15:05 +00002030void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002031 Primitive::Type result_type = conversion->GetResultType();
2032 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002033 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002034
Roland Levillain5b3ee562015-04-14 16:02:41 +01002035 // The float-to-long, double-to-long and long-to-float type conversions
2036 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002037 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002038 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2039 && result_type == Primitive::kPrimLong)
2040 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002041 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002042 : LocationSummary::kNoCall;
2043 LocationSummary* locations =
2044 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2045
David Brazdilb2bd1c52015-03-25 11:17:37 +00002046 // The Java language does not allow treating boolean as an integral type but
2047 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002048
Roland Levillaindff1f282014-11-05 14:15:05 +00002049 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002050 case Primitive::kPrimByte:
2051 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002052 case Primitive::kPrimLong:
2053 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002054 case Primitive::kPrimBoolean:
2055 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002056 case Primitive::kPrimShort:
2057 case Primitive::kPrimInt:
2058 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002059 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002060 locations->SetInAt(0, Location::RequiresRegister());
2061 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2062 break;
2063
2064 default:
2065 LOG(FATAL) << "Unexpected type conversion from " << input_type
2066 << " to " << result_type;
2067 }
2068 break;
2069
Roland Levillain01a8d712014-11-14 16:27:39 +00002070 case Primitive::kPrimShort:
2071 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002072 case Primitive::kPrimLong:
2073 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002074 case Primitive::kPrimBoolean:
2075 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002076 case Primitive::kPrimByte:
2077 case Primitive::kPrimInt:
2078 case Primitive::kPrimChar:
2079 // Processing a Dex `int-to-short' instruction.
2080 locations->SetInAt(0, Location::RequiresRegister());
2081 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2082 break;
2083
2084 default:
2085 LOG(FATAL) << "Unexpected type conversion from " << input_type
2086 << " to " << result_type;
2087 }
2088 break;
2089
Roland Levillain946e1432014-11-11 17:35:19 +00002090 case Primitive::kPrimInt:
2091 switch (input_type) {
2092 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002093 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002094 locations->SetInAt(0, Location::Any());
2095 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2096 break;
2097
2098 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002099 // Processing a Dex `float-to-int' instruction.
2100 locations->SetInAt(0, Location::RequiresFpuRegister());
2101 locations->SetOut(Location::RequiresRegister());
2102 locations->AddTemp(Location::RequiresFpuRegister());
2103 break;
2104
Roland Levillain946e1432014-11-11 17:35:19 +00002105 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002106 // Processing a Dex `double-to-int' instruction.
2107 locations->SetInAt(0, Location::RequiresFpuRegister());
2108 locations->SetOut(Location::RequiresRegister());
2109 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002110 break;
2111
2112 default:
2113 LOG(FATAL) << "Unexpected type conversion from " << input_type
2114 << " to " << result_type;
2115 }
2116 break;
2117
Roland Levillaindff1f282014-11-05 14:15:05 +00002118 case Primitive::kPrimLong:
2119 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002120 case Primitive::kPrimBoolean:
2121 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002122 case Primitive::kPrimByte:
2123 case Primitive::kPrimShort:
2124 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002125 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002126 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002127 locations->SetInAt(0, Location::RequiresRegister());
2128 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2129 break;
2130
Roland Levillain624279f2014-12-04 11:54:28 +00002131 case Primitive::kPrimFloat: {
2132 // Processing a Dex `float-to-long' instruction.
2133 InvokeRuntimeCallingConvention calling_convention;
2134 locations->SetInAt(0, Location::FpuRegisterLocation(
2135 calling_convention.GetFpuRegisterAt(0)));
2136 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2137 break;
2138 }
2139
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002140 case Primitive::kPrimDouble: {
2141 // Processing a Dex `double-to-long' instruction.
2142 InvokeRuntimeCallingConvention calling_convention;
2143 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2144 calling_convention.GetFpuRegisterAt(0),
2145 calling_convention.GetFpuRegisterAt(1)));
2146 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002147 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002148 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002149
2150 default:
2151 LOG(FATAL) << "Unexpected type conversion from " << input_type
2152 << " to " << result_type;
2153 }
2154 break;
2155
Roland Levillain981e4542014-11-14 11:47:14 +00002156 case Primitive::kPrimChar:
2157 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002158 case Primitive::kPrimLong:
2159 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002160 case Primitive::kPrimBoolean:
2161 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002162 case Primitive::kPrimByte:
2163 case Primitive::kPrimShort:
2164 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002165 // Processing a Dex `int-to-char' instruction.
2166 locations->SetInAt(0, Location::RequiresRegister());
2167 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2168 break;
2169
2170 default:
2171 LOG(FATAL) << "Unexpected type conversion from " << input_type
2172 << " to " << result_type;
2173 }
2174 break;
2175
Roland Levillaindff1f282014-11-05 14:15:05 +00002176 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002177 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002178 case Primitive::kPrimBoolean:
2179 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002180 case Primitive::kPrimByte:
2181 case Primitive::kPrimShort:
2182 case Primitive::kPrimInt:
2183 case Primitive::kPrimChar:
2184 // Processing a Dex `int-to-float' instruction.
2185 locations->SetInAt(0, Location::RequiresRegister());
2186 locations->SetOut(Location::RequiresFpuRegister());
2187 break;
2188
Roland Levillain5b3ee562015-04-14 16:02:41 +01002189 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002190 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002191 InvokeRuntimeCallingConvention calling_convention;
2192 locations->SetInAt(0, Location::RegisterPairLocation(
2193 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2194 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002195 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002196 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002197
Roland Levillaincff13742014-11-17 14:32:17 +00002198 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002199 // Processing a Dex `double-to-float' instruction.
2200 locations->SetInAt(0, Location::RequiresFpuRegister());
2201 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002202 break;
2203
2204 default:
2205 LOG(FATAL) << "Unexpected type conversion from " << input_type
2206 << " to " << result_type;
2207 };
2208 break;
2209
Roland Levillaindff1f282014-11-05 14:15:05 +00002210 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002211 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002212 case Primitive::kPrimBoolean:
2213 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002214 case Primitive::kPrimByte:
2215 case Primitive::kPrimShort:
2216 case Primitive::kPrimInt:
2217 case Primitive::kPrimChar:
2218 // Processing a Dex `int-to-double' instruction.
2219 locations->SetInAt(0, Location::RequiresRegister());
2220 locations->SetOut(Location::RequiresFpuRegister());
2221 break;
2222
2223 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002224 // Processing a Dex `long-to-double' instruction.
2225 locations->SetInAt(0, Location::RequiresRegister());
2226 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002227 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002228 locations->AddTemp(Location::RequiresFpuRegister());
2229 break;
2230
Roland Levillaincff13742014-11-17 14:32:17 +00002231 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002232 // Processing a Dex `float-to-double' instruction.
2233 locations->SetInAt(0, Location::RequiresFpuRegister());
2234 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002235 break;
2236
2237 default:
2238 LOG(FATAL) << "Unexpected type conversion from " << input_type
2239 << " to " << result_type;
2240 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002241 break;
2242
2243 default:
2244 LOG(FATAL) << "Unexpected type conversion from " << input_type
2245 << " to " << result_type;
2246 }
2247}
2248
2249void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2250 LocationSummary* locations = conversion->GetLocations();
2251 Location out = locations->Out();
2252 Location in = locations->InAt(0);
2253 Primitive::Type result_type = conversion->GetResultType();
2254 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002255 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002256 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002257 case Primitive::kPrimByte:
2258 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002259 case Primitive::kPrimLong:
2260 // Type conversion from long to byte is a result of code transformations.
2261 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2262 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002263 case Primitive::kPrimBoolean:
2264 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002265 case Primitive::kPrimShort:
2266 case Primitive::kPrimInt:
2267 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002268 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002269 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002270 break;
2271
2272 default:
2273 LOG(FATAL) << "Unexpected type conversion from " << input_type
2274 << " to " << result_type;
2275 }
2276 break;
2277
Roland Levillain01a8d712014-11-14 16:27:39 +00002278 case Primitive::kPrimShort:
2279 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002280 case Primitive::kPrimLong:
2281 // Type conversion from long to short is a result of code transformations.
2282 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2283 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002284 case Primitive::kPrimBoolean:
2285 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002286 case Primitive::kPrimByte:
2287 case Primitive::kPrimInt:
2288 case Primitive::kPrimChar:
2289 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002290 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002291 break;
2292
2293 default:
2294 LOG(FATAL) << "Unexpected type conversion from " << input_type
2295 << " to " << result_type;
2296 }
2297 break;
2298
Roland Levillain946e1432014-11-11 17:35:19 +00002299 case Primitive::kPrimInt:
2300 switch (input_type) {
2301 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002302 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002303 DCHECK(out.IsRegister());
2304 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002305 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002306 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002307 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002308 } else {
2309 DCHECK(in.IsConstant());
2310 DCHECK(in.GetConstant()->IsLongConstant());
2311 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002312 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002313 }
2314 break;
2315
Roland Levillain3f8f9362014-12-02 17:45:01 +00002316 case Primitive::kPrimFloat: {
2317 // Processing a Dex `float-to-int' instruction.
2318 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002319 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002320 __ vmovrs(out.AsRegister<Register>(), temp);
2321 break;
2322 }
2323
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002324 case Primitive::kPrimDouble: {
2325 // Processing a Dex `double-to-int' instruction.
2326 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002327 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002328 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002329 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002330 }
Roland Levillain946e1432014-11-11 17:35:19 +00002331
2332 default:
2333 LOG(FATAL) << "Unexpected type conversion from " << input_type
2334 << " to " << result_type;
2335 }
2336 break;
2337
Roland Levillaindff1f282014-11-05 14:15:05 +00002338 case Primitive::kPrimLong:
2339 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002340 case Primitive::kPrimBoolean:
2341 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002342 case Primitive::kPrimByte:
2343 case Primitive::kPrimShort:
2344 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002345 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002346 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002347 DCHECK(out.IsRegisterPair());
2348 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002349 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002350 // Sign extension.
2351 __ Asr(out.AsRegisterPairHigh<Register>(),
2352 out.AsRegisterPairLow<Register>(),
2353 31);
2354 break;
2355
2356 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002357 // Processing a Dex `float-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002358 codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002359 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002360 break;
2361
Roland Levillaindff1f282014-11-05 14:15:05 +00002362 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002363 // Processing a Dex `double-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002364 codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002365 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002366 break;
2367
2368 default:
2369 LOG(FATAL) << "Unexpected type conversion from " << input_type
2370 << " to " << result_type;
2371 }
2372 break;
2373
Roland Levillain981e4542014-11-14 11:47:14 +00002374 case Primitive::kPrimChar:
2375 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002376 case Primitive::kPrimLong:
2377 // Type conversion from long to char is a result of code transformations.
2378 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2379 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002380 case Primitive::kPrimBoolean:
2381 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002382 case Primitive::kPrimByte:
2383 case Primitive::kPrimShort:
2384 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002385 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002386 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002387 break;
2388
2389 default:
2390 LOG(FATAL) << "Unexpected type conversion from " << input_type
2391 << " to " << result_type;
2392 }
2393 break;
2394
Roland Levillaindff1f282014-11-05 14:15:05 +00002395 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002396 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002397 case Primitive::kPrimBoolean:
2398 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002399 case Primitive::kPrimByte:
2400 case Primitive::kPrimShort:
2401 case Primitive::kPrimInt:
2402 case Primitive::kPrimChar: {
2403 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002404 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2405 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002406 break;
2407 }
2408
Roland Levillain5b3ee562015-04-14 16:02:41 +01002409 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002410 // Processing a Dex `long-to-float' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002411 codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002412 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002413 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002414
Roland Levillaincff13742014-11-17 14:32:17 +00002415 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002416 // Processing a Dex `double-to-float' instruction.
2417 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2418 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002419 break;
2420
2421 default:
2422 LOG(FATAL) << "Unexpected type conversion from " << input_type
2423 << " to " << result_type;
2424 };
2425 break;
2426
Roland Levillaindff1f282014-11-05 14:15:05 +00002427 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002428 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002429 case Primitive::kPrimBoolean:
2430 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002431 case Primitive::kPrimByte:
2432 case Primitive::kPrimShort:
2433 case Primitive::kPrimInt:
2434 case Primitive::kPrimChar: {
2435 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002436 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002437 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2438 out.AsFpuRegisterPairLow<SRegister>());
2439 break;
2440 }
2441
Roland Levillain647b9ed2014-11-27 12:06:00 +00002442 case Primitive::kPrimLong: {
2443 // Processing a Dex `long-to-double' instruction.
2444 Register low = in.AsRegisterPairLow<Register>();
2445 Register high = in.AsRegisterPairHigh<Register>();
2446 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2447 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002448 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002449 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002450 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2451 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002452
Roland Levillain682393c2015-04-14 15:57:52 +01002453 // temp_d = int-to-double(high)
2454 __ vmovsr(temp_s, high);
2455 __ vcvtdi(temp_d, temp_s);
2456 // constant_d = k2Pow32EncodingForDouble
2457 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2458 // out_d = unsigned-to-double(low)
2459 __ vmovsr(out_s, low);
2460 __ vcvtdu(out_d, out_s);
2461 // out_d += temp_d * constant_d
2462 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002463 break;
2464 }
2465
Roland Levillaincff13742014-11-17 14:32:17 +00002466 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002467 // Processing a Dex `float-to-double' instruction.
2468 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2469 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002470 break;
2471
2472 default:
2473 LOG(FATAL) << "Unexpected type conversion from " << input_type
2474 << " to " << result_type;
2475 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002476 break;
2477
2478 default:
2479 LOG(FATAL) << "Unexpected type conversion from " << input_type
2480 << " to " << result_type;
2481 }
2482}
2483
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002484void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002485 LocationSummary* locations =
2486 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002487 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002488 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002489 locations->SetInAt(0, Location::RequiresRegister());
2490 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002491 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2492 break;
2493 }
2494
2495 case Primitive::kPrimLong: {
2496 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002497 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002498 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002499 break;
2500 }
2501
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002502 case Primitive::kPrimFloat:
2503 case Primitive::kPrimDouble: {
2504 locations->SetInAt(0, Location::RequiresFpuRegister());
2505 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002506 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002507 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002508 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002509
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002510 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002511 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002512 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002513}
2514
2515void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2516 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002517 Location out = locations->Out();
2518 Location first = locations->InAt(0);
2519 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002520 switch (add->GetResultType()) {
2521 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002522 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002523 __ add(out.AsRegister<Register>(),
2524 first.AsRegister<Register>(),
2525 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002526 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002527 __ AddConstant(out.AsRegister<Register>(),
2528 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002529 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002530 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002531 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002532
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002533 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002534 if (second.IsConstant()) {
2535 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2536 GenerateAddLongConst(out, first, value);
2537 } else {
2538 DCHECK(second.IsRegisterPair());
2539 __ adds(out.AsRegisterPairLow<Register>(),
2540 first.AsRegisterPairLow<Register>(),
2541 ShifterOperand(second.AsRegisterPairLow<Register>()));
2542 __ adc(out.AsRegisterPairHigh<Register>(),
2543 first.AsRegisterPairHigh<Register>(),
2544 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2545 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002546 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002547 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002548
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002549 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002550 __ vadds(out.AsFpuRegister<SRegister>(),
2551 first.AsFpuRegister<SRegister>(),
2552 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002553 break;
2554
2555 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002556 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2557 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2558 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002559 break;
2560
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002561 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002562 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002563 }
2564}
2565
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002566void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002567 LocationSummary* locations =
2568 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002569 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002570 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002571 locations->SetInAt(0, Location::RequiresRegister());
2572 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002573 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2574 break;
2575 }
2576
2577 case Primitive::kPrimLong: {
2578 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002579 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002580 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002581 break;
2582 }
Calin Juravle11351682014-10-23 15:38:15 +01002583 case Primitive::kPrimFloat:
2584 case Primitive::kPrimDouble: {
2585 locations->SetInAt(0, Location::RequiresFpuRegister());
2586 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002587 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002588 break;
Calin Juravle11351682014-10-23 15:38:15 +01002589 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002590 default:
Calin Juravle11351682014-10-23 15:38:15 +01002591 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002592 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002593}
2594
2595void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2596 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002597 Location out = locations->Out();
2598 Location first = locations->InAt(0);
2599 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002600 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002601 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002602 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002603 __ sub(out.AsRegister<Register>(),
2604 first.AsRegister<Register>(),
2605 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002606 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002607 __ AddConstant(out.AsRegister<Register>(),
2608 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002609 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002610 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002611 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002612 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002613
Calin Juravle11351682014-10-23 15:38:15 +01002614 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002615 if (second.IsConstant()) {
2616 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2617 GenerateAddLongConst(out, first, -value);
2618 } else {
2619 DCHECK(second.IsRegisterPair());
2620 __ subs(out.AsRegisterPairLow<Register>(),
2621 first.AsRegisterPairLow<Register>(),
2622 ShifterOperand(second.AsRegisterPairLow<Register>()));
2623 __ sbc(out.AsRegisterPairHigh<Register>(),
2624 first.AsRegisterPairHigh<Register>(),
2625 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2626 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002627 break;
Calin Juravle11351682014-10-23 15:38:15 +01002628 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002629
Calin Juravle11351682014-10-23 15:38:15 +01002630 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002631 __ vsubs(out.AsFpuRegister<SRegister>(),
2632 first.AsFpuRegister<SRegister>(),
2633 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002634 break;
Calin Juravle11351682014-10-23 15:38:15 +01002635 }
2636
2637 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002638 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2639 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2640 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002641 break;
2642 }
2643
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002644
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002645 default:
Calin Juravle11351682014-10-23 15:38:15 +01002646 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002647 }
2648}
2649
Calin Juravle34bacdf2014-10-07 20:23:36 +01002650void LocationsBuilderARM::VisitMul(HMul* mul) {
2651 LocationSummary* locations =
2652 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2653 switch (mul->GetResultType()) {
2654 case Primitive::kPrimInt:
2655 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002656 locations->SetInAt(0, Location::RequiresRegister());
2657 locations->SetInAt(1, Location::RequiresRegister());
2658 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002659 break;
2660 }
2661
Calin Juravleb5bfa962014-10-21 18:02:24 +01002662 case Primitive::kPrimFloat:
2663 case Primitive::kPrimDouble: {
2664 locations->SetInAt(0, Location::RequiresFpuRegister());
2665 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002666 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002667 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002668 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002669
2670 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002671 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002672 }
2673}
2674
2675void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2676 LocationSummary* locations = mul->GetLocations();
2677 Location out = locations->Out();
2678 Location first = locations->InAt(0);
2679 Location second = locations->InAt(1);
2680 switch (mul->GetResultType()) {
2681 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002682 __ mul(out.AsRegister<Register>(),
2683 first.AsRegister<Register>(),
2684 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002685 break;
2686 }
2687 case Primitive::kPrimLong: {
2688 Register out_hi = out.AsRegisterPairHigh<Register>();
2689 Register out_lo = out.AsRegisterPairLow<Register>();
2690 Register in1_hi = first.AsRegisterPairHigh<Register>();
2691 Register in1_lo = first.AsRegisterPairLow<Register>();
2692 Register in2_hi = second.AsRegisterPairHigh<Register>();
2693 Register in2_lo = second.AsRegisterPairLow<Register>();
2694
2695 // Extra checks to protect caused by the existence of R1_R2.
2696 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2697 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2698 DCHECK_NE(out_hi, in1_lo);
2699 DCHECK_NE(out_hi, in2_lo);
2700
2701 // input: in1 - 64 bits, in2 - 64 bits
2702 // output: out
2703 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2704 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2705 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2706
2707 // IP <- in1.lo * in2.hi
2708 __ mul(IP, in1_lo, in2_hi);
2709 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2710 __ mla(out_hi, in1_hi, in2_lo, IP);
2711 // out.lo <- (in1.lo * in2.lo)[31:0];
2712 __ umull(out_lo, IP, in1_lo, in2_lo);
2713 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2714 __ add(out_hi, out_hi, ShifterOperand(IP));
2715 break;
2716 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002717
2718 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002719 __ vmuls(out.AsFpuRegister<SRegister>(),
2720 first.AsFpuRegister<SRegister>(),
2721 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002722 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002723 }
2724
2725 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002726 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2727 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2728 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002729 break;
2730 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002731
2732 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002733 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002734 }
2735}
2736
Zheng Xuc6667102015-05-15 16:08:45 +08002737void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2738 DCHECK(instruction->IsDiv() || instruction->IsRem());
2739 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2740
2741 LocationSummary* locations = instruction->GetLocations();
2742 Location second = locations->InAt(1);
2743 DCHECK(second.IsConstant());
2744
2745 Register out = locations->Out().AsRegister<Register>();
2746 Register dividend = locations->InAt(0).AsRegister<Register>();
2747 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2748 DCHECK(imm == 1 || imm == -1);
2749
2750 if (instruction->IsRem()) {
2751 __ LoadImmediate(out, 0);
2752 } else {
2753 if (imm == 1) {
2754 __ Mov(out, dividend);
2755 } else {
2756 __ rsb(out, dividend, ShifterOperand(0));
2757 }
2758 }
2759}
2760
2761void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2762 DCHECK(instruction->IsDiv() || instruction->IsRem());
2763 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2764
2765 LocationSummary* locations = instruction->GetLocations();
2766 Location second = locations->InAt(1);
2767 DCHECK(second.IsConstant());
2768
2769 Register out = locations->Out().AsRegister<Register>();
2770 Register dividend = locations->InAt(0).AsRegister<Register>();
2771 Register temp = locations->GetTemp(0).AsRegister<Register>();
2772 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002773 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002774 int ctz_imm = CTZ(abs_imm);
2775
2776 if (ctz_imm == 1) {
2777 __ Lsr(temp, dividend, 32 - ctz_imm);
2778 } else {
2779 __ Asr(temp, dividend, 31);
2780 __ Lsr(temp, temp, 32 - ctz_imm);
2781 }
2782 __ add(out, temp, ShifterOperand(dividend));
2783
2784 if (instruction->IsDiv()) {
2785 __ Asr(out, out, ctz_imm);
2786 if (imm < 0) {
2787 __ rsb(out, out, ShifterOperand(0));
2788 }
2789 } else {
2790 __ ubfx(out, out, 0, ctz_imm);
2791 __ sub(out, out, ShifterOperand(temp));
2792 }
2793}
2794
2795void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2796 DCHECK(instruction->IsDiv() || instruction->IsRem());
2797 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2798
2799 LocationSummary* locations = instruction->GetLocations();
2800 Location second = locations->InAt(1);
2801 DCHECK(second.IsConstant());
2802
2803 Register out = locations->Out().AsRegister<Register>();
2804 Register dividend = locations->InAt(0).AsRegister<Register>();
2805 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2806 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2807 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2808
2809 int64_t magic;
2810 int shift;
2811 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2812
2813 __ LoadImmediate(temp1, magic);
2814 __ smull(temp2, temp1, dividend, temp1);
2815
2816 if (imm > 0 && magic < 0) {
2817 __ add(temp1, temp1, ShifterOperand(dividend));
2818 } else if (imm < 0 && magic > 0) {
2819 __ sub(temp1, temp1, ShifterOperand(dividend));
2820 }
2821
2822 if (shift != 0) {
2823 __ Asr(temp1, temp1, shift);
2824 }
2825
2826 if (instruction->IsDiv()) {
2827 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2828 } else {
2829 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2830 // TODO: Strength reduction for mls.
2831 __ LoadImmediate(temp2, imm);
2832 __ mls(out, temp1, temp2, dividend);
2833 }
2834}
2835
2836void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2837 DCHECK(instruction->IsDiv() || instruction->IsRem());
2838 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2839
2840 LocationSummary* locations = instruction->GetLocations();
2841 Location second = locations->InAt(1);
2842 DCHECK(second.IsConstant());
2843
2844 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2845 if (imm == 0) {
2846 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2847 } else if (imm == 1 || imm == -1) {
2848 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002849 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002850 DivRemByPowerOfTwo(instruction);
2851 } else {
2852 DCHECK(imm <= -2 || imm >= 2);
2853 GenerateDivRemWithAnyConstant(instruction);
2854 }
2855}
2856
Calin Juravle7c4954d2014-10-28 16:57:40 +00002857void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002858 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2859 if (div->GetResultType() == Primitive::kPrimLong) {
2860 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002861 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002862 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2863 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002864 } else if (div->GetResultType() == Primitive::kPrimInt &&
2865 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2866 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002867 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002868 }
2869
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002870 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2871
Calin Juravle7c4954d2014-10-28 16:57:40 +00002872 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002873 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002874 if (div->InputAt(1)->IsConstant()) {
2875 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00002876 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08002877 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002878 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
2879 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08002880 // No temp register required.
2881 } else {
2882 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002883 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002884 locations->AddTemp(Location::RequiresRegister());
2885 }
2886 }
2887 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002888 locations->SetInAt(0, Location::RequiresRegister());
2889 locations->SetInAt(1, Location::RequiresRegister());
2890 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2891 } else {
2892 InvokeRuntimeCallingConvention calling_convention;
2893 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2894 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2895 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2896 // we only need the former.
2897 locations->SetOut(Location::RegisterLocation(R0));
2898 }
Calin Juravled0d48522014-11-04 16:40:20 +00002899 break;
2900 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002901 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002902 InvokeRuntimeCallingConvention calling_convention;
2903 locations->SetInAt(0, Location::RegisterPairLocation(
2904 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2905 locations->SetInAt(1, Location::RegisterPairLocation(
2906 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002907 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002908 break;
2909 }
2910 case Primitive::kPrimFloat:
2911 case Primitive::kPrimDouble: {
2912 locations->SetInAt(0, Location::RequiresFpuRegister());
2913 locations->SetInAt(1, Location::RequiresFpuRegister());
2914 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2915 break;
2916 }
2917
2918 default:
2919 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2920 }
2921}
2922
2923void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2924 LocationSummary* locations = div->GetLocations();
2925 Location out = locations->Out();
2926 Location first = locations->InAt(0);
2927 Location second = locations->InAt(1);
2928
2929 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002930 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002931 if (second.IsConstant()) {
2932 GenerateDivRemConstantIntegral(div);
2933 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002934 __ sdiv(out.AsRegister<Register>(),
2935 first.AsRegister<Register>(),
2936 second.AsRegister<Register>());
2937 } else {
2938 InvokeRuntimeCallingConvention calling_convention;
2939 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2940 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2941 DCHECK_EQ(R0, out.AsRegister<Register>());
2942
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002943 codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002944 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002945 }
Calin Juravled0d48522014-11-04 16:40:20 +00002946 break;
2947 }
2948
Calin Juravle7c4954d2014-10-28 16:57:40 +00002949 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002950 InvokeRuntimeCallingConvention calling_convention;
2951 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2952 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2953 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2954 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2955 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002956 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002957
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002958 codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002959 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002960 break;
2961 }
2962
2963 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002964 __ vdivs(out.AsFpuRegister<SRegister>(),
2965 first.AsFpuRegister<SRegister>(),
2966 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002967 break;
2968 }
2969
2970 case Primitive::kPrimDouble: {
2971 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2972 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2973 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2974 break;
2975 }
2976
2977 default:
2978 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2979 }
2980}
2981
Calin Juravlebacfec32014-11-14 15:54:36 +00002982void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002983 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002984
2985 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002986 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002987 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2988 // sdiv will be replaced by other instruction sequence.
2989 call_kind = LocationSummary::kNoCall;
2990 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2991 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002992 // Have hardware divide instruction for int, do it with three instructions.
2993 call_kind = LocationSummary::kNoCall;
2994 }
2995
Calin Juravlebacfec32014-11-14 15:54:36 +00002996 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2997
Calin Juravled2ec87d2014-12-08 14:24:46 +00002998 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002999 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003000 if (rem->InputAt(1)->IsConstant()) {
3001 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003002 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003003 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003004 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3005 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003006 // No temp register required.
3007 } else {
3008 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003009 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003010 locations->AddTemp(Location::RequiresRegister());
3011 }
3012 }
3013 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003014 locations->SetInAt(0, Location::RequiresRegister());
3015 locations->SetInAt(1, Location::RequiresRegister());
3016 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3017 locations->AddTemp(Location::RequiresRegister());
3018 } else {
3019 InvokeRuntimeCallingConvention calling_convention;
3020 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3021 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3022 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3023 // we only need the latter.
3024 locations->SetOut(Location::RegisterLocation(R1));
3025 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003026 break;
3027 }
3028 case Primitive::kPrimLong: {
3029 InvokeRuntimeCallingConvention calling_convention;
3030 locations->SetInAt(0, Location::RegisterPairLocation(
3031 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3032 locations->SetInAt(1, Location::RegisterPairLocation(
3033 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3034 // The runtime helper puts the output in R2,R3.
3035 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3036 break;
3037 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003038 case Primitive::kPrimFloat: {
3039 InvokeRuntimeCallingConvention calling_convention;
3040 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3041 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3042 locations->SetOut(Location::FpuRegisterLocation(S0));
3043 break;
3044 }
3045
Calin Juravlebacfec32014-11-14 15:54:36 +00003046 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003047 InvokeRuntimeCallingConvention calling_convention;
3048 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3049 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3050 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3051 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3052 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003053 break;
3054 }
3055
3056 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003057 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003058 }
3059}
3060
3061void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3062 LocationSummary* locations = rem->GetLocations();
3063 Location out = locations->Out();
3064 Location first = locations->InAt(0);
3065 Location second = locations->InAt(1);
3066
Calin Juravled2ec87d2014-12-08 14:24:46 +00003067 Primitive::Type type = rem->GetResultType();
3068 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003069 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003070 if (second.IsConstant()) {
3071 GenerateDivRemConstantIntegral(rem);
3072 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003073 Register reg1 = first.AsRegister<Register>();
3074 Register reg2 = second.AsRegister<Register>();
3075 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003076
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003077 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003078 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003079 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003080 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003081 } else {
3082 InvokeRuntimeCallingConvention calling_convention;
3083 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3084 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3085 DCHECK_EQ(R1, out.AsRegister<Register>());
3086
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003087 codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003088 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003089 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003090 break;
3091 }
3092
3093 case Primitive::kPrimLong: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003094 codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003095 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003096 break;
3097 }
3098
Calin Juravled2ec87d2014-12-08 14:24:46 +00003099 case Primitive::kPrimFloat: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003100 codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003101 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003102 break;
3103 }
3104
Calin Juravlebacfec32014-11-14 15:54:36 +00003105 case Primitive::kPrimDouble: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003106 codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003107 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003108 break;
3109 }
3110
3111 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003112 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003113 }
3114}
3115
Calin Juravled0d48522014-11-04 16:40:20 +00003116void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003117 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3118 ? LocationSummary::kCallOnSlowPath
3119 : LocationSummary::kNoCall;
3120 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003121 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003122 if (instruction->HasUses()) {
3123 locations->SetOut(Location::SameAsFirstInput());
3124 }
3125}
3126
3127void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003128 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003129 codegen_->AddSlowPath(slow_path);
3130
3131 LocationSummary* locations = instruction->GetLocations();
3132 Location value = locations->InAt(0);
3133
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003134 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003135 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003136 case Primitive::kPrimByte:
3137 case Primitive::kPrimChar:
3138 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003139 case Primitive::kPrimInt: {
3140 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003141 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003142 } else {
3143 DCHECK(value.IsConstant()) << value;
3144 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3145 __ b(slow_path->GetEntryLabel());
3146 }
3147 }
3148 break;
3149 }
3150 case Primitive::kPrimLong: {
3151 if (value.IsRegisterPair()) {
3152 __ orrs(IP,
3153 value.AsRegisterPairLow<Register>(),
3154 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3155 __ b(slow_path->GetEntryLabel(), EQ);
3156 } else {
3157 DCHECK(value.IsConstant()) << value;
3158 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3159 __ b(slow_path->GetEntryLabel());
3160 }
3161 }
3162 break;
3163 default:
3164 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3165 }
3166 }
Calin Juravled0d48522014-11-04 16:40:20 +00003167}
3168
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003169void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3170 Register in = locations->InAt(0).AsRegister<Register>();
3171 Location rhs = locations->InAt(1);
3172 Register out = locations->Out().AsRegister<Register>();
3173
3174 if (rhs.IsConstant()) {
3175 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3176 // so map all rotations to a +ve. equivalent in that range.
3177 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3178 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3179 if (rot) {
3180 // Rotate, mapping left rotations to right equivalents if necessary.
3181 // (e.g. left by 2 bits == right by 30.)
3182 __ Ror(out, in, rot);
3183 } else if (out != in) {
3184 __ Mov(out, in);
3185 }
3186 } else {
3187 __ Ror(out, in, rhs.AsRegister<Register>());
3188 }
3189}
3190
3191// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3192// rotates by swapping input regs (effectively rotating by the first 32-bits of
3193// a larger rotation) or flipping direction (thus treating larger right/left
3194// rotations as sub-word sized rotations in the other direction) as appropriate.
3195void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3196 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3197 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3198 Location rhs = locations->InAt(1);
3199 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3200 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3201
3202 if (rhs.IsConstant()) {
3203 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3204 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003205 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003206 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3207 // logic below to a simple pair of binary orr.
3208 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3209 if (rot >= kArmBitsPerWord) {
3210 rot -= kArmBitsPerWord;
3211 std::swap(in_reg_hi, in_reg_lo);
3212 }
3213 // Rotate, or mov to out for zero or word size rotations.
3214 if (rot != 0u) {
3215 __ Lsr(out_reg_hi, in_reg_hi, rot);
3216 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3217 __ Lsr(out_reg_lo, in_reg_lo, rot);
3218 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3219 } else {
3220 __ Mov(out_reg_lo, in_reg_lo);
3221 __ Mov(out_reg_hi, in_reg_hi);
3222 }
3223 } else {
3224 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3225 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3226 Label end;
3227 Label shift_by_32_plus_shift_right;
3228
3229 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3230 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3231 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3232 __ b(&shift_by_32_plus_shift_right, CC);
3233
3234 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3235 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3236 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3237 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3238 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3239 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3240 __ Lsr(shift_left, in_reg_hi, shift_right);
3241 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3242 __ b(&end);
3243
3244 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3245 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3246 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3247 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3248 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3249 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3250 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3251 __ Lsl(shift_right, in_reg_hi, shift_left);
3252 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3253
3254 __ Bind(&end);
3255 }
3256}
Roland Levillain22c49222016-03-18 14:04:28 +00003257
3258void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003259 LocationSummary* locations =
3260 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3261 switch (ror->GetResultType()) {
3262 case Primitive::kPrimInt: {
3263 locations->SetInAt(0, Location::RequiresRegister());
3264 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3265 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3266 break;
3267 }
3268 case Primitive::kPrimLong: {
3269 locations->SetInAt(0, Location::RequiresRegister());
3270 if (ror->InputAt(1)->IsConstant()) {
3271 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3272 } else {
3273 locations->SetInAt(1, Location::RequiresRegister());
3274 locations->AddTemp(Location::RequiresRegister());
3275 locations->AddTemp(Location::RequiresRegister());
3276 }
3277 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3278 break;
3279 }
3280 default:
3281 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3282 }
3283}
3284
Roland Levillain22c49222016-03-18 14:04:28 +00003285void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003286 LocationSummary* locations = ror->GetLocations();
3287 Primitive::Type type = ror->GetResultType();
3288 switch (type) {
3289 case Primitive::kPrimInt: {
3290 HandleIntegerRotate(locations);
3291 break;
3292 }
3293 case Primitive::kPrimLong: {
3294 HandleLongRotate(locations);
3295 break;
3296 }
3297 default:
3298 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003299 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003300 }
3301}
3302
Calin Juravle9aec02f2014-11-18 23:06:35 +00003303void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3304 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3305
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003306 LocationSummary* locations =
3307 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003308
3309 switch (op->GetResultType()) {
3310 case Primitive::kPrimInt: {
3311 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003312 if (op->InputAt(1)->IsConstant()) {
3313 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3314 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3315 } else {
3316 locations->SetInAt(1, Location::RequiresRegister());
3317 // Make the output overlap, as it will be used to hold the masked
3318 // second input.
3319 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3320 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003321 break;
3322 }
3323 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003324 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003325 if (op->InputAt(1)->IsConstant()) {
3326 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3327 // For simplicity, use kOutputOverlap even though we only require that low registers
3328 // don't clash with high registers which the register allocator currently guarantees.
3329 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3330 } else {
3331 locations->SetInAt(1, Location::RequiresRegister());
3332 locations->AddTemp(Location::RequiresRegister());
3333 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3334 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003335 break;
3336 }
3337 default:
3338 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3339 }
3340}
3341
3342void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3343 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3344
3345 LocationSummary* locations = op->GetLocations();
3346 Location out = locations->Out();
3347 Location first = locations->InAt(0);
3348 Location second = locations->InAt(1);
3349
3350 Primitive::Type type = op->GetResultType();
3351 switch (type) {
3352 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003353 Register out_reg = out.AsRegister<Register>();
3354 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003355 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003356 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003357 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003358 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003359 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003360 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003361 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003362 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003363 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003364 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003365 }
3366 } else {
3367 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003368 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003369 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003370 __ Mov(out_reg, first_reg);
3371 } else if (op->IsShl()) {
3372 __ Lsl(out_reg, first_reg, shift_value);
3373 } else if (op->IsShr()) {
3374 __ Asr(out_reg, first_reg, shift_value);
3375 } else {
3376 __ Lsr(out_reg, first_reg, shift_value);
3377 }
3378 }
3379 break;
3380 }
3381 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003382 Register o_h = out.AsRegisterPairHigh<Register>();
3383 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003384
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003385 Register high = first.AsRegisterPairHigh<Register>();
3386 Register low = first.AsRegisterPairLow<Register>();
3387
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003388 if (second.IsRegister()) {
3389 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003390
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003391 Register second_reg = second.AsRegister<Register>();
3392
3393 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003394 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003395 // Shift the high part
3396 __ Lsl(o_h, high, o_l);
3397 // Shift the low part and `or` what overflew on the high part
3398 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3399 __ Lsr(temp, low, temp);
3400 __ orr(o_h, o_h, ShifterOperand(temp));
3401 // If the shift is > 32 bits, override the high part
3402 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3403 __ it(PL);
3404 __ Lsl(o_h, low, temp, PL);
3405 // Shift the low part
3406 __ Lsl(o_l, low, o_l);
3407 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003408 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003409 // Shift the low part
3410 __ Lsr(o_l, low, o_h);
3411 // Shift the high part and `or` what underflew on the low part
3412 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3413 __ Lsl(temp, high, temp);
3414 __ orr(o_l, o_l, ShifterOperand(temp));
3415 // If the shift is > 32 bits, override the low part
3416 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3417 __ it(PL);
3418 __ Asr(o_l, high, temp, PL);
3419 // Shift the high part
3420 __ Asr(o_h, high, o_h);
3421 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003422 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003423 // same as Shr except we use `Lsr`s and not `Asr`s
3424 __ Lsr(o_l, low, o_h);
3425 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3426 __ Lsl(temp, high, temp);
3427 __ orr(o_l, o_l, ShifterOperand(temp));
3428 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3429 __ it(PL);
3430 __ Lsr(o_l, high, temp, PL);
3431 __ Lsr(o_h, high, o_h);
3432 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003433 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003434 // Register allocator doesn't create partial overlap.
3435 DCHECK_NE(o_l, high);
3436 DCHECK_NE(o_h, low);
3437 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003438 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003439 if (shift_value > 32) {
3440 if (op->IsShl()) {
3441 __ Lsl(o_h, low, shift_value - 32);
3442 __ LoadImmediate(o_l, 0);
3443 } else if (op->IsShr()) {
3444 __ Asr(o_l, high, shift_value - 32);
3445 __ Asr(o_h, high, 31);
3446 } else {
3447 __ Lsr(o_l, high, shift_value - 32);
3448 __ LoadImmediate(o_h, 0);
3449 }
3450 } else if (shift_value == 32) {
3451 if (op->IsShl()) {
3452 __ mov(o_h, ShifterOperand(low));
3453 __ LoadImmediate(o_l, 0);
3454 } else if (op->IsShr()) {
3455 __ mov(o_l, ShifterOperand(high));
3456 __ Asr(o_h, high, 31);
3457 } else {
3458 __ mov(o_l, ShifterOperand(high));
3459 __ LoadImmediate(o_h, 0);
3460 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003461 } else if (shift_value == 1) {
3462 if (op->IsShl()) {
3463 __ Lsls(o_l, low, 1);
3464 __ adc(o_h, high, ShifterOperand(high));
3465 } else if (op->IsShr()) {
3466 __ Asrs(o_h, high, 1);
3467 __ Rrx(o_l, low);
3468 } else {
3469 __ Lsrs(o_h, high, 1);
3470 __ Rrx(o_l, low);
3471 }
3472 } else {
3473 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003474 if (op->IsShl()) {
3475 __ Lsl(o_h, high, shift_value);
3476 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3477 __ Lsl(o_l, low, shift_value);
3478 } else if (op->IsShr()) {
3479 __ Lsr(o_l, low, shift_value);
3480 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3481 __ Asr(o_h, high, shift_value);
3482 } else {
3483 __ Lsr(o_l, low, shift_value);
3484 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3485 __ Lsr(o_h, high, shift_value);
3486 }
3487 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003488 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003489 break;
3490 }
3491 default:
3492 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003493 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003494 }
3495}
3496
3497void LocationsBuilderARM::VisitShl(HShl* shl) {
3498 HandleShift(shl);
3499}
3500
3501void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3502 HandleShift(shl);
3503}
3504
3505void LocationsBuilderARM::VisitShr(HShr* shr) {
3506 HandleShift(shr);
3507}
3508
3509void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3510 HandleShift(shr);
3511}
3512
3513void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3514 HandleShift(ushr);
3515}
3516
3517void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3518 HandleShift(ushr);
3519}
3520
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003521void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003522 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003523 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003524 if (instruction->IsStringAlloc()) {
3525 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3526 } else {
3527 InvokeRuntimeCallingConvention calling_convention;
3528 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3529 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3530 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003531 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003532}
3533
3534void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003535 // Note: if heap poisoning is enabled, the entry point takes cares
3536 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003537 if (instruction->IsStringAlloc()) {
3538 // String is allocated through StringFactory. Call NewEmptyString entry point.
3539 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003540 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003541 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3542 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3543 __ blx(LR);
3544 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3545 } else {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003546 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
David Brazdil6de19382016-01-08 17:37:10 +00003547 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3548 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003549}
3550
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003551void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3552 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003553 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003554 InvokeRuntimeCallingConvention calling_convention;
3555 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003556 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003557 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003558 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003559}
3560
3561void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3562 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003563 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003564 // Note: if heap poisoning is enabled, the entry point takes cares
3565 // of poisoning the reference.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003566 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003567 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003568}
3569
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003570void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003571 LocationSummary* locations =
3572 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003573 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3574 if (location.IsStackSlot()) {
3575 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3576 } else if (location.IsDoubleStackSlot()) {
3577 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003578 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003579 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003580}
3581
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003582void InstructionCodeGeneratorARM::VisitParameterValue(
3583 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003584 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003585}
3586
3587void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3588 LocationSummary* locations =
3589 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3590 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3591}
3592
3593void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3594 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003595}
3596
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003597void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003598 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003599 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003600 locations->SetInAt(0, Location::RequiresRegister());
3601 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003602}
3603
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003604void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3605 LocationSummary* locations = not_->GetLocations();
3606 Location out = locations->Out();
3607 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003608 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003609 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003610 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003611 break;
3612
3613 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003614 __ mvn(out.AsRegisterPairLow<Register>(),
3615 ShifterOperand(in.AsRegisterPairLow<Register>()));
3616 __ mvn(out.AsRegisterPairHigh<Register>(),
3617 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003618 break;
3619
3620 default:
3621 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3622 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003623}
3624
David Brazdil66d126e2015-04-03 16:02:44 +01003625void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3626 LocationSummary* locations =
3627 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3628 locations->SetInAt(0, Location::RequiresRegister());
3629 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3630}
3631
3632void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003633 LocationSummary* locations = bool_not->GetLocations();
3634 Location out = locations->Out();
3635 Location in = locations->InAt(0);
3636 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3637}
3638
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003639void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003640 LocationSummary* locations =
3641 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003642 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003643 case Primitive::kPrimBoolean:
3644 case Primitive::kPrimByte:
3645 case Primitive::kPrimShort:
3646 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003647 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00003648 case Primitive::kPrimLong: {
3649 locations->SetInAt(0, Location::RequiresRegister());
3650 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003651 // Output overlaps because it is written before doing the low comparison.
3652 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003653 break;
3654 }
3655 case Primitive::kPrimFloat:
3656 case Primitive::kPrimDouble: {
3657 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003658 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00003659 locations->SetOut(Location::RequiresRegister());
3660 break;
3661 }
3662 default:
3663 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3664 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003665}
3666
3667void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003668 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003669 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003670 Location left = locations->InAt(0);
3671 Location right = locations->InAt(1);
3672
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003673 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003674 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00003675 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00003676 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003677 case Primitive::kPrimBoolean:
3678 case Primitive::kPrimByte:
3679 case Primitive::kPrimShort:
3680 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003681 case Primitive::kPrimInt: {
3682 __ LoadImmediate(out, 0);
3683 __ cmp(left.AsRegister<Register>(),
3684 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
3685 less_cond = LT;
3686 break;
3687 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003688 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003689 __ cmp(left.AsRegisterPairHigh<Register>(),
3690 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003691 __ b(&less, LT);
3692 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003693 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003694 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003695 __ cmp(left.AsRegisterPairLow<Register>(),
3696 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003697 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00003698 break;
3699 }
3700 case Primitive::kPrimFloat:
3701 case Primitive::kPrimDouble: {
3702 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003703 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00003704 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003705 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003706 break;
3707 }
3708 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003709 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00003710 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003711 }
Aart Bika19616e2016-02-01 18:57:58 -08003712
Calin Juravleddb7df22014-11-25 20:56:51 +00003713 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00003714 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00003715
3716 __ Bind(&greater);
3717 __ LoadImmediate(out, 1);
3718 __ b(&done);
3719
3720 __ Bind(&less);
3721 __ LoadImmediate(out, -1);
3722
3723 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003724}
3725
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003726void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003727 LocationSummary* locations =
3728 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003729 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003730 locations->SetInAt(i, Location::Any());
3731 }
3732 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003733}
3734
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003735void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003736 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003737}
3738
Roland Levillainc9285912015-12-18 10:38:42 +00003739void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3740 // TODO (ported from quick): revisit ARM barrier kinds.
3741 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00003742 switch (kind) {
3743 case MemBarrierKind::kAnyStore:
3744 case MemBarrierKind::kLoadAny:
3745 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003746 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003747 break;
3748 }
3749 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003750 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003751 break;
3752 }
3753 default:
3754 LOG(FATAL) << "Unexpected memory barrier " << kind;
3755 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003756 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003757}
3758
3759void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3760 uint32_t offset,
3761 Register out_lo,
3762 Register out_hi) {
3763 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00003764 // Ensure `out_lo` is different from `addr`, so that loading
3765 // `offset` into `out_lo` does not clutter `addr`.
3766 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00003767 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003768 __ add(IP, addr, ShifterOperand(out_lo));
3769 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003770 }
3771 __ ldrexd(out_lo, out_hi, addr);
3772}
3773
3774void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3775 uint32_t offset,
3776 Register value_lo,
3777 Register value_hi,
3778 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003779 Register temp2,
3780 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003781 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003782 if (offset != 0) {
3783 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003784 __ add(IP, addr, ShifterOperand(temp1));
3785 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003786 }
3787 __ Bind(&fail);
3788 // We need a load followed by store. (The address used in a STREX instruction must
3789 // be the same as the address in the most recently executed LDREX instruction.)
3790 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003791 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003792 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003793 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003794}
3795
3796void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3797 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3798
Nicolas Geoffray39468442014-09-02 15:17:15 +01003799 LocationSummary* locations =
3800 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003801 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003802
Calin Juravle52c48962014-12-16 17:02:57 +00003803 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003804 if (Primitive::IsFloatingPointType(field_type)) {
3805 locations->SetInAt(1, Location::RequiresFpuRegister());
3806 } else {
3807 locations->SetInAt(1, Location::RequiresRegister());
3808 }
3809
Calin Juravle52c48962014-12-16 17:02:57 +00003810 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003811 bool generate_volatile = field_info.IsVolatile()
3812 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003813 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003814 bool needs_write_barrier =
3815 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003816 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003817 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003818 if (needs_write_barrier) {
3819 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003820 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003821 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003822 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003823 // - registers need to be consecutive
3824 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003825 // We don't test for ARM yet, and the assertion makes sure that we
3826 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003827 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3828
3829 locations->AddTemp(Location::RequiresRegister());
3830 locations->AddTemp(Location::RequiresRegister());
3831 if (field_type == Primitive::kPrimDouble) {
3832 // For doubles we need two more registers to copy the value.
3833 locations->AddTemp(Location::RegisterLocation(R2));
3834 locations->AddTemp(Location::RegisterLocation(R3));
3835 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003836 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003837}
3838
Calin Juravle52c48962014-12-16 17:02:57 +00003839void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003840 const FieldInfo& field_info,
3841 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003842 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3843
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003844 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003845 Register base = locations->InAt(0).AsRegister<Register>();
3846 Location value = locations->InAt(1);
3847
3848 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003849 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003850 Primitive::Type field_type = field_info.GetFieldType();
3851 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003852 bool needs_write_barrier =
3853 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003854
3855 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003856 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00003857 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003858
3859 switch (field_type) {
3860 case Primitive::kPrimBoolean:
3861 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003862 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003863 break;
3864 }
3865
3866 case Primitive::kPrimShort:
3867 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003868 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003869 break;
3870 }
3871
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003872 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003873 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003874 if (kPoisonHeapReferences && needs_write_barrier) {
3875 // Note that in the case where `value` is a null reference,
3876 // we do not enter this block, as a null reference does not
3877 // need poisoning.
3878 DCHECK_EQ(field_type, Primitive::kPrimNot);
3879 Register temp = locations->GetTemp(0).AsRegister<Register>();
3880 __ Mov(temp, value.AsRegister<Register>());
3881 __ PoisonHeapReference(temp);
3882 __ StoreToOffset(kStoreWord, temp, base, offset);
3883 } else {
3884 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3885 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003886 break;
3887 }
3888
3889 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003890 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003891 GenerateWideAtomicStore(base, offset,
3892 value.AsRegisterPairLow<Register>(),
3893 value.AsRegisterPairHigh<Register>(),
3894 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003895 locations->GetTemp(1).AsRegister<Register>(),
3896 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003897 } else {
3898 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003899 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003900 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003901 break;
3902 }
3903
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003904 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003905 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003906 break;
3907 }
3908
3909 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003910 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003911 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003912 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3913 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3914
3915 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3916
3917 GenerateWideAtomicStore(base, offset,
3918 value_reg_lo,
3919 value_reg_hi,
3920 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003921 locations->GetTemp(3).AsRegister<Register>(),
3922 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003923 } else {
3924 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003925 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003926 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003927 break;
3928 }
3929
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003930 case Primitive::kPrimVoid:
3931 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003932 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003933 }
Calin Juravle52c48962014-12-16 17:02:57 +00003934
Calin Juravle77520bc2015-01-12 18:45:46 +00003935 // Longs and doubles are handled in the switch.
3936 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3937 codegen_->MaybeRecordImplicitNullCheck(instruction);
3938 }
3939
3940 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3941 Register temp = locations->GetTemp(0).AsRegister<Register>();
3942 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003943 codegen_->MarkGCCard(
3944 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003945 }
3946
Calin Juravle52c48962014-12-16 17:02:57 +00003947 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003948 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00003949 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003950}
3951
Calin Juravle52c48962014-12-16 17:02:57 +00003952void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3953 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00003954
3955 bool object_field_get_with_read_barrier =
3956 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003957 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00003958 new (GetGraph()->GetArena()) LocationSummary(instruction,
3959 object_field_get_with_read_barrier ?
3960 LocationSummary::kCallOnSlowPath :
3961 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003962 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003963
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003964 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003965 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003966 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00003967 // The output overlaps in case of volatile long: we don't want the
3968 // code generated by GenerateWideAtomicLoad to overwrite the
3969 // object's location. Likewise, in the case of an object field get
3970 // with read barriers enabled, we do not want the load to overwrite
3971 // the object's location, as we need it to emit the read barrier.
3972 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
3973 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003974
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003975 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3976 locations->SetOut(Location::RequiresFpuRegister());
3977 } else {
3978 locations->SetOut(Location::RequiresRegister(),
3979 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3980 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003981 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00003982 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003983 // - registers need to be consecutive
3984 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003985 // We don't test for ARM yet, and the assertion makes sure that we
3986 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003987 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3988 locations->AddTemp(Location::RequiresRegister());
3989 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00003990 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
3991 // We need a temporary register for the read barrier marking slow
3992 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
3993 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003994 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003995}
3996
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003997Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
3998 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
3999 << input->GetType();
4000 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
4001 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4002 return Location::ConstantLocation(input->AsConstant());
4003 } else {
4004 return Location::RequiresFpuRegister();
4005 }
4006}
4007
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004008Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4009 Opcode opcode) {
4010 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4011 if (constant->IsConstant() &&
4012 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4013 return Location::ConstantLocation(constant->AsConstant());
4014 }
4015 return Location::RequiresRegister();
4016}
4017
4018bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4019 Opcode opcode) {
4020 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4021 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004022 Opcode high_opcode = opcode;
4023 SetCc low_set_cc = kCcDontCare;
4024 switch (opcode) {
4025 case SUB:
4026 // Flip the operation to an ADD.
4027 value = -value;
4028 opcode = ADD;
4029 FALLTHROUGH_INTENDED;
4030 case ADD:
4031 if (Low32Bits(value) == 0u) {
4032 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4033 }
4034 high_opcode = ADC;
4035 low_set_cc = kCcSet;
4036 break;
4037 default:
4038 break;
4039 }
4040 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4041 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004042 } else {
4043 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4044 }
4045}
4046
Vladimir Marko59751a72016-08-05 14:37:27 +01004047bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4048 Opcode opcode,
4049 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004050 ShifterOperand so;
4051 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004052 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004053 return true;
4054 }
4055 Opcode neg_opcode = kNoOperand;
4056 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004057 case AND: neg_opcode = BIC; value = ~value; break;
4058 case ORR: neg_opcode = ORN; value = ~value; break;
4059 case ADD: neg_opcode = SUB; value = -value; break;
4060 case ADC: neg_opcode = SBC; value = ~value; break;
4061 case SUB: neg_opcode = ADD; value = -value; break;
4062 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004063 default:
4064 return false;
4065 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004066 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004067}
4068
Calin Juravle52c48962014-12-16 17:02:57 +00004069void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4070 const FieldInfo& field_info) {
4071 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004072
Calin Juravle52c48962014-12-16 17:02:57 +00004073 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004074 Location base_loc = locations->InAt(0);
4075 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004076 Location out = locations->Out();
4077 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004078 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004079 Primitive::Type field_type = field_info.GetFieldType();
4080 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4081
4082 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004083 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004084 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004085 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004086
Roland Levillainc9285912015-12-18 10:38:42 +00004087 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004088 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004089 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004090
Roland Levillainc9285912015-12-18 10:38:42 +00004091 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004092 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004093 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004094
Roland Levillainc9285912015-12-18 10:38:42 +00004095 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004096 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004097 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004098
4099 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004100 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004101 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004102
4103 case Primitive::kPrimNot: {
4104 // /* HeapReference<Object> */ out = *(base + offset)
4105 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4106 Location temp_loc = locations->GetTemp(0);
4107 // Note that a potential implicit null check is handled in this
4108 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4109 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4110 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4111 if (is_volatile) {
4112 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4113 }
4114 } else {
4115 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4116 codegen_->MaybeRecordImplicitNullCheck(instruction);
4117 if (is_volatile) {
4118 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4119 }
4120 // If read barriers are enabled, emit read barriers other than
4121 // Baker's using a slow path (and also unpoison the loaded
4122 // reference, if heap poisoning is enabled).
4123 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4124 }
4125 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004126 }
4127
Roland Levillainc9285912015-12-18 10:38:42 +00004128 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004129 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004130 GenerateWideAtomicLoad(base, offset,
4131 out.AsRegisterPairLow<Register>(),
4132 out.AsRegisterPairHigh<Register>());
4133 } else {
4134 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4135 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004136 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004137
Roland Levillainc9285912015-12-18 10:38:42 +00004138 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004139 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004140 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004141
4142 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004143 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004144 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004145 Register lo = locations->GetTemp(0).AsRegister<Register>();
4146 Register hi = locations->GetTemp(1).AsRegister<Register>();
4147 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004148 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004149 __ vmovdrr(out_reg, lo, hi);
4150 } else {
4151 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004152 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004153 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004154 break;
4155 }
4156
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004157 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004158 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004159 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004160 }
Calin Juravle52c48962014-12-16 17:02:57 +00004161
Roland Levillainc9285912015-12-18 10:38:42 +00004162 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4163 // Potential implicit null checks, in the case of reference or
4164 // double fields, are handled in the previous switch statement.
4165 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004166 codegen_->MaybeRecordImplicitNullCheck(instruction);
4167 }
4168
Calin Juravle52c48962014-12-16 17:02:57 +00004169 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004170 if (field_type == Primitive::kPrimNot) {
4171 // Memory barriers, in the case of references, are also handled
4172 // in the previous switch statement.
4173 } else {
4174 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4175 }
Roland Levillain4d027112015-07-01 15:41:14 +01004176 }
Calin Juravle52c48962014-12-16 17:02:57 +00004177}
4178
4179void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4180 HandleFieldSet(instruction, instruction->GetFieldInfo());
4181}
4182
4183void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004184 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004185}
4186
4187void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4188 HandleFieldGet(instruction, instruction->GetFieldInfo());
4189}
4190
4191void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4192 HandleFieldGet(instruction, instruction->GetFieldInfo());
4193}
4194
4195void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4196 HandleFieldGet(instruction, instruction->GetFieldInfo());
4197}
4198
4199void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4200 HandleFieldGet(instruction, instruction->GetFieldInfo());
4201}
4202
4203void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4204 HandleFieldSet(instruction, instruction->GetFieldInfo());
4205}
4206
4207void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004208 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004209}
4210
Calin Juravlee460d1d2015-09-29 04:52:17 +01004211void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4212 HUnresolvedInstanceFieldGet* instruction) {
4213 FieldAccessCallingConventionARM calling_convention;
4214 codegen_->CreateUnresolvedFieldLocationSummary(
4215 instruction, instruction->GetFieldType(), calling_convention);
4216}
4217
4218void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4219 HUnresolvedInstanceFieldGet* instruction) {
4220 FieldAccessCallingConventionARM calling_convention;
4221 codegen_->GenerateUnresolvedFieldAccess(instruction,
4222 instruction->GetFieldType(),
4223 instruction->GetFieldIndex(),
4224 instruction->GetDexPc(),
4225 calling_convention);
4226}
4227
4228void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4229 HUnresolvedInstanceFieldSet* instruction) {
4230 FieldAccessCallingConventionARM calling_convention;
4231 codegen_->CreateUnresolvedFieldLocationSummary(
4232 instruction, instruction->GetFieldType(), calling_convention);
4233}
4234
4235void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4236 HUnresolvedInstanceFieldSet* instruction) {
4237 FieldAccessCallingConventionARM calling_convention;
4238 codegen_->GenerateUnresolvedFieldAccess(instruction,
4239 instruction->GetFieldType(),
4240 instruction->GetFieldIndex(),
4241 instruction->GetDexPc(),
4242 calling_convention);
4243}
4244
4245void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4246 HUnresolvedStaticFieldGet* instruction) {
4247 FieldAccessCallingConventionARM calling_convention;
4248 codegen_->CreateUnresolvedFieldLocationSummary(
4249 instruction, instruction->GetFieldType(), calling_convention);
4250}
4251
4252void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4253 HUnresolvedStaticFieldGet* instruction) {
4254 FieldAccessCallingConventionARM calling_convention;
4255 codegen_->GenerateUnresolvedFieldAccess(instruction,
4256 instruction->GetFieldType(),
4257 instruction->GetFieldIndex(),
4258 instruction->GetDexPc(),
4259 calling_convention);
4260}
4261
4262void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4263 HUnresolvedStaticFieldSet* instruction) {
4264 FieldAccessCallingConventionARM calling_convention;
4265 codegen_->CreateUnresolvedFieldLocationSummary(
4266 instruction, instruction->GetFieldType(), calling_convention);
4267}
4268
4269void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4270 HUnresolvedStaticFieldSet* instruction) {
4271 FieldAccessCallingConventionARM calling_convention;
4272 codegen_->GenerateUnresolvedFieldAccess(instruction,
4273 instruction->GetFieldType(),
4274 instruction->GetFieldIndex(),
4275 instruction->GetDexPc(),
4276 calling_convention);
4277}
4278
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004279void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004280 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4281 ? LocationSummary::kCallOnSlowPath
4282 : LocationSummary::kNoCall;
4283 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00004284 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004285 if (instruction->HasUses()) {
4286 locations->SetOut(Location::SameAsFirstInput());
4287 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004288}
4289
Calin Juravle2ae48182016-03-16 14:05:09 +00004290void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4291 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004292 return;
4293 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004294 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004295
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004296 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004297 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004298}
4299
Calin Juravle2ae48182016-03-16 14:05:09 +00004300void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004301 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004302 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004303
4304 LocationSummary* locations = instruction->GetLocations();
4305 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004306
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004307 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004308}
4309
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004310void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004311 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004312}
4313
Artem Serov6c916792016-07-11 14:02:34 +01004314static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4315 switch (type) {
4316 case Primitive::kPrimNot:
4317 return kLoadWord;
4318 case Primitive::kPrimBoolean:
4319 return kLoadUnsignedByte;
4320 case Primitive::kPrimByte:
4321 return kLoadSignedByte;
4322 case Primitive::kPrimChar:
4323 return kLoadUnsignedHalfword;
4324 case Primitive::kPrimShort:
4325 return kLoadSignedHalfword;
4326 case Primitive::kPrimInt:
4327 return kLoadWord;
4328 case Primitive::kPrimLong:
4329 return kLoadWordPair;
4330 case Primitive::kPrimFloat:
4331 return kLoadSWord;
4332 case Primitive::kPrimDouble:
4333 return kLoadDWord;
4334 default:
4335 LOG(FATAL) << "Unreachable type " << type;
4336 UNREACHABLE();
4337 }
4338}
4339
4340static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4341 switch (type) {
4342 case Primitive::kPrimNot:
4343 return kStoreWord;
4344 case Primitive::kPrimBoolean:
4345 case Primitive::kPrimByte:
4346 return kStoreByte;
4347 case Primitive::kPrimChar:
4348 case Primitive::kPrimShort:
4349 return kStoreHalfword;
4350 case Primitive::kPrimInt:
4351 return kStoreWord;
4352 case Primitive::kPrimLong:
4353 return kStoreWordPair;
4354 case Primitive::kPrimFloat:
4355 return kStoreSWord;
4356 case Primitive::kPrimDouble:
4357 return kStoreDWord;
4358 default:
4359 LOG(FATAL) << "Unreachable type " << type;
4360 UNREACHABLE();
4361 }
4362}
4363
4364void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4365 Location out_loc,
4366 Register base,
4367 Register reg_offset,
4368 Condition cond) {
4369 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4370 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4371
4372 switch (type) {
4373 case Primitive::kPrimByte:
4374 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4375 break;
4376 case Primitive::kPrimBoolean:
4377 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4378 break;
4379 case Primitive::kPrimShort:
4380 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4381 break;
4382 case Primitive::kPrimChar:
4383 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4384 break;
4385 case Primitive::kPrimNot:
4386 case Primitive::kPrimInt:
4387 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4388 break;
4389 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4390 case Primitive::kPrimLong:
4391 case Primitive::kPrimFloat:
4392 case Primitive::kPrimDouble:
4393 default:
4394 LOG(FATAL) << "Unreachable type " << type;
4395 UNREACHABLE();
4396 }
4397}
4398
4399void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4400 Location loc,
4401 Register base,
4402 Register reg_offset,
4403 Condition cond) {
4404 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4405 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4406
4407 switch (type) {
4408 case Primitive::kPrimByte:
4409 case Primitive::kPrimBoolean:
4410 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4411 break;
4412 case Primitive::kPrimShort:
4413 case Primitive::kPrimChar:
4414 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4415 break;
4416 case Primitive::kPrimNot:
4417 case Primitive::kPrimInt:
4418 __ str(loc.AsRegister<Register>(), mem_address, cond);
4419 break;
4420 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4421 case Primitive::kPrimLong:
4422 case Primitive::kPrimFloat:
4423 case Primitive::kPrimDouble:
4424 default:
4425 LOG(FATAL) << "Unreachable type " << type;
4426 UNREACHABLE();
4427 }
4428}
4429
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004430void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004431 bool object_array_get_with_read_barrier =
4432 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004433 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004434 new (GetGraph()->GetArena()) LocationSummary(instruction,
4435 object_array_get_with_read_barrier ?
4436 LocationSummary::kCallOnSlowPath :
4437 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004438 locations->SetInAt(0, Location::RequiresRegister());
4439 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004440 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4441 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4442 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004443 // The output overlaps in the case of an object array get with
4444 // read barriers enabled: we do not want the move to overwrite the
4445 // array's location, as we need it to emit the read barrier.
4446 locations->SetOut(
4447 Location::RequiresRegister(),
4448 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004449 }
Roland Levillainc9285912015-12-18 10:38:42 +00004450 // We need a temporary register for the read barrier marking slow
4451 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
4452 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4453 locations->AddTemp(Location::RequiresRegister());
4454 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004455}
4456
4457void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4458 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004459 Location obj_loc = locations->InAt(0);
4460 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004461 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004462 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004463 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004464 Primitive::Type type = instruction->GetType();
Artem Serov328429f2016-07-06 16:23:04 +01004465 HInstruction* array_instr = instruction->GetArray();
4466 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004467 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4468 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Artem Serov6c916792016-07-11 14:02:34 +01004469
Roland Levillain4d027112015-07-01 15:41:14 +01004470 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004471 case Primitive::kPrimBoolean:
4472 case Primitive::kPrimByte:
4473 case Primitive::kPrimShort:
4474 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004475 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004476 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004477 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4478 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
4479
4480 LoadOperandType load_type = GetLoadOperandType(type);
4481 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004482 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004483 Register temp = IP;
4484
4485 if (has_intermediate_address) {
4486 // We do not need to compute the intermediate address from the array: the
4487 // input instruction has done it already. See the comment in
4488 // `TryExtractArrayAccessAddress()`.
4489 if (kIsDebugBuild) {
4490 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4491 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4492 }
4493 temp = obj;
4494 } else {
4495 __ add(temp, obj, ShifterOperand(data_offset));
4496 }
4497 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004498 }
4499 break;
4500 }
4501
Roland Levillainc9285912015-12-18 10:38:42 +00004502 case Primitive::kPrimNot: {
4503 static_assert(
4504 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4505 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004506 // /* HeapReference<Object> */ out =
4507 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4508 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4509 Location temp = locations->GetTemp(0);
4510 // Note that a potential implicit null check is handled in this
4511 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4512 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4513 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4514 } else {
4515 Register out = out_loc.AsRegister<Register>();
4516 if (index.IsConstant()) {
4517 size_t offset =
4518 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4519 __ LoadFromOffset(kLoadWord, out, obj, offset);
4520 codegen_->MaybeRecordImplicitNullCheck(instruction);
4521 // If read barriers are enabled, emit read barriers other than
4522 // Baker's using a slow path (and also unpoison the loaded
4523 // reference, if heap poisoning is enabled).
4524 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4525 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004526 Register temp = IP;
4527
4528 if (has_intermediate_address) {
4529 // We do not need to compute the intermediate address from the array: the
4530 // input instruction has done it already. See the comment in
4531 // `TryExtractArrayAccessAddress()`.
4532 if (kIsDebugBuild) {
4533 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4534 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4535 }
4536 temp = obj;
4537 } else {
4538 __ add(temp, obj, ShifterOperand(data_offset));
4539 }
4540 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004541
Roland Levillainc9285912015-12-18 10:38:42 +00004542 codegen_->MaybeRecordImplicitNullCheck(instruction);
4543 // If read barriers are enabled, emit read barriers other than
4544 // Baker's using a slow path (and also unpoison the loaded
4545 // reference, if heap poisoning is enabled).
4546 codegen_->MaybeGenerateReadBarrierSlow(
4547 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4548 }
4549 }
4550 break;
4551 }
4552
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004553 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004554 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004555 size_t offset =
4556 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004557 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004558 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004559 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004560 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004561 }
4562 break;
4563 }
4564
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004565 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004566 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004567 if (index.IsConstant()) {
4568 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004569 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004570 } else {
4571 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004572 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004573 }
4574 break;
4575 }
4576
4577 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004578 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004579 if (index.IsConstant()) {
4580 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004581 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004582 } else {
4583 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004584 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004585 }
4586 break;
4587 }
4588
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004589 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01004590 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004591 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004592 }
Roland Levillain4d027112015-07-01 15:41:14 +01004593
4594 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00004595 // Potential implicit null checks, in the case of reference
4596 // arrays, are handled in the previous switch statement.
4597 } else {
4598 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01004599 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004600}
4601
4602void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004603 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004604
4605 bool needs_write_barrier =
4606 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00004607 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004608
Nicolas Geoffray39468442014-09-02 15:17:15 +01004609 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004610 instruction,
Vladimir Marko8d49fd72016-08-25 15:20:47 +01004611 may_need_runtime_call_for_type_check ?
Roland Levillain3b359c72015-11-17 19:35:12 +00004612 LocationSummary::kCallOnSlowPath :
4613 LocationSummary::kNoCall);
4614
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004615 locations->SetInAt(0, Location::RequiresRegister());
4616 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
4617 if (Primitive::IsFloatingPointType(value_type)) {
4618 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004619 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004620 locations->SetInAt(2, Location::RequiresRegister());
4621 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004622 if (needs_write_barrier) {
4623 // Temporary registers for the write barrier.
Roland Levillain16d9f942016-08-25 17:27:56 +01004624 // These registers may be used for Baker read barriers too.
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004625 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00004626 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004627 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004628}
4629
4630void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4631 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004632 Location array_loc = locations->InAt(0);
4633 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004634 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004635 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00004636 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004637 bool needs_write_barrier =
4638 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01004639 uint32_t data_offset =
4640 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
4641 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01004642 HInstruction* array_instr = instruction->GetArray();
4643 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004644 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4645 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004646
4647 switch (value_type) {
4648 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01004649 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004650 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01004651 case Primitive::kPrimChar:
4652 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004653 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004654 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4655 uint32_t full_offset =
4656 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
4657 StoreOperandType store_type = GetStoreOperandType(value_type);
4658 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004659 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004660 Register temp = IP;
4661
4662 if (has_intermediate_address) {
4663 // We do not need to compute the intermediate address from the array: the
4664 // input instruction has done it already. See the comment in
4665 // `TryExtractArrayAccessAddress()`.
4666 if (kIsDebugBuild) {
4667 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4668 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
4669 }
4670 temp = array;
4671 } else {
4672 __ add(temp, array, ShifterOperand(data_offset));
4673 }
Artem Serov6c916792016-07-11 14:02:34 +01004674 codegen_->StoreToShiftedRegOffset(value_type,
4675 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01004676 temp,
Artem Serov6c916792016-07-11 14:02:34 +01004677 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004678 }
4679 break;
4680 }
4681
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004682 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00004683 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01004684 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
4685 // See the comment in instruction_simplifier_shared.cc.
4686 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004687
4688 if (instruction->InputAt(2)->IsNullConstant()) {
4689 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004690 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004691 size_t offset =
4692 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01004693 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004694 } else {
4695 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004696 __ add(IP, array, ShifterOperand(data_offset));
4697 codegen_->StoreToShiftedRegOffset(value_type,
4698 value_loc,
4699 IP,
4700 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004701 }
Roland Levillain1407ee72016-01-08 15:56:19 +00004702 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00004703 DCHECK(!needs_write_barrier);
4704 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004705 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004706 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004707
4708 DCHECK(needs_write_barrier);
Roland Levillain16d9f942016-08-25 17:27:56 +01004709 Location temp1_loc = locations->GetTemp(0);
4710 Register temp1 = temp1_loc.AsRegister<Register>();
4711 Location temp2_loc = locations->GetTemp(1);
4712 Register temp2 = temp2_loc.AsRegister<Register>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004713 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4714 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4715 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4716 Label done;
4717 SlowPathCode* slow_path = nullptr;
4718
Roland Levillain3b359c72015-11-17 19:35:12 +00004719 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004720 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4721 codegen_->AddSlowPath(slow_path);
4722 if (instruction->GetValueCanBeNull()) {
4723 Label non_zero;
4724 __ CompareAndBranchIfNonZero(value, &non_zero);
4725 if (index.IsConstant()) {
4726 size_t offset =
4727 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4728 __ StoreToOffset(kStoreWord, value, array, offset);
4729 } else {
4730 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004731 __ add(IP, array, ShifterOperand(data_offset));
4732 codegen_->StoreToShiftedRegOffset(value_type,
4733 value_loc,
4734 IP,
4735 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004736 }
4737 codegen_->MaybeRecordImplicitNullCheck(instruction);
4738 __ b(&done);
4739 __ Bind(&non_zero);
4740 }
4741
Roland Levillain3b359c72015-11-17 19:35:12 +00004742 if (kEmitCompilerReadBarrier) {
Roland Levillain16d9f942016-08-25 17:27:56 +01004743 if (!kUseBakerReadBarrier) {
4744 // When (non-Baker) read barriers are enabled, the type
4745 // checking instrumentation requires two read barriers
4746 // generated by CodeGeneratorARM::GenerateReadBarrierSlow:
4747 //
4748 // __ Mov(temp2, temp1);
4749 // // /* HeapReference<Class> */ temp1 = temp1->component_type_
4750 // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4751 // codegen_->GenerateReadBarrierSlow(
4752 // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset);
4753 //
4754 // // /* HeapReference<Class> */ temp2 = value->klass_
4755 // __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4756 // codegen_->GenerateReadBarrierSlow(
4757 // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc);
4758 //
4759 // __ cmp(temp1, ShifterOperand(temp2));
4760 //
4761 // However, the second read barrier may trash `temp`, as it
4762 // is a temporary register, and as such would not be saved
4763 // along with live registers before calling the runtime (nor
4764 // restored afterwards). So in this case, we bail out and
4765 // delegate the work to the array set slow path.
4766 //
4767 // TODO: Extend the register allocator to support a new
4768 // "(locally) live temp" location so as to avoid always
4769 // going into the slow path when read barriers are enabled?
4770 //
4771 // There is no such problem with Baker read barriers (see below).
4772 __ b(slow_path->GetEntryLabel());
4773 } else {
4774 Register temp3 = IP;
4775 Location temp3_loc = Location::RegisterLocation(temp3);
4776
4777 // Note: `temp3` (scratch register IP) cannot be used as
4778 // `ref` argument of GenerateFieldLoadWithBakerReadBarrier
4779 // calls below (see ReadBarrierMarkSlowPathARM for more
4780 // details).
4781
4782 // /* HeapReference<Class> */ temp1 = array->klass_
4783 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4784 temp1_loc,
4785 array,
4786 class_offset,
4787 temp3_loc,
4788 /* needs_null_check */ true);
4789
4790 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4791 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4792 temp1_loc,
4793 temp1,
4794 component_offset,
4795 temp3_loc,
4796 /* needs_null_check */ false);
4797 // Register `temp1` is not trashed by the read barrier
4798 // emitted by GenerateFieldLoadWithBakerReadBarrier below,
4799 // as that method produces a call to a ReadBarrierMarkRegX
4800 // entry point, which saves all potentially live registers,
4801 // including temporaries such a `temp1`.
4802 // /* HeapReference<Class> */ temp2 = value->klass_
4803 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4804 temp2_loc,
4805 value,
4806 class_offset,
4807 temp3_loc,
4808 /* needs_null_check */ false);
4809 // If heap poisoning is enabled, `temp1` and `temp2` have
4810 // been unpoisoned by the the previous calls to
4811 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4812 __ cmp(temp1, ShifterOperand(temp2));
4813
4814 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4815 Label do_put;
4816 __ b(&do_put, EQ);
4817 // We do not need to emit a read barrier for the
4818 // following heap reference load, as `temp1` is only used
4819 // in a comparison with null below, and this reference
4820 // is not kept afterwards.
4821 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4822 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4823 // If heap poisoning is enabled, no need to unpoison
4824 // `temp`, as we are comparing against null below.
4825 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4826 __ Bind(&do_put);
4827 } else {
4828 __ b(slow_path->GetEntryLabel(), NE);
4829 }
4830 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004831 } else {
Roland Levillain16d9f942016-08-25 17:27:56 +01004832 // Non read barrier code.
4833
Roland Levillain3b359c72015-11-17 19:35:12 +00004834 // /* HeapReference<Class> */ temp1 = array->klass_
4835 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4836 codegen_->MaybeRecordImplicitNullCheck(instruction);
4837 __ MaybeUnpoisonHeapReference(temp1);
4838
4839 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4840 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4841 // /* HeapReference<Class> */ temp2 = value->klass_
4842 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4843 // If heap poisoning is enabled, no need to unpoison `temp1`
4844 // nor `temp2`, as we are comparing two poisoned references.
4845 __ cmp(temp1, ShifterOperand(temp2));
4846
4847 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4848 Label do_put;
4849 __ b(&do_put, EQ);
4850 // If heap poisoning is enabled, the `temp1` reference has
4851 // not been unpoisoned yet; unpoison it now.
4852 __ MaybeUnpoisonHeapReference(temp1);
4853
4854 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4855 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4856 // If heap poisoning is enabled, no need to unpoison
4857 // `temp1`, as we are comparing against null below.
4858 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4859 __ Bind(&do_put);
4860 } else {
4861 __ b(slow_path->GetEntryLabel(), NE);
4862 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004863 }
4864 }
4865
Artem Serov6c916792016-07-11 14:02:34 +01004866 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004867 if (kPoisonHeapReferences) {
4868 // Note that in the case where `value` is a null reference,
4869 // we do not enter this block, as a null reference does not
4870 // need poisoning.
4871 DCHECK_EQ(value_type, Primitive::kPrimNot);
4872 __ Mov(temp1, value);
4873 __ PoisonHeapReference(temp1);
4874 source = temp1;
4875 }
4876
4877 if (index.IsConstant()) {
4878 size_t offset =
4879 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4880 __ StoreToOffset(kStoreWord, source, array, offset);
4881 } else {
4882 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004883
4884 __ add(IP, array, ShifterOperand(data_offset));
4885 codegen_->StoreToShiftedRegOffset(value_type,
4886 Location::RegisterLocation(source),
4887 IP,
4888 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004889 }
4890
Roland Levillain3b359c72015-11-17 19:35:12 +00004891 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004892 codegen_->MaybeRecordImplicitNullCheck(instruction);
4893 }
4894
4895 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4896
4897 if (done.IsLinked()) {
4898 __ Bind(&done);
4899 }
4900
4901 if (slow_path != nullptr) {
4902 __ Bind(slow_path->GetExitLabel());
4903 }
4904
4905 break;
4906 }
4907
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004908 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004909 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004910 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004911 size_t offset =
4912 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004913 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004914 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004915 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004916 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004917 }
4918 break;
4919 }
4920
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004921 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004922 Location value = locations->InAt(2);
4923 DCHECK(value.IsFpuRegister());
4924 if (index.IsConstant()) {
4925 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004926 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004927 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004928 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004929 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4930 }
4931 break;
4932 }
4933
4934 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004935 Location value = locations->InAt(2);
4936 DCHECK(value.IsFpuRegisterPair());
4937 if (index.IsConstant()) {
4938 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004939 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004940 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004941 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004942 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4943 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004944
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004945 break;
4946 }
4947
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004948 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004949 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004950 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004951 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004952
Roland Levillain80e67092016-01-08 16:04:55 +00004953 // Objects are handled in the switch.
4954 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004955 codegen_->MaybeRecordImplicitNullCheck(instruction);
4956 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004957}
4958
4959void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004960 LocationSummary* locations =
4961 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004962 locations->SetInAt(0, Location::RequiresRegister());
4963 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004964}
4965
4966void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4967 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01004968 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00004969 Register obj = locations->InAt(0).AsRegister<Register>();
4970 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004971 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004972 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004973}
4974
Artem Serov328429f2016-07-06 16:23:04 +01004975void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Roland Levillain4a3aa572016-08-15 13:17:06 +00004976 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4977 DCHECK(!kEmitCompilerReadBarrier);
Artem Serov328429f2016-07-06 16:23:04 +01004978 LocationSummary* locations =
4979 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4980
4981 locations->SetInAt(0, Location::RequiresRegister());
4982 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
4983 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4984}
4985
4986void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
4987 LocationSummary* locations = instruction->GetLocations();
4988 Location out = locations->Out();
4989 Location first = locations->InAt(0);
4990 Location second = locations->InAt(1);
4991
Roland Levillain4a3aa572016-08-15 13:17:06 +00004992 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4993 DCHECK(!kEmitCompilerReadBarrier);
4994
Artem Serov328429f2016-07-06 16:23:04 +01004995 if (second.IsRegister()) {
4996 __ add(out.AsRegister<Register>(),
4997 first.AsRegister<Register>(),
4998 ShifterOperand(second.AsRegister<Register>()));
4999 } else {
5000 __ AddConstant(out.AsRegister<Register>(),
5001 first.AsRegister<Register>(),
5002 second.GetConstant()->AsIntConstant()->GetValue());
5003 }
5004}
5005
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005006void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00005007 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
5008 ? LocationSummary::kCallOnSlowPath
5009 : LocationSummary::kNoCall;
5010 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005011 locations->SetInAt(0, Location::RequiresRegister());
5012 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01005013 if (instruction->HasUses()) {
5014 locations->SetOut(Location::SameAsFirstInput());
5015 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005016}
5017
5018void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
5019 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07005020 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005021 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005022 codegen_->AddSlowPath(slow_path);
5023
Roland Levillain271ab9c2014-11-27 15:23:57 +00005024 Register index = locations->InAt(0).AsRegister<Register>();
5025 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005026
5027 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01005028 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005029}
5030
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005031void CodeGeneratorARM::MarkGCCard(Register temp,
5032 Register card,
5033 Register object,
5034 Register value,
5035 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005036 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005037 if (can_be_null) {
5038 __ CompareAndBranchIfZero(value, &is_null);
5039 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005040 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005041 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5042 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005043 if (can_be_null) {
5044 __ Bind(&is_null);
5045 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005046}
5047
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005048void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005049 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005050}
5051
5052void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005053 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5054}
5055
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005056void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
5057 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5058}
5059
5060void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005061 HBasicBlock* block = instruction->GetBlock();
5062 if (block->GetLoopInformation() != nullptr) {
5063 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5064 // The back edge will generate the suspend check.
5065 return;
5066 }
5067 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5068 // The goto will generate the suspend check.
5069 return;
5070 }
5071 GenerateSuspendCheck(instruction, nullptr);
5072}
5073
5074void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5075 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005076 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005077 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5078 if (slow_path == nullptr) {
5079 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5080 instruction->SetSlowPath(slow_path);
5081 codegen_->AddSlowPath(slow_path);
5082 if (successor != nullptr) {
5083 DCHECK(successor->IsLoopHeader());
5084 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5085 }
5086 } else {
5087 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5088 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005089
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005090 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005091 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005092 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005093 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005094 __ Bind(slow_path->GetReturnLabel());
5095 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005096 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005097 __ b(slow_path->GetEntryLabel());
5098 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005099}
5100
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005101ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5102 return codegen_->GetAssembler();
5103}
5104
5105void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005106 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005107 Location source = move->GetSource();
5108 Location destination = move->GetDestination();
5109
5110 if (source.IsRegister()) {
5111 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005112 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005113 } else if (destination.IsFpuRegister()) {
5114 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005115 } else {
5116 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005117 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005118 SP, destination.GetStackIndex());
5119 }
5120 } else if (source.IsStackSlot()) {
5121 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005122 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005123 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005124 } else if (destination.IsFpuRegister()) {
5125 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005126 } else {
5127 DCHECK(destination.IsStackSlot());
5128 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5129 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5130 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005131 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005132 if (destination.IsRegister()) {
5133 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5134 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005135 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005136 } else {
5137 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005138 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5139 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005140 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005141 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005142 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5143 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005144 } else if (destination.IsRegisterPair()) {
5145 DCHECK(ExpectedPairLayout(destination));
5146 __ LoadFromOffset(
5147 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5148 } else {
5149 DCHECK(destination.IsFpuRegisterPair()) << destination;
5150 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5151 SP,
5152 source.GetStackIndex());
5153 }
5154 } else if (source.IsRegisterPair()) {
5155 if (destination.IsRegisterPair()) {
5156 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5157 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005158 } else if (destination.IsFpuRegisterPair()) {
5159 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5160 source.AsRegisterPairLow<Register>(),
5161 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005162 } else {
5163 DCHECK(destination.IsDoubleStackSlot()) << destination;
5164 DCHECK(ExpectedPairLayout(source));
5165 __ StoreToOffset(
5166 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5167 }
5168 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005169 if (destination.IsRegisterPair()) {
5170 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5171 destination.AsRegisterPairHigh<Register>(),
5172 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5173 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005174 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5175 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5176 } else {
5177 DCHECK(destination.IsDoubleStackSlot()) << destination;
5178 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5179 SP,
5180 destination.GetStackIndex());
5181 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005182 } else {
5183 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005184 HConstant* constant = source.GetConstant();
5185 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5186 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005187 if (destination.IsRegister()) {
5188 __ LoadImmediate(destination.AsRegister<Register>(), value);
5189 } else {
5190 DCHECK(destination.IsStackSlot());
5191 __ LoadImmediate(IP, value);
5192 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5193 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005194 } else if (constant->IsLongConstant()) {
5195 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005196 if (destination.IsRegisterPair()) {
5197 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5198 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005199 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005200 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005201 __ LoadImmediate(IP, Low32Bits(value));
5202 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5203 __ LoadImmediate(IP, High32Bits(value));
5204 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5205 }
5206 } else if (constant->IsDoubleConstant()) {
5207 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005208 if (destination.IsFpuRegisterPair()) {
5209 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005210 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005211 DCHECK(destination.IsDoubleStackSlot()) << destination;
5212 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005213 __ LoadImmediate(IP, Low32Bits(int_value));
5214 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5215 __ LoadImmediate(IP, High32Bits(int_value));
5216 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5217 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005218 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005219 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005220 float value = constant->AsFloatConstant()->GetValue();
5221 if (destination.IsFpuRegister()) {
5222 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5223 } else {
5224 DCHECK(destination.IsStackSlot());
5225 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5226 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5227 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005228 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005229 }
5230}
5231
5232void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5233 __ Mov(IP, reg);
5234 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5235 __ StoreToOffset(kStoreWord, IP, SP, mem);
5236}
5237
5238void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5239 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5240 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5241 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5242 SP, mem1 + stack_offset);
5243 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5244 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5245 SP, mem2 + stack_offset);
5246 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5247}
5248
5249void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005250 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005251 Location source = move->GetSource();
5252 Location destination = move->GetDestination();
5253
5254 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005255 DCHECK_NE(source.AsRegister<Register>(), IP);
5256 DCHECK_NE(destination.AsRegister<Register>(), IP);
5257 __ Mov(IP, source.AsRegister<Register>());
5258 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5259 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005260 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005261 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005262 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005263 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005264 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5265 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005266 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005267 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005268 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005269 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005270 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005271 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005272 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005273 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005274 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5275 destination.AsRegisterPairHigh<Register>(),
5276 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005277 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005278 Register low_reg = source.IsRegisterPair()
5279 ? source.AsRegisterPairLow<Register>()
5280 : destination.AsRegisterPairLow<Register>();
5281 int mem = source.IsRegisterPair()
5282 ? destination.GetStackIndex()
5283 : source.GetStackIndex();
5284 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005285 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005286 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005287 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005288 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005289 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5290 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005291 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005292 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005293 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005294 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5295 DRegister reg = source.IsFpuRegisterPair()
5296 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5297 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5298 int mem = source.IsFpuRegisterPair()
5299 ? destination.GetStackIndex()
5300 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005301 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005302 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005303 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005304 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5305 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5306 : destination.AsFpuRegister<SRegister>();
5307 int mem = source.IsFpuRegister()
5308 ? destination.GetStackIndex()
5309 : source.GetStackIndex();
5310
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005311 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005312 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005313 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005314 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005315 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5316 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005317 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005318 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005319 }
5320}
5321
5322void ParallelMoveResolverARM::SpillScratch(int reg) {
5323 __ Push(static_cast<Register>(reg));
5324}
5325
5326void ParallelMoveResolverARM::RestoreScratch(int reg) {
5327 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005328}
5329
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005330HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5331 HLoadClass::LoadKind desired_class_load_kind) {
5332 if (kEmitCompilerReadBarrier) {
5333 switch (desired_class_load_kind) {
5334 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5335 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5336 case HLoadClass::LoadKind::kBootImageAddress:
5337 // TODO: Implement for read barrier.
5338 return HLoadClass::LoadKind::kDexCacheViaMethod;
5339 default:
5340 break;
5341 }
5342 }
5343 switch (desired_class_load_kind) {
5344 case HLoadClass::LoadKind::kReferrersClass:
5345 break;
5346 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5347 DCHECK(!GetCompilerOptions().GetCompilePic());
5348 break;
5349 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5350 DCHECK(GetCompilerOptions().GetCompilePic());
5351 break;
5352 case HLoadClass::LoadKind::kBootImageAddress:
5353 break;
5354 case HLoadClass::LoadKind::kDexCacheAddress:
5355 DCHECK(Runtime::Current()->UseJitCompilation());
5356 break;
5357 case HLoadClass::LoadKind::kDexCachePcRelative:
5358 DCHECK(!Runtime::Current()->UseJitCompilation());
5359 // We disable pc-relative load when there is an irreducible loop, as the optimization
5360 // is incompatible with it.
5361 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5362 // with irreducible loops.
5363 if (GetGraph()->HasIrreducibleLoops()) {
5364 return HLoadClass::LoadKind::kDexCacheViaMethod;
5365 }
5366 break;
5367 case HLoadClass::LoadKind::kDexCacheViaMethod:
5368 break;
5369 }
5370 return desired_class_load_kind;
5371}
5372
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005373void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005374 if (cls->NeedsAccessCheck()) {
5375 InvokeRuntimeCallingConvention calling_convention;
5376 CodeGenerator::CreateLoadClassLocationSummary(
5377 cls,
5378 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5379 Location::RegisterLocation(R0),
5380 /* code_generator_supports_read_barrier */ true);
5381 return;
5382 }
5383
5384 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5385 ? LocationSummary::kCallOnSlowPath
5386 : LocationSummary::kNoCall;
5387 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
5388 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5389 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5390 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5391 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5392 locations->SetInAt(0, Location::RequiresRegister());
5393 }
5394 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005395}
5396
5397void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005398 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005399 if (cls->NeedsAccessCheck()) {
5400 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01005401 codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005402 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005403 return;
5404 }
5405
Roland Levillain3b359c72015-11-17 19:35:12 +00005406 Location out_loc = locations->Out();
5407 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005408
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005409 bool generate_null_check = false;
5410 switch (cls->GetLoadKind()) {
5411 case HLoadClass::LoadKind::kReferrersClass: {
5412 DCHECK(!cls->CanCallRuntime());
5413 DCHECK(!cls->MustGenerateClinitCheck());
5414 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5415 Register current_method = locations->InAt(0).AsRegister<Register>();
5416 GenerateGcRootFieldLoad(
5417 cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5418 break;
5419 }
5420 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
5421 DCHECK(!kEmitCompilerReadBarrier);
5422 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5423 cls->GetTypeIndex()));
5424 break;
5425 }
5426 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
5427 DCHECK(!kEmitCompilerReadBarrier);
5428 CodeGeneratorARM::PcRelativePatchInfo* labels =
5429 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5430 __ BindTrackedLabel(&labels->movw_label);
5431 __ movw(out, /* placeholder */ 0u);
5432 __ BindTrackedLabel(&labels->movt_label);
5433 __ movt(out, /* placeholder */ 0u);
5434 __ BindTrackedLabel(&labels->add_pc_label);
5435 __ add(out, out, ShifterOperand(PC));
5436 break;
5437 }
5438 case HLoadClass::LoadKind::kBootImageAddress: {
5439 DCHECK(!kEmitCompilerReadBarrier);
5440 DCHECK_NE(cls->GetAddress(), 0u);
5441 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5442 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5443 break;
5444 }
5445 case HLoadClass::LoadKind::kDexCacheAddress: {
5446 DCHECK_NE(cls->GetAddress(), 0u);
5447 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5448 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5449 // a 128B range. To try and reduce the number of literals if we load multiple types,
5450 // simply split the dex cache address to a 128B aligned base loaded from a literal
5451 // and the remaining offset embedded in the load.
5452 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5453 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5454 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5455 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5456 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5457 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5458 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
5459 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5460 generate_null_check = !cls->IsInDexCache();
5461 break;
5462 }
5463 case HLoadClass::LoadKind::kDexCachePcRelative: {
5464 Register base_reg = locations->InAt(0).AsRegister<Register>();
5465 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5466 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5467 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
5468 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset);
5469 generate_null_check = !cls->IsInDexCache();
5470 break;
5471 }
5472 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5473 // /* GcRoot<mirror::Class>[] */ out =
5474 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5475 Register current_method = locations->InAt(0).AsRegister<Register>();
5476 __ LoadFromOffset(kLoadWord,
5477 out,
5478 current_method,
5479 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5480 // /* GcRoot<mirror::Class> */ out = out[type_index]
5481 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
5482 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5483 generate_null_check = !cls->IsInDexCache();
5484 }
5485 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005486
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005487 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5488 DCHECK(cls->CanCallRuntime());
5489 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
5490 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5491 codegen_->AddSlowPath(slow_path);
5492 if (generate_null_check) {
5493 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5494 }
5495 if (cls->MustGenerateClinitCheck()) {
5496 GenerateClassInitializationCheck(slow_path, out);
5497 } else {
5498 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005499 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005500 }
5501}
5502
5503void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5504 LocationSummary* locations =
5505 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5506 locations->SetInAt(0, Location::RequiresRegister());
5507 if (check->HasUses()) {
5508 locations->SetOut(Location::SameAsFirstInput());
5509 }
5510}
5511
5512void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005513 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07005514 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005515 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005516 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005517 GenerateClassInitializationCheck(slow_path,
5518 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005519}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005520
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005521void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07005522 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005523 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5524 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5525 __ b(slow_path->GetEntryLabel(), LT);
5526 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5527 // properly. Therefore, we do a memory fence.
5528 __ dmb(ISH);
5529 __ Bind(slow_path->GetExitLabel());
5530}
5531
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005532HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5533 HLoadString::LoadKind desired_string_load_kind) {
5534 if (kEmitCompilerReadBarrier) {
5535 switch (desired_string_load_kind) {
5536 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5537 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5538 case HLoadString::LoadKind::kBootImageAddress:
5539 // TODO: Implement for read barrier.
5540 return HLoadString::LoadKind::kDexCacheViaMethod;
5541 default:
5542 break;
5543 }
5544 }
5545 switch (desired_string_load_kind) {
5546 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5547 DCHECK(!GetCompilerOptions().GetCompilePic());
5548 break;
5549 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5550 DCHECK(GetCompilerOptions().GetCompilePic());
5551 break;
5552 case HLoadString::LoadKind::kBootImageAddress:
5553 break;
5554 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005555 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005556 break;
5557 case HLoadString::LoadKind::kDexCachePcRelative:
Calin Juravleffc87072016-04-20 14:22:09 +01005558 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005559 // We disable pc-relative load when there is an irreducible loop, as the optimization
5560 // is incompatible with it.
5561 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5562 // with irreducible loops.
5563 if (GetGraph()->HasIrreducibleLoops()) {
5564 return HLoadString::LoadKind::kDexCacheViaMethod;
5565 }
5566 break;
5567 case HLoadString::LoadKind::kDexCacheViaMethod:
5568 break;
5569 }
5570 return desired_string_load_kind;
5571}
5572
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005573void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005574 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005575 ? LocationSummary::kCallOnSlowPath
5576 : LocationSummary::kNoCall;
5577 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005578 HLoadString::LoadKind load_kind = load->GetLoadKind();
5579 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod ||
5580 load_kind == HLoadString::LoadKind::kDexCachePcRelative) {
5581 locations->SetInAt(0, Location::RequiresRegister());
5582 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005583 locations->SetOut(Location::RequiresRegister());
5584}
5585
5586void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005587 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005588 Location out_loc = locations->Out();
5589 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005590
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005591 switch (load->GetLoadKind()) {
5592 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
5593 DCHECK(!kEmitCompilerReadBarrier);
5594 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5595 load->GetStringIndex()));
5596 return; // No dex cache slow path.
5597 }
5598 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
5599 DCHECK(!kEmitCompilerReadBarrier);
5600 CodeGeneratorARM::PcRelativePatchInfo* labels =
5601 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5602 __ BindTrackedLabel(&labels->movw_label);
5603 __ movw(out, /* placeholder */ 0u);
5604 __ BindTrackedLabel(&labels->movt_label);
5605 __ movt(out, /* placeholder */ 0u);
5606 __ BindTrackedLabel(&labels->add_pc_label);
5607 __ add(out, out, ShifterOperand(PC));
5608 return; // No dex cache slow path.
5609 }
5610 case HLoadString::LoadKind::kBootImageAddress: {
5611 DCHECK(!kEmitCompilerReadBarrier);
5612 DCHECK_NE(load->GetAddress(), 0u);
5613 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5614 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5615 return; // No dex cache slow path.
5616 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005617 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005618 break;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005619 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005620
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005621 // TODO: Re-add the compiler code to do string dex cache lookup again.
5622 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5623 codegen_->AddSlowPath(slow_path);
5624 __ b(slow_path->GetEntryLabel());
5625 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005626}
5627
David Brazdilcb1c0552015-08-04 16:22:25 +01005628static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005629 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005630}
5631
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005632void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5633 LocationSummary* locations =
5634 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5635 locations->SetOut(Location::RequiresRegister());
5636}
5637
5638void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005639 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005640 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5641}
5642
5643void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5644 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5645}
5646
5647void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005648 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005649 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005650}
5651
5652void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5653 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005654 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005655 InvokeRuntimeCallingConvention calling_convention;
5656 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5657}
5658
5659void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01005660 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005661 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005662}
5663
Roland Levillainc9285912015-12-18 10:38:42 +00005664static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
5665 return kEmitCompilerReadBarrier &&
5666 (kUseBakerReadBarrier ||
5667 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5668 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5669 type_check_kind == TypeCheckKind::kArrayObjectCheck);
5670}
5671
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005672void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005673 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00005674 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5675 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005676 case TypeCheckKind::kExactCheck:
5677 case TypeCheckKind::kAbstractClassCheck:
5678 case TypeCheckKind::kClassHierarchyCheck:
5679 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005680 call_kind =
5681 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005682 break;
5683 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005684 case TypeCheckKind::kUnresolvedCheck:
5685 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005686 call_kind = LocationSummary::kCallOnSlowPath;
5687 break;
5688 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005689
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005690 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Roland Levillain3b359c72015-11-17 19:35:12 +00005691 locations->SetInAt(0, Location::RequiresRegister());
5692 locations->SetInAt(1, Location::RequiresRegister());
5693 // The "out" register is used as a temporary, so it overlaps with the inputs.
5694 // Note that TypeCheckSlowPathARM uses this register too.
5695 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5696 // When read barriers are enabled, we need a temporary register for
5697 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005698 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00005699 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005700 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005701}
5702
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005703void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005704 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005705 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005706 Location obj_loc = locations->InAt(0);
5707 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005708 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005709 Location out_loc = locations->Out();
5710 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005711 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005712 locations->GetTemp(0) :
5713 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005714 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005715 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5716 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5717 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005718 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07005719 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005720
5721 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005722 // avoid null check if we know obj is not null.
5723 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00005724 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005725 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005726
Roland Levillain3b359c72015-11-17 19:35:12 +00005727 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005728 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005729
Roland Levillainc9285912015-12-18 10:38:42 +00005730 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005731 case TypeCheckKind::kExactCheck: {
5732 __ cmp(out, ShifterOperand(cls));
5733 // Classes must be equal for the instanceof to succeed.
5734 __ b(&zero, NE);
5735 __ LoadImmediate(out, 1);
5736 __ b(&done);
5737 break;
5738 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005739
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005740 case TypeCheckKind::kAbstractClassCheck: {
5741 // If the class is abstract, we eagerly fetch the super class of the
5742 // object to avoid doing a comparison we know will fail.
5743 Label loop;
5744 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005745 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005746 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005747 // If `out` is null, we use it for the result, and jump to `done`.
5748 __ CompareAndBranchIfZero(out, &done);
5749 __ cmp(out, ShifterOperand(cls));
5750 __ b(&loop, NE);
5751 __ LoadImmediate(out, 1);
5752 if (zero.IsLinked()) {
5753 __ b(&done);
5754 }
5755 break;
5756 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005757
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005758 case TypeCheckKind::kClassHierarchyCheck: {
5759 // Walk over the class hierarchy to find a match.
5760 Label loop, success;
5761 __ Bind(&loop);
5762 __ cmp(out, ShifterOperand(cls));
5763 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005764 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005765 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005766 __ CompareAndBranchIfNonZero(out, &loop);
5767 // If `out` is null, we use it for the result, and jump to `done`.
5768 __ b(&done);
5769 __ Bind(&success);
5770 __ LoadImmediate(out, 1);
5771 if (zero.IsLinked()) {
5772 __ b(&done);
5773 }
5774 break;
5775 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005776
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005777 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005778 // Do an exact check.
5779 Label exact_check;
5780 __ cmp(out, ShifterOperand(cls));
5781 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005782 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005783 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005784 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005785 // If `out` is null, we use it for the result, and jump to `done`.
5786 __ CompareAndBranchIfZero(out, &done);
5787 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5788 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5789 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005790 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005791 __ LoadImmediate(out, 1);
5792 __ b(&done);
5793 break;
5794 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005795
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005796 case TypeCheckKind::kArrayCheck: {
5797 __ cmp(out, ShifterOperand(cls));
5798 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00005799 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5800 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005801 codegen_->AddSlowPath(slow_path);
5802 __ b(slow_path->GetEntryLabel(), NE);
5803 __ LoadImmediate(out, 1);
5804 if (zero.IsLinked()) {
5805 __ b(&done);
5806 }
5807 break;
5808 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005809
Calin Juravle98893e12015-10-02 21:05:03 +01005810 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005811 case TypeCheckKind::kInterfaceCheck: {
5812 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00005813 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00005814 // cases.
5815 //
5816 // We cannot directly call the InstanceofNonTrivial runtime
5817 // entry point without resorting to a type checking slow path
5818 // here (i.e. by calling InvokeRuntime directly), as it would
5819 // require to assign fixed registers for the inputs of this
5820 // HInstanceOf instruction (following the runtime calling
5821 // convention), which might be cluttered by the potential first
5822 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00005823 //
5824 // TODO: Introduce a new runtime entry point taking the object
5825 // to test (instead of its class) as argument, and let it deal
5826 // with the read barrier issues. This will let us refactor this
5827 // case of the `switch` code as it was previously (with a direct
5828 // call to the runtime not using a type checking slow path).
5829 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00005830 DCHECK(locations->OnlyCallsOnSlowPath());
5831 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5832 /* is_fatal */ false);
5833 codegen_->AddSlowPath(slow_path);
5834 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005835 if (zero.IsLinked()) {
5836 __ b(&done);
5837 }
5838 break;
5839 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005840 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005841
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005842 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005843 __ Bind(&zero);
5844 __ LoadImmediate(out, 0);
5845 }
5846
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005847 if (done.IsLinked()) {
5848 __ Bind(&done);
5849 }
5850
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005851 if (slow_path != nullptr) {
5852 __ Bind(slow_path->GetExitLabel());
5853 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005854}
5855
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005856void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005857 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5858 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
5859
Roland Levillain3b359c72015-11-17 19:35:12 +00005860 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5861 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005862 case TypeCheckKind::kExactCheck:
5863 case TypeCheckKind::kAbstractClassCheck:
5864 case TypeCheckKind::kClassHierarchyCheck:
5865 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005866 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
5867 LocationSummary::kCallOnSlowPath :
5868 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005869 break;
5870 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005871 case TypeCheckKind::kUnresolvedCheck:
5872 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005873 call_kind = LocationSummary::kCallOnSlowPath;
5874 break;
5875 }
5876
Roland Levillain3b359c72015-11-17 19:35:12 +00005877 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
5878 locations->SetInAt(0, Location::RequiresRegister());
5879 locations->SetInAt(1, Location::RequiresRegister());
5880 // Note that TypeCheckSlowPathARM uses this "temp" register too.
5881 locations->AddTemp(Location::RequiresRegister());
5882 // When read barriers are enabled, we need an additional temporary
5883 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005884 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005885 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005886 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005887}
5888
5889void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005890 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005891 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005892 Location obj_loc = locations->InAt(0);
5893 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005894 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005895 Location temp_loc = locations->GetTemp(0);
5896 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005897 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005898 locations->GetTemp(1) :
5899 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005900 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005901 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5902 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5903 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005904
Roland Levillain3b359c72015-11-17 19:35:12 +00005905 bool is_type_check_slow_path_fatal =
5906 (type_check_kind == TypeCheckKind::kExactCheck ||
5907 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5908 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5909 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
5910 !instruction->CanThrowIntoCatchBlock();
5911 SlowPathCode* type_check_slow_path =
5912 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5913 is_type_check_slow_path_fatal);
5914 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005915
5916 Label done;
5917 // Avoid null check if we know obj is not null.
5918 if (instruction->MustDoNullCheck()) {
5919 __ CompareAndBranchIfZero(obj, &done);
5920 }
5921
Roland Levillain3b359c72015-11-17 19:35:12 +00005922 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005923 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005924
Roland Levillain3b359c72015-11-17 19:35:12 +00005925 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005926 case TypeCheckKind::kExactCheck:
5927 case TypeCheckKind::kArrayCheck: {
5928 __ cmp(temp, ShifterOperand(cls));
5929 // Jump to slow path for throwing the exception or doing a
5930 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005931 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005932 break;
5933 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005934
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005935 case TypeCheckKind::kAbstractClassCheck: {
5936 // If the class is abstract, we eagerly fetch the super class of the
5937 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00005938 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005939 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005940 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005941 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005942
5943 // If the class reference currently in `temp` is not null, jump
5944 // to the `compare_classes` label to compare it with the checked
5945 // class.
5946 __ CompareAndBranchIfNonZero(temp, &compare_classes);
5947 // Otherwise, jump to the slow path to throw the exception.
5948 //
5949 // But before, move back the object's class into `temp` before
5950 // going into the slow path, as it has been overwritten in the
5951 // meantime.
5952 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005953 GenerateReferenceLoadTwoRegisters(
5954 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005955 __ b(type_check_slow_path->GetEntryLabel());
5956
5957 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005958 __ cmp(temp, ShifterOperand(cls));
5959 __ b(&loop, NE);
5960 break;
5961 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005962
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005963 case TypeCheckKind::kClassHierarchyCheck: {
5964 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005965 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005966 __ Bind(&loop);
5967 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005968 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005969
Roland Levillain3b359c72015-11-17 19:35:12 +00005970 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005971 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005972
5973 // If the class reference currently in `temp` is not null, jump
5974 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005975 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005976 // Otherwise, jump to the slow path to throw the exception.
5977 //
5978 // But before, move back the object's class into `temp` before
5979 // going into the slow path, as it has been overwritten in the
5980 // meantime.
5981 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005982 GenerateReferenceLoadTwoRegisters(
5983 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005984 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005985 break;
5986 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005987
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005988 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005989 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005990 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005991 __ cmp(temp, ShifterOperand(cls));
5992 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005993
5994 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005995 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005996 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005997
5998 // If the component type is not null (i.e. the object is indeed
5999 // an array), jump to label `check_non_primitive_component_type`
6000 // to further check that this component type is not a primitive
6001 // type.
6002 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6003 // Otherwise, jump to the slow path to throw the exception.
6004 //
6005 // But before, move back the object's class into `temp` before
6006 // going into the slow path, as it has been overwritten in the
6007 // meantime.
6008 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006009 GenerateReferenceLoadTwoRegisters(
6010 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006011 __ b(type_check_slow_path->GetEntryLabel());
6012
6013 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006014 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006015 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6016 __ CompareAndBranchIfZero(temp, &done);
6017 // Same comment as above regarding `temp` and the slow path.
6018 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006019 GenerateReferenceLoadTwoRegisters(
6020 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006021 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006022 break;
6023 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006024
Calin Juravle98893e12015-10-02 21:05:03 +01006025 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006026 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006027 // We always go into the type check slow path for the unresolved
6028 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006029 //
6030 // We cannot directly call the CheckCast runtime entry point
6031 // without resorting to a type checking slow path here (i.e. by
6032 // calling InvokeRuntime directly), as it would require to
6033 // assign fixed registers for the inputs of this HInstanceOf
6034 // instruction (following the runtime calling convention), which
6035 // might be cluttered by the potential first read barrier
6036 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006037 //
6038 // TODO: Introduce a new runtime entry point taking the object
6039 // to test (instead of its class) as argument, and let it deal
6040 // with the read barrier issues. This will let us refactor this
6041 // case of the `switch` code as it was previously (with a direct
6042 // call to the runtime not using a type checking slow path).
6043 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006044 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006045 break;
6046 }
6047 __ Bind(&done);
6048
Roland Levillain3b359c72015-11-17 19:35:12 +00006049 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006050}
6051
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006052void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6053 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006054 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006055 InvokeRuntimeCallingConvention calling_convention;
6056 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6057}
6058
6059void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01006060 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
6061 instruction,
6062 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006063 if (instruction->IsEnter()) {
6064 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6065 } else {
6066 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6067 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006068}
6069
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006070void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6071void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6072void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006073
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006074void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006075 LocationSummary* locations =
6076 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6077 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6078 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006079 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006080 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006081 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006082 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006083}
6084
6085void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6086 HandleBitwiseOperation(instruction);
6087}
6088
6089void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6090 HandleBitwiseOperation(instruction);
6091}
6092
6093void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6094 HandleBitwiseOperation(instruction);
6095}
6096
Artem Serov7fc63502016-02-09 17:15:29 +00006097
6098void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6099 LocationSummary* locations =
6100 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6101 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6102 || instruction->GetResultType() == Primitive::kPrimLong);
6103
6104 locations->SetInAt(0, Location::RequiresRegister());
6105 locations->SetInAt(1, Location::RequiresRegister());
6106 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6107}
6108
6109void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6110 LocationSummary* locations = instruction->GetLocations();
6111 Location first = locations->InAt(0);
6112 Location second = locations->InAt(1);
6113 Location out = locations->Out();
6114
6115 if (instruction->GetResultType() == Primitive::kPrimInt) {
6116 Register first_reg = first.AsRegister<Register>();
6117 ShifterOperand second_reg(second.AsRegister<Register>());
6118 Register out_reg = out.AsRegister<Register>();
6119
6120 switch (instruction->GetOpKind()) {
6121 case HInstruction::kAnd:
6122 __ bic(out_reg, first_reg, second_reg);
6123 break;
6124 case HInstruction::kOr:
6125 __ orn(out_reg, first_reg, second_reg);
6126 break;
6127 // There is no EON on arm.
6128 case HInstruction::kXor:
6129 default:
6130 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6131 UNREACHABLE();
6132 }
6133 return;
6134
6135 } else {
6136 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6137 Register first_low = first.AsRegisterPairLow<Register>();
6138 Register first_high = first.AsRegisterPairHigh<Register>();
6139 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6140 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6141 Register out_low = out.AsRegisterPairLow<Register>();
6142 Register out_high = out.AsRegisterPairHigh<Register>();
6143
6144 switch (instruction->GetOpKind()) {
6145 case HInstruction::kAnd:
6146 __ bic(out_low, first_low, second_low);
6147 __ bic(out_high, first_high, second_high);
6148 break;
6149 case HInstruction::kOr:
6150 __ orn(out_low, first_low, second_low);
6151 __ orn(out_high, first_high, second_high);
6152 break;
6153 // There is no EON on arm.
6154 case HInstruction::kXor:
6155 default:
6156 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6157 UNREACHABLE();
6158 }
6159 }
6160}
6161
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006162void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6163 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6164 if (value == 0xffffffffu) {
6165 if (out != first) {
6166 __ mov(out, ShifterOperand(first));
6167 }
6168 return;
6169 }
6170 if (value == 0u) {
6171 __ mov(out, ShifterOperand(0));
6172 return;
6173 }
6174 ShifterOperand so;
6175 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6176 __ and_(out, first, so);
6177 } else {
6178 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6179 __ bic(out, first, ShifterOperand(~value));
6180 }
6181}
6182
6183void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6184 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6185 if (value == 0u) {
6186 if (out != first) {
6187 __ mov(out, ShifterOperand(first));
6188 }
6189 return;
6190 }
6191 if (value == 0xffffffffu) {
6192 __ mvn(out, ShifterOperand(0));
6193 return;
6194 }
6195 ShifterOperand so;
6196 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6197 __ orr(out, first, so);
6198 } else {
6199 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6200 __ orn(out, first, ShifterOperand(~value));
6201 }
6202}
6203
6204void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6205 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6206 if (value == 0u) {
6207 if (out != first) {
6208 __ mov(out, ShifterOperand(first));
6209 }
6210 return;
6211 }
6212 __ eor(out, first, ShifterOperand(value));
6213}
6214
Vladimir Marko59751a72016-08-05 14:37:27 +01006215void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6216 Location first,
6217 uint64_t value) {
6218 Register out_low = out.AsRegisterPairLow<Register>();
6219 Register out_high = out.AsRegisterPairHigh<Register>();
6220 Register first_low = first.AsRegisterPairLow<Register>();
6221 Register first_high = first.AsRegisterPairHigh<Register>();
6222 uint32_t value_low = Low32Bits(value);
6223 uint32_t value_high = High32Bits(value);
6224 if (value_low == 0u) {
6225 if (out_low != first_low) {
6226 __ mov(out_low, ShifterOperand(first_low));
6227 }
6228 __ AddConstant(out_high, first_high, value_high);
6229 return;
6230 }
6231 __ AddConstantSetFlags(out_low, first_low, value_low);
6232 ShifterOperand so;
6233 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6234 __ adc(out_high, first_high, so);
6235 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6236 __ sbc(out_high, first_high, so);
6237 } else {
6238 LOG(FATAL) << "Unexpected constant " << value_high;
6239 UNREACHABLE();
6240 }
6241}
6242
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006243void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6244 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006245 Location first = locations->InAt(0);
6246 Location second = locations->InAt(1);
6247 Location out = locations->Out();
6248
6249 if (second.IsConstant()) {
6250 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6251 uint32_t value_low = Low32Bits(value);
6252 if (instruction->GetResultType() == Primitive::kPrimInt) {
6253 Register first_reg = first.AsRegister<Register>();
6254 Register out_reg = out.AsRegister<Register>();
6255 if (instruction->IsAnd()) {
6256 GenerateAndConst(out_reg, first_reg, value_low);
6257 } else if (instruction->IsOr()) {
6258 GenerateOrrConst(out_reg, first_reg, value_low);
6259 } else {
6260 DCHECK(instruction->IsXor());
6261 GenerateEorConst(out_reg, first_reg, value_low);
6262 }
6263 } else {
6264 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6265 uint32_t value_high = High32Bits(value);
6266 Register first_low = first.AsRegisterPairLow<Register>();
6267 Register first_high = first.AsRegisterPairHigh<Register>();
6268 Register out_low = out.AsRegisterPairLow<Register>();
6269 Register out_high = out.AsRegisterPairHigh<Register>();
6270 if (instruction->IsAnd()) {
6271 GenerateAndConst(out_low, first_low, value_low);
6272 GenerateAndConst(out_high, first_high, value_high);
6273 } else if (instruction->IsOr()) {
6274 GenerateOrrConst(out_low, first_low, value_low);
6275 GenerateOrrConst(out_high, first_high, value_high);
6276 } else {
6277 DCHECK(instruction->IsXor());
6278 GenerateEorConst(out_low, first_low, value_low);
6279 GenerateEorConst(out_high, first_high, value_high);
6280 }
6281 }
6282 return;
6283 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006284
6285 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006286 Register first_reg = first.AsRegister<Register>();
6287 ShifterOperand second_reg(second.AsRegister<Register>());
6288 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006289 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006290 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006291 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006292 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006293 } else {
6294 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006295 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006296 }
6297 } else {
6298 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006299 Register first_low = first.AsRegisterPairLow<Register>();
6300 Register first_high = first.AsRegisterPairHigh<Register>();
6301 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6302 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6303 Register out_low = out.AsRegisterPairLow<Register>();
6304 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006305 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006306 __ and_(out_low, first_low, second_low);
6307 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006308 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006309 __ orr(out_low, first_low, second_low);
6310 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006311 } else {
6312 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006313 __ eor(out_low, first_low, second_low);
6314 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006315 }
6316 }
6317}
6318
Roland Levillainc9285912015-12-18 10:38:42 +00006319void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6320 Location out,
6321 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006322 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006323 Register out_reg = out.AsRegister<Register>();
6324 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006325 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006326 if (kUseBakerReadBarrier) {
6327 // Load with fast path based Baker's read barrier.
6328 // /* HeapReference<Object> */ out = *(out + offset)
6329 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006330 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006331 } else {
6332 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006333 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006334 // in the following move operation, as we will need it for the
6335 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006336 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006337 // /* HeapReference<Object> */ out = *(out + offset)
6338 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006339 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006340 }
6341 } else {
6342 // Plain load with no read barrier.
6343 // /* HeapReference<Object> */ out = *(out + offset)
6344 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6345 __ MaybeUnpoisonHeapReference(out_reg);
6346 }
6347}
6348
6349void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6350 Location out,
6351 Location obj,
6352 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006353 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006354 Register out_reg = out.AsRegister<Register>();
6355 Register obj_reg = obj.AsRegister<Register>();
6356 if (kEmitCompilerReadBarrier) {
6357 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006358 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006359 // Load with fast path based Baker's read barrier.
6360 // /* HeapReference<Object> */ out = *(obj + offset)
6361 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006362 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006363 } else {
6364 // Load with slow path based read barrier.
6365 // /* HeapReference<Object> */ out = *(obj + offset)
6366 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6367 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6368 }
6369 } else {
6370 // Plain load with no read barrier.
6371 // /* HeapReference<Object> */ out = *(obj + offset)
6372 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6373 __ MaybeUnpoisonHeapReference(out_reg);
6374 }
6375}
6376
6377void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6378 Location root,
6379 Register obj,
6380 uint32_t offset) {
6381 Register root_reg = root.AsRegister<Register>();
6382 if (kEmitCompilerReadBarrier) {
6383 if (kUseBakerReadBarrier) {
6384 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6385 // Baker's read barrier are used:
6386 //
6387 // root = obj.field;
6388 // if (Thread::Current()->GetIsGcMarking()) {
6389 // root = ReadBarrier::Mark(root)
6390 // }
6391
6392 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6393 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6394 static_assert(
6395 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6396 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6397 "have different sizes.");
6398 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6399 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6400 "have different sizes.");
6401
Vladimir Marko953437b2016-08-24 08:30:46 +00006402 // Slow path marking the GC root `root`.
Roland Levillainc9285912015-12-18 10:38:42 +00006403 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006404 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006405 codegen_->AddSlowPath(slow_path);
6406
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006407 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006408 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006409 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006410 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6411 __ Bind(slow_path->GetExitLabel());
6412 } else {
6413 // GC root loaded through a slow path for read barriers other
6414 // than Baker's.
6415 // /* GcRoot<mirror::Object>* */ root = obj + offset
6416 __ AddConstant(root_reg, obj, offset);
6417 // /* mirror::Object* */ root = root->Read()
6418 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6419 }
6420 } else {
6421 // Plain GC root load with no read barrier.
6422 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6423 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6424 // Note that GC roots are not affected by heap poisoning, thus we
6425 // do not have to unpoison `root_reg` here.
6426 }
6427}
6428
6429void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6430 Location ref,
6431 Register obj,
6432 uint32_t offset,
6433 Location temp,
6434 bool needs_null_check) {
6435 DCHECK(kEmitCompilerReadBarrier);
6436 DCHECK(kUseBakerReadBarrier);
6437
6438 // /* HeapReference<Object> */ ref = *(obj + offset)
6439 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006440 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006441 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006442 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006443}
6444
6445void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6446 Location ref,
6447 Register obj,
6448 uint32_t data_offset,
6449 Location index,
6450 Location temp,
6451 bool needs_null_check) {
6452 DCHECK(kEmitCompilerReadBarrier);
6453 DCHECK(kUseBakerReadBarrier);
6454
Roland Levillainbfea3352016-06-23 13:48:47 +01006455 static_assert(
6456 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6457 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006458 // /* HeapReference<Object> */ ref =
6459 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006460 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006461 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006462 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006463}
6464
6465void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6466 Location ref,
6467 Register obj,
6468 uint32_t offset,
6469 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006470 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006471 Location temp,
6472 bool needs_null_check) {
6473 DCHECK(kEmitCompilerReadBarrier);
6474 DCHECK(kUseBakerReadBarrier);
6475
6476 // In slow path based read barriers, the read barrier call is
6477 // inserted after the original load. However, in fast path based
6478 // Baker's read barriers, we need to perform the load of
6479 // mirror::Object::monitor_ *before* the original reference load.
6480 // This load-load ordering is required by the read barrier.
6481 // The fast path/slow path (for Baker's algorithm) should look like:
6482 //
6483 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6484 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6485 // HeapReference<Object> ref = *src; // Original reference load.
6486 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6487 // if (is_gray) {
6488 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6489 // }
6490 //
6491 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006492 // slightly more complex as it performs additional checks that we do
6493 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006494
6495 Register ref_reg = ref.AsRegister<Register>();
6496 Register temp_reg = temp.AsRegister<Register>();
6497 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6498
6499 // /* int32_t */ monitor = obj->monitor_
6500 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6501 if (needs_null_check) {
6502 MaybeRecordImplicitNullCheck(instruction);
6503 }
6504 // /* LockWord */ lock_word = LockWord(monitor)
6505 static_assert(sizeof(LockWord) == sizeof(int32_t),
6506 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006507
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006508 // Introduce a dependency on the lock_word including the rb_state,
6509 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006510 // a memory barrier (which would be more expensive).
Roland Levillain0b671c02016-08-19 12:02:34 +01006511 // `obj` is unchanged by this operation, but its value now depends
6512 // on `temp_reg`.
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006513 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006514
6515 // The actual reference load.
6516 if (index.IsValid()) {
Roland Levillainbfea3352016-06-23 13:48:47 +01006517 // Load types involving an "index": ArrayGet and
6518 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
6519 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006520 if (index.IsConstant()) {
6521 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006522 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006523 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6524 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006525 // Handle the special case of the
6526 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use
6527 // a register pair as index ("long offset"), of which only the low
6528 // part contains data.
6529 Register index_reg = index.IsRegisterPair()
6530 ? index.AsRegisterPairLow<Register>()
6531 : index.AsRegister<Register>();
6532 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006533 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6534 }
6535 } else {
6536 // /* HeapReference<Object> */ ref = *(obj + offset)
6537 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6538 }
6539
6540 // Object* ref = ref_addr->AsMirrorPtr()
6541 __ MaybeUnpoisonHeapReference(ref_reg);
6542
Vladimir Marko953437b2016-08-24 08:30:46 +00006543 // Slow path marking the object `ref` when it is gray.
Roland Levillainc9285912015-12-18 10:38:42 +00006544 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006545 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
Roland Levillainc9285912015-12-18 10:38:42 +00006546 AddSlowPath(slow_path);
6547
6548 // if (rb_state == ReadBarrier::gray_ptr_)
6549 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006550 // Given the numeric representation, it's enough to check the low bit of the
6551 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6552 // which can be a 16-bit instruction unlike the TST immediate.
6553 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6554 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6555 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6556 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6557 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006558 __ Bind(slow_path->GetExitLabel());
6559}
6560
6561void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6562 Location out,
6563 Location ref,
6564 Location obj,
6565 uint32_t offset,
6566 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006567 DCHECK(kEmitCompilerReadBarrier);
6568
Roland Levillainc9285912015-12-18 10:38:42 +00006569 // Insert a slow path based read barrier *after* the reference load.
6570 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006571 // If heap poisoning is enabled, the unpoisoning of the loaded
6572 // reference will be carried out by the runtime within the slow
6573 // path.
6574 //
6575 // Note that `ref` currently does not get unpoisoned (when heap
6576 // poisoning is enabled), which is alright as the `ref` argument is
6577 // not used by the artReadBarrierSlow entry point.
6578 //
6579 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
6580 SlowPathCode* slow_path = new (GetGraph()->GetArena())
6581 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6582 AddSlowPath(slow_path);
6583
Roland Levillain3b359c72015-11-17 19:35:12 +00006584 __ b(slow_path->GetEntryLabel());
6585 __ Bind(slow_path->GetExitLabel());
6586}
6587
Roland Levillainc9285912015-12-18 10:38:42 +00006588void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6589 Location out,
6590 Location ref,
6591 Location obj,
6592 uint32_t offset,
6593 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006594 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006595 // Baker's read barriers shall be handled by the fast path
6596 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6597 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006598 // If heap poisoning is enabled, unpoisoning will be taken care of
6599 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006600 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006601 } else if (kPoisonHeapReferences) {
6602 __ UnpoisonHeapReference(out.AsRegister<Register>());
6603 }
6604}
6605
Roland Levillainc9285912015-12-18 10:38:42 +00006606void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6607 Location out,
6608 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006609 DCHECK(kEmitCompilerReadBarrier);
6610
Roland Levillainc9285912015-12-18 10:38:42 +00006611 // Insert a slow path based read barrier *after* the GC root load.
6612 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006613 // Note that GC roots are not affected by heap poisoning, so we do
6614 // not need to do anything special for this here.
6615 SlowPathCode* slow_path =
6616 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6617 AddSlowPath(slow_path);
6618
Roland Levillain3b359c72015-11-17 19:35:12 +00006619 __ b(slow_path->GetEntryLabel());
6620 __ Bind(slow_path->GetExitLabel());
6621}
6622
Vladimir Markodc151b22015-10-15 18:02:30 +01006623HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6624 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
6625 MethodReference target_method) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006626 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6627 // We disable pc-relative load when there is an irreducible loop, as the optimization
6628 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006629 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6630 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006631 if (GetGraph()->HasIrreducibleLoops() &&
6632 (dispatch_info.method_load_kind ==
6633 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
6634 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
6635 }
6636
6637 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01006638 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
6639 if (&outer_dex_file != target_method.dex_file) {
6640 // Calls across dex files are more likely to exceed the available BL range,
6641 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
6642 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
6643 (desired_dispatch_info.method_load_kind ==
6644 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
6645 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
6646 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
6647 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006648 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01006649 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006650 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01006651 0u
6652 };
6653 }
6654 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006655 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006656}
6657
Vladimir Markob4536b72015-11-24 13:45:23 +00006658Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
6659 Register temp) {
6660 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
6661 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
6662 if (!invoke->GetLocations()->Intrinsified()) {
6663 return location.AsRegister<Register>();
6664 }
6665 // For intrinsics we allow any location, so it may be on the stack.
6666 if (!location.IsRegister()) {
6667 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
6668 return temp;
6669 }
6670 // For register locations, check if the register was saved. If so, get it from the stack.
6671 // Note: There is a chance that the register was saved but not overwritten, so we could
6672 // save one load. However, since this is just an intrinsic slow path we prefer this
6673 // simple and more robust approach rather that trying to determine if that's the case.
6674 SlowPathCode* slow_path = GetCurrentSlowPath();
6675 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
6676 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
6677 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
6678 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
6679 return temp;
6680 }
6681 return location.AsRegister<Register>();
6682}
6683
Nicolas Geoffray38207af2015-06-01 15:46:22 +01006684void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00006685 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00006686 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00006687 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6688 // LR = code address from literal pool with link-time patch.
6689 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00006690 break;
6691 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6692 // LR = invoke->GetDirectCodePtr();
6693 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00006694 break;
6695 default:
6696 break;
6697 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006698
Vladimir Marko58155012015-08-19 12:49:41 +00006699 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
6700 switch (invoke->GetMethodLoadKind()) {
6701 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
6702 // temp = thread->string_init_entrypoint
6703 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
6704 break;
6705 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006706 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006707 break;
6708 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
6709 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
6710 break;
6711 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
6712 __ LoadLiteral(temp.AsRegister<Register>(),
6713 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
6714 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00006715 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
6716 HArmDexCacheArraysBase* base =
6717 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
6718 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
6719 temp.AsRegister<Register>());
6720 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
6721 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
6722 break;
6723 }
Vladimir Marko58155012015-08-19 12:49:41 +00006724 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00006725 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006726 Register method_reg;
6727 Register reg = temp.AsRegister<Register>();
6728 if (current_method.IsRegister()) {
6729 method_reg = current_method.AsRegister<Register>();
6730 } else {
6731 DCHECK(invoke->GetLocations()->Intrinsified());
6732 DCHECK(!current_method.IsValid());
6733 method_reg = reg;
6734 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
6735 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006736 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
6737 __ LoadFromOffset(kLoadWord,
6738 reg,
6739 method_reg,
6740 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01006741 // temp = temp[index_in_cache];
6742 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
6743 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00006744 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
6745 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01006746 }
Vladimir Marko58155012015-08-19 12:49:41 +00006747 }
6748
6749 switch (invoke->GetCodePtrLocation()) {
6750 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
6751 __ bl(GetFrameEntryLabel());
6752 break;
6753 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01006754 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07006755 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01006756 // Arbitrarily branch to the BL itself, override at link time.
6757 __ bl(&relative_call_patches_.back().label);
6758 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006759 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6760 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6761 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00006762 // LR()
6763 __ blx(LR);
6764 break;
6765 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6766 // LR = callee_method->entry_point_from_quick_compiled_code_
6767 __ LoadFromOffset(
6768 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07006769 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006770 // LR()
6771 __ blx(LR);
6772 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006773 }
6774
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006775 DCHECK(!IsLeafMethod());
6776}
6777
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006778void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
6779 Register temp = temp_location.AsRegister<Register>();
6780 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6781 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006782
6783 // Use the calling convention instead of the location of the receiver, as
6784 // intrinsics may have put the receiver in a different register. In the intrinsics
6785 // slow path, the arguments have been moved to the right place, so here we are
6786 // guaranteed that the receiver is the first register of the calling convention.
6787 InvokeDexCallingConvention calling_convention;
6788 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006789 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00006790 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006791 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006792 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00006793 // Instead of simply (possibly) unpoisoning `temp` here, we should
6794 // emit a read barrier for the previous class reference load.
6795 // However this is not required in practice, as this is an
6796 // intermediate/temporary reference and because the current
6797 // concurrent copying collector keeps the from-space memory
6798 // intact/accessible until the end of the marking phase (the
6799 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006800 __ MaybeUnpoisonHeapReference(temp);
6801 // temp = temp->GetMethodAt(method_offset);
6802 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006803 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006804 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
6805 // LR = temp->GetEntryPoint();
6806 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
6807 // LR();
6808 __ blx(LR);
6809}
6810
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006811CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
6812 const DexFile& dex_file, uint32_t string_index) {
6813 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
6814}
6815
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006816CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
6817 const DexFile& dex_file, uint32_t type_index) {
6818 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
6819}
6820
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006821CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
6822 const DexFile& dex_file, uint32_t element_offset) {
6823 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
6824}
6825
6826CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
6827 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
6828 patches->emplace_back(dex_file, offset_or_index);
6829 return &patches->back();
6830}
6831
6832Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
6833 uint32_t string_index) {
6834 return boot_image_string_patches_.GetOrCreate(
6835 StringReference(&dex_file, string_index),
6836 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6837}
6838
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006839Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
6840 uint32_t type_index) {
6841 return boot_image_type_patches_.GetOrCreate(
6842 TypeReference(&dex_file, type_index),
6843 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6844}
6845
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006846Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
6847 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
6848 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
6849 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
6850}
6851
6852Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
6853 return DeduplicateUint32Literal(address, &uint32_literals_);
6854}
6855
Vladimir Marko58155012015-08-19 12:49:41 +00006856void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
6857 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00006858 size_t size =
6859 method_patches_.size() +
6860 call_patches_.size() +
6861 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006862 /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() +
6863 boot_image_string_patches_.size() +
6864 /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006865 boot_image_type_patches_.size() +
6866 /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006867 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00006868 linker_patches->reserve(size);
6869 for (const auto& entry : method_patches_) {
6870 const MethodReference& target_method = entry.first;
6871 Literal* literal = entry.second;
6872 DCHECK(literal->GetLabel()->IsBound());
6873 uint32_t literal_offset = literal->GetLabel()->Position();
6874 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
6875 target_method.dex_file,
6876 target_method.dex_method_index));
6877 }
6878 for (const auto& entry : call_patches_) {
6879 const MethodReference& target_method = entry.first;
6880 Literal* literal = entry.second;
6881 DCHECK(literal->GetLabel()->IsBound());
6882 uint32_t literal_offset = literal->GetLabel()->Position();
6883 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
6884 target_method.dex_file,
6885 target_method.dex_method_index));
6886 }
6887 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
6888 uint32_t literal_offset = info.label.Position();
6889 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
6890 info.target_method.dex_file,
6891 info.target_method.dex_method_index));
6892 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006893 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
6894 const DexFile& dex_file = info.target_dex_file;
6895 size_t base_element_offset = info.offset_or_index;
6896 DCHECK(info.add_pc_label.IsBound());
6897 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006898 // Add MOVW patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006899 DCHECK(info.movw_label.IsBound());
6900 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006901 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset,
6902 &dex_file,
6903 add_pc_offset,
6904 base_element_offset));
6905 // Add MOVT patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006906 DCHECK(info.movt_label.IsBound());
6907 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006908 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset,
6909 &dex_file,
6910 add_pc_offset,
6911 base_element_offset));
6912 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006913 for (const auto& entry : boot_image_string_patches_) {
6914 const StringReference& target_string = entry.first;
6915 Literal* literal = entry.second;
6916 DCHECK(literal->GetLabel()->IsBound());
6917 uint32_t literal_offset = literal->GetLabel()->Position();
6918 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
6919 target_string.dex_file,
6920 target_string.string_index));
6921 }
6922 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
6923 const DexFile& dex_file = info.target_dex_file;
6924 uint32_t string_index = info.offset_or_index;
6925 DCHECK(info.add_pc_label.IsBound());
6926 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6927 // Add MOVW patch.
6928 DCHECK(info.movw_label.IsBound());
6929 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6930 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset,
6931 &dex_file,
6932 add_pc_offset,
6933 string_index));
6934 // Add MOVT patch.
6935 DCHECK(info.movt_label.IsBound());
6936 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6937 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset,
6938 &dex_file,
6939 add_pc_offset,
6940 string_index));
6941 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006942 for (const auto& entry : boot_image_type_patches_) {
6943 const TypeReference& target_type = entry.first;
6944 Literal* literal = entry.second;
6945 DCHECK(literal->GetLabel()->IsBound());
6946 uint32_t literal_offset = literal->GetLabel()->Position();
6947 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
6948 target_type.dex_file,
6949 target_type.type_index));
6950 }
6951 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
6952 const DexFile& dex_file = info.target_dex_file;
6953 uint32_t type_index = info.offset_or_index;
6954 DCHECK(info.add_pc_label.IsBound());
6955 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6956 // Add MOVW patch.
6957 DCHECK(info.movw_label.IsBound());
6958 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6959 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset,
6960 &dex_file,
6961 add_pc_offset,
6962 type_index));
6963 // Add MOVT patch.
6964 DCHECK(info.movt_label.IsBound());
6965 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6966 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset,
6967 &dex_file,
6968 add_pc_offset,
6969 type_index));
6970 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006971 for (const auto& entry : boot_image_address_patches_) {
6972 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
6973 Literal* literal = entry.second;
6974 DCHECK(literal->GetLabel()->IsBound());
6975 uint32_t literal_offset = literal->GetLabel()->Position();
6976 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
6977 }
6978}
6979
6980Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
6981 return map->GetOrCreate(
6982 value,
6983 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00006984}
6985
6986Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
6987 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006988 return map->GetOrCreate(
6989 target_method,
6990 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00006991}
6992
6993Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
6994 return DeduplicateMethodLiteral(target_method, &method_patches_);
6995}
6996
6997Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
6998 return DeduplicateMethodLiteral(target_method, &call_patches_);
6999}
7000
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03007001void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7002 LocationSummary* locations =
7003 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7004 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7005 Location::RequiresRegister());
7006 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7007 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7008 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7009}
7010
7011void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7012 LocationSummary* locations = instr->GetLocations();
7013 Register res = locations->Out().AsRegister<Register>();
7014 Register accumulator =
7015 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7016 Register mul_left =
7017 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7018 Register mul_right =
7019 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7020
7021 if (instr->GetOpKind() == HInstruction::kAdd) {
7022 __ mla(res, mul_left, mul_right, accumulator);
7023 } else {
7024 __ mls(res, mul_left, mul_right, accumulator);
7025 }
7026}
7027
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007028void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007029 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007030 LOG(FATAL) << "Unreachable";
7031}
7032
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007033void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007034 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007035 LOG(FATAL) << "Unreachable";
7036}
7037
Mark Mendellfe57faa2015-09-18 09:26:15 -04007038// Simple implementation of packed switch - generate cascaded compare/jumps.
7039void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7040 LocationSummary* locations =
7041 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7042 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007043 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007044 codegen_->GetAssembler()->IsThumb()) {
7045 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7046 if (switch_instr->GetStartValue() != 0) {
7047 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7048 }
7049 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007050}
7051
7052void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7053 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007054 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007055 LocationSummary* locations = switch_instr->GetLocations();
7056 Register value_reg = locations->InAt(0).AsRegister<Register>();
7057 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7058
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007059 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007060 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007061 Register temp_reg = IP;
7062 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7063 // the immediate, because IP is used as the destination register. For the other
7064 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7065 // and they can be encoded in the instruction without making use of IP register.
7066 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7067
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007068 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007069 // Jump to successors[0] if value == lower_bound.
7070 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7071 int32_t last_index = 0;
7072 for (; num_entries - last_index > 2; last_index += 2) {
7073 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7074 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7075 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7076 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7077 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7078 }
7079 if (num_entries - last_index == 2) {
7080 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007081 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007082 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007083 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007084
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007085 // And the default for any other value.
7086 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7087 __ b(codegen_->GetLabelOf(default_block));
7088 }
7089 } else {
7090 // Create a table lookup.
7091 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7092
7093 // Materialize a pointer to the switch table
7094 std::vector<Label*> labels(num_entries);
7095 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7096 for (uint32_t i = 0; i < num_entries; i++) {
7097 labels[i] = codegen_->GetLabelOf(successors[i]);
7098 }
7099 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7100
7101 // Remove the bias.
7102 Register key_reg;
7103 if (lower_bound != 0) {
7104 key_reg = locations->GetTemp(1).AsRegister<Register>();
7105 __ AddConstant(key_reg, value_reg, -lower_bound);
7106 } else {
7107 key_reg = value_reg;
7108 }
7109
7110 // Check whether the value is in the table, jump to default block if not.
7111 __ CmpConstant(key_reg, num_entries - 1);
7112 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7113
7114 // Load the displacement from the table.
7115 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7116
7117 // Dispatch is a direct add to the PC (for Thumb2).
7118 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007119 }
7120}
7121
Vladimir Markob4536b72015-11-24 13:45:23 +00007122void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7123 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7124 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007125}
7126
7127void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7128 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007129 CodeGeneratorARM::PcRelativePatchInfo* labels =
7130 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007131 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007132 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007133 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007134 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007135 __ BindTrackedLabel(&labels->add_pc_label);
7136 __ add(base_reg, base_reg, ShifterOperand(PC));
7137}
7138
Andreas Gampe85b62f22015-09-09 13:15:38 -07007139void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7140 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007141 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007142 return;
7143 }
7144
7145 DCHECK_NE(type, Primitive::kPrimVoid);
7146
7147 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7148 if (return_loc.Equals(trg)) {
7149 return;
7150 }
7151
7152 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7153 // with the last branch.
7154 if (type == Primitive::kPrimLong) {
7155 HParallelMove parallel_move(GetGraph()->GetArena());
7156 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7157 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7158 GetMoveResolver()->EmitNativeCode(&parallel_move);
7159 } else if (type == Primitive::kPrimDouble) {
7160 HParallelMove parallel_move(GetGraph()->GetArena());
7161 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7162 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7163 GetMoveResolver()->EmitNativeCode(&parallel_move);
7164 } else {
7165 // Let the parallel move resolver take care of all of this.
7166 HParallelMove parallel_move(GetGraph()->GetArena());
7167 parallel_move.AddMove(return_loc, trg, type, nullptr);
7168 GetMoveResolver()->EmitNativeCode(&parallel_move);
7169 }
7170}
7171
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007172void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7173 LocationSummary* locations =
7174 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7175 locations->SetInAt(0, Location::RequiresRegister());
7176 locations->SetOut(Location::RequiresRegister());
7177}
7178
7179void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7180 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007181 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007182 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007183 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007184 __ LoadFromOffset(kLoadWord,
7185 locations->Out().AsRegister<Register>(),
7186 locations->InAt(0).AsRegister<Register>(),
7187 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007188 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007189 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007190 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007191 __ LoadFromOffset(kLoadWord,
7192 locations->Out().AsRegister<Register>(),
7193 locations->InAt(0).AsRegister<Register>(),
7194 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7195 __ LoadFromOffset(kLoadWord,
7196 locations->Out().AsRegister<Register>(),
7197 locations->Out().AsRegister<Register>(),
7198 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007199 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007200}
7201
Roland Levillain4d027112015-07-01 15:41:14 +01007202#undef __
7203#undef QUICK_ENTRY_POINT
7204
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007205} // namespace arm
7206} // namespace art