blob: d8866a92c1fbe3c7908bffa5cea7aef9ef43edd2 [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());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001212 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001213}
1214
Roland Levillaindec8f632016-07-22 17:10:06 +01001215void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1216 HInstruction* instruction,
1217 SlowPathCode* slow_path) {
1218 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001219 GenerateInvokeRuntime(entry_point_offset);
1220}
1221
1222void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) {
Roland Levillaindec8f632016-07-22 17:10:06 +01001223 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1224 __ blx(LR);
1225}
1226
David Brazdilfc6a86a2015-06-26 10:33:45 +00001227void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001228 DCHECK(!successor->IsExitBlock());
1229
1230 HBasicBlock* block = got->GetBlock();
1231 HInstruction* previous = got->GetPrevious();
1232
1233 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001234 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001235 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1236 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1237 return;
1238 }
1239
1240 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1241 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1242 }
1243 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001244 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001245 }
1246}
1247
David Brazdilfc6a86a2015-06-26 10:33:45 +00001248void LocationsBuilderARM::VisitGoto(HGoto* got) {
1249 got->SetLocations(nullptr);
1250}
1251
1252void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1253 HandleGoto(got, got->GetSuccessor());
1254}
1255
1256void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1257 try_boundary->SetLocations(nullptr);
1258}
1259
1260void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1261 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1262 if (!successor->IsExitBlock()) {
1263 HandleGoto(try_boundary, successor);
1264 }
1265}
1266
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001267void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001268 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001269}
1270
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001271void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001272}
1273
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001274void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1275 Primitive::Type type = instruction->InputAt(0)->GetType();
1276 Location lhs_loc = instruction->GetLocations()->InAt(0);
1277 Location rhs_loc = instruction->GetLocations()->InAt(1);
1278 if (rhs_loc.IsConstant()) {
1279 // 0.0 is the only immediate that can be encoded directly in
1280 // a VCMP instruction.
1281 //
1282 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1283 // specify that in a floating-point comparison, positive zero
1284 // and negative zero are considered equal, so we can use the
1285 // literal 0.0 for both cases here.
1286 //
1287 // Note however that some methods (Float.equal, Float.compare,
1288 // Float.compareTo, Double.equal, Double.compare,
1289 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1290 // StrictMath.min) consider 0.0 to be (strictly) greater than
1291 // -0.0. So if we ever translate calls to these methods into a
1292 // HCompare instruction, we must handle the -0.0 case with
1293 // care here.
1294 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1295 if (type == Primitive::kPrimFloat) {
1296 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1297 } else {
1298 DCHECK_EQ(type, Primitive::kPrimDouble);
1299 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1300 }
1301 } else {
1302 if (type == Primitive::kPrimFloat) {
1303 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1304 } else {
1305 DCHECK_EQ(type, Primitive::kPrimDouble);
1306 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1307 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1308 }
1309 }
1310}
1311
Roland Levillain4fa13f62015-07-06 18:11:54 +01001312void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1313 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001314 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001315 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001316 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001317}
1318
1319void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1320 Label* true_label,
1321 Label* false_label) {
1322 LocationSummary* locations = cond->GetLocations();
1323 Location left = locations->InAt(0);
1324 Location right = locations->InAt(1);
1325 IfCondition if_cond = cond->GetCondition();
1326
1327 Register left_high = left.AsRegisterPairHigh<Register>();
1328 Register left_low = left.AsRegisterPairLow<Register>();
1329 IfCondition true_high_cond = if_cond;
1330 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001331 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001332
1333 // Set the conditions for the test, remembering that == needs to be
1334 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001335 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001336 switch (if_cond) {
1337 case kCondEQ:
1338 case kCondNE:
1339 // Nothing to do.
1340 break;
1341 case kCondLT:
1342 false_high_cond = kCondGT;
1343 break;
1344 case kCondLE:
1345 true_high_cond = kCondLT;
1346 break;
1347 case kCondGT:
1348 false_high_cond = kCondLT;
1349 break;
1350 case kCondGE:
1351 true_high_cond = kCondGT;
1352 break;
Aart Bike9f37602015-10-09 11:15:55 -07001353 case kCondB:
1354 false_high_cond = kCondA;
1355 break;
1356 case kCondBE:
1357 true_high_cond = kCondB;
1358 break;
1359 case kCondA:
1360 false_high_cond = kCondB;
1361 break;
1362 case kCondAE:
1363 true_high_cond = kCondA;
1364 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001365 }
1366 if (right.IsConstant()) {
1367 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1368 int32_t val_low = Low32Bits(value);
1369 int32_t val_high = High32Bits(value);
1370
Vladimir Markoac6ac102015-12-17 12:14:00 +00001371 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001372 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001373 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001374 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001375 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001376 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001377 __ b(true_label, ARMCondition(true_high_cond));
1378 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001379 }
1380 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001381 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001382 } else {
1383 Register right_high = right.AsRegisterPairHigh<Register>();
1384 Register right_low = right.AsRegisterPairLow<Register>();
1385
1386 __ cmp(left_high, ShifterOperand(right_high));
1387 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001388 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001389 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001390 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001391 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001392 __ b(true_label, ARMCondition(true_high_cond));
1393 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001394 }
1395 // Must be equal high, so compare the lows.
1396 __ cmp(left_low, ShifterOperand(right_low));
1397 }
1398 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001399 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001400 __ b(true_label, final_condition);
1401}
1402
David Brazdil0debae72015-11-12 18:37:00 +00001403void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1404 Label* true_target_in,
1405 Label* false_target_in) {
1406 // Generated branching requires both targets to be explicit. If either of the
1407 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1408 Label fallthrough_target;
1409 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1410 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1411
Roland Levillain4fa13f62015-07-06 18:11:54 +01001412 Primitive::Type type = condition->InputAt(0)->GetType();
1413 switch (type) {
1414 case Primitive::kPrimLong:
1415 GenerateLongComparesAndJumps(condition, true_target, false_target);
1416 break;
1417 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001418 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001419 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001420 GenerateFPJumps(condition, true_target, false_target);
1421 break;
1422 default:
1423 LOG(FATAL) << "Unexpected compare type " << type;
1424 }
1425
David Brazdil0debae72015-11-12 18:37:00 +00001426 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001427 __ b(false_target);
1428 }
David Brazdil0debae72015-11-12 18:37:00 +00001429
1430 if (fallthrough_target.IsLinked()) {
1431 __ Bind(&fallthrough_target);
1432 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001433}
1434
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001435void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001436 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001437 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001438 Label* false_target) {
1439 HInstruction* cond = instruction->InputAt(condition_input_index);
1440
1441 if (true_target == nullptr && false_target == nullptr) {
1442 // Nothing to do. The code always falls through.
1443 return;
1444 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001445 // Constant condition, statically compared against "true" (integer value 1).
1446 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001447 if (true_target != nullptr) {
1448 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001449 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001450 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001451 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001452 if (false_target != nullptr) {
1453 __ b(false_target);
1454 }
1455 }
1456 return;
1457 }
1458
1459 // The following code generates these patterns:
1460 // (1) true_target == nullptr && false_target != nullptr
1461 // - opposite condition true => branch to false_target
1462 // (2) true_target != nullptr && false_target == nullptr
1463 // - condition true => branch to true_target
1464 // (3) true_target != nullptr && false_target != nullptr
1465 // - condition true => branch to true_target
1466 // - branch to false_target
1467 if (IsBooleanValueOrMaterializedCondition(cond)) {
1468 // Condition has been materialized, compare the output to 0.
1469 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1470 DCHECK(cond_val.IsRegister());
1471 if (true_target == nullptr) {
1472 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1473 } else {
1474 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001475 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001476 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001477 // Condition has not been materialized. Use its inputs as the comparison and
1478 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001479 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001480
1481 // If this is a long or FP comparison that has been folded into
1482 // the HCondition, generate the comparison directly.
1483 Primitive::Type type = condition->InputAt(0)->GetType();
1484 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1485 GenerateCompareTestAndBranch(condition, true_target, false_target);
1486 return;
1487 }
1488
1489 LocationSummary* locations = cond->GetLocations();
1490 DCHECK(locations->InAt(0).IsRegister());
1491 Register left = locations->InAt(0).AsRegister<Register>();
1492 Location right = locations->InAt(1);
1493 if (right.IsRegister()) {
1494 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001495 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001496 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001497 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001498 }
1499 if (true_target == nullptr) {
1500 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1501 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001502 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001503 }
Dave Allison20dfc792014-06-16 20:44:29 -07001504 }
David Brazdil0debae72015-11-12 18:37:00 +00001505
1506 // If neither branch falls through (case 3), the conditional branch to `true_target`
1507 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1508 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001509 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001510 }
1511}
1512
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001513void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001514 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1515 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001516 locations->SetInAt(0, Location::RequiresRegister());
1517 }
1518}
1519
1520void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001521 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1522 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1523 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1524 nullptr : codegen_->GetLabelOf(true_successor);
1525 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1526 nullptr : codegen_->GetLabelOf(false_successor);
1527 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001528}
1529
1530void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1531 LocationSummary* locations = new (GetGraph()->GetArena())
1532 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00001533 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001534 locations->SetInAt(0, Location::RequiresRegister());
1535 }
1536}
1537
1538void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08001539 SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001540 GenerateTestAndBranch(deoptimize,
1541 /* condition_input_index */ 0,
1542 slow_path->GetEntryLabel(),
1543 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001544}
Dave Allison20dfc792014-06-16 20:44:29 -07001545
David Brazdil74eb1b22015-12-14 11:44:01 +00001546void LocationsBuilderARM::VisitSelect(HSelect* select) {
1547 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1548 if (Primitive::IsFloatingPointType(select->GetType())) {
1549 locations->SetInAt(0, Location::RequiresFpuRegister());
1550 locations->SetInAt(1, Location::RequiresFpuRegister());
1551 } else {
1552 locations->SetInAt(0, Location::RequiresRegister());
1553 locations->SetInAt(1, Location::RequiresRegister());
1554 }
1555 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1556 locations->SetInAt(2, Location::RequiresRegister());
1557 }
1558 locations->SetOut(Location::SameAsFirstInput());
1559}
1560
1561void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1562 LocationSummary* locations = select->GetLocations();
1563 Label false_target;
1564 GenerateTestAndBranch(select,
1565 /* condition_input_index */ 2,
1566 /* true_target */ nullptr,
1567 &false_target);
1568 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1569 __ Bind(&false_target);
1570}
1571
David Srbecky0cf44932015-12-09 14:09:59 +00001572void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1573 new (GetGraph()->GetArena()) LocationSummary(info);
1574}
1575
David Srbeckyd28f4a02016-03-14 17:14:24 +00001576void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1577 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001578}
1579
1580void CodeGeneratorARM::GenerateNop() {
1581 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001582}
1583
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001584void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001585 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001586 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001587 // Handle the long/FP comparisons made in instruction simplification.
1588 switch (cond->InputAt(0)->GetType()) {
1589 case Primitive::kPrimLong:
1590 locations->SetInAt(0, Location::RequiresRegister());
1591 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001592 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001593 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1594 }
1595 break;
1596
1597 case Primitive::kPrimFloat:
1598 case Primitive::kPrimDouble:
1599 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001600 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001601 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001602 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1603 }
1604 break;
1605
1606 default:
1607 locations->SetInAt(0, Location::RequiresRegister());
1608 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001609 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001610 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1611 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001612 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001613}
1614
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001615void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001616 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001617 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001618 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001619
1620 LocationSummary* locations = cond->GetLocations();
1621 Location left = locations->InAt(0);
1622 Location right = locations->InAt(1);
1623 Register out = locations->Out().AsRegister<Register>();
1624 Label true_label, false_label;
1625
1626 switch (cond->InputAt(0)->GetType()) {
1627 default: {
1628 // Integer case.
1629 if (right.IsRegister()) {
1630 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1631 } else {
1632 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001633 __ CmpConstant(left.AsRegister<Register>(),
1634 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001635 }
Aart Bike9f37602015-10-09 11:15:55 -07001636 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001637 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001638 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001639 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001640 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001641 return;
1642 }
1643 case Primitive::kPrimLong:
1644 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1645 break;
1646 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001647 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001648 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001649 GenerateFPJumps(cond, &true_label, &false_label);
1650 break;
1651 }
1652
1653 // Convert the jumps into the result.
1654 Label done_label;
1655
1656 // False case: result = 0.
1657 __ Bind(&false_label);
1658 __ LoadImmediate(out, 0);
1659 __ b(&done_label);
1660
1661 // True case: result = 1.
1662 __ Bind(&true_label);
1663 __ LoadImmediate(out, 1);
1664 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001665}
1666
1667void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001668 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001669}
1670
1671void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001672 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001673}
1674
1675void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001676 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001677}
1678
1679void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001680 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001681}
1682
1683void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001684 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001685}
1686
1687void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001688 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001689}
1690
1691void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001692 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001693}
1694
1695void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001696 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001697}
1698
1699void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001700 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001701}
1702
1703void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001704 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001705}
1706
1707void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001708 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001709}
1710
1711void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001712 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001713}
1714
Aart Bike9f37602015-10-09 11:15:55 -07001715void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001716 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001717}
1718
1719void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001720 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001721}
1722
1723void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001724 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001725}
1726
1727void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001728 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001729}
1730
1731void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001732 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001733}
1734
1735void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001736 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001737}
1738
1739void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001740 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001741}
1742
1743void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001744 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001745}
1746
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001747void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001748 LocationSummary* locations =
1749 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001750 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001751}
1752
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001753void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001754 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001755}
1756
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001757void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1758 LocationSummary* locations =
1759 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1760 locations->SetOut(Location::ConstantLocation(constant));
1761}
1762
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001763void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001764 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001765}
1766
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001767void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001768 LocationSummary* locations =
1769 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001770 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001771}
1772
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001773void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001774 // Will be generated at use site.
1775}
1776
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001777void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1778 LocationSummary* locations =
1779 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1780 locations->SetOut(Location::ConstantLocation(constant));
1781}
1782
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001783void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001784 // Will be generated at use site.
1785}
1786
1787void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1788 LocationSummary* locations =
1789 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1790 locations->SetOut(Location::ConstantLocation(constant));
1791}
1792
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001793void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001794 // Will be generated at use site.
1795}
1796
Calin Juravle27df7582015-04-17 19:12:31 +01001797void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1798 memory_barrier->SetLocations(nullptr);
1799}
1800
1801void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00001802 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01001803}
1804
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001805void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001806 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001807}
1808
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001809void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001810 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001811}
1812
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001813void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001814 LocationSummary* locations =
1815 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001816 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001817}
1818
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001819void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001820 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001821}
1822
Calin Juravle175dc732015-08-25 15:42:32 +01001823void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1824 // The trampoline uses the same calling convention as dex calling conventions,
1825 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1826 // the method_idx.
1827 HandleInvoke(invoke);
1828}
1829
1830void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1831 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1832}
1833
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001834void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001835 // Explicit clinit checks triggered by static invokes must have been pruned by
1836 // art::PrepareForRegisterAllocation.
1837 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001838
Vladimir Marko68c981f2016-08-26 13:13:33 +01001839 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001840 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00001841 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
1842 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
1843 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001844 return;
1845 }
1846
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001847 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00001848
1849 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
1850 if (invoke->HasPcRelativeDexCache()) {
1851 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
1852 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001853}
1854
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001855static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1856 if (invoke->GetLocations()->Intrinsified()) {
1857 IntrinsicCodeGeneratorARM intrinsic(codegen);
1858 intrinsic.Dispatch(invoke);
1859 return true;
1860 }
1861 return false;
1862}
1863
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001864void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001865 // Explicit clinit checks triggered by static invokes must have been pruned by
1866 // art::PrepareForRegisterAllocation.
1867 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001868
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001869 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1870 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001871 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001872
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001873 LocationSummary* locations = invoke->GetLocations();
1874 codegen_->GenerateStaticOrDirectCall(
1875 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001876 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001877}
1878
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001879void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001880 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001881 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001882}
1883
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001884void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Vladimir Marko68c981f2016-08-26 13:13:33 +01001885 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001886 if (intrinsic.TryDispatch(invoke)) {
1887 return;
1888 }
1889
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001890 HandleInvoke(invoke);
1891}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001892
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001893void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001894 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1895 return;
1896 }
1897
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001898 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001899 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001900 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001901}
1902
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001903void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1904 HandleInvoke(invoke);
1905 // Add the hidden argument.
1906 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1907}
1908
1909void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1910 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00001911 LocationSummary* locations = invoke->GetLocations();
1912 Register temp = locations->GetTemp(0).AsRegister<Register>();
1913 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001914 Location receiver = locations->InAt(0);
1915 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1916
Roland Levillain3b359c72015-11-17 19:35:12 +00001917 // Set the hidden argument. This is safe to do this here, as R12
1918 // won't be modified thereafter, before the `blx` (call) instruction.
1919 DCHECK_EQ(R12, hidden_reg);
1920 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001921
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001922 if (receiver.IsStackSlot()) {
1923 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00001924 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001925 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1926 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00001927 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00001928 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001929 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001930 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00001931 // Instead of simply (possibly) unpoisoning `temp` here, we should
1932 // emit a read barrier for the previous class reference load.
1933 // However this is not required in practice, as this is an
1934 // intermediate/temporary reference and because the current
1935 // concurrent copying collector keeps the from-space memory
1936 // intact/accessible until the end of the marking phase (the
1937 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01001938 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001939 __ LoadFromOffset(kLoadWord, temp, temp,
1940 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
1941 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00001942 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001943 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001944 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00001945 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07001946 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001947 // LR = temp->GetEntryPoint();
1948 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1949 // LR();
1950 __ blx(LR);
1951 DCHECK(!codegen_->IsLeafMethod());
1952 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1953}
1954
Roland Levillain88cb1752014-10-20 16:36:47 +01001955void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1956 LocationSummary* locations =
1957 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1958 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001959 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001960 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001961 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1962 break;
1963 }
1964 case Primitive::kPrimLong: {
1965 locations->SetInAt(0, Location::RequiresRegister());
1966 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001967 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001968 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001969
Roland Levillain88cb1752014-10-20 16:36:47 +01001970 case Primitive::kPrimFloat:
1971 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001972 locations->SetInAt(0, Location::RequiresFpuRegister());
1973 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001974 break;
1975
1976 default:
1977 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1978 }
1979}
1980
1981void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1982 LocationSummary* locations = neg->GetLocations();
1983 Location out = locations->Out();
1984 Location in = locations->InAt(0);
1985 switch (neg->GetResultType()) {
1986 case Primitive::kPrimInt:
1987 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001988 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001989 break;
1990
1991 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001992 DCHECK(in.IsRegisterPair());
1993 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1994 __ rsbs(out.AsRegisterPairLow<Register>(),
1995 in.AsRegisterPairLow<Register>(),
1996 ShifterOperand(0));
1997 // We cannot emit an RSC (Reverse Subtract with Carry)
1998 // instruction here, as it does not exist in the Thumb-2
1999 // instruction set. We use the following approach
2000 // using SBC and SUB instead.
2001 //
2002 // out.hi = -C
2003 __ sbc(out.AsRegisterPairHigh<Register>(),
2004 out.AsRegisterPairHigh<Register>(),
2005 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2006 // out.hi = out.hi - in.hi
2007 __ sub(out.AsRegisterPairHigh<Register>(),
2008 out.AsRegisterPairHigh<Register>(),
2009 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2010 break;
2011
Roland Levillain88cb1752014-10-20 16:36:47 +01002012 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002013 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002014 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002015 break;
2016
Roland Levillain88cb1752014-10-20 16:36:47 +01002017 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002018 DCHECK(in.IsFpuRegisterPair());
2019 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2020 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002021 break;
2022
2023 default:
2024 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2025 }
2026}
2027
Roland Levillaindff1f282014-11-05 14:15:05 +00002028void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002029 Primitive::Type result_type = conversion->GetResultType();
2030 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002031 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002032
Roland Levillain5b3ee562015-04-14 16:02:41 +01002033 // The float-to-long, double-to-long and long-to-float type conversions
2034 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002035 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002036 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2037 && result_type == Primitive::kPrimLong)
2038 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002039 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002040 : LocationSummary::kNoCall;
2041 LocationSummary* locations =
2042 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2043
David Brazdilb2bd1c52015-03-25 11:17:37 +00002044 // The Java language does not allow treating boolean as an integral type but
2045 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002046
Roland Levillaindff1f282014-11-05 14:15:05 +00002047 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002048 case Primitive::kPrimByte:
2049 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002050 case Primitive::kPrimLong:
2051 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002052 case Primitive::kPrimBoolean:
2053 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002054 case Primitive::kPrimShort:
2055 case Primitive::kPrimInt:
2056 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002057 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002058 locations->SetInAt(0, Location::RequiresRegister());
2059 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2060 break;
2061
2062 default:
2063 LOG(FATAL) << "Unexpected type conversion from " << input_type
2064 << " to " << result_type;
2065 }
2066 break;
2067
Roland Levillain01a8d712014-11-14 16:27:39 +00002068 case Primitive::kPrimShort:
2069 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002070 case Primitive::kPrimLong:
2071 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002072 case Primitive::kPrimBoolean:
2073 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002074 case Primitive::kPrimByte:
2075 case Primitive::kPrimInt:
2076 case Primitive::kPrimChar:
2077 // Processing a Dex `int-to-short' instruction.
2078 locations->SetInAt(0, Location::RequiresRegister());
2079 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2080 break;
2081
2082 default:
2083 LOG(FATAL) << "Unexpected type conversion from " << input_type
2084 << " to " << result_type;
2085 }
2086 break;
2087
Roland Levillain946e1432014-11-11 17:35:19 +00002088 case Primitive::kPrimInt:
2089 switch (input_type) {
2090 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002091 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002092 locations->SetInAt(0, Location::Any());
2093 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2094 break;
2095
2096 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002097 // Processing a Dex `float-to-int' instruction.
2098 locations->SetInAt(0, Location::RequiresFpuRegister());
2099 locations->SetOut(Location::RequiresRegister());
2100 locations->AddTemp(Location::RequiresFpuRegister());
2101 break;
2102
Roland Levillain946e1432014-11-11 17:35:19 +00002103 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002104 // Processing a Dex `double-to-int' instruction.
2105 locations->SetInAt(0, Location::RequiresFpuRegister());
2106 locations->SetOut(Location::RequiresRegister());
2107 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002108 break;
2109
2110 default:
2111 LOG(FATAL) << "Unexpected type conversion from " << input_type
2112 << " to " << result_type;
2113 }
2114 break;
2115
Roland Levillaindff1f282014-11-05 14:15:05 +00002116 case Primitive::kPrimLong:
2117 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002118 case Primitive::kPrimBoolean:
2119 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002120 case Primitive::kPrimByte:
2121 case Primitive::kPrimShort:
2122 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002123 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002124 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002125 locations->SetInAt(0, Location::RequiresRegister());
2126 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2127 break;
2128
Roland Levillain624279f2014-12-04 11:54:28 +00002129 case Primitive::kPrimFloat: {
2130 // Processing a Dex `float-to-long' instruction.
2131 InvokeRuntimeCallingConvention calling_convention;
2132 locations->SetInAt(0, Location::FpuRegisterLocation(
2133 calling_convention.GetFpuRegisterAt(0)));
2134 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2135 break;
2136 }
2137
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002138 case Primitive::kPrimDouble: {
2139 // Processing a Dex `double-to-long' instruction.
2140 InvokeRuntimeCallingConvention calling_convention;
2141 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2142 calling_convention.GetFpuRegisterAt(0),
2143 calling_convention.GetFpuRegisterAt(1)));
2144 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002145 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002146 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002147
2148 default:
2149 LOG(FATAL) << "Unexpected type conversion from " << input_type
2150 << " to " << result_type;
2151 }
2152 break;
2153
Roland Levillain981e4542014-11-14 11:47:14 +00002154 case Primitive::kPrimChar:
2155 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002156 case Primitive::kPrimLong:
2157 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002158 case Primitive::kPrimBoolean:
2159 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002160 case Primitive::kPrimByte:
2161 case Primitive::kPrimShort:
2162 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002163 // Processing a Dex `int-to-char' instruction.
2164 locations->SetInAt(0, Location::RequiresRegister());
2165 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2166 break;
2167
2168 default:
2169 LOG(FATAL) << "Unexpected type conversion from " << input_type
2170 << " to " << result_type;
2171 }
2172 break;
2173
Roland Levillaindff1f282014-11-05 14:15:05 +00002174 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002175 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002176 case Primitive::kPrimBoolean:
2177 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002178 case Primitive::kPrimByte:
2179 case Primitive::kPrimShort:
2180 case Primitive::kPrimInt:
2181 case Primitive::kPrimChar:
2182 // Processing a Dex `int-to-float' instruction.
2183 locations->SetInAt(0, Location::RequiresRegister());
2184 locations->SetOut(Location::RequiresFpuRegister());
2185 break;
2186
Roland Levillain5b3ee562015-04-14 16:02:41 +01002187 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002188 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002189 InvokeRuntimeCallingConvention calling_convention;
2190 locations->SetInAt(0, Location::RegisterPairLocation(
2191 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2192 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002193 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002194 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002195
Roland Levillaincff13742014-11-17 14:32:17 +00002196 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002197 // Processing a Dex `double-to-float' instruction.
2198 locations->SetInAt(0, Location::RequiresFpuRegister());
2199 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002200 break;
2201
2202 default:
2203 LOG(FATAL) << "Unexpected type conversion from " << input_type
2204 << " to " << result_type;
2205 };
2206 break;
2207
Roland Levillaindff1f282014-11-05 14:15:05 +00002208 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002209 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002210 case Primitive::kPrimBoolean:
2211 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002212 case Primitive::kPrimByte:
2213 case Primitive::kPrimShort:
2214 case Primitive::kPrimInt:
2215 case Primitive::kPrimChar:
2216 // Processing a Dex `int-to-double' instruction.
2217 locations->SetInAt(0, Location::RequiresRegister());
2218 locations->SetOut(Location::RequiresFpuRegister());
2219 break;
2220
2221 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002222 // Processing a Dex `long-to-double' instruction.
2223 locations->SetInAt(0, Location::RequiresRegister());
2224 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002225 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002226 locations->AddTemp(Location::RequiresFpuRegister());
2227 break;
2228
Roland Levillaincff13742014-11-17 14:32:17 +00002229 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002230 // Processing a Dex `float-to-double' instruction.
2231 locations->SetInAt(0, Location::RequiresFpuRegister());
2232 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002233 break;
2234
2235 default:
2236 LOG(FATAL) << "Unexpected type conversion from " << input_type
2237 << " to " << result_type;
2238 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002239 break;
2240
2241 default:
2242 LOG(FATAL) << "Unexpected type conversion from " << input_type
2243 << " to " << result_type;
2244 }
2245}
2246
2247void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2248 LocationSummary* locations = conversion->GetLocations();
2249 Location out = locations->Out();
2250 Location in = locations->InAt(0);
2251 Primitive::Type result_type = conversion->GetResultType();
2252 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002253 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002254 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002255 case Primitive::kPrimByte:
2256 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002257 case Primitive::kPrimLong:
2258 // Type conversion from long to byte is a result of code transformations.
2259 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2260 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002261 case Primitive::kPrimBoolean:
2262 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002263 case Primitive::kPrimShort:
2264 case Primitive::kPrimInt:
2265 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002266 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002267 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002268 break;
2269
2270 default:
2271 LOG(FATAL) << "Unexpected type conversion from " << input_type
2272 << " to " << result_type;
2273 }
2274 break;
2275
Roland Levillain01a8d712014-11-14 16:27:39 +00002276 case Primitive::kPrimShort:
2277 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002278 case Primitive::kPrimLong:
2279 // Type conversion from long to short is a result of code transformations.
2280 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2281 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002282 case Primitive::kPrimBoolean:
2283 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002284 case Primitive::kPrimByte:
2285 case Primitive::kPrimInt:
2286 case Primitive::kPrimChar:
2287 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002288 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002289 break;
2290
2291 default:
2292 LOG(FATAL) << "Unexpected type conversion from " << input_type
2293 << " to " << result_type;
2294 }
2295 break;
2296
Roland Levillain946e1432014-11-11 17:35:19 +00002297 case Primitive::kPrimInt:
2298 switch (input_type) {
2299 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002300 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002301 DCHECK(out.IsRegister());
2302 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002303 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002304 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002305 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002306 } else {
2307 DCHECK(in.IsConstant());
2308 DCHECK(in.GetConstant()->IsLongConstant());
2309 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002310 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002311 }
2312 break;
2313
Roland Levillain3f8f9362014-12-02 17:45:01 +00002314 case Primitive::kPrimFloat: {
2315 // Processing a Dex `float-to-int' instruction.
2316 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002317 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002318 __ vmovrs(out.AsRegister<Register>(), temp);
2319 break;
2320 }
2321
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002322 case Primitive::kPrimDouble: {
2323 // Processing a Dex `double-to-int' instruction.
2324 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002325 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002326 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002327 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002328 }
Roland Levillain946e1432014-11-11 17:35:19 +00002329
2330 default:
2331 LOG(FATAL) << "Unexpected type conversion from " << input_type
2332 << " to " << result_type;
2333 }
2334 break;
2335
Roland Levillaindff1f282014-11-05 14:15:05 +00002336 case Primitive::kPrimLong:
2337 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002338 case Primitive::kPrimBoolean:
2339 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002340 case Primitive::kPrimByte:
2341 case Primitive::kPrimShort:
2342 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002343 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002344 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002345 DCHECK(out.IsRegisterPair());
2346 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002347 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002348 // Sign extension.
2349 __ Asr(out.AsRegisterPairHigh<Register>(),
2350 out.AsRegisterPairLow<Register>(),
2351 31);
2352 break;
2353
2354 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002355 // Processing a Dex `float-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002356 codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002357 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002358 break;
2359
Roland Levillaindff1f282014-11-05 14:15:05 +00002360 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002361 // Processing a Dex `double-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002362 codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002363 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002364 break;
2365
2366 default:
2367 LOG(FATAL) << "Unexpected type conversion from " << input_type
2368 << " to " << result_type;
2369 }
2370 break;
2371
Roland Levillain981e4542014-11-14 11:47:14 +00002372 case Primitive::kPrimChar:
2373 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002374 case Primitive::kPrimLong:
2375 // Type conversion from long to char is a result of code transformations.
2376 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2377 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002378 case Primitive::kPrimBoolean:
2379 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002380 case Primitive::kPrimByte:
2381 case Primitive::kPrimShort:
2382 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002383 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002384 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002385 break;
2386
2387 default:
2388 LOG(FATAL) << "Unexpected type conversion from " << input_type
2389 << " to " << result_type;
2390 }
2391 break;
2392
Roland Levillaindff1f282014-11-05 14:15:05 +00002393 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002394 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002395 case Primitive::kPrimBoolean:
2396 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002397 case Primitive::kPrimByte:
2398 case Primitive::kPrimShort:
2399 case Primitive::kPrimInt:
2400 case Primitive::kPrimChar: {
2401 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002402 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2403 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002404 break;
2405 }
2406
Roland Levillain5b3ee562015-04-14 16:02:41 +01002407 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002408 // Processing a Dex `long-to-float' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002409 codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002410 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002411 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002412
Roland Levillaincff13742014-11-17 14:32:17 +00002413 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002414 // Processing a Dex `double-to-float' instruction.
2415 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2416 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002417 break;
2418
2419 default:
2420 LOG(FATAL) << "Unexpected type conversion from " << input_type
2421 << " to " << result_type;
2422 };
2423 break;
2424
Roland Levillaindff1f282014-11-05 14:15:05 +00002425 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002426 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002427 case Primitive::kPrimBoolean:
2428 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002429 case Primitive::kPrimByte:
2430 case Primitive::kPrimShort:
2431 case Primitive::kPrimInt:
2432 case Primitive::kPrimChar: {
2433 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002434 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002435 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2436 out.AsFpuRegisterPairLow<SRegister>());
2437 break;
2438 }
2439
Roland Levillain647b9ed2014-11-27 12:06:00 +00002440 case Primitive::kPrimLong: {
2441 // Processing a Dex `long-to-double' instruction.
2442 Register low = in.AsRegisterPairLow<Register>();
2443 Register high = in.AsRegisterPairHigh<Register>();
2444 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2445 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002446 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002447 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002448 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2449 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002450
Roland Levillain682393c2015-04-14 15:57:52 +01002451 // temp_d = int-to-double(high)
2452 __ vmovsr(temp_s, high);
2453 __ vcvtdi(temp_d, temp_s);
2454 // constant_d = k2Pow32EncodingForDouble
2455 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2456 // out_d = unsigned-to-double(low)
2457 __ vmovsr(out_s, low);
2458 __ vcvtdu(out_d, out_s);
2459 // out_d += temp_d * constant_d
2460 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002461 break;
2462 }
2463
Roland Levillaincff13742014-11-17 14:32:17 +00002464 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002465 // Processing a Dex `float-to-double' instruction.
2466 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2467 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002468 break;
2469
2470 default:
2471 LOG(FATAL) << "Unexpected type conversion from " << input_type
2472 << " to " << result_type;
2473 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002474 break;
2475
2476 default:
2477 LOG(FATAL) << "Unexpected type conversion from " << input_type
2478 << " to " << result_type;
2479 }
2480}
2481
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002482void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002483 LocationSummary* locations =
2484 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002485 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002486 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002487 locations->SetInAt(0, Location::RequiresRegister());
2488 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002489 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2490 break;
2491 }
2492
2493 case Primitive::kPrimLong: {
2494 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002495 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002496 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002497 break;
2498 }
2499
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002500 case Primitive::kPrimFloat:
2501 case Primitive::kPrimDouble: {
2502 locations->SetInAt(0, Location::RequiresFpuRegister());
2503 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002504 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002505 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002506 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002507
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002508 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002509 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002510 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002511}
2512
2513void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2514 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002515 Location out = locations->Out();
2516 Location first = locations->InAt(0);
2517 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002518 switch (add->GetResultType()) {
2519 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002520 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002521 __ add(out.AsRegister<Register>(),
2522 first.AsRegister<Register>(),
2523 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002524 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002525 __ AddConstant(out.AsRegister<Register>(),
2526 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002527 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002528 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002529 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002530
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002531 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002532 if (second.IsConstant()) {
2533 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2534 GenerateAddLongConst(out, first, value);
2535 } else {
2536 DCHECK(second.IsRegisterPair());
2537 __ adds(out.AsRegisterPairLow<Register>(),
2538 first.AsRegisterPairLow<Register>(),
2539 ShifterOperand(second.AsRegisterPairLow<Register>()));
2540 __ adc(out.AsRegisterPairHigh<Register>(),
2541 first.AsRegisterPairHigh<Register>(),
2542 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2543 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002544 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002545 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002546
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002547 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002548 __ vadds(out.AsFpuRegister<SRegister>(),
2549 first.AsFpuRegister<SRegister>(),
2550 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002551 break;
2552
2553 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002554 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2555 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2556 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002557 break;
2558
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002559 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002560 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002561 }
2562}
2563
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002564void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002565 LocationSummary* locations =
2566 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002567 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002568 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002569 locations->SetInAt(0, Location::RequiresRegister());
2570 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002571 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2572 break;
2573 }
2574
2575 case Primitive::kPrimLong: {
2576 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002577 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002578 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002579 break;
2580 }
Calin Juravle11351682014-10-23 15:38:15 +01002581 case Primitive::kPrimFloat:
2582 case Primitive::kPrimDouble: {
2583 locations->SetInAt(0, Location::RequiresFpuRegister());
2584 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002585 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002586 break;
Calin Juravle11351682014-10-23 15:38:15 +01002587 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002588 default:
Calin Juravle11351682014-10-23 15:38:15 +01002589 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002590 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002591}
2592
2593void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2594 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002595 Location out = locations->Out();
2596 Location first = locations->InAt(0);
2597 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002598 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002599 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002600 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002601 __ sub(out.AsRegister<Register>(),
2602 first.AsRegister<Register>(),
2603 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002604 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002605 __ AddConstant(out.AsRegister<Register>(),
2606 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002607 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002608 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002609 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002610 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002611
Calin Juravle11351682014-10-23 15:38:15 +01002612 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002613 if (second.IsConstant()) {
2614 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2615 GenerateAddLongConst(out, first, -value);
2616 } else {
2617 DCHECK(second.IsRegisterPair());
2618 __ subs(out.AsRegisterPairLow<Register>(),
2619 first.AsRegisterPairLow<Register>(),
2620 ShifterOperand(second.AsRegisterPairLow<Register>()));
2621 __ sbc(out.AsRegisterPairHigh<Register>(),
2622 first.AsRegisterPairHigh<Register>(),
2623 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2624 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002625 break;
Calin Juravle11351682014-10-23 15:38:15 +01002626 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002627
Calin Juravle11351682014-10-23 15:38:15 +01002628 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002629 __ vsubs(out.AsFpuRegister<SRegister>(),
2630 first.AsFpuRegister<SRegister>(),
2631 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002632 break;
Calin Juravle11351682014-10-23 15:38:15 +01002633 }
2634
2635 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002636 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2637 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2638 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002639 break;
2640 }
2641
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002642
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002643 default:
Calin Juravle11351682014-10-23 15:38:15 +01002644 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002645 }
2646}
2647
Calin Juravle34bacdf2014-10-07 20:23:36 +01002648void LocationsBuilderARM::VisitMul(HMul* mul) {
2649 LocationSummary* locations =
2650 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2651 switch (mul->GetResultType()) {
2652 case Primitive::kPrimInt:
2653 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002654 locations->SetInAt(0, Location::RequiresRegister());
2655 locations->SetInAt(1, Location::RequiresRegister());
2656 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002657 break;
2658 }
2659
Calin Juravleb5bfa962014-10-21 18:02:24 +01002660 case Primitive::kPrimFloat:
2661 case Primitive::kPrimDouble: {
2662 locations->SetInAt(0, Location::RequiresFpuRegister());
2663 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002664 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002665 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002666 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002667
2668 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002669 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002670 }
2671}
2672
2673void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2674 LocationSummary* locations = mul->GetLocations();
2675 Location out = locations->Out();
2676 Location first = locations->InAt(0);
2677 Location second = locations->InAt(1);
2678 switch (mul->GetResultType()) {
2679 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002680 __ mul(out.AsRegister<Register>(),
2681 first.AsRegister<Register>(),
2682 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002683 break;
2684 }
2685 case Primitive::kPrimLong: {
2686 Register out_hi = out.AsRegisterPairHigh<Register>();
2687 Register out_lo = out.AsRegisterPairLow<Register>();
2688 Register in1_hi = first.AsRegisterPairHigh<Register>();
2689 Register in1_lo = first.AsRegisterPairLow<Register>();
2690 Register in2_hi = second.AsRegisterPairHigh<Register>();
2691 Register in2_lo = second.AsRegisterPairLow<Register>();
2692
2693 // Extra checks to protect caused by the existence of R1_R2.
2694 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2695 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2696 DCHECK_NE(out_hi, in1_lo);
2697 DCHECK_NE(out_hi, in2_lo);
2698
2699 // input: in1 - 64 bits, in2 - 64 bits
2700 // output: out
2701 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2702 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2703 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2704
2705 // IP <- in1.lo * in2.hi
2706 __ mul(IP, in1_lo, in2_hi);
2707 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2708 __ mla(out_hi, in1_hi, in2_lo, IP);
2709 // out.lo <- (in1.lo * in2.lo)[31:0];
2710 __ umull(out_lo, IP, in1_lo, in2_lo);
2711 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2712 __ add(out_hi, out_hi, ShifterOperand(IP));
2713 break;
2714 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002715
2716 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002717 __ vmuls(out.AsFpuRegister<SRegister>(),
2718 first.AsFpuRegister<SRegister>(),
2719 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002720 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002721 }
2722
2723 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002724 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2725 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2726 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002727 break;
2728 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002729
2730 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002731 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002732 }
2733}
2734
Zheng Xuc6667102015-05-15 16:08:45 +08002735void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2736 DCHECK(instruction->IsDiv() || instruction->IsRem());
2737 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2738
2739 LocationSummary* locations = instruction->GetLocations();
2740 Location second = locations->InAt(1);
2741 DCHECK(second.IsConstant());
2742
2743 Register out = locations->Out().AsRegister<Register>();
2744 Register dividend = locations->InAt(0).AsRegister<Register>();
2745 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2746 DCHECK(imm == 1 || imm == -1);
2747
2748 if (instruction->IsRem()) {
2749 __ LoadImmediate(out, 0);
2750 } else {
2751 if (imm == 1) {
2752 __ Mov(out, dividend);
2753 } else {
2754 __ rsb(out, dividend, ShifterOperand(0));
2755 }
2756 }
2757}
2758
2759void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2760 DCHECK(instruction->IsDiv() || instruction->IsRem());
2761 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2762
2763 LocationSummary* locations = instruction->GetLocations();
2764 Location second = locations->InAt(1);
2765 DCHECK(second.IsConstant());
2766
2767 Register out = locations->Out().AsRegister<Register>();
2768 Register dividend = locations->InAt(0).AsRegister<Register>();
2769 Register temp = locations->GetTemp(0).AsRegister<Register>();
2770 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002771 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002772 int ctz_imm = CTZ(abs_imm);
2773
2774 if (ctz_imm == 1) {
2775 __ Lsr(temp, dividend, 32 - ctz_imm);
2776 } else {
2777 __ Asr(temp, dividend, 31);
2778 __ Lsr(temp, temp, 32 - ctz_imm);
2779 }
2780 __ add(out, temp, ShifterOperand(dividend));
2781
2782 if (instruction->IsDiv()) {
2783 __ Asr(out, out, ctz_imm);
2784 if (imm < 0) {
2785 __ rsb(out, out, ShifterOperand(0));
2786 }
2787 } else {
2788 __ ubfx(out, out, 0, ctz_imm);
2789 __ sub(out, out, ShifterOperand(temp));
2790 }
2791}
2792
2793void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2794 DCHECK(instruction->IsDiv() || instruction->IsRem());
2795 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2796
2797 LocationSummary* locations = instruction->GetLocations();
2798 Location second = locations->InAt(1);
2799 DCHECK(second.IsConstant());
2800
2801 Register out = locations->Out().AsRegister<Register>();
2802 Register dividend = locations->InAt(0).AsRegister<Register>();
2803 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2804 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2805 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2806
2807 int64_t magic;
2808 int shift;
2809 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2810
2811 __ LoadImmediate(temp1, magic);
2812 __ smull(temp2, temp1, dividend, temp1);
2813
2814 if (imm > 0 && magic < 0) {
2815 __ add(temp1, temp1, ShifterOperand(dividend));
2816 } else if (imm < 0 && magic > 0) {
2817 __ sub(temp1, temp1, ShifterOperand(dividend));
2818 }
2819
2820 if (shift != 0) {
2821 __ Asr(temp1, temp1, shift);
2822 }
2823
2824 if (instruction->IsDiv()) {
2825 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2826 } else {
2827 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2828 // TODO: Strength reduction for mls.
2829 __ LoadImmediate(temp2, imm);
2830 __ mls(out, temp1, temp2, dividend);
2831 }
2832}
2833
2834void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2835 DCHECK(instruction->IsDiv() || instruction->IsRem());
2836 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2837
2838 LocationSummary* locations = instruction->GetLocations();
2839 Location second = locations->InAt(1);
2840 DCHECK(second.IsConstant());
2841
2842 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2843 if (imm == 0) {
2844 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2845 } else if (imm == 1 || imm == -1) {
2846 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002847 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002848 DivRemByPowerOfTwo(instruction);
2849 } else {
2850 DCHECK(imm <= -2 || imm >= 2);
2851 GenerateDivRemWithAnyConstant(instruction);
2852 }
2853}
2854
Calin Juravle7c4954d2014-10-28 16:57:40 +00002855void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002856 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2857 if (div->GetResultType() == Primitive::kPrimLong) {
2858 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002859 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002860 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2861 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002862 } else if (div->GetResultType() == Primitive::kPrimInt &&
2863 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2864 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002865 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002866 }
2867
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002868 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2869
Calin Juravle7c4954d2014-10-28 16:57:40 +00002870 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002871 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002872 if (div->InputAt(1)->IsConstant()) {
2873 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00002874 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08002875 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002876 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
2877 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08002878 // No temp register required.
2879 } else {
2880 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002881 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002882 locations->AddTemp(Location::RequiresRegister());
2883 }
2884 }
2885 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002886 locations->SetInAt(0, Location::RequiresRegister());
2887 locations->SetInAt(1, Location::RequiresRegister());
2888 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2889 } else {
2890 InvokeRuntimeCallingConvention calling_convention;
2891 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2892 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2893 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2894 // we only need the former.
2895 locations->SetOut(Location::RegisterLocation(R0));
2896 }
Calin Juravled0d48522014-11-04 16:40:20 +00002897 break;
2898 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002899 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002900 InvokeRuntimeCallingConvention calling_convention;
2901 locations->SetInAt(0, Location::RegisterPairLocation(
2902 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2903 locations->SetInAt(1, Location::RegisterPairLocation(
2904 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002905 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002906 break;
2907 }
2908 case Primitive::kPrimFloat:
2909 case Primitive::kPrimDouble: {
2910 locations->SetInAt(0, Location::RequiresFpuRegister());
2911 locations->SetInAt(1, Location::RequiresFpuRegister());
2912 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2913 break;
2914 }
2915
2916 default:
2917 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2918 }
2919}
2920
2921void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2922 LocationSummary* locations = div->GetLocations();
2923 Location out = locations->Out();
2924 Location first = locations->InAt(0);
2925 Location second = locations->InAt(1);
2926
2927 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002928 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002929 if (second.IsConstant()) {
2930 GenerateDivRemConstantIntegral(div);
2931 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002932 __ sdiv(out.AsRegister<Register>(),
2933 first.AsRegister<Register>(),
2934 second.AsRegister<Register>());
2935 } else {
2936 InvokeRuntimeCallingConvention calling_convention;
2937 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2938 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2939 DCHECK_EQ(R0, out.AsRegister<Register>());
2940
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002941 codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002942 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002943 }
Calin Juravled0d48522014-11-04 16:40:20 +00002944 break;
2945 }
2946
Calin Juravle7c4954d2014-10-28 16:57:40 +00002947 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002948 InvokeRuntimeCallingConvention calling_convention;
2949 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2950 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2951 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2952 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2953 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002954 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002955
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002956 codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002957 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002958 break;
2959 }
2960
2961 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002962 __ vdivs(out.AsFpuRegister<SRegister>(),
2963 first.AsFpuRegister<SRegister>(),
2964 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002965 break;
2966 }
2967
2968 case Primitive::kPrimDouble: {
2969 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2970 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2971 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2972 break;
2973 }
2974
2975 default:
2976 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2977 }
2978}
2979
Calin Juravlebacfec32014-11-14 15:54:36 +00002980void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002981 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002982
2983 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002984 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002985 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2986 // sdiv will be replaced by other instruction sequence.
2987 call_kind = LocationSummary::kNoCall;
2988 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2989 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002990 // Have hardware divide instruction for int, do it with three instructions.
2991 call_kind = LocationSummary::kNoCall;
2992 }
2993
Calin Juravlebacfec32014-11-14 15:54:36 +00002994 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2995
Calin Juravled2ec87d2014-12-08 14:24:46 +00002996 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002997 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002998 if (rem->InputAt(1)->IsConstant()) {
2999 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003000 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003001 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003002 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3003 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003004 // No temp register required.
3005 } else {
3006 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003007 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003008 locations->AddTemp(Location::RequiresRegister());
3009 }
3010 }
3011 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003012 locations->SetInAt(0, Location::RequiresRegister());
3013 locations->SetInAt(1, Location::RequiresRegister());
3014 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3015 locations->AddTemp(Location::RequiresRegister());
3016 } else {
3017 InvokeRuntimeCallingConvention calling_convention;
3018 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3019 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3020 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3021 // we only need the latter.
3022 locations->SetOut(Location::RegisterLocation(R1));
3023 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003024 break;
3025 }
3026 case Primitive::kPrimLong: {
3027 InvokeRuntimeCallingConvention calling_convention;
3028 locations->SetInAt(0, Location::RegisterPairLocation(
3029 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3030 locations->SetInAt(1, Location::RegisterPairLocation(
3031 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3032 // The runtime helper puts the output in R2,R3.
3033 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3034 break;
3035 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003036 case Primitive::kPrimFloat: {
3037 InvokeRuntimeCallingConvention calling_convention;
3038 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3039 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3040 locations->SetOut(Location::FpuRegisterLocation(S0));
3041 break;
3042 }
3043
Calin Juravlebacfec32014-11-14 15:54:36 +00003044 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003045 InvokeRuntimeCallingConvention calling_convention;
3046 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3047 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3048 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3049 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3050 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003051 break;
3052 }
3053
3054 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003055 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003056 }
3057}
3058
3059void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3060 LocationSummary* locations = rem->GetLocations();
3061 Location out = locations->Out();
3062 Location first = locations->InAt(0);
3063 Location second = locations->InAt(1);
3064
Calin Juravled2ec87d2014-12-08 14:24:46 +00003065 Primitive::Type type = rem->GetResultType();
3066 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003067 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003068 if (second.IsConstant()) {
3069 GenerateDivRemConstantIntegral(rem);
3070 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003071 Register reg1 = first.AsRegister<Register>();
3072 Register reg2 = second.AsRegister<Register>();
3073 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003074
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003075 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003076 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003077 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003078 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003079 } else {
3080 InvokeRuntimeCallingConvention calling_convention;
3081 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3082 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3083 DCHECK_EQ(R1, out.AsRegister<Register>());
3084
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003085 codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003086 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003087 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003088 break;
3089 }
3090
3091 case Primitive::kPrimLong: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003092 codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003093 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003094 break;
3095 }
3096
Calin Juravled2ec87d2014-12-08 14:24:46 +00003097 case Primitive::kPrimFloat: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003098 codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003099 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003100 break;
3101 }
3102
Calin Juravlebacfec32014-11-14 15:54:36 +00003103 case Primitive::kPrimDouble: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003104 codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003105 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003106 break;
3107 }
3108
3109 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003110 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003111 }
3112}
3113
Calin Juravled0d48522014-11-04 16:40:20 +00003114void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003115 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3116 ? LocationSummary::kCallOnSlowPath
3117 : LocationSummary::kNoCall;
3118 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003119 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003120 if (instruction->HasUses()) {
3121 locations->SetOut(Location::SameAsFirstInput());
3122 }
3123}
3124
3125void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003126 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003127 codegen_->AddSlowPath(slow_path);
3128
3129 LocationSummary* locations = instruction->GetLocations();
3130 Location value = locations->InAt(0);
3131
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003132 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003133 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003134 case Primitive::kPrimByte:
3135 case Primitive::kPrimChar:
3136 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003137 case Primitive::kPrimInt: {
3138 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003139 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003140 } else {
3141 DCHECK(value.IsConstant()) << value;
3142 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3143 __ b(slow_path->GetEntryLabel());
3144 }
3145 }
3146 break;
3147 }
3148 case Primitive::kPrimLong: {
3149 if (value.IsRegisterPair()) {
3150 __ orrs(IP,
3151 value.AsRegisterPairLow<Register>(),
3152 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3153 __ b(slow_path->GetEntryLabel(), EQ);
3154 } else {
3155 DCHECK(value.IsConstant()) << value;
3156 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3157 __ b(slow_path->GetEntryLabel());
3158 }
3159 }
3160 break;
3161 default:
3162 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3163 }
3164 }
Calin Juravled0d48522014-11-04 16:40:20 +00003165}
3166
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003167void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3168 Register in = locations->InAt(0).AsRegister<Register>();
3169 Location rhs = locations->InAt(1);
3170 Register out = locations->Out().AsRegister<Register>();
3171
3172 if (rhs.IsConstant()) {
3173 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3174 // so map all rotations to a +ve. equivalent in that range.
3175 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3176 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3177 if (rot) {
3178 // Rotate, mapping left rotations to right equivalents if necessary.
3179 // (e.g. left by 2 bits == right by 30.)
3180 __ Ror(out, in, rot);
3181 } else if (out != in) {
3182 __ Mov(out, in);
3183 }
3184 } else {
3185 __ Ror(out, in, rhs.AsRegister<Register>());
3186 }
3187}
3188
3189// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3190// rotates by swapping input regs (effectively rotating by the first 32-bits of
3191// a larger rotation) or flipping direction (thus treating larger right/left
3192// rotations as sub-word sized rotations in the other direction) as appropriate.
3193void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3194 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3195 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3196 Location rhs = locations->InAt(1);
3197 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3198 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3199
3200 if (rhs.IsConstant()) {
3201 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3202 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003203 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003204 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3205 // logic below to a simple pair of binary orr.
3206 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3207 if (rot >= kArmBitsPerWord) {
3208 rot -= kArmBitsPerWord;
3209 std::swap(in_reg_hi, in_reg_lo);
3210 }
3211 // Rotate, or mov to out for zero or word size rotations.
3212 if (rot != 0u) {
3213 __ Lsr(out_reg_hi, in_reg_hi, rot);
3214 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3215 __ Lsr(out_reg_lo, in_reg_lo, rot);
3216 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3217 } else {
3218 __ Mov(out_reg_lo, in_reg_lo);
3219 __ Mov(out_reg_hi, in_reg_hi);
3220 }
3221 } else {
3222 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3223 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3224 Label end;
3225 Label shift_by_32_plus_shift_right;
3226
3227 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3228 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3229 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3230 __ b(&shift_by_32_plus_shift_right, CC);
3231
3232 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3233 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3234 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3235 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3236 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3237 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3238 __ Lsr(shift_left, in_reg_hi, shift_right);
3239 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3240 __ b(&end);
3241
3242 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3243 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3244 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3245 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3246 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3247 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3248 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3249 __ Lsl(shift_right, in_reg_hi, shift_left);
3250 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3251
3252 __ Bind(&end);
3253 }
3254}
Roland Levillain22c49222016-03-18 14:04:28 +00003255
3256void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003257 LocationSummary* locations =
3258 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3259 switch (ror->GetResultType()) {
3260 case Primitive::kPrimInt: {
3261 locations->SetInAt(0, Location::RequiresRegister());
3262 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3263 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3264 break;
3265 }
3266 case Primitive::kPrimLong: {
3267 locations->SetInAt(0, Location::RequiresRegister());
3268 if (ror->InputAt(1)->IsConstant()) {
3269 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3270 } else {
3271 locations->SetInAt(1, Location::RequiresRegister());
3272 locations->AddTemp(Location::RequiresRegister());
3273 locations->AddTemp(Location::RequiresRegister());
3274 }
3275 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3276 break;
3277 }
3278 default:
3279 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3280 }
3281}
3282
Roland Levillain22c49222016-03-18 14:04:28 +00003283void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003284 LocationSummary* locations = ror->GetLocations();
3285 Primitive::Type type = ror->GetResultType();
3286 switch (type) {
3287 case Primitive::kPrimInt: {
3288 HandleIntegerRotate(locations);
3289 break;
3290 }
3291 case Primitive::kPrimLong: {
3292 HandleLongRotate(locations);
3293 break;
3294 }
3295 default:
3296 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003297 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003298 }
3299}
3300
Calin Juravle9aec02f2014-11-18 23:06:35 +00003301void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3302 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3303
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003304 LocationSummary* locations =
3305 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003306
3307 switch (op->GetResultType()) {
3308 case Primitive::kPrimInt: {
3309 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003310 if (op->InputAt(1)->IsConstant()) {
3311 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3312 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3313 } else {
3314 locations->SetInAt(1, Location::RequiresRegister());
3315 // Make the output overlap, as it will be used to hold the masked
3316 // second input.
3317 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3318 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003319 break;
3320 }
3321 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003322 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003323 if (op->InputAt(1)->IsConstant()) {
3324 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3325 // For simplicity, use kOutputOverlap even though we only require that low registers
3326 // don't clash with high registers which the register allocator currently guarantees.
3327 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3328 } else {
3329 locations->SetInAt(1, Location::RequiresRegister());
3330 locations->AddTemp(Location::RequiresRegister());
3331 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3332 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003333 break;
3334 }
3335 default:
3336 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3337 }
3338}
3339
3340void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3341 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3342
3343 LocationSummary* locations = op->GetLocations();
3344 Location out = locations->Out();
3345 Location first = locations->InAt(0);
3346 Location second = locations->InAt(1);
3347
3348 Primitive::Type type = op->GetResultType();
3349 switch (type) {
3350 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003351 Register out_reg = out.AsRegister<Register>();
3352 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003353 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003354 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003355 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003356 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003357 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003358 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003359 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003360 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003361 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003362 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003363 }
3364 } else {
3365 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003366 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003367 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003368 __ Mov(out_reg, first_reg);
3369 } else if (op->IsShl()) {
3370 __ Lsl(out_reg, first_reg, shift_value);
3371 } else if (op->IsShr()) {
3372 __ Asr(out_reg, first_reg, shift_value);
3373 } else {
3374 __ Lsr(out_reg, first_reg, shift_value);
3375 }
3376 }
3377 break;
3378 }
3379 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003380 Register o_h = out.AsRegisterPairHigh<Register>();
3381 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003382
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003383 Register high = first.AsRegisterPairHigh<Register>();
3384 Register low = first.AsRegisterPairLow<Register>();
3385
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003386 if (second.IsRegister()) {
3387 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003388
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003389 Register second_reg = second.AsRegister<Register>();
3390
3391 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003392 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003393 // Shift the high part
3394 __ Lsl(o_h, high, o_l);
3395 // Shift the low part and `or` what overflew on the high part
3396 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3397 __ Lsr(temp, low, temp);
3398 __ orr(o_h, o_h, ShifterOperand(temp));
3399 // If the shift is > 32 bits, override the high part
3400 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3401 __ it(PL);
3402 __ Lsl(o_h, low, temp, PL);
3403 // Shift the low part
3404 __ Lsl(o_l, low, o_l);
3405 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003406 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003407 // Shift the low part
3408 __ Lsr(o_l, low, o_h);
3409 // Shift the high part and `or` what underflew on the low part
3410 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3411 __ Lsl(temp, high, temp);
3412 __ orr(o_l, o_l, ShifterOperand(temp));
3413 // If the shift is > 32 bits, override the low part
3414 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3415 __ it(PL);
3416 __ Asr(o_l, high, temp, PL);
3417 // Shift the high part
3418 __ Asr(o_h, high, o_h);
3419 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003420 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003421 // same as Shr except we use `Lsr`s and not `Asr`s
3422 __ Lsr(o_l, low, o_h);
3423 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3424 __ Lsl(temp, high, temp);
3425 __ orr(o_l, o_l, ShifterOperand(temp));
3426 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3427 __ it(PL);
3428 __ Lsr(o_l, high, temp, PL);
3429 __ Lsr(o_h, high, o_h);
3430 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003431 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003432 // Register allocator doesn't create partial overlap.
3433 DCHECK_NE(o_l, high);
3434 DCHECK_NE(o_h, low);
3435 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003436 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003437 if (shift_value > 32) {
3438 if (op->IsShl()) {
3439 __ Lsl(o_h, low, shift_value - 32);
3440 __ LoadImmediate(o_l, 0);
3441 } else if (op->IsShr()) {
3442 __ Asr(o_l, high, shift_value - 32);
3443 __ Asr(o_h, high, 31);
3444 } else {
3445 __ Lsr(o_l, high, shift_value - 32);
3446 __ LoadImmediate(o_h, 0);
3447 }
3448 } else if (shift_value == 32) {
3449 if (op->IsShl()) {
3450 __ mov(o_h, ShifterOperand(low));
3451 __ LoadImmediate(o_l, 0);
3452 } else if (op->IsShr()) {
3453 __ mov(o_l, ShifterOperand(high));
3454 __ Asr(o_h, high, 31);
3455 } else {
3456 __ mov(o_l, ShifterOperand(high));
3457 __ LoadImmediate(o_h, 0);
3458 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003459 } else if (shift_value == 1) {
3460 if (op->IsShl()) {
3461 __ Lsls(o_l, low, 1);
3462 __ adc(o_h, high, ShifterOperand(high));
3463 } else if (op->IsShr()) {
3464 __ Asrs(o_h, high, 1);
3465 __ Rrx(o_l, low);
3466 } else {
3467 __ Lsrs(o_h, high, 1);
3468 __ Rrx(o_l, low);
3469 }
3470 } else {
3471 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003472 if (op->IsShl()) {
3473 __ Lsl(o_h, high, shift_value);
3474 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3475 __ Lsl(o_l, low, shift_value);
3476 } else if (op->IsShr()) {
3477 __ Lsr(o_l, low, shift_value);
3478 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3479 __ Asr(o_h, high, shift_value);
3480 } else {
3481 __ Lsr(o_l, low, shift_value);
3482 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3483 __ Lsr(o_h, high, shift_value);
3484 }
3485 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003486 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003487 break;
3488 }
3489 default:
3490 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003491 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003492 }
3493}
3494
3495void LocationsBuilderARM::VisitShl(HShl* shl) {
3496 HandleShift(shl);
3497}
3498
3499void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3500 HandleShift(shl);
3501}
3502
3503void LocationsBuilderARM::VisitShr(HShr* shr) {
3504 HandleShift(shr);
3505}
3506
3507void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3508 HandleShift(shr);
3509}
3510
3511void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3512 HandleShift(ushr);
3513}
3514
3515void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3516 HandleShift(ushr);
3517}
3518
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003519void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003520 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003521 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003522 if (instruction->IsStringAlloc()) {
3523 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3524 } else {
3525 InvokeRuntimeCallingConvention calling_convention;
3526 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3527 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3528 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003529 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003530}
3531
3532void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003533 // Note: if heap poisoning is enabled, the entry point takes cares
3534 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003535 if (instruction->IsStringAlloc()) {
3536 // String is allocated through StringFactory. Call NewEmptyString entry point.
3537 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003538 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003539 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3540 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3541 __ blx(LR);
3542 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3543 } else {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003544 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
David Brazdil6de19382016-01-08 17:37:10 +00003545 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3546 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003547}
3548
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003549void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3550 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003551 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003552 InvokeRuntimeCallingConvention calling_convention;
3553 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003554 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003555 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003556 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003557}
3558
3559void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3560 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003561 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003562 // Note: if heap poisoning is enabled, the entry point takes cares
3563 // of poisoning the reference.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003564 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003565 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003566}
3567
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003568void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003569 LocationSummary* locations =
3570 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003571 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3572 if (location.IsStackSlot()) {
3573 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3574 } else if (location.IsDoubleStackSlot()) {
3575 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003576 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003577 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003578}
3579
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003580void InstructionCodeGeneratorARM::VisitParameterValue(
3581 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003582 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003583}
3584
3585void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3586 LocationSummary* locations =
3587 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3588 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3589}
3590
3591void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3592 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003593}
3594
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003595void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003596 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003597 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003598 locations->SetInAt(0, Location::RequiresRegister());
3599 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003600}
3601
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003602void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3603 LocationSummary* locations = not_->GetLocations();
3604 Location out = locations->Out();
3605 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003606 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003607 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003608 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003609 break;
3610
3611 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003612 __ mvn(out.AsRegisterPairLow<Register>(),
3613 ShifterOperand(in.AsRegisterPairLow<Register>()));
3614 __ mvn(out.AsRegisterPairHigh<Register>(),
3615 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003616 break;
3617
3618 default:
3619 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3620 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003621}
3622
David Brazdil66d126e2015-04-03 16:02:44 +01003623void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3624 LocationSummary* locations =
3625 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3626 locations->SetInAt(0, Location::RequiresRegister());
3627 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3628}
3629
3630void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003631 LocationSummary* locations = bool_not->GetLocations();
3632 Location out = locations->Out();
3633 Location in = locations->InAt(0);
3634 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3635}
3636
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003637void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003638 LocationSummary* locations =
3639 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003640 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003641 case Primitive::kPrimBoolean:
3642 case Primitive::kPrimByte:
3643 case Primitive::kPrimShort:
3644 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003645 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00003646 case Primitive::kPrimLong: {
3647 locations->SetInAt(0, Location::RequiresRegister());
3648 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003649 // Output overlaps because it is written before doing the low comparison.
3650 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003651 break;
3652 }
3653 case Primitive::kPrimFloat:
3654 case Primitive::kPrimDouble: {
3655 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003656 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00003657 locations->SetOut(Location::RequiresRegister());
3658 break;
3659 }
3660 default:
3661 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3662 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003663}
3664
3665void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003666 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003667 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003668 Location left = locations->InAt(0);
3669 Location right = locations->InAt(1);
3670
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003671 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003672 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00003673 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00003674 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003675 case Primitive::kPrimBoolean:
3676 case Primitive::kPrimByte:
3677 case Primitive::kPrimShort:
3678 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003679 case Primitive::kPrimInt: {
3680 __ LoadImmediate(out, 0);
3681 __ cmp(left.AsRegister<Register>(),
3682 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
3683 less_cond = LT;
3684 break;
3685 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003686 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003687 __ cmp(left.AsRegisterPairHigh<Register>(),
3688 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003689 __ b(&less, LT);
3690 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003691 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003692 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003693 __ cmp(left.AsRegisterPairLow<Register>(),
3694 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003695 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00003696 break;
3697 }
3698 case Primitive::kPrimFloat:
3699 case Primitive::kPrimDouble: {
3700 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003701 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00003702 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003703 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003704 break;
3705 }
3706 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003707 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00003708 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003709 }
Aart Bika19616e2016-02-01 18:57:58 -08003710
Calin Juravleddb7df22014-11-25 20:56:51 +00003711 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00003712 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00003713
3714 __ Bind(&greater);
3715 __ LoadImmediate(out, 1);
3716 __ b(&done);
3717
3718 __ Bind(&less);
3719 __ LoadImmediate(out, -1);
3720
3721 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003722}
3723
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003724void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003725 LocationSummary* locations =
3726 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003727 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003728 locations->SetInAt(i, Location::Any());
3729 }
3730 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003731}
3732
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003733void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003734 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003735}
3736
Roland Levillainc9285912015-12-18 10:38:42 +00003737void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3738 // TODO (ported from quick): revisit ARM barrier kinds.
3739 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00003740 switch (kind) {
3741 case MemBarrierKind::kAnyStore:
3742 case MemBarrierKind::kLoadAny:
3743 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003744 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003745 break;
3746 }
3747 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003748 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003749 break;
3750 }
3751 default:
3752 LOG(FATAL) << "Unexpected memory barrier " << kind;
3753 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003754 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003755}
3756
3757void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3758 uint32_t offset,
3759 Register out_lo,
3760 Register out_hi) {
3761 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00003762 // Ensure `out_lo` is different from `addr`, so that loading
3763 // `offset` into `out_lo` does not clutter `addr`.
3764 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00003765 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003766 __ add(IP, addr, ShifterOperand(out_lo));
3767 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003768 }
3769 __ ldrexd(out_lo, out_hi, addr);
3770}
3771
3772void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3773 uint32_t offset,
3774 Register value_lo,
3775 Register value_hi,
3776 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003777 Register temp2,
3778 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003779 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003780 if (offset != 0) {
3781 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003782 __ add(IP, addr, ShifterOperand(temp1));
3783 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003784 }
3785 __ Bind(&fail);
3786 // We need a load followed by store. (The address used in a STREX instruction must
3787 // be the same as the address in the most recently executed LDREX instruction.)
3788 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003789 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003790 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003791 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003792}
3793
3794void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3795 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3796
Nicolas Geoffray39468442014-09-02 15:17:15 +01003797 LocationSummary* locations =
3798 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003799 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003800
Calin Juravle52c48962014-12-16 17:02:57 +00003801 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003802 if (Primitive::IsFloatingPointType(field_type)) {
3803 locations->SetInAt(1, Location::RequiresFpuRegister());
3804 } else {
3805 locations->SetInAt(1, Location::RequiresRegister());
3806 }
3807
Calin Juravle52c48962014-12-16 17:02:57 +00003808 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003809 bool generate_volatile = field_info.IsVolatile()
3810 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003811 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003812 bool needs_write_barrier =
3813 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003814 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003815 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003816 if (needs_write_barrier) {
3817 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003818 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003819 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003820 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003821 // - registers need to be consecutive
3822 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003823 // We don't test for ARM yet, and the assertion makes sure that we
3824 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003825 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3826
3827 locations->AddTemp(Location::RequiresRegister());
3828 locations->AddTemp(Location::RequiresRegister());
3829 if (field_type == Primitive::kPrimDouble) {
3830 // For doubles we need two more registers to copy the value.
3831 locations->AddTemp(Location::RegisterLocation(R2));
3832 locations->AddTemp(Location::RegisterLocation(R3));
3833 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003834 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003835}
3836
Calin Juravle52c48962014-12-16 17:02:57 +00003837void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003838 const FieldInfo& field_info,
3839 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003840 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3841
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003842 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003843 Register base = locations->InAt(0).AsRegister<Register>();
3844 Location value = locations->InAt(1);
3845
3846 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003847 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003848 Primitive::Type field_type = field_info.GetFieldType();
3849 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003850 bool needs_write_barrier =
3851 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003852
3853 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003854 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00003855 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003856
3857 switch (field_type) {
3858 case Primitive::kPrimBoolean:
3859 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003860 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003861 break;
3862 }
3863
3864 case Primitive::kPrimShort:
3865 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003866 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003867 break;
3868 }
3869
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003870 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003871 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003872 if (kPoisonHeapReferences && needs_write_barrier) {
3873 // Note that in the case where `value` is a null reference,
3874 // we do not enter this block, as a null reference does not
3875 // need poisoning.
3876 DCHECK_EQ(field_type, Primitive::kPrimNot);
3877 Register temp = locations->GetTemp(0).AsRegister<Register>();
3878 __ Mov(temp, value.AsRegister<Register>());
3879 __ PoisonHeapReference(temp);
3880 __ StoreToOffset(kStoreWord, temp, base, offset);
3881 } else {
3882 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3883 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003884 break;
3885 }
3886
3887 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003888 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003889 GenerateWideAtomicStore(base, offset,
3890 value.AsRegisterPairLow<Register>(),
3891 value.AsRegisterPairHigh<Register>(),
3892 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003893 locations->GetTemp(1).AsRegister<Register>(),
3894 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003895 } else {
3896 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003897 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003898 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003899 break;
3900 }
3901
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003902 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003903 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003904 break;
3905 }
3906
3907 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003908 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003909 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003910 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3911 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3912
3913 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3914
3915 GenerateWideAtomicStore(base, offset,
3916 value_reg_lo,
3917 value_reg_hi,
3918 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003919 locations->GetTemp(3).AsRegister<Register>(),
3920 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003921 } else {
3922 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003923 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003924 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003925 break;
3926 }
3927
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003928 case Primitive::kPrimVoid:
3929 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003930 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003931 }
Calin Juravle52c48962014-12-16 17:02:57 +00003932
Calin Juravle77520bc2015-01-12 18:45:46 +00003933 // Longs and doubles are handled in the switch.
3934 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3935 codegen_->MaybeRecordImplicitNullCheck(instruction);
3936 }
3937
3938 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3939 Register temp = locations->GetTemp(0).AsRegister<Register>();
3940 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003941 codegen_->MarkGCCard(
3942 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003943 }
3944
Calin Juravle52c48962014-12-16 17:02:57 +00003945 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003946 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00003947 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003948}
3949
Calin Juravle52c48962014-12-16 17:02:57 +00003950void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3951 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00003952
3953 bool object_field_get_with_read_barrier =
3954 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003955 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00003956 new (GetGraph()->GetArena()) LocationSummary(instruction,
3957 object_field_get_with_read_barrier ?
3958 LocationSummary::kCallOnSlowPath :
3959 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003960 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003961
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003962 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003963 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003964 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00003965 // The output overlaps in case of volatile long: we don't want the
3966 // code generated by GenerateWideAtomicLoad to overwrite the
3967 // object's location. Likewise, in the case of an object field get
3968 // with read barriers enabled, we do not want the load to overwrite
3969 // the object's location, as we need it to emit the read barrier.
3970 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
3971 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003972
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003973 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3974 locations->SetOut(Location::RequiresFpuRegister());
3975 } else {
3976 locations->SetOut(Location::RequiresRegister(),
3977 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3978 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003979 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00003980 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003981 // - registers need to be consecutive
3982 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003983 // We don't test for ARM yet, and the assertion makes sure that we
3984 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003985 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3986 locations->AddTemp(Location::RequiresRegister());
3987 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00003988 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
3989 // We need a temporary register for the read barrier marking slow
3990 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
3991 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003992 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003993}
3994
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003995Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
3996 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
3997 << input->GetType();
3998 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
3999 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4000 return Location::ConstantLocation(input->AsConstant());
4001 } else {
4002 return Location::RequiresFpuRegister();
4003 }
4004}
4005
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004006Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4007 Opcode opcode) {
4008 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4009 if (constant->IsConstant() &&
4010 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4011 return Location::ConstantLocation(constant->AsConstant());
4012 }
4013 return Location::RequiresRegister();
4014}
4015
4016bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4017 Opcode opcode) {
4018 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4019 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004020 Opcode high_opcode = opcode;
4021 SetCc low_set_cc = kCcDontCare;
4022 switch (opcode) {
4023 case SUB:
4024 // Flip the operation to an ADD.
4025 value = -value;
4026 opcode = ADD;
4027 FALLTHROUGH_INTENDED;
4028 case ADD:
4029 if (Low32Bits(value) == 0u) {
4030 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4031 }
4032 high_opcode = ADC;
4033 low_set_cc = kCcSet;
4034 break;
4035 default:
4036 break;
4037 }
4038 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4039 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004040 } else {
4041 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4042 }
4043}
4044
Vladimir Marko59751a72016-08-05 14:37:27 +01004045bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4046 Opcode opcode,
4047 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004048 ShifterOperand so;
4049 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004050 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004051 return true;
4052 }
4053 Opcode neg_opcode = kNoOperand;
4054 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004055 case AND: neg_opcode = BIC; value = ~value; break;
4056 case ORR: neg_opcode = ORN; value = ~value; break;
4057 case ADD: neg_opcode = SUB; value = -value; break;
4058 case ADC: neg_opcode = SBC; value = ~value; break;
4059 case SUB: neg_opcode = ADD; value = -value; break;
4060 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004061 default:
4062 return false;
4063 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004064 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004065}
4066
Calin Juravle52c48962014-12-16 17:02:57 +00004067void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4068 const FieldInfo& field_info) {
4069 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004070
Calin Juravle52c48962014-12-16 17:02:57 +00004071 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004072 Location base_loc = locations->InAt(0);
4073 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004074 Location out = locations->Out();
4075 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004076 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004077 Primitive::Type field_type = field_info.GetFieldType();
4078 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4079
4080 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004081 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004082 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004083 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004084
Roland Levillainc9285912015-12-18 10:38:42 +00004085 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004086 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004087 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004088
Roland Levillainc9285912015-12-18 10:38:42 +00004089 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004090 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004091 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004092
Roland Levillainc9285912015-12-18 10:38:42 +00004093 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004094 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004095 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004096
4097 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004098 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004099 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004100
4101 case Primitive::kPrimNot: {
4102 // /* HeapReference<Object> */ out = *(base + offset)
4103 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4104 Location temp_loc = locations->GetTemp(0);
4105 // Note that a potential implicit null check is handled in this
4106 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4107 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4108 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4109 if (is_volatile) {
4110 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4111 }
4112 } else {
4113 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4114 codegen_->MaybeRecordImplicitNullCheck(instruction);
4115 if (is_volatile) {
4116 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4117 }
4118 // If read barriers are enabled, emit read barriers other than
4119 // Baker's using a slow path (and also unpoison the loaded
4120 // reference, if heap poisoning is enabled).
4121 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4122 }
4123 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004124 }
4125
Roland Levillainc9285912015-12-18 10:38:42 +00004126 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004127 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004128 GenerateWideAtomicLoad(base, offset,
4129 out.AsRegisterPairLow<Register>(),
4130 out.AsRegisterPairHigh<Register>());
4131 } else {
4132 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4133 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004134 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004135
Roland Levillainc9285912015-12-18 10:38:42 +00004136 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004137 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004138 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004139
4140 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004141 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004142 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004143 Register lo = locations->GetTemp(0).AsRegister<Register>();
4144 Register hi = locations->GetTemp(1).AsRegister<Register>();
4145 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004146 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004147 __ vmovdrr(out_reg, lo, hi);
4148 } else {
4149 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004150 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004151 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004152 break;
4153 }
4154
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004155 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004156 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004157 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004158 }
Calin Juravle52c48962014-12-16 17:02:57 +00004159
Roland Levillainc9285912015-12-18 10:38:42 +00004160 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4161 // Potential implicit null checks, in the case of reference or
4162 // double fields, are handled in the previous switch statement.
4163 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004164 codegen_->MaybeRecordImplicitNullCheck(instruction);
4165 }
4166
Calin Juravle52c48962014-12-16 17:02:57 +00004167 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004168 if (field_type == Primitive::kPrimNot) {
4169 // Memory barriers, in the case of references, are also handled
4170 // in the previous switch statement.
4171 } else {
4172 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4173 }
Roland Levillain4d027112015-07-01 15:41:14 +01004174 }
Calin Juravle52c48962014-12-16 17:02:57 +00004175}
4176
4177void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4178 HandleFieldSet(instruction, instruction->GetFieldInfo());
4179}
4180
4181void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004182 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004183}
4184
4185void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4186 HandleFieldGet(instruction, instruction->GetFieldInfo());
4187}
4188
4189void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4190 HandleFieldGet(instruction, instruction->GetFieldInfo());
4191}
4192
4193void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4194 HandleFieldGet(instruction, instruction->GetFieldInfo());
4195}
4196
4197void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4198 HandleFieldGet(instruction, instruction->GetFieldInfo());
4199}
4200
4201void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4202 HandleFieldSet(instruction, instruction->GetFieldInfo());
4203}
4204
4205void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004206 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004207}
4208
Calin Juravlee460d1d2015-09-29 04:52:17 +01004209void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4210 HUnresolvedInstanceFieldGet* instruction) {
4211 FieldAccessCallingConventionARM calling_convention;
4212 codegen_->CreateUnresolvedFieldLocationSummary(
4213 instruction, instruction->GetFieldType(), calling_convention);
4214}
4215
4216void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4217 HUnresolvedInstanceFieldGet* instruction) {
4218 FieldAccessCallingConventionARM calling_convention;
4219 codegen_->GenerateUnresolvedFieldAccess(instruction,
4220 instruction->GetFieldType(),
4221 instruction->GetFieldIndex(),
4222 instruction->GetDexPc(),
4223 calling_convention);
4224}
4225
4226void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4227 HUnresolvedInstanceFieldSet* instruction) {
4228 FieldAccessCallingConventionARM calling_convention;
4229 codegen_->CreateUnresolvedFieldLocationSummary(
4230 instruction, instruction->GetFieldType(), calling_convention);
4231}
4232
4233void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4234 HUnresolvedInstanceFieldSet* instruction) {
4235 FieldAccessCallingConventionARM calling_convention;
4236 codegen_->GenerateUnresolvedFieldAccess(instruction,
4237 instruction->GetFieldType(),
4238 instruction->GetFieldIndex(),
4239 instruction->GetDexPc(),
4240 calling_convention);
4241}
4242
4243void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4244 HUnresolvedStaticFieldGet* instruction) {
4245 FieldAccessCallingConventionARM calling_convention;
4246 codegen_->CreateUnresolvedFieldLocationSummary(
4247 instruction, instruction->GetFieldType(), calling_convention);
4248}
4249
4250void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4251 HUnresolvedStaticFieldGet* instruction) {
4252 FieldAccessCallingConventionARM calling_convention;
4253 codegen_->GenerateUnresolvedFieldAccess(instruction,
4254 instruction->GetFieldType(),
4255 instruction->GetFieldIndex(),
4256 instruction->GetDexPc(),
4257 calling_convention);
4258}
4259
4260void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4261 HUnresolvedStaticFieldSet* instruction) {
4262 FieldAccessCallingConventionARM calling_convention;
4263 codegen_->CreateUnresolvedFieldLocationSummary(
4264 instruction, instruction->GetFieldType(), calling_convention);
4265}
4266
4267void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4268 HUnresolvedStaticFieldSet* instruction) {
4269 FieldAccessCallingConventionARM calling_convention;
4270 codegen_->GenerateUnresolvedFieldAccess(instruction,
4271 instruction->GetFieldType(),
4272 instruction->GetFieldIndex(),
4273 instruction->GetDexPc(),
4274 calling_convention);
4275}
4276
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004277void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004278 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4279 ? LocationSummary::kCallOnSlowPath
4280 : LocationSummary::kNoCall;
4281 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00004282 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004283 if (instruction->HasUses()) {
4284 locations->SetOut(Location::SameAsFirstInput());
4285 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004286}
4287
Calin Juravle2ae48182016-03-16 14:05:09 +00004288void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4289 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004290 return;
4291 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004292 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004293
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004294 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004295 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004296}
4297
Calin Juravle2ae48182016-03-16 14:05:09 +00004298void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004299 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004300 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004301
4302 LocationSummary* locations = instruction->GetLocations();
4303 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004304
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004305 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004306}
4307
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004308void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004309 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004310}
4311
Artem Serov6c916792016-07-11 14:02:34 +01004312static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4313 switch (type) {
4314 case Primitive::kPrimNot:
4315 return kLoadWord;
4316 case Primitive::kPrimBoolean:
4317 return kLoadUnsignedByte;
4318 case Primitive::kPrimByte:
4319 return kLoadSignedByte;
4320 case Primitive::kPrimChar:
4321 return kLoadUnsignedHalfword;
4322 case Primitive::kPrimShort:
4323 return kLoadSignedHalfword;
4324 case Primitive::kPrimInt:
4325 return kLoadWord;
4326 case Primitive::kPrimLong:
4327 return kLoadWordPair;
4328 case Primitive::kPrimFloat:
4329 return kLoadSWord;
4330 case Primitive::kPrimDouble:
4331 return kLoadDWord;
4332 default:
4333 LOG(FATAL) << "Unreachable type " << type;
4334 UNREACHABLE();
4335 }
4336}
4337
4338static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4339 switch (type) {
4340 case Primitive::kPrimNot:
4341 return kStoreWord;
4342 case Primitive::kPrimBoolean:
4343 case Primitive::kPrimByte:
4344 return kStoreByte;
4345 case Primitive::kPrimChar:
4346 case Primitive::kPrimShort:
4347 return kStoreHalfword;
4348 case Primitive::kPrimInt:
4349 return kStoreWord;
4350 case Primitive::kPrimLong:
4351 return kStoreWordPair;
4352 case Primitive::kPrimFloat:
4353 return kStoreSWord;
4354 case Primitive::kPrimDouble:
4355 return kStoreDWord;
4356 default:
4357 LOG(FATAL) << "Unreachable type " << type;
4358 UNREACHABLE();
4359 }
4360}
4361
4362void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4363 Location out_loc,
4364 Register base,
4365 Register reg_offset,
4366 Condition cond) {
4367 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4368 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4369
4370 switch (type) {
4371 case Primitive::kPrimByte:
4372 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4373 break;
4374 case Primitive::kPrimBoolean:
4375 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4376 break;
4377 case Primitive::kPrimShort:
4378 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4379 break;
4380 case Primitive::kPrimChar:
4381 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4382 break;
4383 case Primitive::kPrimNot:
4384 case Primitive::kPrimInt:
4385 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4386 break;
4387 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4388 case Primitive::kPrimLong:
4389 case Primitive::kPrimFloat:
4390 case Primitive::kPrimDouble:
4391 default:
4392 LOG(FATAL) << "Unreachable type " << type;
4393 UNREACHABLE();
4394 }
4395}
4396
4397void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4398 Location loc,
4399 Register base,
4400 Register reg_offset,
4401 Condition cond) {
4402 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4403 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4404
4405 switch (type) {
4406 case Primitive::kPrimByte:
4407 case Primitive::kPrimBoolean:
4408 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4409 break;
4410 case Primitive::kPrimShort:
4411 case Primitive::kPrimChar:
4412 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4413 break;
4414 case Primitive::kPrimNot:
4415 case Primitive::kPrimInt:
4416 __ str(loc.AsRegister<Register>(), mem_address, cond);
4417 break;
4418 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4419 case Primitive::kPrimLong:
4420 case Primitive::kPrimFloat:
4421 case Primitive::kPrimDouble:
4422 default:
4423 LOG(FATAL) << "Unreachable type " << type;
4424 UNREACHABLE();
4425 }
4426}
4427
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004428void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004429 bool object_array_get_with_read_barrier =
4430 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004431 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004432 new (GetGraph()->GetArena()) LocationSummary(instruction,
4433 object_array_get_with_read_barrier ?
4434 LocationSummary::kCallOnSlowPath :
4435 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004436 locations->SetInAt(0, Location::RequiresRegister());
4437 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004438 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4439 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4440 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004441 // The output overlaps in the case of an object array get with
4442 // read barriers enabled: we do not want the move to overwrite the
4443 // array's location, as we need it to emit the read barrier.
4444 locations->SetOut(
4445 Location::RequiresRegister(),
4446 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004447 }
Roland Levillainc9285912015-12-18 10:38:42 +00004448 // We need a temporary register for the read barrier marking slow
4449 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
4450 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4451 locations->AddTemp(Location::RequiresRegister());
4452 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004453}
4454
4455void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4456 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004457 Location obj_loc = locations->InAt(0);
4458 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004459 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004460 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004461 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004462 Primitive::Type type = instruction->GetType();
Artem Serov328429f2016-07-06 16:23:04 +01004463 HInstruction* array_instr = instruction->GetArray();
4464 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004465 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4466 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Artem Serov6c916792016-07-11 14:02:34 +01004467
Roland Levillain4d027112015-07-01 15:41:14 +01004468 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004469 case Primitive::kPrimBoolean:
4470 case Primitive::kPrimByte:
4471 case Primitive::kPrimShort:
4472 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004473 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004474 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004475 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4476 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
4477
4478 LoadOperandType load_type = GetLoadOperandType(type);
4479 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004480 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004481 Register temp = IP;
4482
4483 if (has_intermediate_address) {
4484 // We do not need to compute the intermediate address from the array: the
4485 // input instruction has done it already. See the comment in
4486 // `TryExtractArrayAccessAddress()`.
4487 if (kIsDebugBuild) {
4488 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4489 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4490 }
4491 temp = obj;
4492 } else {
4493 __ add(temp, obj, ShifterOperand(data_offset));
4494 }
4495 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004496 }
4497 break;
4498 }
4499
Roland Levillainc9285912015-12-18 10:38:42 +00004500 case Primitive::kPrimNot: {
4501 static_assert(
4502 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4503 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004504 // /* HeapReference<Object> */ out =
4505 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4506 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4507 Location temp = locations->GetTemp(0);
4508 // Note that a potential implicit null check is handled in this
4509 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4510 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4511 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4512 } else {
4513 Register out = out_loc.AsRegister<Register>();
4514 if (index.IsConstant()) {
4515 size_t offset =
4516 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4517 __ LoadFromOffset(kLoadWord, out, obj, offset);
4518 codegen_->MaybeRecordImplicitNullCheck(instruction);
4519 // If read barriers are enabled, emit read barriers other than
4520 // Baker's using a slow path (and also unpoison the loaded
4521 // reference, if heap poisoning is enabled).
4522 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4523 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004524 Register temp = IP;
4525
4526 if (has_intermediate_address) {
4527 // We do not need to compute the intermediate address from the array: the
4528 // input instruction has done it already. See the comment in
4529 // `TryExtractArrayAccessAddress()`.
4530 if (kIsDebugBuild) {
4531 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4532 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4533 }
4534 temp = obj;
4535 } else {
4536 __ add(temp, obj, ShifterOperand(data_offset));
4537 }
4538 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004539
Roland Levillainc9285912015-12-18 10:38:42 +00004540 codegen_->MaybeRecordImplicitNullCheck(instruction);
4541 // If read barriers are enabled, emit read barriers other than
4542 // Baker's using a slow path (and also unpoison the loaded
4543 // reference, if heap poisoning is enabled).
4544 codegen_->MaybeGenerateReadBarrierSlow(
4545 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4546 }
4547 }
4548 break;
4549 }
4550
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004551 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004552 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004553 size_t offset =
4554 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004555 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004556 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004557 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004558 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004559 }
4560 break;
4561 }
4562
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004563 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004564 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004565 if (index.IsConstant()) {
4566 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004567 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004568 } else {
4569 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004570 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004571 }
4572 break;
4573 }
4574
4575 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004576 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004577 if (index.IsConstant()) {
4578 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004579 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004580 } else {
4581 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004582 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004583 }
4584 break;
4585 }
4586
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004587 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01004588 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004589 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004590 }
Roland Levillain4d027112015-07-01 15:41:14 +01004591
4592 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00004593 // Potential implicit null checks, in the case of reference
4594 // arrays, are handled in the previous switch statement.
4595 } else {
4596 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01004597 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004598}
4599
4600void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004601 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004602
4603 bool needs_write_barrier =
4604 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00004605 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004606
Nicolas Geoffray39468442014-09-02 15:17:15 +01004607 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004608 instruction,
Vladimir Marko8d49fd72016-08-25 15:20:47 +01004609 may_need_runtime_call_for_type_check ?
Roland Levillain3b359c72015-11-17 19:35:12 +00004610 LocationSummary::kCallOnSlowPath :
4611 LocationSummary::kNoCall);
4612
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004613 locations->SetInAt(0, Location::RequiresRegister());
4614 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
4615 if (Primitive::IsFloatingPointType(value_type)) {
4616 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004617 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004618 locations->SetInAt(2, Location::RequiresRegister());
4619 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004620 if (needs_write_barrier) {
4621 // Temporary registers for the write barrier.
Roland Levillain16d9f942016-08-25 17:27:56 +01004622 // These registers may be used for Baker read barriers too.
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004623 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00004624 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004625 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004626}
4627
4628void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4629 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004630 Location array_loc = locations->InAt(0);
4631 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004632 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004633 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00004634 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004635 bool needs_write_barrier =
4636 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01004637 uint32_t data_offset =
4638 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
4639 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01004640 HInstruction* array_instr = instruction->GetArray();
4641 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004642 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4643 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004644
4645 switch (value_type) {
4646 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01004647 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004648 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01004649 case Primitive::kPrimChar:
4650 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004651 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004652 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4653 uint32_t full_offset =
4654 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
4655 StoreOperandType store_type = GetStoreOperandType(value_type);
4656 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004657 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004658 Register temp = IP;
4659
4660 if (has_intermediate_address) {
4661 // We do not need to compute the intermediate address from the array: the
4662 // input instruction has done it already. See the comment in
4663 // `TryExtractArrayAccessAddress()`.
4664 if (kIsDebugBuild) {
4665 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4666 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
4667 }
4668 temp = array;
4669 } else {
4670 __ add(temp, array, ShifterOperand(data_offset));
4671 }
Artem Serov6c916792016-07-11 14:02:34 +01004672 codegen_->StoreToShiftedRegOffset(value_type,
4673 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01004674 temp,
Artem Serov6c916792016-07-11 14:02:34 +01004675 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004676 }
4677 break;
4678 }
4679
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004680 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00004681 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01004682 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
4683 // See the comment in instruction_simplifier_shared.cc.
4684 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004685
4686 if (instruction->InputAt(2)->IsNullConstant()) {
4687 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004688 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004689 size_t offset =
4690 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01004691 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004692 } else {
4693 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004694 __ add(IP, array, ShifterOperand(data_offset));
4695 codegen_->StoreToShiftedRegOffset(value_type,
4696 value_loc,
4697 IP,
4698 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004699 }
Roland Levillain1407ee72016-01-08 15:56:19 +00004700 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00004701 DCHECK(!needs_write_barrier);
4702 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004703 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004704 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004705
4706 DCHECK(needs_write_barrier);
Roland Levillain16d9f942016-08-25 17:27:56 +01004707 Location temp1_loc = locations->GetTemp(0);
4708 Register temp1 = temp1_loc.AsRegister<Register>();
4709 Location temp2_loc = locations->GetTemp(1);
4710 Register temp2 = temp2_loc.AsRegister<Register>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004711 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4712 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4713 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4714 Label done;
4715 SlowPathCode* slow_path = nullptr;
4716
Roland Levillain3b359c72015-11-17 19:35:12 +00004717 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004718 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4719 codegen_->AddSlowPath(slow_path);
4720 if (instruction->GetValueCanBeNull()) {
4721 Label non_zero;
4722 __ CompareAndBranchIfNonZero(value, &non_zero);
4723 if (index.IsConstant()) {
4724 size_t offset =
4725 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4726 __ StoreToOffset(kStoreWord, value, array, offset);
4727 } else {
4728 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004729 __ add(IP, array, ShifterOperand(data_offset));
4730 codegen_->StoreToShiftedRegOffset(value_type,
4731 value_loc,
4732 IP,
4733 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004734 }
4735 codegen_->MaybeRecordImplicitNullCheck(instruction);
4736 __ b(&done);
4737 __ Bind(&non_zero);
4738 }
4739
Roland Levillain3b359c72015-11-17 19:35:12 +00004740 if (kEmitCompilerReadBarrier) {
Roland Levillain16d9f942016-08-25 17:27:56 +01004741 if (!kUseBakerReadBarrier) {
4742 // When (non-Baker) read barriers are enabled, the type
4743 // checking instrumentation requires two read barriers
4744 // generated by CodeGeneratorARM::GenerateReadBarrierSlow:
4745 //
4746 // __ Mov(temp2, temp1);
4747 // // /* HeapReference<Class> */ temp1 = temp1->component_type_
4748 // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4749 // codegen_->GenerateReadBarrierSlow(
4750 // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset);
4751 //
4752 // // /* HeapReference<Class> */ temp2 = value->klass_
4753 // __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4754 // codegen_->GenerateReadBarrierSlow(
4755 // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc);
4756 //
4757 // __ cmp(temp1, ShifterOperand(temp2));
4758 //
4759 // However, the second read barrier may trash `temp`, as it
4760 // is a temporary register, and as such would not be saved
4761 // along with live registers before calling the runtime (nor
4762 // restored afterwards). So in this case, we bail out and
4763 // delegate the work to the array set slow path.
4764 //
4765 // TODO: Extend the register allocator to support a new
4766 // "(locally) live temp" location so as to avoid always
4767 // going into the slow path when read barriers are enabled?
4768 //
4769 // There is no such problem with Baker read barriers (see below).
4770 __ b(slow_path->GetEntryLabel());
4771 } else {
4772 Register temp3 = IP;
4773 Location temp3_loc = Location::RegisterLocation(temp3);
4774
4775 // Note: `temp3` (scratch register IP) cannot be used as
4776 // `ref` argument of GenerateFieldLoadWithBakerReadBarrier
4777 // calls below (see ReadBarrierMarkSlowPathARM for more
4778 // details).
4779
4780 // /* HeapReference<Class> */ temp1 = array->klass_
4781 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4782 temp1_loc,
4783 array,
4784 class_offset,
4785 temp3_loc,
4786 /* needs_null_check */ true);
4787
4788 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4789 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4790 temp1_loc,
4791 temp1,
4792 component_offset,
4793 temp3_loc,
4794 /* needs_null_check */ false);
4795 // Register `temp1` is not trashed by the read barrier
4796 // emitted by GenerateFieldLoadWithBakerReadBarrier below,
4797 // as that method produces a call to a ReadBarrierMarkRegX
4798 // entry point, which saves all potentially live registers,
4799 // including temporaries such a `temp1`.
4800 // /* HeapReference<Class> */ temp2 = value->klass_
4801 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4802 temp2_loc,
4803 value,
4804 class_offset,
4805 temp3_loc,
4806 /* needs_null_check */ false);
4807 // If heap poisoning is enabled, `temp1` and `temp2` have
4808 // been unpoisoned by the the previous calls to
4809 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4810 __ cmp(temp1, ShifterOperand(temp2));
4811
4812 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4813 Label do_put;
4814 __ b(&do_put, EQ);
4815 // We do not need to emit a read barrier for the
4816 // following heap reference load, as `temp1` is only used
4817 // in a comparison with null below, and this reference
4818 // is not kept afterwards.
4819 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4820 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4821 // If heap poisoning is enabled, no need to unpoison
4822 // `temp`, as we are comparing against null below.
4823 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4824 __ Bind(&do_put);
4825 } else {
4826 __ b(slow_path->GetEntryLabel(), NE);
4827 }
4828 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004829 } else {
Roland Levillain16d9f942016-08-25 17:27:56 +01004830 // Non read barrier code.
4831
Roland Levillain3b359c72015-11-17 19:35:12 +00004832 // /* HeapReference<Class> */ temp1 = array->klass_
4833 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4834 codegen_->MaybeRecordImplicitNullCheck(instruction);
4835 __ MaybeUnpoisonHeapReference(temp1);
4836
4837 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4838 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4839 // /* HeapReference<Class> */ temp2 = value->klass_
4840 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4841 // If heap poisoning is enabled, no need to unpoison `temp1`
4842 // nor `temp2`, as we are comparing two poisoned references.
4843 __ cmp(temp1, ShifterOperand(temp2));
4844
4845 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4846 Label do_put;
4847 __ b(&do_put, EQ);
4848 // If heap poisoning is enabled, the `temp1` reference has
4849 // not been unpoisoned yet; unpoison it now.
4850 __ MaybeUnpoisonHeapReference(temp1);
4851
4852 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4853 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4854 // If heap poisoning is enabled, no need to unpoison
4855 // `temp1`, as we are comparing against null below.
4856 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4857 __ Bind(&do_put);
4858 } else {
4859 __ b(slow_path->GetEntryLabel(), NE);
4860 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004861 }
4862 }
4863
Artem Serov6c916792016-07-11 14:02:34 +01004864 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004865 if (kPoisonHeapReferences) {
4866 // Note that in the case where `value` is a null reference,
4867 // we do not enter this block, as a null reference does not
4868 // need poisoning.
4869 DCHECK_EQ(value_type, Primitive::kPrimNot);
4870 __ Mov(temp1, value);
4871 __ PoisonHeapReference(temp1);
4872 source = temp1;
4873 }
4874
4875 if (index.IsConstant()) {
4876 size_t offset =
4877 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4878 __ StoreToOffset(kStoreWord, source, array, offset);
4879 } else {
4880 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004881
4882 __ add(IP, array, ShifterOperand(data_offset));
4883 codegen_->StoreToShiftedRegOffset(value_type,
4884 Location::RegisterLocation(source),
4885 IP,
4886 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004887 }
4888
Roland Levillain3b359c72015-11-17 19:35:12 +00004889 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004890 codegen_->MaybeRecordImplicitNullCheck(instruction);
4891 }
4892
4893 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4894
4895 if (done.IsLinked()) {
4896 __ Bind(&done);
4897 }
4898
4899 if (slow_path != nullptr) {
4900 __ Bind(slow_path->GetExitLabel());
4901 }
4902
4903 break;
4904 }
4905
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004906 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004907 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004908 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004909 size_t offset =
4910 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004911 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004912 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004913 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004914 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004915 }
4916 break;
4917 }
4918
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004919 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004920 Location value = locations->InAt(2);
4921 DCHECK(value.IsFpuRegister());
4922 if (index.IsConstant()) {
4923 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004924 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004925 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004926 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004927 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4928 }
4929 break;
4930 }
4931
4932 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004933 Location value = locations->InAt(2);
4934 DCHECK(value.IsFpuRegisterPair());
4935 if (index.IsConstant()) {
4936 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004937 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004938 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004939 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004940 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4941 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004942
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004943 break;
4944 }
4945
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004946 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004947 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004948 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004949 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004950
Roland Levillain80e67092016-01-08 16:04:55 +00004951 // Objects are handled in the switch.
4952 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004953 codegen_->MaybeRecordImplicitNullCheck(instruction);
4954 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004955}
4956
4957void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004958 LocationSummary* locations =
4959 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004960 locations->SetInAt(0, Location::RequiresRegister());
4961 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004962}
4963
4964void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4965 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01004966 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00004967 Register obj = locations->InAt(0).AsRegister<Register>();
4968 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004969 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004970 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004971}
4972
Artem Serov328429f2016-07-06 16:23:04 +01004973void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Roland Levillain4a3aa572016-08-15 13:17:06 +00004974 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4975 DCHECK(!kEmitCompilerReadBarrier);
Artem Serov328429f2016-07-06 16:23:04 +01004976 LocationSummary* locations =
4977 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4978
4979 locations->SetInAt(0, Location::RequiresRegister());
4980 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
4981 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4982}
4983
4984void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
4985 LocationSummary* locations = instruction->GetLocations();
4986 Location out = locations->Out();
4987 Location first = locations->InAt(0);
4988 Location second = locations->InAt(1);
4989
Roland Levillain4a3aa572016-08-15 13:17:06 +00004990 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4991 DCHECK(!kEmitCompilerReadBarrier);
4992
Artem Serov328429f2016-07-06 16:23:04 +01004993 if (second.IsRegister()) {
4994 __ add(out.AsRegister<Register>(),
4995 first.AsRegister<Register>(),
4996 ShifterOperand(second.AsRegister<Register>()));
4997 } else {
4998 __ AddConstant(out.AsRegister<Register>(),
4999 first.AsRegister<Register>(),
5000 second.GetConstant()->AsIntConstant()->GetValue());
5001 }
5002}
5003
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005004void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00005005 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
5006 ? LocationSummary::kCallOnSlowPath
5007 : LocationSummary::kNoCall;
5008 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005009 locations->SetInAt(0, Location::RequiresRegister());
5010 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01005011 if (instruction->HasUses()) {
5012 locations->SetOut(Location::SameAsFirstInput());
5013 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005014}
5015
5016void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
5017 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07005018 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005019 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005020 codegen_->AddSlowPath(slow_path);
5021
Roland Levillain271ab9c2014-11-27 15:23:57 +00005022 Register index = locations->InAt(0).AsRegister<Register>();
5023 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005024
5025 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01005026 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005027}
5028
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005029void CodeGeneratorARM::MarkGCCard(Register temp,
5030 Register card,
5031 Register object,
5032 Register value,
5033 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005034 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005035 if (can_be_null) {
5036 __ CompareAndBranchIfZero(value, &is_null);
5037 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005038 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005039 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5040 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005041 if (can_be_null) {
5042 __ Bind(&is_null);
5043 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005044}
5045
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005046void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005047 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005048}
5049
5050void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005051 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5052}
5053
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005054void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
5055 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5056}
5057
5058void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005059 HBasicBlock* block = instruction->GetBlock();
5060 if (block->GetLoopInformation() != nullptr) {
5061 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5062 // The back edge will generate the suspend check.
5063 return;
5064 }
5065 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5066 // The goto will generate the suspend check.
5067 return;
5068 }
5069 GenerateSuspendCheck(instruction, nullptr);
5070}
5071
5072void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5073 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005074 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005075 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5076 if (slow_path == nullptr) {
5077 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5078 instruction->SetSlowPath(slow_path);
5079 codegen_->AddSlowPath(slow_path);
5080 if (successor != nullptr) {
5081 DCHECK(successor->IsLoopHeader());
5082 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5083 }
5084 } else {
5085 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5086 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005087
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005088 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005089 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005090 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005091 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005092 __ Bind(slow_path->GetReturnLabel());
5093 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005094 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005095 __ b(slow_path->GetEntryLabel());
5096 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005097}
5098
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005099ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5100 return codegen_->GetAssembler();
5101}
5102
5103void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005104 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005105 Location source = move->GetSource();
5106 Location destination = move->GetDestination();
5107
5108 if (source.IsRegister()) {
5109 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005110 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005111 } else if (destination.IsFpuRegister()) {
5112 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005113 } else {
5114 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005115 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005116 SP, destination.GetStackIndex());
5117 }
5118 } else if (source.IsStackSlot()) {
5119 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005120 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005121 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005122 } else if (destination.IsFpuRegister()) {
5123 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005124 } else {
5125 DCHECK(destination.IsStackSlot());
5126 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5127 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5128 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005129 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005130 if (destination.IsRegister()) {
5131 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5132 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005133 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005134 } else {
5135 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005136 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5137 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005138 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005139 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005140 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5141 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005142 } else if (destination.IsRegisterPair()) {
5143 DCHECK(ExpectedPairLayout(destination));
5144 __ LoadFromOffset(
5145 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5146 } else {
5147 DCHECK(destination.IsFpuRegisterPair()) << destination;
5148 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5149 SP,
5150 source.GetStackIndex());
5151 }
5152 } else if (source.IsRegisterPair()) {
5153 if (destination.IsRegisterPair()) {
5154 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5155 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005156 } else if (destination.IsFpuRegisterPair()) {
5157 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5158 source.AsRegisterPairLow<Register>(),
5159 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005160 } else {
5161 DCHECK(destination.IsDoubleStackSlot()) << destination;
5162 DCHECK(ExpectedPairLayout(source));
5163 __ StoreToOffset(
5164 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5165 }
5166 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005167 if (destination.IsRegisterPair()) {
5168 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5169 destination.AsRegisterPairHigh<Register>(),
5170 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5171 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005172 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5173 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5174 } else {
5175 DCHECK(destination.IsDoubleStackSlot()) << destination;
5176 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5177 SP,
5178 destination.GetStackIndex());
5179 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005180 } else {
5181 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005182 HConstant* constant = source.GetConstant();
5183 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5184 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005185 if (destination.IsRegister()) {
5186 __ LoadImmediate(destination.AsRegister<Register>(), value);
5187 } else {
5188 DCHECK(destination.IsStackSlot());
5189 __ LoadImmediate(IP, value);
5190 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5191 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005192 } else if (constant->IsLongConstant()) {
5193 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005194 if (destination.IsRegisterPair()) {
5195 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5196 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005197 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005198 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005199 __ LoadImmediate(IP, Low32Bits(value));
5200 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5201 __ LoadImmediate(IP, High32Bits(value));
5202 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5203 }
5204 } else if (constant->IsDoubleConstant()) {
5205 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005206 if (destination.IsFpuRegisterPair()) {
5207 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005208 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005209 DCHECK(destination.IsDoubleStackSlot()) << destination;
5210 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005211 __ LoadImmediate(IP, Low32Bits(int_value));
5212 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5213 __ LoadImmediate(IP, High32Bits(int_value));
5214 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5215 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005216 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005217 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005218 float value = constant->AsFloatConstant()->GetValue();
5219 if (destination.IsFpuRegister()) {
5220 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5221 } else {
5222 DCHECK(destination.IsStackSlot());
5223 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5224 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5225 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005226 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005227 }
5228}
5229
5230void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5231 __ Mov(IP, reg);
5232 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5233 __ StoreToOffset(kStoreWord, IP, SP, mem);
5234}
5235
5236void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5237 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5238 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5239 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5240 SP, mem1 + stack_offset);
5241 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5242 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5243 SP, mem2 + stack_offset);
5244 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5245}
5246
5247void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005248 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005249 Location source = move->GetSource();
5250 Location destination = move->GetDestination();
5251
5252 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005253 DCHECK_NE(source.AsRegister<Register>(), IP);
5254 DCHECK_NE(destination.AsRegister<Register>(), IP);
5255 __ Mov(IP, source.AsRegister<Register>());
5256 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5257 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005258 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005259 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005260 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005261 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005262 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5263 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005264 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005265 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005266 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005267 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005268 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005269 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005270 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005271 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005272 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5273 destination.AsRegisterPairHigh<Register>(),
5274 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005275 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005276 Register low_reg = source.IsRegisterPair()
5277 ? source.AsRegisterPairLow<Register>()
5278 : destination.AsRegisterPairLow<Register>();
5279 int mem = source.IsRegisterPair()
5280 ? destination.GetStackIndex()
5281 : source.GetStackIndex();
5282 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005283 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005284 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005285 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005286 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005287 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5288 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005289 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005290 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005291 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005292 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5293 DRegister reg = source.IsFpuRegisterPair()
5294 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5295 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5296 int mem = source.IsFpuRegisterPair()
5297 ? destination.GetStackIndex()
5298 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005299 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005300 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005301 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005302 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5303 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5304 : destination.AsFpuRegister<SRegister>();
5305 int mem = source.IsFpuRegister()
5306 ? destination.GetStackIndex()
5307 : source.GetStackIndex();
5308
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005309 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005310 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005311 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005312 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005313 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5314 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005315 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005316 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005317 }
5318}
5319
5320void ParallelMoveResolverARM::SpillScratch(int reg) {
5321 __ Push(static_cast<Register>(reg));
5322}
5323
5324void ParallelMoveResolverARM::RestoreScratch(int reg) {
5325 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005326}
5327
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005328HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5329 HLoadClass::LoadKind desired_class_load_kind) {
5330 if (kEmitCompilerReadBarrier) {
5331 switch (desired_class_load_kind) {
5332 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5333 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5334 case HLoadClass::LoadKind::kBootImageAddress:
5335 // TODO: Implement for read barrier.
5336 return HLoadClass::LoadKind::kDexCacheViaMethod;
5337 default:
5338 break;
5339 }
5340 }
5341 switch (desired_class_load_kind) {
5342 case HLoadClass::LoadKind::kReferrersClass:
5343 break;
5344 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5345 DCHECK(!GetCompilerOptions().GetCompilePic());
5346 break;
5347 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5348 DCHECK(GetCompilerOptions().GetCompilePic());
5349 break;
5350 case HLoadClass::LoadKind::kBootImageAddress:
5351 break;
5352 case HLoadClass::LoadKind::kDexCacheAddress:
5353 DCHECK(Runtime::Current()->UseJitCompilation());
5354 break;
5355 case HLoadClass::LoadKind::kDexCachePcRelative:
5356 DCHECK(!Runtime::Current()->UseJitCompilation());
5357 // We disable pc-relative load when there is an irreducible loop, as the optimization
5358 // is incompatible with it.
5359 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5360 // with irreducible loops.
5361 if (GetGraph()->HasIrreducibleLoops()) {
5362 return HLoadClass::LoadKind::kDexCacheViaMethod;
5363 }
5364 break;
5365 case HLoadClass::LoadKind::kDexCacheViaMethod:
5366 break;
5367 }
5368 return desired_class_load_kind;
5369}
5370
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005371void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005372 if (cls->NeedsAccessCheck()) {
5373 InvokeRuntimeCallingConvention calling_convention;
5374 CodeGenerator::CreateLoadClassLocationSummary(
5375 cls,
5376 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5377 Location::RegisterLocation(R0),
5378 /* code_generator_supports_read_barrier */ true);
5379 return;
5380 }
5381
5382 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5383 ? LocationSummary::kCallOnSlowPath
5384 : LocationSummary::kNoCall;
5385 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
5386 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5387 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5388 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5389 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5390 locations->SetInAt(0, Location::RequiresRegister());
5391 }
5392 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005393}
5394
5395void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005396 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005397 if (cls->NeedsAccessCheck()) {
5398 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01005399 codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005400 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005401 return;
5402 }
5403
Roland Levillain3b359c72015-11-17 19:35:12 +00005404 Location out_loc = locations->Out();
5405 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005406
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005407 bool generate_null_check = false;
5408 switch (cls->GetLoadKind()) {
5409 case HLoadClass::LoadKind::kReferrersClass: {
5410 DCHECK(!cls->CanCallRuntime());
5411 DCHECK(!cls->MustGenerateClinitCheck());
5412 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5413 Register current_method = locations->InAt(0).AsRegister<Register>();
5414 GenerateGcRootFieldLoad(
5415 cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5416 break;
5417 }
5418 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
5419 DCHECK(!kEmitCompilerReadBarrier);
5420 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5421 cls->GetTypeIndex()));
5422 break;
5423 }
5424 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
5425 DCHECK(!kEmitCompilerReadBarrier);
5426 CodeGeneratorARM::PcRelativePatchInfo* labels =
5427 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5428 __ BindTrackedLabel(&labels->movw_label);
5429 __ movw(out, /* placeholder */ 0u);
5430 __ BindTrackedLabel(&labels->movt_label);
5431 __ movt(out, /* placeholder */ 0u);
5432 __ BindTrackedLabel(&labels->add_pc_label);
5433 __ add(out, out, ShifterOperand(PC));
5434 break;
5435 }
5436 case HLoadClass::LoadKind::kBootImageAddress: {
5437 DCHECK(!kEmitCompilerReadBarrier);
5438 DCHECK_NE(cls->GetAddress(), 0u);
5439 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5440 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5441 break;
5442 }
5443 case HLoadClass::LoadKind::kDexCacheAddress: {
5444 DCHECK_NE(cls->GetAddress(), 0u);
5445 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5446 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5447 // a 128B range. To try and reduce the number of literals if we load multiple types,
5448 // simply split the dex cache address to a 128B aligned base loaded from a literal
5449 // and the remaining offset embedded in the load.
5450 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5451 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5452 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5453 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5454 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5455 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5456 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
5457 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5458 generate_null_check = !cls->IsInDexCache();
5459 break;
5460 }
5461 case HLoadClass::LoadKind::kDexCachePcRelative: {
5462 Register base_reg = locations->InAt(0).AsRegister<Register>();
5463 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5464 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5465 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
5466 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset);
5467 generate_null_check = !cls->IsInDexCache();
5468 break;
5469 }
5470 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5471 // /* GcRoot<mirror::Class>[] */ out =
5472 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5473 Register current_method = locations->InAt(0).AsRegister<Register>();
5474 __ LoadFromOffset(kLoadWord,
5475 out,
5476 current_method,
5477 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5478 // /* GcRoot<mirror::Class> */ out = out[type_index]
5479 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
5480 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5481 generate_null_check = !cls->IsInDexCache();
5482 }
5483 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005484
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005485 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5486 DCHECK(cls->CanCallRuntime());
5487 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
5488 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5489 codegen_->AddSlowPath(slow_path);
5490 if (generate_null_check) {
5491 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5492 }
5493 if (cls->MustGenerateClinitCheck()) {
5494 GenerateClassInitializationCheck(slow_path, out);
5495 } else {
5496 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005497 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005498 }
5499}
5500
5501void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5502 LocationSummary* locations =
5503 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5504 locations->SetInAt(0, Location::RequiresRegister());
5505 if (check->HasUses()) {
5506 locations->SetOut(Location::SameAsFirstInput());
5507 }
5508}
5509
5510void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005511 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07005512 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005513 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005514 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005515 GenerateClassInitializationCheck(slow_path,
5516 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005517}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005518
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005519void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07005520 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005521 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5522 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5523 __ b(slow_path->GetEntryLabel(), LT);
5524 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5525 // properly. Therefore, we do a memory fence.
5526 __ dmb(ISH);
5527 __ Bind(slow_path->GetExitLabel());
5528}
5529
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005530HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5531 HLoadString::LoadKind desired_string_load_kind) {
5532 if (kEmitCompilerReadBarrier) {
5533 switch (desired_string_load_kind) {
5534 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5535 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5536 case HLoadString::LoadKind::kBootImageAddress:
5537 // TODO: Implement for read barrier.
5538 return HLoadString::LoadKind::kDexCacheViaMethod;
5539 default:
5540 break;
5541 }
5542 }
5543 switch (desired_string_load_kind) {
5544 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5545 DCHECK(!GetCompilerOptions().GetCompilePic());
5546 break;
5547 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5548 DCHECK(GetCompilerOptions().GetCompilePic());
5549 break;
5550 case HLoadString::LoadKind::kBootImageAddress:
5551 break;
5552 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005553 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005554 break;
5555 case HLoadString::LoadKind::kDexCachePcRelative:
Calin Juravleffc87072016-04-20 14:22:09 +01005556 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005557 // We disable pc-relative load when there is an irreducible loop, as the optimization
5558 // is incompatible with it.
5559 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5560 // with irreducible loops.
5561 if (GetGraph()->HasIrreducibleLoops()) {
5562 return HLoadString::LoadKind::kDexCacheViaMethod;
5563 }
5564 break;
5565 case HLoadString::LoadKind::kDexCacheViaMethod:
5566 break;
5567 }
5568 return desired_string_load_kind;
5569}
5570
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005571void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005572 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005573 ? LocationSummary::kCallOnSlowPath
5574 : LocationSummary::kNoCall;
5575 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005576 HLoadString::LoadKind load_kind = load->GetLoadKind();
5577 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod ||
5578 load_kind == HLoadString::LoadKind::kDexCachePcRelative) {
5579 locations->SetInAt(0, Location::RequiresRegister());
5580 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005581 locations->SetOut(Location::RequiresRegister());
5582}
5583
5584void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005585 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005586 Location out_loc = locations->Out();
5587 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005588
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005589 switch (load->GetLoadKind()) {
5590 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
5591 DCHECK(!kEmitCompilerReadBarrier);
5592 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5593 load->GetStringIndex()));
5594 return; // No dex cache slow path.
5595 }
5596 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
5597 DCHECK(!kEmitCompilerReadBarrier);
5598 CodeGeneratorARM::PcRelativePatchInfo* labels =
5599 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5600 __ BindTrackedLabel(&labels->movw_label);
5601 __ movw(out, /* placeholder */ 0u);
5602 __ BindTrackedLabel(&labels->movt_label);
5603 __ movt(out, /* placeholder */ 0u);
5604 __ BindTrackedLabel(&labels->add_pc_label);
5605 __ add(out, out, ShifterOperand(PC));
5606 return; // No dex cache slow path.
5607 }
5608 case HLoadString::LoadKind::kBootImageAddress: {
5609 DCHECK(!kEmitCompilerReadBarrier);
5610 DCHECK_NE(load->GetAddress(), 0u);
5611 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5612 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5613 return; // No dex cache slow path.
5614 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005615 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005616 break;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005617 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005618
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005619 // TODO: Re-add the compiler code to do string dex cache lookup again.
5620 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5621 codegen_->AddSlowPath(slow_path);
5622 __ b(slow_path->GetEntryLabel());
5623 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005624}
5625
David Brazdilcb1c0552015-08-04 16:22:25 +01005626static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005627 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005628}
5629
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005630void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5631 LocationSummary* locations =
5632 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5633 locations->SetOut(Location::RequiresRegister());
5634}
5635
5636void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005637 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005638 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5639}
5640
5641void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5642 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5643}
5644
5645void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005646 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005647 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005648}
5649
5650void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5651 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005652 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005653 InvokeRuntimeCallingConvention calling_convention;
5654 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5655}
5656
5657void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01005658 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005659 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005660}
5661
Roland Levillainc9285912015-12-18 10:38:42 +00005662static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
5663 return kEmitCompilerReadBarrier &&
5664 (kUseBakerReadBarrier ||
5665 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5666 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5667 type_check_kind == TypeCheckKind::kArrayObjectCheck);
5668}
5669
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005670void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005671 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00005672 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5673 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005674 case TypeCheckKind::kExactCheck:
5675 case TypeCheckKind::kAbstractClassCheck:
5676 case TypeCheckKind::kClassHierarchyCheck:
5677 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005678 call_kind =
5679 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005680 break;
5681 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005682 case TypeCheckKind::kUnresolvedCheck:
5683 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005684 call_kind = LocationSummary::kCallOnSlowPath;
5685 break;
5686 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005687
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005688 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Roland Levillain3b359c72015-11-17 19:35:12 +00005689 locations->SetInAt(0, Location::RequiresRegister());
5690 locations->SetInAt(1, Location::RequiresRegister());
5691 // The "out" register is used as a temporary, so it overlaps with the inputs.
5692 // Note that TypeCheckSlowPathARM uses this register too.
5693 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5694 // When read barriers are enabled, we need a temporary register for
5695 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005696 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00005697 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005698 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005699}
5700
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005701void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005702 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005703 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005704 Location obj_loc = locations->InAt(0);
5705 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005706 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005707 Location out_loc = locations->Out();
5708 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005709 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005710 locations->GetTemp(0) :
5711 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005712 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005713 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5714 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5715 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005716 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07005717 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005718
5719 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005720 // avoid null check if we know obj is not null.
5721 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00005722 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005723 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005724
Roland Levillain3b359c72015-11-17 19:35:12 +00005725 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005726 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005727
Roland Levillainc9285912015-12-18 10:38:42 +00005728 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005729 case TypeCheckKind::kExactCheck: {
5730 __ cmp(out, ShifterOperand(cls));
5731 // Classes must be equal for the instanceof to succeed.
5732 __ b(&zero, NE);
5733 __ LoadImmediate(out, 1);
5734 __ b(&done);
5735 break;
5736 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005737
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005738 case TypeCheckKind::kAbstractClassCheck: {
5739 // If the class is abstract, we eagerly fetch the super class of the
5740 // object to avoid doing a comparison we know will fail.
5741 Label loop;
5742 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005743 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005744 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005745 // If `out` is null, we use it for the result, and jump to `done`.
5746 __ CompareAndBranchIfZero(out, &done);
5747 __ cmp(out, ShifterOperand(cls));
5748 __ b(&loop, NE);
5749 __ LoadImmediate(out, 1);
5750 if (zero.IsLinked()) {
5751 __ b(&done);
5752 }
5753 break;
5754 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005755
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005756 case TypeCheckKind::kClassHierarchyCheck: {
5757 // Walk over the class hierarchy to find a match.
5758 Label loop, success;
5759 __ Bind(&loop);
5760 __ cmp(out, ShifterOperand(cls));
5761 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005762 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005763 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005764 __ CompareAndBranchIfNonZero(out, &loop);
5765 // If `out` is null, we use it for the result, and jump to `done`.
5766 __ b(&done);
5767 __ Bind(&success);
5768 __ LoadImmediate(out, 1);
5769 if (zero.IsLinked()) {
5770 __ b(&done);
5771 }
5772 break;
5773 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005774
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005775 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005776 // Do an exact check.
5777 Label exact_check;
5778 __ cmp(out, ShifterOperand(cls));
5779 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005780 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005781 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005782 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005783 // If `out` is null, we use it for the result, and jump to `done`.
5784 __ CompareAndBranchIfZero(out, &done);
5785 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5786 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5787 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005788 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005789 __ LoadImmediate(out, 1);
5790 __ b(&done);
5791 break;
5792 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005793
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005794 case TypeCheckKind::kArrayCheck: {
5795 __ cmp(out, ShifterOperand(cls));
5796 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00005797 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5798 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005799 codegen_->AddSlowPath(slow_path);
5800 __ b(slow_path->GetEntryLabel(), NE);
5801 __ LoadImmediate(out, 1);
5802 if (zero.IsLinked()) {
5803 __ b(&done);
5804 }
5805 break;
5806 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005807
Calin Juravle98893e12015-10-02 21:05:03 +01005808 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005809 case TypeCheckKind::kInterfaceCheck: {
5810 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00005811 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00005812 // cases.
5813 //
5814 // We cannot directly call the InstanceofNonTrivial runtime
5815 // entry point without resorting to a type checking slow path
5816 // here (i.e. by calling InvokeRuntime directly), as it would
5817 // require to assign fixed registers for the inputs of this
5818 // HInstanceOf instruction (following the runtime calling
5819 // convention), which might be cluttered by the potential first
5820 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00005821 //
5822 // TODO: Introduce a new runtime entry point taking the object
5823 // to test (instead of its class) as argument, and let it deal
5824 // with the read barrier issues. This will let us refactor this
5825 // case of the `switch` code as it was previously (with a direct
5826 // call to the runtime not using a type checking slow path).
5827 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00005828 DCHECK(locations->OnlyCallsOnSlowPath());
5829 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5830 /* is_fatal */ false);
5831 codegen_->AddSlowPath(slow_path);
5832 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005833 if (zero.IsLinked()) {
5834 __ b(&done);
5835 }
5836 break;
5837 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005838 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005839
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005840 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005841 __ Bind(&zero);
5842 __ LoadImmediate(out, 0);
5843 }
5844
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005845 if (done.IsLinked()) {
5846 __ Bind(&done);
5847 }
5848
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005849 if (slow_path != nullptr) {
5850 __ Bind(slow_path->GetExitLabel());
5851 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005852}
5853
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005854void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005855 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5856 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
5857
Roland Levillain3b359c72015-11-17 19:35:12 +00005858 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5859 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005860 case TypeCheckKind::kExactCheck:
5861 case TypeCheckKind::kAbstractClassCheck:
5862 case TypeCheckKind::kClassHierarchyCheck:
5863 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005864 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
5865 LocationSummary::kCallOnSlowPath :
5866 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005867 break;
5868 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005869 case TypeCheckKind::kUnresolvedCheck:
5870 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005871 call_kind = LocationSummary::kCallOnSlowPath;
5872 break;
5873 }
5874
Roland Levillain3b359c72015-11-17 19:35:12 +00005875 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
5876 locations->SetInAt(0, Location::RequiresRegister());
5877 locations->SetInAt(1, Location::RequiresRegister());
5878 // Note that TypeCheckSlowPathARM uses this "temp" register too.
5879 locations->AddTemp(Location::RequiresRegister());
5880 // When read barriers are enabled, we need an additional temporary
5881 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005882 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005883 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005884 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005885}
5886
5887void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005888 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005889 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005890 Location obj_loc = locations->InAt(0);
5891 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005892 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005893 Location temp_loc = locations->GetTemp(0);
5894 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005895 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005896 locations->GetTemp(1) :
5897 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005898 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005899 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5900 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5901 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005902
Roland Levillain3b359c72015-11-17 19:35:12 +00005903 bool is_type_check_slow_path_fatal =
5904 (type_check_kind == TypeCheckKind::kExactCheck ||
5905 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5906 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5907 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
5908 !instruction->CanThrowIntoCatchBlock();
5909 SlowPathCode* type_check_slow_path =
5910 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5911 is_type_check_slow_path_fatal);
5912 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005913
5914 Label done;
5915 // Avoid null check if we know obj is not null.
5916 if (instruction->MustDoNullCheck()) {
5917 __ CompareAndBranchIfZero(obj, &done);
5918 }
5919
Roland Levillain3b359c72015-11-17 19:35:12 +00005920 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005921 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005922
Roland Levillain3b359c72015-11-17 19:35:12 +00005923 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005924 case TypeCheckKind::kExactCheck:
5925 case TypeCheckKind::kArrayCheck: {
5926 __ cmp(temp, ShifterOperand(cls));
5927 // Jump to slow path for throwing the exception or doing a
5928 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005929 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005930 break;
5931 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005932
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005933 case TypeCheckKind::kAbstractClassCheck: {
5934 // If the class is abstract, we eagerly fetch the super class of the
5935 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00005936 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005937 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005938 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005939 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005940
5941 // If the class reference currently in `temp` is not null, jump
5942 // to the `compare_classes` label to compare it with the checked
5943 // class.
5944 __ CompareAndBranchIfNonZero(temp, &compare_classes);
5945 // Otherwise, jump to the slow path to throw the exception.
5946 //
5947 // But before, move back the object's class into `temp` before
5948 // going into the slow path, as it has been overwritten in the
5949 // meantime.
5950 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005951 GenerateReferenceLoadTwoRegisters(
5952 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005953 __ b(type_check_slow_path->GetEntryLabel());
5954
5955 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005956 __ cmp(temp, ShifterOperand(cls));
5957 __ b(&loop, NE);
5958 break;
5959 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005960
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005961 case TypeCheckKind::kClassHierarchyCheck: {
5962 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005963 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005964 __ Bind(&loop);
5965 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005966 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005967
Roland Levillain3b359c72015-11-17 19:35:12 +00005968 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005969 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005970
5971 // If the class reference currently in `temp` is not null, jump
5972 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005973 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005974 // Otherwise, jump to the slow path to throw the exception.
5975 //
5976 // But before, move back the object's class into `temp` before
5977 // going into the slow path, as it has been overwritten in the
5978 // meantime.
5979 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005980 GenerateReferenceLoadTwoRegisters(
5981 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005982 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005983 break;
5984 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005985
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005986 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005987 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005988 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005989 __ cmp(temp, ShifterOperand(cls));
5990 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005991
5992 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005993 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005994 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005995
5996 // If the component type is not null (i.e. the object is indeed
5997 // an array), jump to label `check_non_primitive_component_type`
5998 // to further check that this component type is not a primitive
5999 // type.
6000 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6001 // Otherwise, jump to the slow path to throw the exception.
6002 //
6003 // But before, move back the object's class into `temp` before
6004 // going into the slow path, as it has been overwritten in the
6005 // meantime.
6006 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006007 GenerateReferenceLoadTwoRegisters(
6008 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006009 __ b(type_check_slow_path->GetEntryLabel());
6010
6011 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006012 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006013 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6014 __ CompareAndBranchIfZero(temp, &done);
6015 // Same comment as above regarding `temp` and the slow path.
6016 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006017 GenerateReferenceLoadTwoRegisters(
6018 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006019 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006020 break;
6021 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006022
Calin Juravle98893e12015-10-02 21:05:03 +01006023 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006024 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006025 // We always go into the type check slow path for the unresolved
6026 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006027 //
6028 // We cannot directly call the CheckCast runtime entry point
6029 // without resorting to a type checking slow path here (i.e. by
6030 // calling InvokeRuntime directly), as it would require to
6031 // assign fixed registers for the inputs of this HInstanceOf
6032 // instruction (following the runtime calling convention), which
6033 // might be cluttered by the potential first read barrier
6034 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006035 //
6036 // TODO: Introduce a new runtime entry point taking the object
6037 // to test (instead of its class) as argument, and let it deal
6038 // with the read barrier issues. This will let us refactor this
6039 // case of the `switch` code as it was previously (with a direct
6040 // call to the runtime not using a type checking slow path).
6041 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006042 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006043 break;
6044 }
6045 __ Bind(&done);
6046
Roland Levillain3b359c72015-11-17 19:35:12 +00006047 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006048}
6049
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006050void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6051 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006052 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006053 InvokeRuntimeCallingConvention calling_convention;
6054 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6055}
6056
6057void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01006058 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
6059 instruction,
6060 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006061 if (instruction->IsEnter()) {
6062 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6063 } else {
6064 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6065 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006066}
6067
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006068void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6069void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6070void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006071
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006072void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006073 LocationSummary* locations =
6074 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6075 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6076 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006077 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006078 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006079 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006080 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006081}
6082
6083void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6084 HandleBitwiseOperation(instruction);
6085}
6086
6087void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6088 HandleBitwiseOperation(instruction);
6089}
6090
6091void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6092 HandleBitwiseOperation(instruction);
6093}
6094
Artem Serov7fc63502016-02-09 17:15:29 +00006095
6096void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6097 LocationSummary* locations =
6098 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6099 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6100 || instruction->GetResultType() == Primitive::kPrimLong);
6101
6102 locations->SetInAt(0, Location::RequiresRegister());
6103 locations->SetInAt(1, Location::RequiresRegister());
6104 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6105}
6106
6107void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6108 LocationSummary* locations = instruction->GetLocations();
6109 Location first = locations->InAt(0);
6110 Location second = locations->InAt(1);
6111 Location out = locations->Out();
6112
6113 if (instruction->GetResultType() == Primitive::kPrimInt) {
6114 Register first_reg = first.AsRegister<Register>();
6115 ShifterOperand second_reg(second.AsRegister<Register>());
6116 Register out_reg = out.AsRegister<Register>();
6117
6118 switch (instruction->GetOpKind()) {
6119 case HInstruction::kAnd:
6120 __ bic(out_reg, first_reg, second_reg);
6121 break;
6122 case HInstruction::kOr:
6123 __ orn(out_reg, first_reg, second_reg);
6124 break;
6125 // There is no EON on arm.
6126 case HInstruction::kXor:
6127 default:
6128 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6129 UNREACHABLE();
6130 }
6131 return;
6132
6133 } else {
6134 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6135 Register first_low = first.AsRegisterPairLow<Register>();
6136 Register first_high = first.AsRegisterPairHigh<Register>();
6137 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6138 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6139 Register out_low = out.AsRegisterPairLow<Register>();
6140 Register out_high = out.AsRegisterPairHigh<Register>();
6141
6142 switch (instruction->GetOpKind()) {
6143 case HInstruction::kAnd:
6144 __ bic(out_low, first_low, second_low);
6145 __ bic(out_high, first_high, second_high);
6146 break;
6147 case HInstruction::kOr:
6148 __ orn(out_low, first_low, second_low);
6149 __ orn(out_high, first_high, second_high);
6150 break;
6151 // There is no EON on arm.
6152 case HInstruction::kXor:
6153 default:
6154 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6155 UNREACHABLE();
6156 }
6157 }
6158}
6159
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006160void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6161 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6162 if (value == 0xffffffffu) {
6163 if (out != first) {
6164 __ mov(out, ShifterOperand(first));
6165 }
6166 return;
6167 }
6168 if (value == 0u) {
6169 __ mov(out, ShifterOperand(0));
6170 return;
6171 }
6172 ShifterOperand so;
6173 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6174 __ and_(out, first, so);
6175 } else {
6176 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6177 __ bic(out, first, ShifterOperand(~value));
6178 }
6179}
6180
6181void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6182 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6183 if (value == 0u) {
6184 if (out != first) {
6185 __ mov(out, ShifterOperand(first));
6186 }
6187 return;
6188 }
6189 if (value == 0xffffffffu) {
6190 __ mvn(out, ShifterOperand(0));
6191 return;
6192 }
6193 ShifterOperand so;
6194 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6195 __ orr(out, first, so);
6196 } else {
6197 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6198 __ orn(out, first, ShifterOperand(~value));
6199 }
6200}
6201
6202void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6203 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6204 if (value == 0u) {
6205 if (out != first) {
6206 __ mov(out, ShifterOperand(first));
6207 }
6208 return;
6209 }
6210 __ eor(out, first, ShifterOperand(value));
6211}
6212
Vladimir Marko59751a72016-08-05 14:37:27 +01006213void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6214 Location first,
6215 uint64_t value) {
6216 Register out_low = out.AsRegisterPairLow<Register>();
6217 Register out_high = out.AsRegisterPairHigh<Register>();
6218 Register first_low = first.AsRegisterPairLow<Register>();
6219 Register first_high = first.AsRegisterPairHigh<Register>();
6220 uint32_t value_low = Low32Bits(value);
6221 uint32_t value_high = High32Bits(value);
6222 if (value_low == 0u) {
6223 if (out_low != first_low) {
6224 __ mov(out_low, ShifterOperand(first_low));
6225 }
6226 __ AddConstant(out_high, first_high, value_high);
6227 return;
6228 }
6229 __ AddConstantSetFlags(out_low, first_low, value_low);
6230 ShifterOperand so;
6231 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6232 __ adc(out_high, first_high, so);
6233 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6234 __ sbc(out_high, first_high, so);
6235 } else {
6236 LOG(FATAL) << "Unexpected constant " << value_high;
6237 UNREACHABLE();
6238 }
6239}
6240
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006241void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6242 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006243 Location first = locations->InAt(0);
6244 Location second = locations->InAt(1);
6245 Location out = locations->Out();
6246
6247 if (second.IsConstant()) {
6248 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6249 uint32_t value_low = Low32Bits(value);
6250 if (instruction->GetResultType() == Primitive::kPrimInt) {
6251 Register first_reg = first.AsRegister<Register>();
6252 Register out_reg = out.AsRegister<Register>();
6253 if (instruction->IsAnd()) {
6254 GenerateAndConst(out_reg, first_reg, value_low);
6255 } else if (instruction->IsOr()) {
6256 GenerateOrrConst(out_reg, first_reg, value_low);
6257 } else {
6258 DCHECK(instruction->IsXor());
6259 GenerateEorConst(out_reg, first_reg, value_low);
6260 }
6261 } else {
6262 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6263 uint32_t value_high = High32Bits(value);
6264 Register first_low = first.AsRegisterPairLow<Register>();
6265 Register first_high = first.AsRegisterPairHigh<Register>();
6266 Register out_low = out.AsRegisterPairLow<Register>();
6267 Register out_high = out.AsRegisterPairHigh<Register>();
6268 if (instruction->IsAnd()) {
6269 GenerateAndConst(out_low, first_low, value_low);
6270 GenerateAndConst(out_high, first_high, value_high);
6271 } else if (instruction->IsOr()) {
6272 GenerateOrrConst(out_low, first_low, value_low);
6273 GenerateOrrConst(out_high, first_high, value_high);
6274 } else {
6275 DCHECK(instruction->IsXor());
6276 GenerateEorConst(out_low, first_low, value_low);
6277 GenerateEorConst(out_high, first_high, value_high);
6278 }
6279 }
6280 return;
6281 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006282
6283 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006284 Register first_reg = first.AsRegister<Register>();
6285 ShifterOperand second_reg(second.AsRegister<Register>());
6286 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006287 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006288 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006289 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006290 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006291 } else {
6292 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006293 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006294 }
6295 } else {
6296 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006297 Register first_low = first.AsRegisterPairLow<Register>();
6298 Register first_high = first.AsRegisterPairHigh<Register>();
6299 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6300 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6301 Register out_low = out.AsRegisterPairLow<Register>();
6302 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006303 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006304 __ and_(out_low, first_low, second_low);
6305 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006306 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006307 __ orr(out_low, first_low, second_low);
6308 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006309 } else {
6310 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006311 __ eor(out_low, first_low, second_low);
6312 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006313 }
6314 }
6315}
6316
Roland Levillainc9285912015-12-18 10:38:42 +00006317void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6318 Location out,
6319 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006320 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006321 Register out_reg = out.AsRegister<Register>();
6322 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006323 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006324 if (kUseBakerReadBarrier) {
6325 // Load with fast path based Baker's read barrier.
6326 // /* HeapReference<Object> */ out = *(out + offset)
6327 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006328 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006329 } else {
6330 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006331 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006332 // in the following move operation, as we will need it for the
6333 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006334 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006335 // /* HeapReference<Object> */ out = *(out + offset)
6336 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006337 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006338 }
6339 } else {
6340 // Plain load with no read barrier.
6341 // /* HeapReference<Object> */ out = *(out + offset)
6342 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6343 __ MaybeUnpoisonHeapReference(out_reg);
6344 }
6345}
6346
6347void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6348 Location out,
6349 Location obj,
6350 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006351 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006352 Register out_reg = out.AsRegister<Register>();
6353 Register obj_reg = obj.AsRegister<Register>();
6354 if (kEmitCompilerReadBarrier) {
6355 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006356 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006357 // Load with fast path based Baker's read barrier.
6358 // /* HeapReference<Object> */ out = *(obj + offset)
6359 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006360 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006361 } else {
6362 // Load with slow path based read barrier.
6363 // /* HeapReference<Object> */ out = *(obj + offset)
6364 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6365 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6366 }
6367 } else {
6368 // Plain load with no read barrier.
6369 // /* HeapReference<Object> */ out = *(obj + offset)
6370 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6371 __ MaybeUnpoisonHeapReference(out_reg);
6372 }
6373}
6374
6375void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6376 Location root,
6377 Register obj,
6378 uint32_t offset) {
6379 Register root_reg = root.AsRegister<Register>();
6380 if (kEmitCompilerReadBarrier) {
6381 if (kUseBakerReadBarrier) {
6382 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6383 // Baker's read barrier are used:
6384 //
6385 // root = obj.field;
6386 // if (Thread::Current()->GetIsGcMarking()) {
6387 // root = ReadBarrier::Mark(root)
6388 // }
6389
6390 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6391 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6392 static_assert(
6393 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6394 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6395 "have different sizes.");
6396 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6397 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6398 "have different sizes.");
6399
Vladimir Marko953437b2016-08-24 08:30:46 +00006400 // Slow path marking the GC root `root`.
Roland Levillainc9285912015-12-18 10:38:42 +00006401 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006402 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006403 codegen_->AddSlowPath(slow_path);
6404
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006405 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006406 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006407 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006408 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6409 __ Bind(slow_path->GetExitLabel());
6410 } else {
6411 // GC root loaded through a slow path for read barriers other
6412 // than Baker's.
6413 // /* GcRoot<mirror::Object>* */ root = obj + offset
6414 __ AddConstant(root_reg, obj, offset);
6415 // /* mirror::Object* */ root = root->Read()
6416 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6417 }
6418 } else {
6419 // Plain GC root load with no read barrier.
6420 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6421 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6422 // Note that GC roots are not affected by heap poisoning, thus we
6423 // do not have to unpoison `root_reg` here.
6424 }
6425}
6426
6427void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6428 Location ref,
6429 Register obj,
6430 uint32_t offset,
6431 Location temp,
6432 bool needs_null_check) {
6433 DCHECK(kEmitCompilerReadBarrier);
6434 DCHECK(kUseBakerReadBarrier);
6435
6436 // /* HeapReference<Object> */ ref = *(obj + offset)
6437 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006438 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006439 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006440 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006441}
6442
6443void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6444 Location ref,
6445 Register obj,
6446 uint32_t data_offset,
6447 Location index,
6448 Location temp,
6449 bool needs_null_check) {
6450 DCHECK(kEmitCompilerReadBarrier);
6451 DCHECK(kUseBakerReadBarrier);
6452
Roland Levillainbfea3352016-06-23 13:48:47 +01006453 static_assert(
6454 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6455 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006456 // /* HeapReference<Object> */ ref =
6457 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006458 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006459 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006460 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006461}
6462
6463void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6464 Location ref,
6465 Register obj,
6466 uint32_t offset,
6467 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006468 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006469 Location temp,
6470 bool needs_null_check) {
6471 DCHECK(kEmitCompilerReadBarrier);
6472 DCHECK(kUseBakerReadBarrier);
6473
6474 // In slow path based read barriers, the read barrier call is
6475 // inserted after the original load. However, in fast path based
6476 // Baker's read barriers, we need to perform the load of
6477 // mirror::Object::monitor_ *before* the original reference load.
6478 // This load-load ordering is required by the read barrier.
6479 // The fast path/slow path (for Baker's algorithm) should look like:
6480 //
6481 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6482 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6483 // HeapReference<Object> ref = *src; // Original reference load.
6484 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6485 // if (is_gray) {
6486 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6487 // }
6488 //
6489 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006490 // slightly more complex as it performs additional checks that we do
6491 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006492
6493 Register ref_reg = ref.AsRegister<Register>();
6494 Register temp_reg = temp.AsRegister<Register>();
6495 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6496
6497 // /* int32_t */ monitor = obj->monitor_
6498 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6499 if (needs_null_check) {
6500 MaybeRecordImplicitNullCheck(instruction);
6501 }
6502 // /* LockWord */ lock_word = LockWord(monitor)
6503 static_assert(sizeof(LockWord) == sizeof(int32_t),
6504 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006505
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006506 // Introduce a dependency on the lock_word including the rb_state,
6507 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006508 // a memory barrier (which would be more expensive).
Roland Levillain0b671c02016-08-19 12:02:34 +01006509 // `obj` is unchanged by this operation, but its value now depends
6510 // on `temp_reg`.
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006511 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006512
6513 // The actual reference load.
6514 if (index.IsValid()) {
Roland Levillainbfea3352016-06-23 13:48:47 +01006515 // Load types involving an "index": ArrayGet and
6516 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
6517 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006518 if (index.IsConstant()) {
6519 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006520 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006521 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6522 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006523 // Handle the special case of the
6524 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use
6525 // a register pair as index ("long offset"), of which only the low
6526 // part contains data.
6527 Register index_reg = index.IsRegisterPair()
6528 ? index.AsRegisterPairLow<Register>()
6529 : index.AsRegister<Register>();
6530 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006531 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6532 }
6533 } else {
6534 // /* HeapReference<Object> */ ref = *(obj + offset)
6535 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6536 }
6537
6538 // Object* ref = ref_addr->AsMirrorPtr()
6539 __ MaybeUnpoisonHeapReference(ref_reg);
6540
Vladimir Marko953437b2016-08-24 08:30:46 +00006541 // Slow path marking the object `ref` when it is gray.
Roland Levillainc9285912015-12-18 10:38:42 +00006542 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006543 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
Roland Levillainc9285912015-12-18 10:38:42 +00006544 AddSlowPath(slow_path);
6545
6546 // if (rb_state == ReadBarrier::gray_ptr_)
6547 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006548 // Given the numeric representation, it's enough to check the low bit of the
6549 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6550 // which can be a 16-bit instruction unlike the TST immediate.
6551 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6552 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6553 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6554 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6555 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006556 __ Bind(slow_path->GetExitLabel());
6557}
6558
6559void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6560 Location out,
6561 Location ref,
6562 Location obj,
6563 uint32_t offset,
6564 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006565 DCHECK(kEmitCompilerReadBarrier);
6566
Roland Levillainc9285912015-12-18 10:38:42 +00006567 // Insert a slow path based read barrier *after* the reference load.
6568 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006569 // If heap poisoning is enabled, the unpoisoning of the loaded
6570 // reference will be carried out by the runtime within the slow
6571 // path.
6572 //
6573 // Note that `ref` currently does not get unpoisoned (when heap
6574 // poisoning is enabled), which is alright as the `ref` argument is
6575 // not used by the artReadBarrierSlow entry point.
6576 //
6577 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
6578 SlowPathCode* slow_path = new (GetGraph()->GetArena())
6579 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6580 AddSlowPath(slow_path);
6581
Roland Levillain3b359c72015-11-17 19:35:12 +00006582 __ b(slow_path->GetEntryLabel());
6583 __ Bind(slow_path->GetExitLabel());
6584}
6585
Roland Levillainc9285912015-12-18 10:38:42 +00006586void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6587 Location out,
6588 Location ref,
6589 Location obj,
6590 uint32_t offset,
6591 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006592 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006593 // Baker's read barriers shall be handled by the fast path
6594 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6595 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006596 // If heap poisoning is enabled, unpoisoning will be taken care of
6597 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006598 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006599 } else if (kPoisonHeapReferences) {
6600 __ UnpoisonHeapReference(out.AsRegister<Register>());
6601 }
6602}
6603
Roland Levillainc9285912015-12-18 10:38:42 +00006604void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6605 Location out,
6606 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006607 DCHECK(kEmitCompilerReadBarrier);
6608
Roland Levillainc9285912015-12-18 10:38:42 +00006609 // Insert a slow path based read barrier *after* the GC root load.
6610 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006611 // Note that GC roots are not affected by heap poisoning, so we do
6612 // not need to do anything special for this here.
6613 SlowPathCode* slow_path =
6614 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6615 AddSlowPath(slow_path);
6616
Roland Levillain3b359c72015-11-17 19:35:12 +00006617 __ b(slow_path->GetEntryLabel());
6618 __ Bind(slow_path->GetExitLabel());
6619}
6620
Vladimir Markodc151b22015-10-15 18:02:30 +01006621HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6622 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
6623 MethodReference target_method) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006624 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6625 // We disable pc-relative load when there is an irreducible loop, as the optimization
6626 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006627 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6628 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006629 if (GetGraph()->HasIrreducibleLoops() &&
6630 (dispatch_info.method_load_kind ==
6631 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
6632 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
6633 }
6634
6635 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01006636 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
6637 if (&outer_dex_file != target_method.dex_file) {
6638 // Calls across dex files are more likely to exceed the available BL range,
6639 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
6640 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
6641 (desired_dispatch_info.method_load_kind ==
6642 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
6643 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
6644 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
6645 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006646 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01006647 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006648 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01006649 0u
6650 };
6651 }
6652 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006653 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006654}
6655
Vladimir Markob4536b72015-11-24 13:45:23 +00006656Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
6657 Register temp) {
6658 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
6659 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
6660 if (!invoke->GetLocations()->Intrinsified()) {
6661 return location.AsRegister<Register>();
6662 }
6663 // For intrinsics we allow any location, so it may be on the stack.
6664 if (!location.IsRegister()) {
6665 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
6666 return temp;
6667 }
6668 // For register locations, check if the register was saved. If so, get it from the stack.
6669 // Note: There is a chance that the register was saved but not overwritten, so we could
6670 // save one load. However, since this is just an intrinsic slow path we prefer this
6671 // simple and more robust approach rather that trying to determine if that's the case.
6672 SlowPathCode* slow_path = GetCurrentSlowPath();
6673 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
6674 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
6675 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
6676 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
6677 return temp;
6678 }
6679 return location.AsRegister<Register>();
6680}
6681
Nicolas Geoffray38207af2015-06-01 15:46:22 +01006682void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00006683 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00006684 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00006685 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6686 // LR = code address from literal pool with link-time patch.
6687 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00006688 break;
6689 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6690 // LR = invoke->GetDirectCodePtr();
6691 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00006692 break;
6693 default:
6694 break;
6695 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006696
Vladimir Marko58155012015-08-19 12:49:41 +00006697 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
6698 switch (invoke->GetMethodLoadKind()) {
6699 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
6700 // temp = thread->string_init_entrypoint
6701 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
6702 break;
6703 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006704 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006705 break;
6706 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
6707 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
6708 break;
6709 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
6710 __ LoadLiteral(temp.AsRegister<Register>(),
6711 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
6712 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00006713 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
6714 HArmDexCacheArraysBase* base =
6715 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
6716 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
6717 temp.AsRegister<Register>());
6718 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
6719 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
6720 break;
6721 }
Vladimir Marko58155012015-08-19 12:49:41 +00006722 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00006723 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006724 Register method_reg;
6725 Register reg = temp.AsRegister<Register>();
6726 if (current_method.IsRegister()) {
6727 method_reg = current_method.AsRegister<Register>();
6728 } else {
6729 DCHECK(invoke->GetLocations()->Intrinsified());
6730 DCHECK(!current_method.IsValid());
6731 method_reg = reg;
6732 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
6733 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006734 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
6735 __ LoadFromOffset(kLoadWord,
6736 reg,
6737 method_reg,
6738 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01006739 // temp = temp[index_in_cache];
6740 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
6741 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00006742 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
6743 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01006744 }
Vladimir Marko58155012015-08-19 12:49:41 +00006745 }
6746
6747 switch (invoke->GetCodePtrLocation()) {
6748 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
6749 __ bl(GetFrameEntryLabel());
6750 break;
6751 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01006752 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07006753 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01006754 // Arbitrarily branch to the BL itself, override at link time.
6755 __ bl(&relative_call_patches_.back().label);
6756 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006757 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6758 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6759 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00006760 // LR()
6761 __ blx(LR);
6762 break;
6763 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6764 // LR = callee_method->entry_point_from_quick_compiled_code_
6765 __ LoadFromOffset(
6766 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07006767 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006768 // LR()
6769 __ blx(LR);
6770 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006771 }
6772
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006773 DCHECK(!IsLeafMethod());
6774}
6775
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006776void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
6777 Register temp = temp_location.AsRegister<Register>();
6778 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6779 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006780
6781 // Use the calling convention instead of the location of the receiver, as
6782 // intrinsics may have put the receiver in a different register. In the intrinsics
6783 // slow path, the arguments have been moved to the right place, so here we are
6784 // guaranteed that the receiver is the first register of the calling convention.
6785 InvokeDexCallingConvention calling_convention;
6786 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006787 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00006788 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006789 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006790 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00006791 // Instead of simply (possibly) unpoisoning `temp` here, we should
6792 // emit a read barrier for the previous class reference load.
6793 // However this is not required in practice, as this is an
6794 // intermediate/temporary reference and because the current
6795 // concurrent copying collector keeps the from-space memory
6796 // intact/accessible until the end of the marking phase (the
6797 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006798 __ MaybeUnpoisonHeapReference(temp);
6799 // temp = temp->GetMethodAt(method_offset);
6800 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006801 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006802 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
6803 // LR = temp->GetEntryPoint();
6804 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
6805 // LR();
6806 __ blx(LR);
6807}
6808
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006809CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
6810 const DexFile& dex_file, uint32_t string_index) {
6811 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
6812}
6813
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006814CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
6815 const DexFile& dex_file, uint32_t type_index) {
6816 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
6817}
6818
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006819CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
6820 const DexFile& dex_file, uint32_t element_offset) {
6821 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
6822}
6823
6824CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
6825 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
6826 patches->emplace_back(dex_file, offset_or_index);
6827 return &patches->back();
6828}
6829
6830Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
6831 uint32_t string_index) {
6832 return boot_image_string_patches_.GetOrCreate(
6833 StringReference(&dex_file, string_index),
6834 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6835}
6836
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006837Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
6838 uint32_t type_index) {
6839 return boot_image_type_patches_.GetOrCreate(
6840 TypeReference(&dex_file, type_index),
6841 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6842}
6843
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006844Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
6845 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
6846 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
6847 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
6848}
6849
6850Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
6851 return DeduplicateUint32Literal(address, &uint32_literals_);
6852}
6853
Vladimir Marko58155012015-08-19 12:49:41 +00006854void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
6855 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00006856 size_t size =
6857 method_patches_.size() +
6858 call_patches_.size() +
6859 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006860 /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() +
6861 boot_image_string_patches_.size() +
6862 /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006863 boot_image_type_patches_.size() +
6864 /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006865 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00006866 linker_patches->reserve(size);
6867 for (const auto& entry : method_patches_) {
6868 const MethodReference& target_method = entry.first;
6869 Literal* literal = entry.second;
6870 DCHECK(literal->GetLabel()->IsBound());
6871 uint32_t literal_offset = literal->GetLabel()->Position();
6872 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
6873 target_method.dex_file,
6874 target_method.dex_method_index));
6875 }
6876 for (const auto& entry : call_patches_) {
6877 const MethodReference& target_method = entry.first;
6878 Literal* literal = entry.second;
6879 DCHECK(literal->GetLabel()->IsBound());
6880 uint32_t literal_offset = literal->GetLabel()->Position();
6881 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
6882 target_method.dex_file,
6883 target_method.dex_method_index));
6884 }
6885 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
6886 uint32_t literal_offset = info.label.Position();
6887 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
6888 info.target_method.dex_file,
6889 info.target_method.dex_method_index));
6890 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006891 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
6892 const DexFile& dex_file = info.target_dex_file;
6893 size_t base_element_offset = info.offset_or_index;
6894 DCHECK(info.add_pc_label.IsBound());
6895 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006896 // Add MOVW patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006897 DCHECK(info.movw_label.IsBound());
6898 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006899 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset,
6900 &dex_file,
6901 add_pc_offset,
6902 base_element_offset));
6903 // Add MOVT patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006904 DCHECK(info.movt_label.IsBound());
6905 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006906 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset,
6907 &dex_file,
6908 add_pc_offset,
6909 base_element_offset));
6910 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006911 for (const auto& entry : boot_image_string_patches_) {
6912 const StringReference& target_string = entry.first;
6913 Literal* literal = entry.second;
6914 DCHECK(literal->GetLabel()->IsBound());
6915 uint32_t literal_offset = literal->GetLabel()->Position();
6916 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
6917 target_string.dex_file,
6918 target_string.string_index));
6919 }
6920 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
6921 const DexFile& dex_file = info.target_dex_file;
6922 uint32_t string_index = info.offset_or_index;
6923 DCHECK(info.add_pc_label.IsBound());
6924 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6925 // Add MOVW patch.
6926 DCHECK(info.movw_label.IsBound());
6927 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6928 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset,
6929 &dex_file,
6930 add_pc_offset,
6931 string_index));
6932 // Add MOVT patch.
6933 DCHECK(info.movt_label.IsBound());
6934 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6935 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset,
6936 &dex_file,
6937 add_pc_offset,
6938 string_index));
6939 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006940 for (const auto& entry : boot_image_type_patches_) {
6941 const TypeReference& target_type = entry.first;
6942 Literal* literal = entry.second;
6943 DCHECK(literal->GetLabel()->IsBound());
6944 uint32_t literal_offset = literal->GetLabel()->Position();
6945 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
6946 target_type.dex_file,
6947 target_type.type_index));
6948 }
6949 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
6950 const DexFile& dex_file = info.target_dex_file;
6951 uint32_t type_index = info.offset_or_index;
6952 DCHECK(info.add_pc_label.IsBound());
6953 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6954 // Add MOVW patch.
6955 DCHECK(info.movw_label.IsBound());
6956 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6957 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset,
6958 &dex_file,
6959 add_pc_offset,
6960 type_index));
6961 // Add MOVT patch.
6962 DCHECK(info.movt_label.IsBound());
6963 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6964 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset,
6965 &dex_file,
6966 add_pc_offset,
6967 type_index));
6968 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006969 for (const auto& entry : boot_image_address_patches_) {
6970 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
6971 Literal* literal = entry.second;
6972 DCHECK(literal->GetLabel()->IsBound());
6973 uint32_t literal_offset = literal->GetLabel()->Position();
6974 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
6975 }
6976}
6977
6978Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
6979 return map->GetOrCreate(
6980 value,
6981 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00006982}
6983
6984Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
6985 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006986 return map->GetOrCreate(
6987 target_method,
6988 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00006989}
6990
6991Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
6992 return DeduplicateMethodLiteral(target_method, &method_patches_);
6993}
6994
6995Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
6996 return DeduplicateMethodLiteral(target_method, &call_patches_);
6997}
6998
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03006999void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7000 LocationSummary* locations =
7001 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7002 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7003 Location::RequiresRegister());
7004 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7005 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7006 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7007}
7008
7009void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7010 LocationSummary* locations = instr->GetLocations();
7011 Register res = locations->Out().AsRegister<Register>();
7012 Register accumulator =
7013 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7014 Register mul_left =
7015 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7016 Register mul_right =
7017 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7018
7019 if (instr->GetOpKind() == HInstruction::kAdd) {
7020 __ mla(res, mul_left, mul_right, accumulator);
7021 } else {
7022 __ mls(res, mul_left, mul_right, accumulator);
7023 }
7024}
7025
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007026void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007027 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007028 LOG(FATAL) << "Unreachable";
7029}
7030
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007031void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007032 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007033 LOG(FATAL) << "Unreachable";
7034}
7035
Mark Mendellfe57faa2015-09-18 09:26:15 -04007036// Simple implementation of packed switch - generate cascaded compare/jumps.
7037void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7038 LocationSummary* locations =
7039 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7040 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007041 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007042 codegen_->GetAssembler()->IsThumb()) {
7043 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7044 if (switch_instr->GetStartValue() != 0) {
7045 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7046 }
7047 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007048}
7049
7050void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7051 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007052 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007053 LocationSummary* locations = switch_instr->GetLocations();
7054 Register value_reg = locations->InAt(0).AsRegister<Register>();
7055 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7056
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007057 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007058 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007059 Register temp_reg = IP;
7060 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7061 // the immediate, because IP is used as the destination register. For the other
7062 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7063 // and they can be encoded in the instruction without making use of IP register.
7064 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7065
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007066 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007067 // Jump to successors[0] if value == lower_bound.
7068 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7069 int32_t last_index = 0;
7070 for (; num_entries - last_index > 2; last_index += 2) {
7071 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7072 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7073 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7074 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7075 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7076 }
7077 if (num_entries - last_index == 2) {
7078 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007079 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007080 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007081 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007082
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007083 // And the default for any other value.
7084 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7085 __ b(codegen_->GetLabelOf(default_block));
7086 }
7087 } else {
7088 // Create a table lookup.
7089 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7090
7091 // Materialize a pointer to the switch table
7092 std::vector<Label*> labels(num_entries);
7093 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7094 for (uint32_t i = 0; i < num_entries; i++) {
7095 labels[i] = codegen_->GetLabelOf(successors[i]);
7096 }
7097 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7098
7099 // Remove the bias.
7100 Register key_reg;
7101 if (lower_bound != 0) {
7102 key_reg = locations->GetTemp(1).AsRegister<Register>();
7103 __ AddConstant(key_reg, value_reg, -lower_bound);
7104 } else {
7105 key_reg = value_reg;
7106 }
7107
7108 // Check whether the value is in the table, jump to default block if not.
7109 __ CmpConstant(key_reg, num_entries - 1);
7110 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7111
7112 // Load the displacement from the table.
7113 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7114
7115 // Dispatch is a direct add to the PC (for Thumb2).
7116 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007117 }
7118}
7119
Vladimir Markob4536b72015-11-24 13:45:23 +00007120void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7121 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7122 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007123}
7124
7125void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7126 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007127 CodeGeneratorARM::PcRelativePatchInfo* labels =
7128 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007129 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007130 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007131 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007132 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007133 __ BindTrackedLabel(&labels->add_pc_label);
7134 __ add(base_reg, base_reg, ShifterOperand(PC));
7135}
7136
Andreas Gampe85b62f22015-09-09 13:15:38 -07007137void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7138 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007139 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007140 return;
7141 }
7142
7143 DCHECK_NE(type, Primitive::kPrimVoid);
7144
7145 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7146 if (return_loc.Equals(trg)) {
7147 return;
7148 }
7149
7150 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7151 // with the last branch.
7152 if (type == Primitive::kPrimLong) {
7153 HParallelMove parallel_move(GetGraph()->GetArena());
7154 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7155 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7156 GetMoveResolver()->EmitNativeCode(&parallel_move);
7157 } else if (type == Primitive::kPrimDouble) {
7158 HParallelMove parallel_move(GetGraph()->GetArena());
7159 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7160 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7161 GetMoveResolver()->EmitNativeCode(&parallel_move);
7162 } else {
7163 // Let the parallel move resolver take care of all of this.
7164 HParallelMove parallel_move(GetGraph()->GetArena());
7165 parallel_move.AddMove(return_loc, trg, type, nullptr);
7166 GetMoveResolver()->EmitNativeCode(&parallel_move);
7167 }
7168}
7169
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007170void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7171 LocationSummary* locations =
7172 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7173 locations->SetInAt(0, Location::RequiresRegister());
7174 locations->SetOut(Location::RequiresRegister());
7175}
7176
7177void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7178 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007179 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007180 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007181 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007182 __ LoadFromOffset(kLoadWord,
7183 locations->Out().AsRegister<Register>(),
7184 locations->InAt(0).AsRegister<Register>(),
7185 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007186 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007187 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007188 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007189 __ LoadFromOffset(kLoadWord,
7190 locations->Out().AsRegister<Register>(),
7191 locations->InAt(0).AsRegister<Register>(),
7192 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7193 __ LoadFromOffset(kLoadWord,
7194 locations->Out().AsRegister<Register>(),
7195 locations->Out().AsRegister<Register>(),
7196 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007197 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007198}
7199
Roland Levillain4d027112015-07-01 15:41:14 +01007200#undef __
7201#undef QUICK_ENTRY_POINT
7202
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007203} // namespace arm
7204} // namespace art