blob: 55083c384fcf7443880f1194a8998142c2b151be [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Vladimir Marko58155012015-08-19 12:49:41 +000022#include "compiled_method.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070023#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010024#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080025#include "intrinsics.h"
26#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070027#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070029#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010030#include "utils/arm/assembler_arm.h"
31#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000032#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010033#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010036
Roland Levillain3b359c72015-11-17 19:35:12 +000037template<class MirrorType>
38class GcRoot;
39
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000040namespace arm {
41
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000042static bool ExpectedPairLayout(Location location) {
43 // We expected this for both core and fpu register pairs.
44 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
45}
46
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010047static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010048static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010049
David Brazdil58282f42016-01-14 12:45:10 +000050static constexpr Register kCoreAlwaysSpillRegister = R5;
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000051static constexpr Register kCoreCalleeSaves[] =
Andreas Gampe501fd632015-09-10 16:11:06 -070052 { R5, R6, R7, R8, R10, R11, LR };
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000053static constexpr SRegister kFpuCalleeSaves[] =
54 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010055
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000056// D31 cannot be split into two S registers, and the register allocator only works on
57// S registers. Therefore there is no need to block it.
58static constexpr DRegister DTMP = D31;
59
Vladimir Markof3e0ee22015-12-17 15:23:13 +000060static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7;
Andreas Gampe7cffc3b2015-10-19 21:31:53 -070061
Roland Levillain7cbd27f2016-08-11 23:53:33 +010062// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
63#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -070064#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065
Andreas Gampe85b62f22015-09-09 13:15:38 -070066class NullCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 public:
David Srbecky9cd6d372016-02-09 15:24:47 +000068 explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010069
Alexandre Rames67555f72014-11-18 10:55:16 +000070 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010071 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010072 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000073 if (instruction_->CanThrowIntoCatchBlock()) {
74 // Live registers will be restored in the catch block if caught.
75 SaveLiveRegisters(codegen, instruction_->GetLocations());
76 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +010077 arm_codegen->InvokeRuntime(kQuickThrowNullPointer,
78 instruction_,
79 instruction_->GetDexPc(),
80 this);
Roland Levillain888d0672015-11-23 18:53:50 +000081 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082 }
83
Alexandre Rames8158f282015-08-07 10:26:17 +010084 bool IsFatal() const OVERRIDE { return true; }
85
Alexandre Rames9931f312015-06-19 14:47:01 +010086 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
87
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 private:
Nicolas Geoffraye5038322014-07-04 09:41:32 +010089 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
90};
91
Andreas Gampe85b62f22015-09-09 13:15:38 -070092class DivZeroCheckSlowPathARM : public SlowPathCode {
Calin Juravled0d48522014-11-04 16:40:20 +000093 public:
David Srbecky9cd6d372016-02-09 15:24:47 +000094 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {}
Calin Juravled0d48522014-11-04 16:40:20 +000095
Alexandre Rames67555f72014-11-18 10:55:16 +000096 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000097 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
98 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000099 if (instruction_->CanThrowIntoCatchBlock()) {
100 // Live registers will be restored in the catch block if caught.
101 SaveLiveRegisters(codegen, instruction_->GetLocations());
102 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100103 arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000104 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Calin Juravled0d48522014-11-04 16:40:20 +0000105 }
106
Alexandre Rames8158f282015-08-07 10:26:17 +0100107 bool IsFatal() const OVERRIDE { return true; }
108
Alexandre Rames9931f312015-06-19 14:47:01 +0100109 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
110
Calin Juravled0d48522014-11-04 16:40:20 +0000111 private:
Calin Juravled0d48522014-11-04 16:40:20 +0000112 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
113};
114
Andreas Gampe85b62f22015-09-09 13:15:38 -0700115class SuspendCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000117 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000118 : SlowPathCode(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000119
Alexandre Rames67555f72014-11-18 10:55:16 +0000120 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100121 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000122 __ Bind(GetEntryLabel());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100123 arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000124 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 if (successor_ == nullptr) {
126 __ b(GetReturnLabel());
127 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100128 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000130 }
131
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100132 Label* GetReturnLabel() {
133 DCHECK(successor_ == nullptr);
134 return &return_label_;
135 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000136
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100137 HBasicBlock* GetSuccessor() const {
138 return successor_;
139 }
140
Alexandre Rames9931f312015-06-19 14:47:01 +0100141 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
142
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000143 private:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100144 // If not null, the block to branch to after the suspend check.
145 HBasicBlock* const successor_;
146
147 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000148 Label return_label_;
149
150 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
151};
152
Andreas Gampe85b62f22015-09-09 13:15:38 -0700153class BoundsCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100154 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100155 explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000156 : SlowPathCode(instruction) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100157
Alexandre Rames67555f72014-11-18 10:55:16 +0000158 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100159 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100160 LocationSummary* locations = instruction_->GetLocations();
161
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000163 if (instruction_->CanThrowIntoCatchBlock()) {
164 // Live registers will be restored in the catch block if caught.
165 SaveLiveRegisters(codegen, instruction_->GetLocations());
166 }
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000167 // We're moving two locations to locations that could overlap, so we need a parallel
168 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100169 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000170 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100171 locations->InAt(0),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000172 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100173 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100174 locations->InAt(1),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100175 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
176 Primitive::kPrimInt);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100177 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
178 ? kQuickThrowStringBounds
179 : kQuickThrowArrayBounds;
180 arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100181 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Roland Levillain888d0672015-11-23 18:53:50 +0000182 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 }
184
Alexandre Rames8158f282015-08-07 10:26:17 +0100185 bool IsFatal() const OVERRIDE { return true; }
186
Alexandre Rames9931f312015-06-19 14:47:01 +0100187 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
188
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100189 private:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100190 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
191};
192
Andreas Gampe85b62f22015-09-09 13:15:38 -0700193class LoadClassSlowPathARM : public SlowPathCode {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100194 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000195 LoadClassSlowPathARM(HLoadClass* cls,
196 HInstruction* at,
197 uint32_t dex_pc,
198 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000199 : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
201 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202
Alexandre Rames67555f72014-11-18 10:55:16 +0000203 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 LocationSummary* locations = at_->GetLocations();
205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
207 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000208 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100212 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
213 : kQuickInitializeType;
214 arm_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this);
Roland Levillain888d0672015-11-23 18:53:50 +0000215 if (do_clinit_) {
216 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
217 } else {
218 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
219 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000220
221 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000222 Location out = locations->Out();
223 if (out.IsValid()) {
224 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000225 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
226 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000227 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100228 __ b(GetExitLabel());
229 }
230
Alexandre Rames9931f312015-06-19 14:47:01 +0100231 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
232
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100233 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000234 // The class this slow path will load.
235 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100236
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000237 // The instruction where this slow path is happening.
238 // (Might be the load class or an initialization check).
239 HInstruction* const at_;
240
241 // The dex PC of `at_`.
242 const uint32_t dex_pc_;
243
244 // Whether to initialize the class.
245 const bool do_clinit_;
246
247 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100248};
249
Andreas Gampe85b62f22015-09-09 13:15:38 -0700250class LoadStringSlowPathARM : public SlowPathCode {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000251 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000252 explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000253
Alexandre Rames67555f72014-11-18 10:55:16 +0000254 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000255 LocationSummary* locations = instruction_->GetLocations();
256 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
257
258 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
259 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000260 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000261
262 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000263 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
264 __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100265 arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000266 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000267 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
268
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000269 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000270 __ b(GetExitLabel());
271 }
272
Alexandre Rames9931f312015-06-19 14:47:01 +0100273 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
274
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000275 private:
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000276 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
277};
278
Andreas Gampe85b62f22015-09-09 13:15:38 -0700279class TypeCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000280 public:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000281 TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal)
David Srbecky9cd6d372016-02-09 15:24:47 +0000282 : SlowPathCode(instruction), is_fatal_(is_fatal) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000283
Alexandre Rames67555f72014-11-18 10:55:16 +0000284 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100286 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
287 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 DCHECK(instruction_->IsCheckCast()
289 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000290
291 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
292 __ Bind(GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000293
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000294 if (!is_fatal_) {
295 SaveLiveRegisters(codegen, locations);
296 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000297
298 // We're moving two locations to locations that could overlap, so we need a parallel
299 // move resolver.
300 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000301 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100302 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000303 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100304 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100305 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100306 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
307 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000308
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000309 if (instruction_->IsInstanceOf()) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100310 arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100311 instruction_,
312 instruction_->GetDexPc(),
313 this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000314 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700315 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000316 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
317 } else {
318 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100319 arm_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000320 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000321 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000322
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000323 if (!is_fatal_) {
324 RestoreLiveRegisters(codegen, locations);
325 __ b(GetExitLabel());
326 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000327 }
328
Alexandre Rames9931f312015-06-19 14:47:01 +0100329 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
330
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000331 bool IsFatal() const OVERRIDE { return is_fatal_; }
332
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000333 private:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000334 const bool is_fatal_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000335
336 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
337};
338
Andreas Gampe85b62f22015-09-09 13:15:38 -0700339class DeoptimizationSlowPathARM : public SlowPathCode {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700340 public:
Aart Bik42249c32016-01-07 15:33:50 -0800341 explicit DeoptimizationSlowPathARM(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000342 : SlowPathCode(instruction) {}
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700343
344 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800345 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700346 __ Bind(GetEntryLabel());
347 SaveLiveRegisters(codegen, instruction_->GetLocations());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100348 arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000349 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700350 }
351
Alexandre Rames9931f312015-06-19 14:47:01 +0100352 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
353
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700354 private:
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700355 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
356};
357
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100358class ArraySetSlowPathARM : public SlowPathCode {
359 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000360 explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100361
362 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
363 LocationSummary* locations = instruction_->GetLocations();
364 __ Bind(GetEntryLabel());
365 SaveLiveRegisters(codegen, locations);
366
367 InvokeRuntimeCallingConvention calling_convention;
368 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
369 parallel_move.AddMove(
370 locations->InAt(0),
371 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
372 Primitive::kPrimNot,
373 nullptr);
374 parallel_move.AddMove(
375 locations->InAt(1),
376 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
377 Primitive::kPrimInt,
378 nullptr);
379 parallel_move.AddMove(
380 locations->InAt(2),
381 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
382 Primitive::kPrimNot,
383 nullptr);
384 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
385
386 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100387 arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000388 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100389 RestoreLiveRegisters(codegen, locations);
390 __ b(GetExitLabel());
391 }
392
393 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; }
394
395 private:
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100396 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM);
397};
398
Roland Levillainc9285912015-12-18 10:38:42 +0000399// Slow path marking an object during a read barrier.
400class ReadBarrierMarkSlowPathARM : public SlowPathCode {
401 public:
Roland Levillain02b75802016-07-13 11:54:35 +0100402 ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj)
403 : SlowPathCode(instruction), obj_(obj) {
Roland Levillainc9285912015-12-18 10:38:42 +0000404 DCHECK(kEmitCompilerReadBarrier);
405 }
406
407 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; }
408
409 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
410 LocationSummary* locations = instruction_->GetLocations();
Roland Levillain02b75802016-07-13 11:54:35 +0100411 Register reg = obj_.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +0000412 DCHECK(locations->CanCall());
Roland Levillain02b75802016-07-13 11:54:35 +0100413 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg));
Roland Levillainc9285912015-12-18 10:38:42 +0000414 DCHECK(instruction_->IsInstanceFieldGet() ||
415 instruction_->IsStaticFieldGet() ||
416 instruction_->IsArrayGet() ||
Roland Levillain16d9f942016-08-25 17:27:56 +0100417 instruction_->IsArraySet() ||
Roland Levillainc9285912015-12-18 10:38:42 +0000418 instruction_->IsLoadClass() ||
419 instruction_->IsLoadString() ||
420 instruction_->IsInstanceOf() ||
Roland Levillain3d312422016-06-23 13:53:42 +0100421 instruction_->IsCheckCast() ||
Roland Levillain0b671c02016-08-19 12:02:34 +0100422 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
423 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
Roland Levillainc9285912015-12-18 10:38:42 +0000424 << "Unexpected instruction in read barrier marking slow path: "
425 << instruction_->DebugName();
426
427 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100428 // No need to save live registers; it's taken care of by the
429 // entrypoint. Also, there is no need to update the stack mask,
430 // as this runtime call will not trigger a garbage collection.
Roland Levillainc9285912015-12-18 10:38:42 +0000431 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Roland Levillain02b75802016-07-13 11:54:35 +0100432 DCHECK_NE(reg, SP);
433 DCHECK_NE(reg, LR);
434 DCHECK_NE(reg, PC);
Roland Levillain0b671c02016-08-19 12:02:34 +0100435 // IP is used internally by the ReadBarrierMarkRegX entry point
436 // as a temporary, it cannot be the entry point's input/output.
437 DCHECK_NE(reg, IP);
Roland Levillain02b75802016-07-13 11:54:35 +0100438 DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg;
439 // "Compact" slow path, saving two moves.
440 //
441 // Instead of using the standard runtime calling convention (input
442 // and output in R0):
443 //
444 // R0 <- obj
445 // R0 <- ReadBarrierMark(R0)
446 // obj <- R0
447 //
448 // we just use rX (the register holding `obj`) as input and output
449 // of a dedicated entrypoint:
450 //
451 // rX <- ReadBarrierMarkRegX(rX)
452 //
453 int32_t entry_point_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -0700454 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg);
Roland Levillaindec8f632016-07-22 17:10:06 +0100455 // This runtime call does not require a stack map.
456 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
Roland Levillainc9285912015-12-18 10:38:42 +0000457 __ b(GetExitLabel());
458 }
459
460 private:
Roland Levillainc9285912015-12-18 10:38:42 +0000461 const Location obj_;
462
463 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM);
464};
465
Roland Levillain3b359c72015-11-17 19:35:12 +0000466// Slow path generating a read barrier for a heap reference.
467class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode {
468 public:
469 ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction,
470 Location out,
471 Location ref,
472 Location obj,
473 uint32_t offset,
474 Location index)
David Srbecky9cd6d372016-02-09 15:24:47 +0000475 : SlowPathCode(instruction),
Roland Levillain3b359c72015-11-17 19:35:12 +0000476 out_(out),
477 ref_(ref),
478 obj_(obj),
479 offset_(offset),
480 index_(index) {
481 DCHECK(kEmitCompilerReadBarrier);
482 // If `obj` is equal to `out` or `ref`, it means the initial object
483 // has been overwritten by (or after) the heap object reference load
484 // to be instrumented, e.g.:
485 //
486 // __ LoadFromOffset(kLoadWord, out, out, offset);
Roland Levillainc9285912015-12-18 10:38:42 +0000487 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
Roland Levillain3b359c72015-11-17 19:35:12 +0000488 //
489 // In that case, we have lost the information about the original
490 // object, and the emitted read barrier cannot work properly.
491 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
492 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
493 }
494
495 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
496 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
497 LocationSummary* locations = instruction_->GetLocations();
498 Register reg_out = out_.AsRegister<Register>();
499 DCHECK(locations->CanCall());
500 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillain3d312422016-06-23 13:53:42 +0100501 DCHECK(instruction_->IsInstanceFieldGet() ||
502 instruction_->IsStaticFieldGet() ||
503 instruction_->IsArrayGet() ||
504 instruction_->IsInstanceOf() ||
505 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100506 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillainc9285912015-12-18 10:38:42 +0000507 << "Unexpected instruction in read barrier for heap reference slow path: "
508 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000509
510 __ Bind(GetEntryLabel());
511 SaveLiveRegisters(codegen, locations);
512
513 // We may have to change the index's value, but as `index_` is a
514 // constant member (like other "inputs" of this slow path),
515 // introduce a copy of it, `index`.
516 Location index = index_;
517 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100518 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain3b359c72015-11-17 19:35:12 +0000519 if (instruction_->IsArrayGet()) {
520 // Compute the actual memory offset and store it in `index`.
521 Register index_reg = index_.AsRegister<Register>();
522 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
523 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
524 // We are about to change the value of `index_reg` (see the
525 // calls to art::arm::Thumb2Assembler::Lsl and
526 // art::arm::Thumb2Assembler::AddConstant below), but it has
527 // not been saved by the previous call to
528 // art::SlowPathCode::SaveLiveRegisters, as it is a
529 // callee-save register --
530 // art::SlowPathCode::SaveLiveRegisters does not consider
531 // callee-save registers, as it has been designed with the
532 // assumption that callee-save registers are supposed to be
533 // handled by the called function. So, as a callee-save
534 // register, `index_reg` _would_ eventually be saved onto
535 // the stack, but it would be too late: we would have
536 // changed its value earlier. Therefore, we manually save
537 // it here into another freely available register,
538 // `free_reg`, chosen of course among the caller-save
539 // registers (as a callee-save `free_reg` register would
540 // exhibit the same problem).
541 //
542 // Note we could have requested a temporary register from
543 // the register allocator instead; but we prefer not to, as
544 // this is a slow path, and we know we can find a
545 // caller-save register that is available.
546 Register free_reg = FindAvailableCallerSaveRegister(codegen);
547 __ Mov(free_reg, index_reg);
548 index_reg = free_reg;
549 index = Location::RegisterLocation(index_reg);
550 } else {
551 // The initial register stored in `index_` has already been
552 // saved in the call to art::SlowPathCode::SaveLiveRegisters
553 // (as it is not a callee-save register), so we can freely
554 // use it.
555 }
556 // Shifting the index value contained in `index_reg` by the scale
557 // factor (2) cannot overflow in practice, as the runtime is
558 // unable to allocate object arrays with a size larger than
559 // 2^26 - 1 (that is, 2^28 - 4 bytes).
560 __ Lsl(index_reg, index_reg, TIMES_4);
561 static_assert(
562 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
563 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
564 __ AddConstant(index_reg, index_reg, offset_);
565 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100566 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
567 // intrinsics, `index_` is not shifted by a scale factor of 2
568 // (as in the case of ArrayGet), as it is actually an offset
569 // to an object field within an object.
570 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000571 DCHECK(instruction_->GetLocations()->Intrinsified());
572 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
573 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
574 << instruction_->AsInvoke()->GetIntrinsic();
575 DCHECK_EQ(offset_, 0U);
576 DCHECK(index_.IsRegisterPair());
577 // UnsafeGet's offset location is a register pair, the low
578 // part contains the correct offset.
579 index = index_.ToLow();
580 }
581 }
582
583 // We're moving two or three locations to locations that could
584 // overlap, so we need a parallel move resolver.
585 InvokeRuntimeCallingConvention calling_convention;
586 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
587 parallel_move.AddMove(ref_,
588 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
589 Primitive::kPrimNot,
590 nullptr);
591 parallel_move.AddMove(obj_,
592 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
593 Primitive::kPrimNot,
594 nullptr);
595 if (index.IsValid()) {
596 parallel_move.AddMove(index,
597 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
598 Primitive::kPrimInt,
599 nullptr);
600 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
601 } else {
602 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
603 __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_);
604 }
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100605 arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000606 CheckEntrypointTypes<
607 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
608 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
609
610 RestoreLiveRegisters(codegen, locations);
611 __ b(GetExitLabel());
612 }
613
614 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; }
615
616 private:
617 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
618 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
619 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
620 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
621 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
622 return static_cast<Register>(i);
623 }
624 }
625 // We shall never fail to find a free caller-save register, as
626 // there are more than two core caller-save registers on ARM
627 // (meaning it is possible to find one which is different from
628 // `ref` and `obj`).
629 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
630 LOG(FATAL) << "Could not find a free caller-save register";
631 UNREACHABLE();
632 }
633
Roland Levillain3b359c72015-11-17 19:35:12 +0000634 const Location out_;
635 const Location ref_;
636 const Location obj_;
637 const uint32_t offset_;
638 // An additional location containing an index to an array.
639 // Only used for HArrayGet and the UnsafeGetObject &
640 // UnsafeGetObjectVolatile intrinsics.
641 const Location index_;
642
643 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM);
644};
645
646// Slow path generating a read barrier for a GC root.
647class ReadBarrierForRootSlowPathARM : public SlowPathCode {
648 public:
649 ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root)
David Srbecky9cd6d372016-02-09 15:24:47 +0000650 : SlowPathCode(instruction), out_(out), root_(root) {
Roland Levillainc9285912015-12-18 10:38:42 +0000651 DCHECK(kEmitCompilerReadBarrier);
652 }
Roland Levillain3b359c72015-11-17 19:35:12 +0000653
654 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
655 LocationSummary* locations = instruction_->GetLocations();
656 Register reg_out = out_.AsRegister<Register>();
657 DCHECK(locations->CanCall());
658 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillainc9285912015-12-18 10:38:42 +0000659 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
660 << "Unexpected instruction in read barrier for GC root slow path: "
661 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000662
663 __ Bind(GetEntryLabel());
664 SaveLiveRegisters(codegen, locations);
665
666 InvokeRuntimeCallingConvention calling_convention;
667 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
668 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +0100669 arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
Roland Levillain3b359c72015-11-17 19:35:12 +0000670 instruction_,
671 instruction_->GetDexPc(),
672 this);
673 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
674 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
675
676 RestoreLiveRegisters(codegen, locations);
677 __ b(GetExitLabel());
678 }
679
680 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; }
681
682 private:
Roland Levillain3b359c72015-11-17 19:35:12 +0000683 const Location out_;
684 const Location root_;
685
686 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM);
687};
688
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000689#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100690// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
691#define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT
Dave Allison20dfc792014-06-16 20:44:29 -0700692
Aart Bike9f37602015-10-09 11:15:55 -0700693inline Condition ARMCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700694 switch (cond) {
695 case kCondEQ: return EQ;
696 case kCondNE: return NE;
697 case kCondLT: return LT;
698 case kCondLE: return LE;
699 case kCondGT: return GT;
700 case kCondGE: return GE;
Aart Bike9f37602015-10-09 11:15:55 -0700701 case kCondB: return LO;
702 case kCondBE: return LS;
703 case kCondA: return HI;
704 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700705 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100706 LOG(FATAL) << "Unreachable";
707 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700708}
709
Aart Bike9f37602015-10-09 11:15:55 -0700710// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100711inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700712 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100713 case kCondEQ: return EQ;
714 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -0700715 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100716 case kCondLT: return LO;
717 case kCondLE: return LS;
718 case kCondGT: return HI;
719 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -0700720 // Unsigned remain unchanged.
721 case kCondB: return LO;
722 case kCondBE: return LS;
723 case kCondA: return HI;
724 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700725 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100726 LOG(FATAL) << "Unreachable";
727 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700728}
729
Vladimir Markod6e069b2016-01-18 11:11:01 +0000730inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) {
731 // The ARM condition codes can express all the necessary branches, see the
732 // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual.
733 // There is no dex instruction or HIR that would need the missing conditions
734 // "equal or unordered" or "not equal".
735 switch (cond) {
736 case kCondEQ: return EQ;
737 case kCondNE: return NE /* unordered */;
738 case kCondLT: return gt_bias ? CC : LT /* unordered */;
739 case kCondLE: return gt_bias ? LS : LE /* unordered */;
740 case kCondGT: return gt_bias ? HI /* unordered */ : GT;
741 case kCondGE: return gt_bias ? CS /* unordered */ : GE;
742 default:
743 LOG(FATAL) << "UNREACHABLE";
744 UNREACHABLE();
745 }
746}
747
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100748void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100749 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100750}
751
752void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100753 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100754}
755
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100756size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
757 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
758 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100759}
760
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100761size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
762 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
763 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100764}
765
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000766size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
767 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
768 return kArmWordSize;
769}
770
771size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
772 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
773 return kArmWordSize;
774}
775
Calin Juravle34166012014-12-19 17:22:29 +0000776CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000777 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100778 const CompilerOptions& compiler_options,
779 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000780 : CodeGenerator(graph,
781 kNumberOfCoreRegisters,
782 kNumberOfSRegisters,
783 kNumberOfRegisterPairs,
784 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
785 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +0000786 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
787 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100788 compiler_options,
789 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100790 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100791 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100792 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100793 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100794 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +0000795 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000796 uint32_literals_(std::less<uint32_t>(),
797 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +0100798 method_patches_(MethodReferenceComparator(),
799 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
800 call_patches_(MethodReferenceComparator(),
801 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markob4536b72015-11-24 13:45:23 +0000802 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000803 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
804 boot_image_string_patches_(StringReferenceValueComparator(),
805 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
806 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100807 boot_image_type_patches_(TypeReferenceValueComparator(),
808 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
809 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000810 boot_image_address_patches_(std::less<uint32_t>(),
811 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700812 // Always save the LR register to mimic Quick.
813 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100814}
815
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000816void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
817 // Ensure that we fix up branches and literal loads and emit the literal pool.
818 __ FinalizeCode();
819
820 // Adjust native pc offsets in stack maps.
821 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
822 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
823 uint32_t new_position = __ GetAdjustedPosition(old_position);
824 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
825 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100826 // Adjust pc offsets for the disassembly information.
827 if (disasm_info_ != nullptr) {
828 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
829 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
830 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
831 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
832 it.second.start = __ GetAdjustedPosition(it.second.start);
833 it.second.end = __ GetAdjustedPosition(it.second.end);
834 }
835 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
836 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
837 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
838 }
839 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000840
841 CodeGenerator::Finalize(allocator);
842}
843
David Brazdil58282f42016-01-14 12:45:10 +0000844void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100845 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100846 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100847
848 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100849 blocked_core_registers_[SP] = true;
850 blocked_core_registers_[LR] = true;
851 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100852
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100853 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100854 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100855
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100856 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100857 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100858
David Brazdil58282f42016-01-14 12:45:10 +0000859 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100860 // Stubs do not save callee-save floating point registers. If the graph
861 // is debuggable, we need to deal with these registers differently. For
862 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000863 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
864 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
865 }
866 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100867
868 UpdateBlockedPairRegisters();
869}
870
871void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
872 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
873 ArmManagedRegister current =
874 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
875 if (blocked_core_registers_[current.AsRegisterPairLow()]
876 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
877 blocked_register_pairs_[i] = true;
878 }
879 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100880}
881
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100882InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
Aart Bik42249c32016-01-07 15:33:50 -0800883 : InstructionCodeGenerator(graph, codegen),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100884 assembler_(codegen->GetAssembler()),
885 codegen_(codegen) {}
886
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000887void CodeGeneratorARM::ComputeSpillMask() {
888 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
889 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
David Brazdil58282f42016-01-14 12:45:10 +0000890 // There is no easy instruction to restore just the PC on thumb2. We spill and
891 // restore another arbitrary register.
892 core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000893 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
894 // We use vpush and vpop for saving and restoring floating point registers, which take
895 // a SRegister and the number of registers to save/restore after that SRegister. We
896 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
897 // but in the range.
898 if (fpu_spill_mask_ != 0) {
899 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
900 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
901 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
902 fpu_spill_mask_ |= (1 << i);
903 }
904 }
905}
906
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100907static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100908 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100909}
910
911static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100912 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100913}
914
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000915void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000916 bool skip_overflow_check =
917 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000918 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000919 __ Bind(&frame_entry_label_);
920
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000921 if (HasEmptyFrame()) {
922 return;
923 }
924
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100925 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000926 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
927 __ LoadFromOffset(kLoadWord, IP, IP, 0);
928 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100929 }
930
Andreas Gampe501fd632015-09-10 16:11:06 -0700931 __ PushList(core_spill_mask_);
932 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
933 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000934 if (fpu_spill_mask_ != 0) {
935 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
936 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100937 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100938 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000939 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100940 int adjust = GetFrameSize() - FrameEntrySpillSize();
941 __ AddConstant(SP, -adjust);
942 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100943 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000944}
945
946void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000947 if (HasEmptyFrame()) {
948 __ bx(LR);
949 return;
950 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100951 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100952 int adjust = GetFrameSize() - FrameEntrySpillSize();
953 __ AddConstant(SP, adjust);
954 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000955 if (fpu_spill_mask_ != 0) {
956 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
957 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
Andreas Gampe542451c2016-07-26 09:02:02 -0700958 __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100959 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000960 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700961 // Pop LR into PC to return.
962 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
963 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
964 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100965 __ cfi().RestoreState();
966 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000967}
968
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100969void CodeGeneratorARM::Bind(HBasicBlock* block) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700970 Label* label = GetLabelOf(block);
971 __ BindTrackedLabel(label);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000972}
973
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100974Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100975 switch (type) {
976 case Primitive::kPrimBoolean:
977 case Primitive::kPrimByte:
978 case Primitive::kPrimChar:
979 case Primitive::kPrimShort:
980 case Primitive::kPrimInt:
981 case Primitive::kPrimNot: {
982 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000983 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100984 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100985 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100986 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000987 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100988 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100989 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100990
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000991 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100992 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000993 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100994 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000995 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100996 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000997 if (calling_convention.GetRegisterAt(index) == R1) {
998 // Skip R1, and use R2_R3 instead.
999 gp_index_++;
1000 index++;
1001 }
1002 }
1003 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
1004 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001005 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +01001006
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001007 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001008 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001009 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001010 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
1011 }
1012 }
1013
1014 case Primitive::kPrimFloat: {
1015 uint32_t stack_index = stack_index_++;
1016 if (float_index_ % 2 == 0) {
1017 float_index_ = std::max(double_index_, float_index_);
1018 }
1019 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
1020 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
1021 } else {
1022 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
1023 }
1024 }
1025
1026 case Primitive::kPrimDouble: {
1027 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
1028 uint32_t stack_index = stack_index_;
1029 stack_index_ += 2;
1030 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
1031 uint32_t index = double_index_;
1032 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001033 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001034 calling_convention.GetFpuRegisterAt(index),
1035 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001036 DCHECK(ExpectedPairLayout(result));
1037 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001038 } else {
1039 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001040 }
1041 }
1042
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001043 case Primitive::kPrimVoid:
1044 LOG(FATAL) << "Unexpected parameter type " << type;
1045 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001046 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001047 return Location::NoLocation();
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001048}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001049
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001050Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001051 switch (type) {
1052 case Primitive::kPrimBoolean:
1053 case Primitive::kPrimByte:
1054 case Primitive::kPrimChar:
1055 case Primitive::kPrimShort:
1056 case Primitive::kPrimInt:
1057 case Primitive::kPrimNot: {
1058 return Location::RegisterLocation(R0);
1059 }
1060
1061 case Primitive::kPrimFloat: {
1062 return Location::FpuRegisterLocation(S0);
1063 }
1064
1065 case Primitive::kPrimLong: {
1066 return Location::RegisterPairLocation(R0, R1);
1067 }
1068
1069 case Primitive::kPrimDouble: {
1070 return Location::FpuRegisterPairLocation(S0, S1);
1071 }
1072
1073 case Primitive::kPrimVoid:
Roland Levillain3b359c72015-11-17 19:35:12 +00001074 return Location::NoLocation();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001075 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +01001076
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001077 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001078}
1079
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001080Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
1081 return Location::RegisterLocation(kMethodRegisterArgument);
1082}
1083
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001084void CodeGeneratorARM::Move32(Location destination, Location source) {
1085 if (source.Equals(destination)) {
1086 return;
1087 }
1088 if (destination.IsRegister()) {
1089 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001090 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001091 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001092 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001093 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001094 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001095 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001096 } else if (destination.IsFpuRegister()) {
1097 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001098 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001099 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001100 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001101 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001102 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001103 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001104 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001105 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001106 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001107 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001108 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001109 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001110 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001111 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001112 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1113 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001114 }
1115 }
1116}
1117
1118void CodeGeneratorARM::Move64(Location destination, Location source) {
1119 if (source.Equals(destination)) {
1120 return;
1121 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001122 if (destination.IsRegisterPair()) {
1123 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001124 EmitParallelMoves(
1125 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
1126 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001127 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001128 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001129 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
1130 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001131 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001132 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001133 } else if (source.IsFpuRegisterPair()) {
1134 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
1135 destination.AsRegisterPairHigh<Register>(),
1136 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001137 } else {
1138 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001139 DCHECK(ExpectedPairLayout(destination));
1140 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
1141 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001142 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001143 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001144 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001145 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1146 SP,
1147 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001148 } else if (source.IsRegisterPair()) {
1149 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1150 source.AsRegisterPairLow<Register>(),
1151 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001152 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001153 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001154 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001155 } else {
1156 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001157 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001158 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001159 if (source.AsRegisterPairLow<Register>() == R1) {
1160 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001161 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
1162 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001163 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001164 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001165 SP, destination.GetStackIndex());
1166 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001167 } else if (source.IsFpuRegisterPair()) {
1168 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
1169 SP,
1170 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001171 } else {
1172 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001173 EmitParallelMoves(
1174 Location::StackSlot(source.GetStackIndex()),
1175 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001176 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001177 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001178 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
1179 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001180 }
1181 }
1182}
1183
Calin Juravle175dc732015-08-25 15:42:32 +01001184void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1185 DCHECK(location.IsRegister());
1186 __ LoadImmediate(location.AsRegister<Register>(), value);
1187}
1188
Calin Juravlee460d1d2015-09-29 04:52:17 +01001189void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001190 HParallelMove move(GetGraph()->GetArena());
1191 move.AddMove(src, dst, dst_type, nullptr);
1192 GetMoveResolver()->EmitNativeCode(&move);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001193}
1194
1195void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1196 if (location.IsRegister()) {
1197 locations->AddTemp(location);
1198 } else if (location.IsRegisterPair()) {
1199 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1200 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1201 } else {
1202 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1203 }
1204}
1205
Calin Juravle175dc732015-08-25 15:42:32 +01001206void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1207 HInstruction* instruction,
1208 uint32_t dex_pc,
1209 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001210 ValidateInvokeRuntime(instruction, slow_path);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001211 GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value());
Serban Constantinescuda8ffec2016-03-09 12:02:11 +00001212 if (EntrypointRequiresStackMap(entrypoint)) {
1213 RecordPcInfo(instruction, dex_pc, slow_path);
1214 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001215}
1216
Roland Levillaindec8f632016-07-22 17:10:06 +01001217void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1218 HInstruction* instruction,
1219 SlowPathCode* slow_path) {
1220 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001221 GenerateInvokeRuntime(entry_point_offset);
1222}
1223
1224void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) {
Roland Levillaindec8f632016-07-22 17:10:06 +01001225 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1226 __ blx(LR);
1227}
1228
David Brazdilfc6a86a2015-06-26 10:33:45 +00001229void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001230 DCHECK(!successor->IsExitBlock());
1231
1232 HBasicBlock* block = got->GetBlock();
1233 HInstruction* previous = got->GetPrevious();
1234
1235 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001236 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001237 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1238 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1239 return;
1240 }
1241
1242 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1243 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1244 }
1245 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001246 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001247 }
1248}
1249
David Brazdilfc6a86a2015-06-26 10:33:45 +00001250void LocationsBuilderARM::VisitGoto(HGoto* got) {
1251 got->SetLocations(nullptr);
1252}
1253
1254void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1255 HandleGoto(got, got->GetSuccessor());
1256}
1257
1258void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1259 try_boundary->SetLocations(nullptr);
1260}
1261
1262void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1263 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1264 if (!successor->IsExitBlock()) {
1265 HandleGoto(try_boundary, successor);
1266 }
1267}
1268
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001269void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001270 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001271}
1272
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001273void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001274}
1275
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001276void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1277 Primitive::Type type = instruction->InputAt(0)->GetType();
1278 Location lhs_loc = instruction->GetLocations()->InAt(0);
1279 Location rhs_loc = instruction->GetLocations()->InAt(1);
1280 if (rhs_loc.IsConstant()) {
1281 // 0.0 is the only immediate that can be encoded directly in
1282 // a VCMP instruction.
1283 //
1284 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1285 // specify that in a floating-point comparison, positive zero
1286 // and negative zero are considered equal, so we can use the
1287 // literal 0.0 for both cases here.
1288 //
1289 // Note however that some methods (Float.equal, Float.compare,
1290 // Float.compareTo, Double.equal, Double.compare,
1291 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1292 // StrictMath.min) consider 0.0 to be (strictly) greater than
1293 // -0.0. So if we ever translate calls to these methods into a
1294 // HCompare instruction, we must handle the -0.0 case with
1295 // care here.
1296 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1297 if (type == Primitive::kPrimFloat) {
1298 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1299 } else {
1300 DCHECK_EQ(type, Primitive::kPrimDouble);
1301 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1302 }
1303 } else {
1304 if (type == Primitive::kPrimFloat) {
1305 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1306 } else {
1307 DCHECK_EQ(type, Primitive::kPrimDouble);
1308 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1309 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1310 }
1311 }
1312}
1313
Roland Levillain4fa13f62015-07-06 18:11:54 +01001314void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1315 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001316 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001317 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001318 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001319}
1320
1321void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1322 Label* true_label,
1323 Label* false_label) {
1324 LocationSummary* locations = cond->GetLocations();
1325 Location left = locations->InAt(0);
1326 Location right = locations->InAt(1);
1327 IfCondition if_cond = cond->GetCondition();
1328
1329 Register left_high = left.AsRegisterPairHigh<Register>();
1330 Register left_low = left.AsRegisterPairLow<Register>();
1331 IfCondition true_high_cond = if_cond;
1332 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001333 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001334
1335 // Set the conditions for the test, remembering that == needs to be
1336 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001337 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001338 switch (if_cond) {
1339 case kCondEQ:
1340 case kCondNE:
1341 // Nothing to do.
1342 break;
1343 case kCondLT:
1344 false_high_cond = kCondGT;
1345 break;
1346 case kCondLE:
1347 true_high_cond = kCondLT;
1348 break;
1349 case kCondGT:
1350 false_high_cond = kCondLT;
1351 break;
1352 case kCondGE:
1353 true_high_cond = kCondGT;
1354 break;
Aart Bike9f37602015-10-09 11:15:55 -07001355 case kCondB:
1356 false_high_cond = kCondA;
1357 break;
1358 case kCondBE:
1359 true_high_cond = kCondB;
1360 break;
1361 case kCondA:
1362 false_high_cond = kCondB;
1363 break;
1364 case kCondAE:
1365 true_high_cond = kCondA;
1366 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001367 }
1368 if (right.IsConstant()) {
1369 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1370 int32_t val_low = Low32Bits(value);
1371 int32_t val_high = High32Bits(value);
1372
Vladimir Markoac6ac102015-12-17 12:14:00 +00001373 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001374 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001375 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001376 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001377 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001378 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001379 __ b(true_label, ARMCondition(true_high_cond));
1380 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001381 }
1382 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001383 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001384 } else {
1385 Register right_high = right.AsRegisterPairHigh<Register>();
1386 Register right_low = right.AsRegisterPairLow<Register>();
1387
1388 __ cmp(left_high, ShifterOperand(right_high));
1389 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001390 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001391 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001392 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001393 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001394 __ b(true_label, ARMCondition(true_high_cond));
1395 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001396 }
1397 // Must be equal high, so compare the lows.
1398 __ cmp(left_low, ShifterOperand(right_low));
1399 }
1400 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001401 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001402 __ b(true_label, final_condition);
1403}
1404
David Brazdil0debae72015-11-12 18:37:00 +00001405void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1406 Label* true_target_in,
1407 Label* false_target_in) {
1408 // Generated branching requires both targets to be explicit. If either of the
1409 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1410 Label fallthrough_target;
1411 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1412 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1413
Roland Levillain4fa13f62015-07-06 18:11:54 +01001414 Primitive::Type type = condition->InputAt(0)->GetType();
1415 switch (type) {
1416 case Primitive::kPrimLong:
1417 GenerateLongComparesAndJumps(condition, true_target, false_target);
1418 break;
1419 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001420 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001421 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001422 GenerateFPJumps(condition, true_target, false_target);
1423 break;
1424 default:
1425 LOG(FATAL) << "Unexpected compare type " << type;
1426 }
1427
David Brazdil0debae72015-11-12 18:37:00 +00001428 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001429 __ b(false_target);
1430 }
David Brazdil0debae72015-11-12 18:37:00 +00001431
1432 if (fallthrough_target.IsLinked()) {
1433 __ Bind(&fallthrough_target);
1434 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001435}
1436
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001437void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001438 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001439 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001440 Label* false_target) {
1441 HInstruction* cond = instruction->InputAt(condition_input_index);
1442
1443 if (true_target == nullptr && false_target == nullptr) {
1444 // Nothing to do. The code always falls through.
1445 return;
1446 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001447 // Constant condition, statically compared against "true" (integer value 1).
1448 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001449 if (true_target != nullptr) {
1450 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001451 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001452 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001453 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001454 if (false_target != nullptr) {
1455 __ b(false_target);
1456 }
1457 }
1458 return;
1459 }
1460
1461 // The following code generates these patterns:
1462 // (1) true_target == nullptr && false_target != nullptr
1463 // - opposite condition true => branch to false_target
1464 // (2) true_target != nullptr && false_target == nullptr
1465 // - condition true => branch to true_target
1466 // (3) true_target != nullptr && false_target != nullptr
1467 // - condition true => branch to true_target
1468 // - branch to false_target
1469 if (IsBooleanValueOrMaterializedCondition(cond)) {
1470 // Condition has been materialized, compare the output to 0.
1471 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1472 DCHECK(cond_val.IsRegister());
1473 if (true_target == nullptr) {
1474 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1475 } else {
1476 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001477 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001478 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001479 // Condition has not been materialized. Use its inputs as the comparison and
1480 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001481 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001482
1483 // If this is a long or FP comparison that has been folded into
1484 // the HCondition, generate the comparison directly.
1485 Primitive::Type type = condition->InputAt(0)->GetType();
1486 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1487 GenerateCompareTestAndBranch(condition, true_target, false_target);
1488 return;
1489 }
1490
1491 LocationSummary* locations = cond->GetLocations();
1492 DCHECK(locations->InAt(0).IsRegister());
1493 Register left = locations->InAt(0).AsRegister<Register>();
1494 Location right = locations->InAt(1);
1495 if (right.IsRegister()) {
1496 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001497 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001498 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001499 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001500 }
1501 if (true_target == nullptr) {
1502 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1503 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001504 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001505 }
Dave Allison20dfc792014-06-16 20:44:29 -07001506 }
David Brazdil0debae72015-11-12 18:37:00 +00001507
1508 // If neither branch falls through (case 3), the conditional branch to `true_target`
1509 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1510 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001511 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001512 }
1513}
1514
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001515void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001516 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1517 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001518 locations->SetInAt(0, Location::RequiresRegister());
1519 }
1520}
1521
1522void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001523 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1524 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1525 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1526 nullptr : codegen_->GetLabelOf(true_successor);
1527 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1528 nullptr : codegen_->GetLabelOf(false_successor);
1529 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001530}
1531
1532void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1533 LocationSummary* locations = new (GetGraph()->GetArena())
1534 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00001535 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001536 locations->SetInAt(0, Location::RequiresRegister());
1537 }
1538}
1539
1540void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08001541 SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001542 GenerateTestAndBranch(deoptimize,
1543 /* condition_input_index */ 0,
1544 slow_path->GetEntryLabel(),
1545 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001546}
Dave Allison20dfc792014-06-16 20:44:29 -07001547
David Brazdil74eb1b22015-12-14 11:44:01 +00001548void LocationsBuilderARM::VisitSelect(HSelect* select) {
1549 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1550 if (Primitive::IsFloatingPointType(select->GetType())) {
1551 locations->SetInAt(0, Location::RequiresFpuRegister());
1552 locations->SetInAt(1, Location::RequiresFpuRegister());
1553 } else {
1554 locations->SetInAt(0, Location::RequiresRegister());
1555 locations->SetInAt(1, Location::RequiresRegister());
1556 }
1557 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1558 locations->SetInAt(2, Location::RequiresRegister());
1559 }
1560 locations->SetOut(Location::SameAsFirstInput());
1561}
1562
1563void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1564 LocationSummary* locations = select->GetLocations();
1565 Label false_target;
1566 GenerateTestAndBranch(select,
1567 /* condition_input_index */ 2,
1568 /* true_target */ nullptr,
1569 &false_target);
1570 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1571 __ Bind(&false_target);
1572}
1573
David Srbecky0cf44932015-12-09 14:09:59 +00001574void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1575 new (GetGraph()->GetArena()) LocationSummary(info);
1576}
1577
David Srbeckyd28f4a02016-03-14 17:14:24 +00001578void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1579 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001580}
1581
1582void CodeGeneratorARM::GenerateNop() {
1583 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001584}
1585
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001586void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001587 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001588 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001589 // Handle the long/FP comparisons made in instruction simplification.
1590 switch (cond->InputAt(0)->GetType()) {
1591 case Primitive::kPrimLong:
1592 locations->SetInAt(0, Location::RequiresRegister());
1593 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001594 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001595 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1596 }
1597 break;
1598
1599 case Primitive::kPrimFloat:
1600 case Primitive::kPrimDouble:
1601 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001602 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001603 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001604 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1605 }
1606 break;
1607
1608 default:
1609 locations->SetInAt(0, Location::RequiresRegister());
1610 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001611 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001612 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1613 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001614 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001615}
1616
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001617void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001618 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001619 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001620 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001621
1622 LocationSummary* locations = cond->GetLocations();
1623 Location left = locations->InAt(0);
1624 Location right = locations->InAt(1);
1625 Register out = locations->Out().AsRegister<Register>();
1626 Label true_label, false_label;
1627
1628 switch (cond->InputAt(0)->GetType()) {
1629 default: {
1630 // Integer case.
1631 if (right.IsRegister()) {
1632 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1633 } else {
1634 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001635 __ CmpConstant(left.AsRegister<Register>(),
1636 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001637 }
Aart Bike9f37602015-10-09 11:15:55 -07001638 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001639 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001640 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001641 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001642 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001643 return;
1644 }
1645 case Primitive::kPrimLong:
1646 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1647 break;
1648 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001649 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001650 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001651 GenerateFPJumps(cond, &true_label, &false_label);
1652 break;
1653 }
1654
1655 // Convert the jumps into the result.
1656 Label done_label;
1657
1658 // False case: result = 0.
1659 __ Bind(&false_label);
1660 __ LoadImmediate(out, 0);
1661 __ b(&done_label);
1662
1663 // True case: result = 1.
1664 __ Bind(&true_label);
1665 __ LoadImmediate(out, 1);
1666 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001667}
1668
1669void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001670 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001671}
1672
1673void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001674 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001675}
1676
1677void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001678 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001679}
1680
1681void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001682 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001683}
1684
1685void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001686 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001687}
1688
1689void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001690 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001691}
1692
1693void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001694 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001695}
1696
1697void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001698 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001699}
1700
1701void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001702 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001703}
1704
1705void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001706 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001707}
1708
1709void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001710 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001711}
1712
1713void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001714 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001715}
1716
Aart Bike9f37602015-10-09 11:15:55 -07001717void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001718 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001719}
1720
1721void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001722 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001723}
1724
1725void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001726 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001727}
1728
1729void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001730 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001731}
1732
1733void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001734 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001735}
1736
1737void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001738 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001739}
1740
1741void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001742 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001743}
1744
1745void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001746 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001747}
1748
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001749void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001750 LocationSummary* locations =
1751 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001752 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001753}
1754
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001755void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001756 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001757}
1758
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001759void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1760 LocationSummary* locations =
1761 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1762 locations->SetOut(Location::ConstantLocation(constant));
1763}
1764
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001765void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001766 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001767}
1768
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001769void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001770 LocationSummary* locations =
1771 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001772 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001773}
1774
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001775void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001776 // Will be generated at use site.
1777}
1778
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001779void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1780 LocationSummary* locations =
1781 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1782 locations->SetOut(Location::ConstantLocation(constant));
1783}
1784
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001785void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001786 // Will be generated at use site.
1787}
1788
1789void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1790 LocationSummary* locations =
1791 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1792 locations->SetOut(Location::ConstantLocation(constant));
1793}
1794
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001795void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001796 // Will be generated at use site.
1797}
1798
Calin Juravle27df7582015-04-17 19:12:31 +01001799void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1800 memory_barrier->SetLocations(nullptr);
1801}
1802
1803void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00001804 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01001805}
1806
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001807void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001808 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001809}
1810
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001811void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001812 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001813}
1814
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001815void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001816 LocationSummary* locations =
1817 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001818 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001819}
1820
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001821void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001822 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001823}
1824
Calin Juravle175dc732015-08-25 15:42:32 +01001825void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1826 // The trampoline uses the same calling convention as dex calling conventions,
1827 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1828 // the method_idx.
1829 HandleInvoke(invoke);
1830}
1831
1832void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1833 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1834}
1835
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001836void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001837 // Explicit clinit checks triggered by static invokes must have been pruned by
1838 // art::PrepareForRegisterAllocation.
1839 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001840
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001841 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001842 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001843 codegen_->GetInstructionSetFeatures());
1844 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00001845 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
1846 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
1847 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001848 return;
1849 }
1850
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001851 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00001852
1853 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
1854 if (invoke->HasPcRelativeDexCache()) {
1855 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
1856 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001857}
1858
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001859static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1860 if (invoke->GetLocations()->Intrinsified()) {
1861 IntrinsicCodeGeneratorARM intrinsic(codegen);
1862 intrinsic.Dispatch(invoke);
1863 return true;
1864 }
1865 return false;
1866}
1867
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001868void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001869 // Explicit clinit checks triggered by static invokes must have been pruned by
1870 // art::PrepareForRegisterAllocation.
1871 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001872
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001873 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1874 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001875 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001876
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001877 LocationSummary* locations = invoke->GetLocations();
1878 codegen_->GenerateStaticOrDirectCall(
1879 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001880 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001881}
1882
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001883void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001884 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001885 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001886}
1887
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001888void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001889 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001890 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001891 codegen_->GetInstructionSetFeatures());
1892 if (intrinsic.TryDispatch(invoke)) {
1893 return;
1894 }
1895
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001896 HandleInvoke(invoke);
1897}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001898
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001899void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001900 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1901 return;
1902 }
1903
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001904 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001905 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001906 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001907}
1908
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001909void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1910 HandleInvoke(invoke);
1911 // Add the hidden argument.
1912 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1913}
1914
1915void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1916 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00001917 LocationSummary* locations = invoke->GetLocations();
1918 Register temp = locations->GetTemp(0).AsRegister<Register>();
1919 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001920 Location receiver = locations->InAt(0);
1921 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1922
Roland Levillain3b359c72015-11-17 19:35:12 +00001923 // Set the hidden argument. This is safe to do this here, as R12
1924 // won't be modified thereafter, before the `blx` (call) instruction.
1925 DCHECK_EQ(R12, hidden_reg);
1926 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001927
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001928 if (receiver.IsStackSlot()) {
1929 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00001930 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001931 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1932 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00001933 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00001934 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001935 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001936 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00001937 // Instead of simply (possibly) unpoisoning `temp` here, we should
1938 // emit a read barrier for the previous class reference load.
1939 // However this is not required in practice, as this is an
1940 // intermediate/temporary reference and because the current
1941 // concurrent copying collector keeps the from-space memory
1942 // intact/accessible until the end of the marking phase (the
1943 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01001944 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001945 __ LoadFromOffset(kLoadWord, temp, temp,
1946 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
1947 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00001948 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001949 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001950 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00001951 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07001952 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001953 // LR = temp->GetEntryPoint();
1954 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1955 // LR();
1956 __ blx(LR);
1957 DCHECK(!codegen_->IsLeafMethod());
1958 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1959}
1960
Roland Levillain88cb1752014-10-20 16:36:47 +01001961void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1962 LocationSummary* locations =
1963 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1964 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001965 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001966 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001967 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1968 break;
1969 }
1970 case Primitive::kPrimLong: {
1971 locations->SetInAt(0, Location::RequiresRegister());
1972 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001973 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001974 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001975
Roland Levillain88cb1752014-10-20 16:36:47 +01001976 case Primitive::kPrimFloat:
1977 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001978 locations->SetInAt(0, Location::RequiresFpuRegister());
1979 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001980 break;
1981
1982 default:
1983 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1984 }
1985}
1986
1987void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1988 LocationSummary* locations = neg->GetLocations();
1989 Location out = locations->Out();
1990 Location in = locations->InAt(0);
1991 switch (neg->GetResultType()) {
1992 case Primitive::kPrimInt:
1993 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001994 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001995 break;
1996
1997 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001998 DCHECK(in.IsRegisterPair());
1999 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
2000 __ rsbs(out.AsRegisterPairLow<Register>(),
2001 in.AsRegisterPairLow<Register>(),
2002 ShifterOperand(0));
2003 // We cannot emit an RSC (Reverse Subtract with Carry)
2004 // instruction here, as it does not exist in the Thumb-2
2005 // instruction set. We use the following approach
2006 // using SBC and SUB instead.
2007 //
2008 // out.hi = -C
2009 __ sbc(out.AsRegisterPairHigh<Register>(),
2010 out.AsRegisterPairHigh<Register>(),
2011 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2012 // out.hi = out.hi - in.hi
2013 __ sub(out.AsRegisterPairHigh<Register>(),
2014 out.AsRegisterPairHigh<Register>(),
2015 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2016 break;
2017
Roland Levillain88cb1752014-10-20 16:36:47 +01002018 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002019 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002020 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002021 break;
2022
Roland Levillain88cb1752014-10-20 16:36:47 +01002023 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002024 DCHECK(in.IsFpuRegisterPair());
2025 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2026 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002027 break;
2028
2029 default:
2030 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2031 }
2032}
2033
Roland Levillaindff1f282014-11-05 14:15:05 +00002034void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002035 Primitive::Type result_type = conversion->GetResultType();
2036 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002037 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002038
Roland Levillain5b3ee562015-04-14 16:02:41 +01002039 // The float-to-long, double-to-long and long-to-float type conversions
2040 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002041 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002042 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2043 && result_type == Primitive::kPrimLong)
2044 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002045 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002046 : LocationSummary::kNoCall;
2047 LocationSummary* locations =
2048 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2049
David Brazdilb2bd1c52015-03-25 11:17:37 +00002050 // The Java language does not allow treating boolean as an integral type but
2051 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002052
Roland Levillaindff1f282014-11-05 14:15:05 +00002053 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002054 case Primitive::kPrimByte:
2055 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002056 case Primitive::kPrimLong:
2057 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002058 case Primitive::kPrimBoolean:
2059 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002060 case Primitive::kPrimShort:
2061 case Primitive::kPrimInt:
2062 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002063 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002064 locations->SetInAt(0, Location::RequiresRegister());
2065 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2066 break;
2067
2068 default:
2069 LOG(FATAL) << "Unexpected type conversion from " << input_type
2070 << " to " << result_type;
2071 }
2072 break;
2073
Roland Levillain01a8d712014-11-14 16:27:39 +00002074 case Primitive::kPrimShort:
2075 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002076 case Primitive::kPrimLong:
2077 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002078 case Primitive::kPrimBoolean:
2079 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002080 case Primitive::kPrimByte:
2081 case Primitive::kPrimInt:
2082 case Primitive::kPrimChar:
2083 // Processing a Dex `int-to-short' instruction.
2084 locations->SetInAt(0, Location::RequiresRegister());
2085 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2086 break;
2087
2088 default:
2089 LOG(FATAL) << "Unexpected type conversion from " << input_type
2090 << " to " << result_type;
2091 }
2092 break;
2093
Roland Levillain946e1432014-11-11 17:35:19 +00002094 case Primitive::kPrimInt:
2095 switch (input_type) {
2096 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002097 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002098 locations->SetInAt(0, Location::Any());
2099 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2100 break;
2101
2102 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002103 // Processing a Dex `float-to-int' instruction.
2104 locations->SetInAt(0, Location::RequiresFpuRegister());
2105 locations->SetOut(Location::RequiresRegister());
2106 locations->AddTemp(Location::RequiresFpuRegister());
2107 break;
2108
Roland Levillain946e1432014-11-11 17:35:19 +00002109 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002110 // Processing a Dex `double-to-int' instruction.
2111 locations->SetInAt(0, Location::RequiresFpuRegister());
2112 locations->SetOut(Location::RequiresRegister());
2113 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002114 break;
2115
2116 default:
2117 LOG(FATAL) << "Unexpected type conversion from " << input_type
2118 << " to " << result_type;
2119 }
2120 break;
2121
Roland Levillaindff1f282014-11-05 14:15:05 +00002122 case Primitive::kPrimLong:
2123 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002124 case Primitive::kPrimBoolean:
2125 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002126 case Primitive::kPrimByte:
2127 case Primitive::kPrimShort:
2128 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002129 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002130 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002131 locations->SetInAt(0, Location::RequiresRegister());
2132 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2133 break;
2134
Roland Levillain624279f2014-12-04 11:54:28 +00002135 case Primitive::kPrimFloat: {
2136 // Processing a Dex `float-to-long' instruction.
2137 InvokeRuntimeCallingConvention calling_convention;
2138 locations->SetInAt(0, Location::FpuRegisterLocation(
2139 calling_convention.GetFpuRegisterAt(0)));
2140 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2141 break;
2142 }
2143
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002144 case Primitive::kPrimDouble: {
2145 // Processing a Dex `double-to-long' instruction.
2146 InvokeRuntimeCallingConvention calling_convention;
2147 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2148 calling_convention.GetFpuRegisterAt(0),
2149 calling_convention.GetFpuRegisterAt(1)));
2150 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002151 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002152 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002153
2154 default:
2155 LOG(FATAL) << "Unexpected type conversion from " << input_type
2156 << " to " << result_type;
2157 }
2158 break;
2159
Roland Levillain981e4542014-11-14 11:47:14 +00002160 case Primitive::kPrimChar:
2161 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002162 case Primitive::kPrimLong:
2163 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002164 case Primitive::kPrimBoolean:
2165 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002166 case Primitive::kPrimByte:
2167 case Primitive::kPrimShort:
2168 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002169 // Processing a Dex `int-to-char' instruction.
2170 locations->SetInAt(0, Location::RequiresRegister());
2171 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2172 break;
2173
2174 default:
2175 LOG(FATAL) << "Unexpected type conversion from " << input_type
2176 << " to " << result_type;
2177 }
2178 break;
2179
Roland Levillaindff1f282014-11-05 14:15:05 +00002180 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002181 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002182 case Primitive::kPrimBoolean:
2183 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002184 case Primitive::kPrimByte:
2185 case Primitive::kPrimShort:
2186 case Primitive::kPrimInt:
2187 case Primitive::kPrimChar:
2188 // Processing a Dex `int-to-float' instruction.
2189 locations->SetInAt(0, Location::RequiresRegister());
2190 locations->SetOut(Location::RequiresFpuRegister());
2191 break;
2192
Roland Levillain5b3ee562015-04-14 16:02:41 +01002193 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002194 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002195 InvokeRuntimeCallingConvention calling_convention;
2196 locations->SetInAt(0, Location::RegisterPairLocation(
2197 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2198 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002199 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002200 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002201
Roland Levillaincff13742014-11-17 14:32:17 +00002202 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002203 // Processing a Dex `double-to-float' instruction.
2204 locations->SetInAt(0, Location::RequiresFpuRegister());
2205 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002206 break;
2207
2208 default:
2209 LOG(FATAL) << "Unexpected type conversion from " << input_type
2210 << " to " << result_type;
2211 };
2212 break;
2213
Roland Levillaindff1f282014-11-05 14:15:05 +00002214 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002215 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002216 case Primitive::kPrimBoolean:
2217 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002218 case Primitive::kPrimByte:
2219 case Primitive::kPrimShort:
2220 case Primitive::kPrimInt:
2221 case Primitive::kPrimChar:
2222 // Processing a Dex `int-to-double' instruction.
2223 locations->SetInAt(0, Location::RequiresRegister());
2224 locations->SetOut(Location::RequiresFpuRegister());
2225 break;
2226
2227 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002228 // Processing a Dex `long-to-double' instruction.
2229 locations->SetInAt(0, Location::RequiresRegister());
2230 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002231 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002232 locations->AddTemp(Location::RequiresFpuRegister());
2233 break;
2234
Roland Levillaincff13742014-11-17 14:32:17 +00002235 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002236 // Processing a Dex `float-to-double' instruction.
2237 locations->SetInAt(0, Location::RequiresFpuRegister());
2238 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002239 break;
2240
2241 default:
2242 LOG(FATAL) << "Unexpected type conversion from " << input_type
2243 << " to " << result_type;
2244 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002245 break;
2246
2247 default:
2248 LOG(FATAL) << "Unexpected type conversion from " << input_type
2249 << " to " << result_type;
2250 }
2251}
2252
2253void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2254 LocationSummary* locations = conversion->GetLocations();
2255 Location out = locations->Out();
2256 Location in = locations->InAt(0);
2257 Primitive::Type result_type = conversion->GetResultType();
2258 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002259 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002260 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002261 case Primitive::kPrimByte:
2262 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002263 case Primitive::kPrimLong:
2264 // Type conversion from long to byte is a result of code transformations.
2265 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2266 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002267 case Primitive::kPrimBoolean:
2268 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002269 case Primitive::kPrimShort:
2270 case Primitive::kPrimInt:
2271 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002272 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002273 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002274 break;
2275
2276 default:
2277 LOG(FATAL) << "Unexpected type conversion from " << input_type
2278 << " to " << result_type;
2279 }
2280 break;
2281
Roland Levillain01a8d712014-11-14 16:27:39 +00002282 case Primitive::kPrimShort:
2283 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002284 case Primitive::kPrimLong:
2285 // Type conversion from long to short is a result of code transformations.
2286 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2287 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002288 case Primitive::kPrimBoolean:
2289 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002290 case Primitive::kPrimByte:
2291 case Primitive::kPrimInt:
2292 case Primitive::kPrimChar:
2293 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002294 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002295 break;
2296
2297 default:
2298 LOG(FATAL) << "Unexpected type conversion from " << input_type
2299 << " to " << result_type;
2300 }
2301 break;
2302
Roland Levillain946e1432014-11-11 17:35:19 +00002303 case Primitive::kPrimInt:
2304 switch (input_type) {
2305 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002306 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002307 DCHECK(out.IsRegister());
2308 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002309 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002310 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002311 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002312 } else {
2313 DCHECK(in.IsConstant());
2314 DCHECK(in.GetConstant()->IsLongConstant());
2315 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002316 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002317 }
2318 break;
2319
Roland Levillain3f8f9362014-12-02 17:45:01 +00002320 case Primitive::kPrimFloat: {
2321 // Processing a Dex `float-to-int' instruction.
2322 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002323 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002324 __ vmovrs(out.AsRegister<Register>(), temp);
2325 break;
2326 }
2327
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002328 case Primitive::kPrimDouble: {
2329 // Processing a Dex `double-to-int' instruction.
2330 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002331 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002332 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002333 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002334 }
Roland Levillain946e1432014-11-11 17:35:19 +00002335
2336 default:
2337 LOG(FATAL) << "Unexpected type conversion from " << input_type
2338 << " to " << result_type;
2339 }
2340 break;
2341
Roland Levillaindff1f282014-11-05 14:15:05 +00002342 case Primitive::kPrimLong:
2343 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002344 case Primitive::kPrimBoolean:
2345 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002346 case Primitive::kPrimByte:
2347 case Primitive::kPrimShort:
2348 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002349 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002350 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002351 DCHECK(out.IsRegisterPair());
2352 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002353 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002354 // Sign extension.
2355 __ Asr(out.AsRegisterPairHigh<Register>(),
2356 out.AsRegisterPairLow<Register>(),
2357 31);
2358 break;
2359
2360 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002361 // Processing a Dex `float-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002362 codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002363 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002364 break;
2365
Roland Levillaindff1f282014-11-05 14:15:05 +00002366 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002367 // Processing a Dex `double-to-long' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002368 codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002369 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002370 break;
2371
2372 default:
2373 LOG(FATAL) << "Unexpected type conversion from " << input_type
2374 << " to " << result_type;
2375 }
2376 break;
2377
Roland Levillain981e4542014-11-14 11:47:14 +00002378 case Primitive::kPrimChar:
2379 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002380 case Primitive::kPrimLong:
2381 // Type conversion from long to char is a result of code transformations.
2382 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2383 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002384 case Primitive::kPrimBoolean:
2385 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002386 case Primitive::kPrimByte:
2387 case Primitive::kPrimShort:
2388 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002389 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002390 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002391 break;
2392
2393 default:
2394 LOG(FATAL) << "Unexpected type conversion from " << input_type
2395 << " to " << result_type;
2396 }
2397 break;
2398
Roland Levillaindff1f282014-11-05 14:15:05 +00002399 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002400 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002401 case Primitive::kPrimBoolean:
2402 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002403 case Primitive::kPrimByte:
2404 case Primitive::kPrimShort:
2405 case Primitive::kPrimInt:
2406 case Primitive::kPrimChar: {
2407 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002408 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2409 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002410 break;
2411 }
2412
Roland Levillain5b3ee562015-04-14 16:02:41 +01002413 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002414 // Processing a Dex `long-to-float' instruction.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002415 codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002416 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002417 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002418
Roland Levillaincff13742014-11-17 14:32:17 +00002419 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002420 // Processing a Dex `double-to-float' instruction.
2421 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2422 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002423 break;
2424
2425 default:
2426 LOG(FATAL) << "Unexpected type conversion from " << input_type
2427 << " to " << result_type;
2428 };
2429 break;
2430
Roland Levillaindff1f282014-11-05 14:15:05 +00002431 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002432 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002433 case Primitive::kPrimBoolean:
2434 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002435 case Primitive::kPrimByte:
2436 case Primitive::kPrimShort:
2437 case Primitive::kPrimInt:
2438 case Primitive::kPrimChar: {
2439 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002440 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002441 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2442 out.AsFpuRegisterPairLow<SRegister>());
2443 break;
2444 }
2445
Roland Levillain647b9ed2014-11-27 12:06:00 +00002446 case Primitive::kPrimLong: {
2447 // Processing a Dex `long-to-double' instruction.
2448 Register low = in.AsRegisterPairLow<Register>();
2449 Register high = in.AsRegisterPairHigh<Register>();
2450 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2451 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002452 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002453 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002454 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2455 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002456
Roland Levillain682393c2015-04-14 15:57:52 +01002457 // temp_d = int-to-double(high)
2458 __ vmovsr(temp_s, high);
2459 __ vcvtdi(temp_d, temp_s);
2460 // constant_d = k2Pow32EncodingForDouble
2461 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2462 // out_d = unsigned-to-double(low)
2463 __ vmovsr(out_s, low);
2464 __ vcvtdu(out_d, out_s);
2465 // out_d += temp_d * constant_d
2466 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002467 break;
2468 }
2469
Roland Levillaincff13742014-11-17 14:32:17 +00002470 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002471 // Processing a Dex `float-to-double' instruction.
2472 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2473 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002474 break;
2475
2476 default:
2477 LOG(FATAL) << "Unexpected type conversion from " << input_type
2478 << " to " << result_type;
2479 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002480 break;
2481
2482 default:
2483 LOG(FATAL) << "Unexpected type conversion from " << input_type
2484 << " to " << result_type;
2485 }
2486}
2487
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002488void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002489 LocationSummary* locations =
2490 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002491 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002492 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002493 locations->SetInAt(0, Location::RequiresRegister());
2494 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002495 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2496 break;
2497 }
2498
2499 case Primitive::kPrimLong: {
2500 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002501 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002502 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002503 break;
2504 }
2505
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002506 case Primitive::kPrimFloat:
2507 case Primitive::kPrimDouble: {
2508 locations->SetInAt(0, Location::RequiresFpuRegister());
2509 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002510 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002511 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002512 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002513
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002514 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002515 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002516 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002517}
2518
2519void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2520 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002521 Location out = locations->Out();
2522 Location first = locations->InAt(0);
2523 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002524 switch (add->GetResultType()) {
2525 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002526 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002527 __ add(out.AsRegister<Register>(),
2528 first.AsRegister<Register>(),
2529 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002530 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002531 __ AddConstant(out.AsRegister<Register>(),
2532 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002533 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002534 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002535 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002536
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002537 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002538 if (second.IsConstant()) {
2539 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2540 GenerateAddLongConst(out, first, value);
2541 } else {
2542 DCHECK(second.IsRegisterPair());
2543 __ adds(out.AsRegisterPairLow<Register>(),
2544 first.AsRegisterPairLow<Register>(),
2545 ShifterOperand(second.AsRegisterPairLow<Register>()));
2546 __ adc(out.AsRegisterPairHigh<Register>(),
2547 first.AsRegisterPairHigh<Register>(),
2548 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2549 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002550 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002551 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002552
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002553 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002554 __ vadds(out.AsFpuRegister<SRegister>(),
2555 first.AsFpuRegister<SRegister>(),
2556 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002557 break;
2558
2559 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002560 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2561 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2562 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002563 break;
2564
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002565 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002566 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002567 }
2568}
2569
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002570void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002571 LocationSummary* locations =
2572 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002573 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002574 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002575 locations->SetInAt(0, Location::RequiresRegister());
2576 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002577 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2578 break;
2579 }
2580
2581 case Primitive::kPrimLong: {
2582 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002583 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002584 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002585 break;
2586 }
Calin Juravle11351682014-10-23 15:38:15 +01002587 case Primitive::kPrimFloat:
2588 case Primitive::kPrimDouble: {
2589 locations->SetInAt(0, Location::RequiresFpuRegister());
2590 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002591 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002592 break;
Calin Juravle11351682014-10-23 15:38:15 +01002593 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002594 default:
Calin Juravle11351682014-10-23 15:38:15 +01002595 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002596 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002597}
2598
2599void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2600 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002601 Location out = locations->Out();
2602 Location first = locations->InAt(0);
2603 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002604 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002605 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002606 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002607 __ sub(out.AsRegister<Register>(),
2608 first.AsRegister<Register>(),
2609 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002610 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002611 __ AddConstant(out.AsRegister<Register>(),
2612 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002613 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002614 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002615 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002616 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002617
Calin Juravle11351682014-10-23 15:38:15 +01002618 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002619 if (second.IsConstant()) {
2620 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2621 GenerateAddLongConst(out, first, -value);
2622 } else {
2623 DCHECK(second.IsRegisterPair());
2624 __ subs(out.AsRegisterPairLow<Register>(),
2625 first.AsRegisterPairLow<Register>(),
2626 ShifterOperand(second.AsRegisterPairLow<Register>()));
2627 __ sbc(out.AsRegisterPairHigh<Register>(),
2628 first.AsRegisterPairHigh<Register>(),
2629 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2630 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002631 break;
Calin Juravle11351682014-10-23 15:38:15 +01002632 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002633
Calin Juravle11351682014-10-23 15:38:15 +01002634 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002635 __ vsubs(out.AsFpuRegister<SRegister>(),
2636 first.AsFpuRegister<SRegister>(),
2637 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002638 break;
Calin Juravle11351682014-10-23 15:38:15 +01002639 }
2640
2641 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002642 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2643 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2644 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002645 break;
2646 }
2647
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002648
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002649 default:
Calin Juravle11351682014-10-23 15:38:15 +01002650 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002651 }
2652}
2653
Calin Juravle34bacdf2014-10-07 20:23:36 +01002654void LocationsBuilderARM::VisitMul(HMul* mul) {
2655 LocationSummary* locations =
2656 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2657 switch (mul->GetResultType()) {
2658 case Primitive::kPrimInt:
2659 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002660 locations->SetInAt(0, Location::RequiresRegister());
2661 locations->SetInAt(1, Location::RequiresRegister());
2662 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002663 break;
2664 }
2665
Calin Juravleb5bfa962014-10-21 18:02:24 +01002666 case Primitive::kPrimFloat:
2667 case Primitive::kPrimDouble: {
2668 locations->SetInAt(0, Location::RequiresFpuRegister());
2669 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002670 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002671 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002672 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002673
2674 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002675 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002676 }
2677}
2678
2679void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2680 LocationSummary* locations = mul->GetLocations();
2681 Location out = locations->Out();
2682 Location first = locations->InAt(0);
2683 Location second = locations->InAt(1);
2684 switch (mul->GetResultType()) {
2685 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002686 __ mul(out.AsRegister<Register>(),
2687 first.AsRegister<Register>(),
2688 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002689 break;
2690 }
2691 case Primitive::kPrimLong: {
2692 Register out_hi = out.AsRegisterPairHigh<Register>();
2693 Register out_lo = out.AsRegisterPairLow<Register>();
2694 Register in1_hi = first.AsRegisterPairHigh<Register>();
2695 Register in1_lo = first.AsRegisterPairLow<Register>();
2696 Register in2_hi = second.AsRegisterPairHigh<Register>();
2697 Register in2_lo = second.AsRegisterPairLow<Register>();
2698
2699 // Extra checks to protect caused by the existence of R1_R2.
2700 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2701 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2702 DCHECK_NE(out_hi, in1_lo);
2703 DCHECK_NE(out_hi, in2_lo);
2704
2705 // input: in1 - 64 bits, in2 - 64 bits
2706 // output: out
2707 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2708 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2709 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2710
2711 // IP <- in1.lo * in2.hi
2712 __ mul(IP, in1_lo, in2_hi);
2713 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2714 __ mla(out_hi, in1_hi, in2_lo, IP);
2715 // out.lo <- (in1.lo * in2.lo)[31:0];
2716 __ umull(out_lo, IP, in1_lo, in2_lo);
2717 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2718 __ add(out_hi, out_hi, ShifterOperand(IP));
2719 break;
2720 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002721
2722 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002723 __ vmuls(out.AsFpuRegister<SRegister>(),
2724 first.AsFpuRegister<SRegister>(),
2725 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002726 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002727 }
2728
2729 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002730 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2731 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2732 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002733 break;
2734 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002735
2736 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002737 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002738 }
2739}
2740
Zheng Xuc6667102015-05-15 16:08:45 +08002741void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2742 DCHECK(instruction->IsDiv() || instruction->IsRem());
2743 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2744
2745 LocationSummary* locations = instruction->GetLocations();
2746 Location second = locations->InAt(1);
2747 DCHECK(second.IsConstant());
2748
2749 Register out = locations->Out().AsRegister<Register>();
2750 Register dividend = locations->InAt(0).AsRegister<Register>();
2751 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2752 DCHECK(imm == 1 || imm == -1);
2753
2754 if (instruction->IsRem()) {
2755 __ LoadImmediate(out, 0);
2756 } else {
2757 if (imm == 1) {
2758 __ Mov(out, dividend);
2759 } else {
2760 __ rsb(out, dividend, ShifterOperand(0));
2761 }
2762 }
2763}
2764
2765void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2766 DCHECK(instruction->IsDiv() || instruction->IsRem());
2767 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2768
2769 LocationSummary* locations = instruction->GetLocations();
2770 Location second = locations->InAt(1);
2771 DCHECK(second.IsConstant());
2772
2773 Register out = locations->Out().AsRegister<Register>();
2774 Register dividend = locations->InAt(0).AsRegister<Register>();
2775 Register temp = locations->GetTemp(0).AsRegister<Register>();
2776 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002777 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002778 int ctz_imm = CTZ(abs_imm);
2779
2780 if (ctz_imm == 1) {
2781 __ Lsr(temp, dividend, 32 - ctz_imm);
2782 } else {
2783 __ Asr(temp, dividend, 31);
2784 __ Lsr(temp, temp, 32 - ctz_imm);
2785 }
2786 __ add(out, temp, ShifterOperand(dividend));
2787
2788 if (instruction->IsDiv()) {
2789 __ Asr(out, out, ctz_imm);
2790 if (imm < 0) {
2791 __ rsb(out, out, ShifterOperand(0));
2792 }
2793 } else {
2794 __ ubfx(out, out, 0, ctz_imm);
2795 __ sub(out, out, ShifterOperand(temp));
2796 }
2797}
2798
2799void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2800 DCHECK(instruction->IsDiv() || instruction->IsRem());
2801 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2802
2803 LocationSummary* locations = instruction->GetLocations();
2804 Location second = locations->InAt(1);
2805 DCHECK(second.IsConstant());
2806
2807 Register out = locations->Out().AsRegister<Register>();
2808 Register dividend = locations->InAt(0).AsRegister<Register>();
2809 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2810 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2811 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2812
2813 int64_t magic;
2814 int shift;
2815 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2816
2817 __ LoadImmediate(temp1, magic);
2818 __ smull(temp2, temp1, dividend, temp1);
2819
2820 if (imm > 0 && magic < 0) {
2821 __ add(temp1, temp1, ShifterOperand(dividend));
2822 } else if (imm < 0 && magic > 0) {
2823 __ sub(temp1, temp1, ShifterOperand(dividend));
2824 }
2825
2826 if (shift != 0) {
2827 __ Asr(temp1, temp1, shift);
2828 }
2829
2830 if (instruction->IsDiv()) {
2831 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2832 } else {
2833 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2834 // TODO: Strength reduction for mls.
2835 __ LoadImmediate(temp2, imm);
2836 __ mls(out, temp1, temp2, dividend);
2837 }
2838}
2839
2840void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2841 DCHECK(instruction->IsDiv() || instruction->IsRem());
2842 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2843
2844 LocationSummary* locations = instruction->GetLocations();
2845 Location second = locations->InAt(1);
2846 DCHECK(second.IsConstant());
2847
2848 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2849 if (imm == 0) {
2850 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2851 } else if (imm == 1 || imm == -1) {
2852 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002853 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002854 DivRemByPowerOfTwo(instruction);
2855 } else {
2856 DCHECK(imm <= -2 || imm >= 2);
2857 GenerateDivRemWithAnyConstant(instruction);
2858 }
2859}
2860
Calin Juravle7c4954d2014-10-28 16:57:40 +00002861void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002862 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2863 if (div->GetResultType() == Primitive::kPrimLong) {
2864 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002865 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002866 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2867 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002868 } else if (div->GetResultType() == Primitive::kPrimInt &&
2869 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2870 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002871 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002872 }
2873
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002874 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2875
Calin Juravle7c4954d2014-10-28 16:57:40 +00002876 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002877 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002878 if (div->InputAt(1)->IsConstant()) {
2879 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00002880 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08002881 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002882 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
2883 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08002884 // No temp register required.
2885 } else {
2886 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002887 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002888 locations->AddTemp(Location::RequiresRegister());
2889 }
2890 }
2891 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002892 locations->SetInAt(0, Location::RequiresRegister());
2893 locations->SetInAt(1, Location::RequiresRegister());
2894 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2895 } else {
2896 InvokeRuntimeCallingConvention calling_convention;
2897 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2898 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2899 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2900 // we only need the former.
2901 locations->SetOut(Location::RegisterLocation(R0));
2902 }
Calin Juravled0d48522014-11-04 16:40:20 +00002903 break;
2904 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002905 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002906 InvokeRuntimeCallingConvention calling_convention;
2907 locations->SetInAt(0, Location::RegisterPairLocation(
2908 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2909 locations->SetInAt(1, Location::RegisterPairLocation(
2910 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002911 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002912 break;
2913 }
2914 case Primitive::kPrimFloat:
2915 case Primitive::kPrimDouble: {
2916 locations->SetInAt(0, Location::RequiresFpuRegister());
2917 locations->SetInAt(1, Location::RequiresFpuRegister());
2918 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2919 break;
2920 }
2921
2922 default:
2923 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2924 }
2925}
2926
2927void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2928 LocationSummary* locations = div->GetLocations();
2929 Location out = locations->Out();
2930 Location first = locations->InAt(0);
2931 Location second = locations->InAt(1);
2932
2933 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002934 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002935 if (second.IsConstant()) {
2936 GenerateDivRemConstantIntegral(div);
2937 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002938 __ sdiv(out.AsRegister<Register>(),
2939 first.AsRegister<Register>(),
2940 second.AsRegister<Register>());
2941 } else {
2942 InvokeRuntimeCallingConvention calling_convention;
2943 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2944 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2945 DCHECK_EQ(R0, out.AsRegister<Register>());
2946
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002947 codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002948 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002949 }
Calin Juravled0d48522014-11-04 16:40:20 +00002950 break;
2951 }
2952
Calin Juravle7c4954d2014-10-28 16:57:40 +00002953 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002954 InvokeRuntimeCallingConvention calling_convention;
2955 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2956 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2957 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2958 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2959 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002960 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002961
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002962 codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00002963 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002964 break;
2965 }
2966
2967 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002968 __ vdivs(out.AsFpuRegister<SRegister>(),
2969 first.AsFpuRegister<SRegister>(),
2970 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002971 break;
2972 }
2973
2974 case Primitive::kPrimDouble: {
2975 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2976 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2977 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2978 break;
2979 }
2980
2981 default:
2982 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2983 }
2984}
2985
Calin Juravlebacfec32014-11-14 15:54:36 +00002986void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002987 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002988
2989 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002990 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002991 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2992 // sdiv will be replaced by other instruction sequence.
2993 call_kind = LocationSummary::kNoCall;
2994 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2995 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002996 // Have hardware divide instruction for int, do it with three instructions.
2997 call_kind = LocationSummary::kNoCall;
2998 }
2999
Calin Juravlebacfec32014-11-14 15:54:36 +00003000 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3001
Calin Juravled2ec87d2014-12-08 14:24:46 +00003002 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003003 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003004 if (rem->InputAt(1)->IsConstant()) {
3005 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003006 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003007 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003008 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3009 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003010 // No temp register required.
3011 } else {
3012 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003013 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003014 locations->AddTemp(Location::RequiresRegister());
3015 }
3016 }
3017 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003018 locations->SetInAt(0, Location::RequiresRegister());
3019 locations->SetInAt(1, Location::RequiresRegister());
3020 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3021 locations->AddTemp(Location::RequiresRegister());
3022 } else {
3023 InvokeRuntimeCallingConvention calling_convention;
3024 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3025 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3026 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3027 // we only need the latter.
3028 locations->SetOut(Location::RegisterLocation(R1));
3029 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003030 break;
3031 }
3032 case Primitive::kPrimLong: {
3033 InvokeRuntimeCallingConvention calling_convention;
3034 locations->SetInAt(0, Location::RegisterPairLocation(
3035 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3036 locations->SetInAt(1, Location::RegisterPairLocation(
3037 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3038 // The runtime helper puts the output in R2,R3.
3039 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3040 break;
3041 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003042 case Primitive::kPrimFloat: {
3043 InvokeRuntimeCallingConvention calling_convention;
3044 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3045 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3046 locations->SetOut(Location::FpuRegisterLocation(S0));
3047 break;
3048 }
3049
Calin Juravlebacfec32014-11-14 15:54:36 +00003050 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003051 InvokeRuntimeCallingConvention calling_convention;
3052 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3053 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3054 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3055 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3056 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003057 break;
3058 }
3059
3060 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003061 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003062 }
3063}
3064
3065void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3066 LocationSummary* locations = rem->GetLocations();
3067 Location out = locations->Out();
3068 Location first = locations->InAt(0);
3069 Location second = locations->InAt(1);
3070
Calin Juravled2ec87d2014-12-08 14:24:46 +00003071 Primitive::Type type = rem->GetResultType();
3072 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003073 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003074 if (second.IsConstant()) {
3075 GenerateDivRemConstantIntegral(rem);
3076 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003077 Register reg1 = first.AsRegister<Register>();
3078 Register reg2 = second.AsRegister<Register>();
3079 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003080
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003081 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003082 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003083 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003084 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003085 } else {
3086 InvokeRuntimeCallingConvention calling_convention;
3087 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3088 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3089 DCHECK_EQ(R1, out.AsRegister<Register>());
3090
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003091 codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003092 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003093 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003094 break;
3095 }
3096
3097 case Primitive::kPrimLong: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003098 codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003099 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003100 break;
3101 }
3102
Calin Juravled2ec87d2014-12-08 14:24:46 +00003103 case Primitive::kPrimFloat: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003104 codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003105 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003106 break;
3107 }
3108
Calin Juravlebacfec32014-11-14 15:54:36 +00003109 case Primitive::kPrimDouble: {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003110 codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003111 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003112 break;
3113 }
3114
3115 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003116 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003117 }
3118}
3119
Calin Juravled0d48522014-11-04 16:40:20 +00003120void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003121 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3122 ? LocationSummary::kCallOnSlowPath
3123 : LocationSummary::kNoCall;
3124 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003125 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003126 if (instruction->HasUses()) {
3127 locations->SetOut(Location::SameAsFirstInput());
3128 }
3129}
3130
3131void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003132 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003133 codegen_->AddSlowPath(slow_path);
3134
3135 LocationSummary* locations = instruction->GetLocations();
3136 Location value = locations->InAt(0);
3137
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003138 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003139 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003140 case Primitive::kPrimByte:
3141 case Primitive::kPrimChar:
3142 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003143 case Primitive::kPrimInt: {
3144 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003145 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003146 } else {
3147 DCHECK(value.IsConstant()) << value;
3148 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3149 __ b(slow_path->GetEntryLabel());
3150 }
3151 }
3152 break;
3153 }
3154 case Primitive::kPrimLong: {
3155 if (value.IsRegisterPair()) {
3156 __ orrs(IP,
3157 value.AsRegisterPairLow<Register>(),
3158 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3159 __ b(slow_path->GetEntryLabel(), EQ);
3160 } else {
3161 DCHECK(value.IsConstant()) << value;
3162 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3163 __ b(slow_path->GetEntryLabel());
3164 }
3165 }
3166 break;
3167 default:
3168 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3169 }
3170 }
Calin Juravled0d48522014-11-04 16:40:20 +00003171}
3172
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003173void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3174 Register in = locations->InAt(0).AsRegister<Register>();
3175 Location rhs = locations->InAt(1);
3176 Register out = locations->Out().AsRegister<Register>();
3177
3178 if (rhs.IsConstant()) {
3179 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3180 // so map all rotations to a +ve. equivalent in that range.
3181 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3182 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3183 if (rot) {
3184 // Rotate, mapping left rotations to right equivalents if necessary.
3185 // (e.g. left by 2 bits == right by 30.)
3186 __ Ror(out, in, rot);
3187 } else if (out != in) {
3188 __ Mov(out, in);
3189 }
3190 } else {
3191 __ Ror(out, in, rhs.AsRegister<Register>());
3192 }
3193}
3194
3195// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3196// rotates by swapping input regs (effectively rotating by the first 32-bits of
3197// a larger rotation) or flipping direction (thus treating larger right/left
3198// rotations as sub-word sized rotations in the other direction) as appropriate.
3199void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3200 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3201 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3202 Location rhs = locations->InAt(1);
3203 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3204 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3205
3206 if (rhs.IsConstant()) {
3207 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3208 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003209 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003210 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3211 // logic below to a simple pair of binary orr.
3212 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3213 if (rot >= kArmBitsPerWord) {
3214 rot -= kArmBitsPerWord;
3215 std::swap(in_reg_hi, in_reg_lo);
3216 }
3217 // Rotate, or mov to out for zero or word size rotations.
3218 if (rot != 0u) {
3219 __ Lsr(out_reg_hi, in_reg_hi, rot);
3220 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3221 __ Lsr(out_reg_lo, in_reg_lo, rot);
3222 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3223 } else {
3224 __ Mov(out_reg_lo, in_reg_lo);
3225 __ Mov(out_reg_hi, in_reg_hi);
3226 }
3227 } else {
3228 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3229 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3230 Label end;
3231 Label shift_by_32_plus_shift_right;
3232
3233 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3234 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3235 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3236 __ b(&shift_by_32_plus_shift_right, CC);
3237
3238 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3239 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3240 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3241 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3242 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3243 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3244 __ Lsr(shift_left, in_reg_hi, shift_right);
3245 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3246 __ b(&end);
3247
3248 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3249 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3250 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3251 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3252 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3253 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3254 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3255 __ Lsl(shift_right, in_reg_hi, shift_left);
3256 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3257
3258 __ Bind(&end);
3259 }
3260}
Roland Levillain22c49222016-03-18 14:04:28 +00003261
3262void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003263 LocationSummary* locations =
3264 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3265 switch (ror->GetResultType()) {
3266 case Primitive::kPrimInt: {
3267 locations->SetInAt(0, Location::RequiresRegister());
3268 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3269 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3270 break;
3271 }
3272 case Primitive::kPrimLong: {
3273 locations->SetInAt(0, Location::RequiresRegister());
3274 if (ror->InputAt(1)->IsConstant()) {
3275 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3276 } else {
3277 locations->SetInAt(1, Location::RequiresRegister());
3278 locations->AddTemp(Location::RequiresRegister());
3279 locations->AddTemp(Location::RequiresRegister());
3280 }
3281 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3282 break;
3283 }
3284 default:
3285 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3286 }
3287}
3288
Roland Levillain22c49222016-03-18 14:04:28 +00003289void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003290 LocationSummary* locations = ror->GetLocations();
3291 Primitive::Type type = ror->GetResultType();
3292 switch (type) {
3293 case Primitive::kPrimInt: {
3294 HandleIntegerRotate(locations);
3295 break;
3296 }
3297 case Primitive::kPrimLong: {
3298 HandleLongRotate(locations);
3299 break;
3300 }
3301 default:
3302 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003303 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003304 }
3305}
3306
Calin Juravle9aec02f2014-11-18 23:06:35 +00003307void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3308 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3309
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003310 LocationSummary* locations =
3311 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003312
3313 switch (op->GetResultType()) {
3314 case Primitive::kPrimInt: {
3315 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003316 if (op->InputAt(1)->IsConstant()) {
3317 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3318 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3319 } else {
3320 locations->SetInAt(1, Location::RequiresRegister());
3321 // Make the output overlap, as it will be used to hold the masked
3322 // second input.
3323 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3324 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003325 break;
3326 }
3327 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003328 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003329 if (op->InputAt(1)->IsConstant()) {
3330 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3331 // For simplicity, use kOutputOverlap even though we only require that low registers
3332 // don't clash with high registers which the register allocator currently guarantees.
3333 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3334 } else {
3335 locations->SetInAt(1, Location::RequiresRegister());
3336 locations->AddTemp(Location::RequiresRegister());
3337 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3338 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003339 break;
3340 }
3341 default:
3342 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3343 }
3344}
3345
3346void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3347 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3348
3349 LocationSummary* locations = op->GetLocations();
3350 Location out = locations->Out();
3351 Location first = locations->InAt(0);
3352 Location second = locations->InAt(1);
3353
3354 Primitive::Type type = op->GetResultType();
3355 switch (type) {
3356 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003357 Register out_reg = out.AsRegister<Register>();
3358 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003359 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003360 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003361 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003362 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003363 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003364 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003365 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003366 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003367 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003368 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003369 }
3370 } else {
3371 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003372 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003373 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003374 __ Mov(out_reg, first_reg);
3375 } else if (op->IsShl()) {
3376 __ Lsl(out_reg, first_reg, shift_value);
3377 } else if (op->IsShr()) {
3378 __ Asr(out_reg, first_reg, shift_value);
3379 } else {
3380 __ Lsr(out_reg, first_reg, shift_value);
3381 }
3382 }
3383 break;
3384 }
3385 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003386 Register o_h = out.AsRegisterPairHigh<Register>();
3387 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003388
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003389 Register high = first.AsRegisterPairHigh<Register>();
3390 Register low = first.AsRegisterPairLow<Register>();
3391
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003392 if (second.IsRegister()) {
3393 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003394
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003395 Register second_reg = second.AsRegister<Register>();
3396
3397 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003398 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003399 // Shift the high part
3400 __ Lsl(o_h, high, o_l);
3401 // Shift the low part and `or` what overflew on the high part
3402 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3403 __ Lsr(temp, low, temp);
3404 __ orr(o_h, o_h, ShifterOperand(temp));
3405 // If the shift is > 32 bits, override the high part
3406 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3407 __ it(PL);
3408 __ Lsl(o_h, low, temp, PL);
3409 // Shift the low part
3410 __ Lsl(o_l, low, o_l);
3411 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003412 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003413 // Shift the low part
3414 __ Lsr(o_l, low, o_h);
3415 // Shift the high part and `or` what underflew on the low part
3416 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3417 __ Lsl(temp, high, temp);
3418 __ orr(o_l, o_l, ShifterOperand(temp));
3419 // If the shift is > 32 bits, override the low part
3420 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3421 __ it(PL);
3422 __ Asr(o_l, high, temp, PL);
3423 // Shift the high part
3424 __ Asr(o_h, high, o_h);
3425 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003426 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003427 // same as Shr except we use `Lsr`s and not `Asr`s
3428 __ Lsr(o_l, low, o_h);
3429 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3430 __ Lsl(temp, high, temp);
3431 __ orr(o_l, o_l, ShifterOperand(temp));
3432 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3433 __ it(PL);
3434 __ Lsr(o_l, high, temp, PL);
3435 __ Lsr(o_h, high, o_h);
3436 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003437 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003438 // Register allocator doesn't create partial overlap.
3439 DCHECK_NE(o_l, high);
3440 DCHECK_NE(o_h, low);
3441 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003442 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003443 if (shift_value > 32) {
3444 if (op->IsShl()) {
3445 __ Lsl(o_h, low, shift_value - 32);
3446 __ LoadImmediate(o_l, 0);
3447 } else if (op->IsShr()) {
3448 __ Asr(o_l, high, shift_value - 32);
3449 __ Asr(o_h, high, 31);
3450 } else {
3451 __ Lsr(o_l, high, shift_value - 32);
3452 __ LoadImmediate(o_h, 0);
3453 }
3454 } else if (shift_value == 32) {
3455 if (op->IsShl()) {
3456 __ mov(o_h, ShifterOperand(low));
3457 __ LoadImmediate(o_l, 0);
3458 } else if (op->IsShr()) {
3459 __ mov(o_l, ShifterOperand(high));
3460 __ Asr(o_h, high, 31);
3461 } else {
3462 __ mov(o_l, ShifterOperand(high));
3463 __ LoadImmediate(o_h, 0);
3464 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003465 } else if (shift_value == 1) {
3466 if (op->IsShl()) {
3467 __ Lsls(o_l, low, 1);
3468 __ adc(o_h, high, ShifterOperand(high));
3469 } else if (op->IsShr()) {
3470 __ Asrs(o_h, high, 1);
3471 __ Rrx(o_l, low);
3472 } else {
3473 __ Lsrs(o_h, high, 1);
3474 __ Rrx(o_l, low);
3475 }
3476 } else {
3477 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003478 if (op->IsShl()) {
3479 __ Lsl(o_h, high, shift_value);
3480 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3481 __ Lsl(o_l, low, shift_value);
3482 } else if (op->IsShr()) {
3483 __ Lsr(o_l, low, shift_value);
3484 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3485 __ Asr(o_h, high, shift_value);
3486 } else {
3487 __ Lsr(o_l, low, shift_value);
3488 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3489 __ Lsr(o_h, high, shift_value);
3490 }
3491 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003492 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003493 break;
3494 }
3495 default:
3496 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003497 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003498 }
3499}
3500
3501void LocationsBuilderARM::VisitShl(HShl* shl) {
3502 HandleShift(shl);
3503}
3504
3505void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3506 HandleShift(shl);
3507}
3508
3509void LocationsBuilderARM::VisitShr(HShr* shr) {
3510 HandleShift(shr);
3511}
3512
3513void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3514 HandleShift(shr);
3515}
3516
3517void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3518 HandleShift(ushr);
3519}
3520
3521void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3522 HandleShift(ushr);
3523}
3524
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003525void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003526 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003527 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003528 if (instruction->IsStringAlloc()) {
3529 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3530 } else {
3531 InvokeRuntimeCallingConvention calling_convention;
3532 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3533 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3534 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003535 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003536}
3537
3538void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003539 // Note: if heap poisoning is enabled, the entry point takes cares
3540 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003541 if (instruction->IsStringAlloc()) {
3542 // String is allocated through StringFactory. Call NewEmptyString entry point.
3543 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003544 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003545 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3546 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3547 __ blx(LR);
3548 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3549 } else {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003550 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
David Brazdil6de19382016-01-08 17:37:10 +00003551 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3552 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003553}
3554
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003555void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3556 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003557 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003558 InvokeRuntimeCallingConvention calling_convention;
3559 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003560 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003561 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003562 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003563}
3564
3565void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3566 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003567 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003568 // Note: if heap poisoning is enabled, the entry point takes cares
3569 // of poisoning the reference.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01003570 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00003571 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003572}
3573
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003574void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003575 LocationSummary* locations =
3576 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003577 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3578 if (location.IsStackSlot()) {
3579 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3580 } else if (location.IsDoubleStackSlot()) {
3581 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003582 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003583 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003584}
3585
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003586void InstructionCodeGeneratorARM::VisitParameterValue(
3587 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003588 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003589}
3590
3591void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3592 LocationSummary* locations =
3593 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3594 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3595}
3596
3597void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3598 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003599}
3600
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003601void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003602 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003603 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003604 locations->SetInAt(0, Location::RequiresRegister());
3605 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003606}
3607
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003608void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3609 LocationSummary* locations = not_->GetLocations();
3610 Location out = locations->Out();
3611 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003612 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003613 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003614 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003615 break;
3616
3617 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003618 __ mvn(out.AsRegisterPairLow<Register>(),
3619 ShifterOperand(in.AsRegisterPairLow<Register>()));
3620 __ mvn(out.AsRegisterPairHigh<Register>(),
3621 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003622 break;
3623
3624 default:
3625 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3626 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003627}
3628
David Brazdil66d126e2015-04-03 16:02:44 +01003629void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3630 LocationSummary* locations =
3631 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3632 locations->SetInAt(0, Location::RequiresRegister());
3633 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3634}
3635
3636void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003637 LocationSummary* locations = bool_not->GetLocations();
3638 Location out = locations->Out();
3639 Location in = locations->InAt(0);
3640 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3641}
3642
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003643void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003644 LocationSummary* locations =
3645 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003646 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003647 case Primitive::kPrimBoolean:
3648 case Primitive::kPrimByte:
3649 case Primitive::kPrimShort:
3650 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003651 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00003652 case Primitive::kPrimLong: {
3653 locations->SetInAt(0, Location::RequiresRegister());
3654 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003655 // Output overlaps because it is written before doing the low comparison.
3656 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003657 break;
3658 }
3659 case Primitive::kPrimFloat:
3660 case Primitive::kPrimDouble: {
3661 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003662 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00003663 locations->SetOut(Location::RequiresRegister());
3664 break;
3665 }
3666 default:
3667 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3668 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003669}
3670
3671void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003672 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003673 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003674 Location left = locations->InAt(0);
3675 Location right = locations->InAt(1);
3676
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003677 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003678 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00003679 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00003680 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003681 case Primitive::kPrimBoolean:
3682 case Primitive::kPrimByte:
3683 case Primitive::kPrimShort:
3684 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003685 case Primitive::kPrimInt: {
3686 __ LoadImmediate(out, 0);
3687 __ cmp(left.AsRegister<Register>(),
3688 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
3689 less_cond = LT;
3690 break;
3691 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003692 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003693 __ cmp(left.AsRegisterPairHigh<Register>(),
3694 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003695 __ b(&less, LT);
3696 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003697 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003698 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003699 __ cmp(left.AsRegisterPairLow<Register>(),
3700 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003701 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00003702 break;
3703 }
3704 case Primitive::kPrimFloat:
3705 case Primitive::kPrimDouble: {
3706 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003707 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00003708 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003709 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003710 break;
3711 }
3712 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003713 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00003714 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003715 }
Aart Bika19616e2016-02-01 18:57:58 -08003716
Calin Juravleddb7df22014-11-25 20:56:51 +00003717 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00003718 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00003719
3720 __ Bind(&greater);
3721 __ LoadImmediate(out, 1);
3722 __ b(&done);
3723
3724 __ Bind(&less);
3725 __ LoadImmediate(out, -1);
3726
3727 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003728}
3729
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003730void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003731 LocationSummary* locations =
3732 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003733 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003734 locations->SetInAt(i, Location::Any());
3735 }
3736 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003737}
3738
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003739void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003740 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003741}
3742
Roland Levillainc9285912015-12-18 10:38:42 +00003743void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3744 // TODO (ported from quick): revisit ARM barrier kinds.
3745 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00003746 switch (kind) {
3747 case MemBarrierKind::kAnyStore:
3748 case MemBarrierKind::kLoadAny:
3749 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003750 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003751 break;
3752 }
3753 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003754 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003755 break;
3756 }
3757 default:
3758 LOG(FATAL) << "Unexpected memory barrier " << kind;
3759 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003760 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003761}
3762
3763void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3764 uint32_t offset,
3765 Register out_lo,
3766 Register out_hi) {
3767 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00003768 // Ensure `out_lo` is different from `addr`, so that loading
3769 // `offset` into `out_lo` does not clutter `addr`.
3770 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00003771 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003772 __ add(IP, addr, ShifterOperand(out_lo));
3773 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003774 }
3775 __ ldrexd(out_lo, out_hi, addr);
3776}
3777
3778void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3779 uint32_t offset,
3780 Register value_lo,
3781 Register value_hi,
3782 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003783 Register temp2,
3784 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003785 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003786 if (offset != 0) {
3787 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003788 __ add(IP, addr, ShifterOperand(temp1));
3789 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003790 }
3791 __ Bind(&fail);
3792 // We need a load followed by store. (The address used in a STREX instruction must
3793 // be the same as the address in the most recently executed LDREX instruction.)
3794 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003795 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003796 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003797 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003798}
3799
3800void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3801 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3802
Nicolas Geoffray39468442014-09-02 15:17:15 +01003803 LocationSummary* locations =
3804 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003805 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003806
Calin Juravle52c48962014-12-16 17:02:57 +00003807 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003808 if (Primitive::IsFloatingPointType(field_type)) {
3809 locations->SetInAt(1, Location::RequiresFpuRegister());
3810 } else {
3811 locations->SetInAt(1, Location::RequiresRegister());
3812 }
3813
Calin Juravle52c48962014-12-16 17:02:57 +00003814 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003815 bool generate_volatile = field_info.IsVolatile()
3816 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003817 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003818 bool needs_write_barrier =
3819 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003820 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003821 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003822 if (needs_write_barrier) {
3823 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003824 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003825 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003826 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003827 // - registers need to be consecutive
3828 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003829 // We don't test for ARM yet, and the assertion makes sure that we
3830 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003831 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3832
3833 locations->AddTemp(Location::RequiresRegister());
3834 locations->AddTemp(Location::RequiresRegister());
3835 if (field_type == Primitive::kPrimDouble) {
3836 // For doubles we need two more registers to copy the value.
3837 locations->AddTemp(Location::RegisterLocation(R2));
3838 locations->AddTemp(Location::RegisterLocation(R3));
3839 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003840 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003841}
3842
Calin Juravle52c48962014-12-16 17:02:57 +00003843void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003844 const FieldInfo& field_info,
3845 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003846 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3847
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003848 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003849 Register base = locations->InAt(0).AsRegister<Register>();
3850 Location value = locations->InAt(1);
3851
3852 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003853 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003854 Primitive::Type field_type = field_info.GetFieldType();
3855 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003856 bool needs_write_barrier =
3857 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003858
3859 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003860 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00003861 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003862
3863 switch (field_type) {
3864 case Primitive::kPrimBoolean:
3865 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003866 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003867 break;
3868 }
3869
3870 case Primitive::kPrimShort:
3871 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003872 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003873 break;
3874 }
3875
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003876 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003877 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003878 if (kPoisonHeapReferences && needs_write_barrier) {
3879 // Note that in the case where `value` is a null reference,
3880 // we do not enter this block, as a null reference does not
3881 // need poisoning.
3882 DCHECK_EQ(field_type, Primitive::kPrimNot);
3883 Register temp = locations->GetTemp(0).AsRegister<Register>();
3884 __ Mov(temp, value.AsRegister<Register>());
3885 __ PoisonHeapReference(temp);
3886 __ StoreToOffset(kStoreWord, temp, base, offset);
3887 } else {
3888 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3889 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003890 break;
3891 }
3892
3893 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003894 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003895 GenerateWideAtomicStore(base, offset,
3896 value.AsRegisterPairLow<Register>(),
3897 value.AsRegisterPairHigh<Register>(),
3898 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003899 locations->GetTemp(1).AsRegister<Register>(),
3900 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003901 } else {
3902 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003903 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003904 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003905 break;
3906 }
3907
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003908 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003909 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003910 break;
3911 }
3912
3913 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003914 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003915 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003916 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3917 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3918
3919 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3920
3921 GenerateWideAtomicStore(base, offset,
3922 value_reg_lo,
3923 value_reg_hi,
3924 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003925 locations->GetTemp(3).AsRegister<Register>(),
3926 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003927 } else {
3928 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003929 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003930 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003931 break;
3932 }
3933
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003934 case Primitive::kPrimVoid:
3935 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003936 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003937 }
Calin Juravle52c48962014-12-16 17:02:57 +00003938
Calin Juravle77520bc2015-01-12 18:45:46 +00003939 // Longs and doubles are handled in the switch.
3940 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3941 codegen_->MaybeRecordImplicitNullCheck(instruction);
3942 }
3943
3944 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3945 Register temp = locations->GetTemp(0).AsRegister<Register>();
3946 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003947 codegen_->MarkGCCard(
3948 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003949 }
3950
Calin Juravle52c48962014-12-16 17:02:57 +00003951 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003952 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00003953 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003954}
3955
Calin Juravle52c48962014-12-16 17:02:57 +00003956void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3957 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00003958
3959 bool object_field_get_with_read_barrier =
3960 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003961 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00003962 new (GetGraph()->GetArena()) LocationSummary(instruction,
3963 object_field_get_with_read_barrier ?
3964 LocationSummary::kCallOnSlowPath :
3965 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003966 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003967
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003968 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003969 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003970 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00003971 // The output overlaps in case of volatile long: we don't want the
3972 // code generated by GenerateWideAtomicLoad to overwrite the
3973 // object's location. Likewise, in the case of an object field get
3974 // with read barriers enabled, we do not want the load to overwrite
3975 // the object's location, as we need it to emit the read barrier.
3976 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
3977 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003978
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003979 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3980 locations->SetOut(Location::RequiresFpuRegister());
3981 } else {
3982 locations->SetOut(Location::RequiresRegister(),
3983 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3984 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003985 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00003986 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003987 // - registers need to be consecutive
3988 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003989 // We don't test for ARM yet, and the assertion makes sure that we
3990 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003991 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3992 locations->AddTemp(Location::RequiresRegister());
3993 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00003994 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
3995 // We need a temporary register for the read barrier marking slow
3996 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
3997 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003998 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003999}
4000
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004001Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
4002 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
4003 << input->GetType();
4004 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
4005 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4006 return Location::ConstantLocation(input->AsConstant());
4007 } else {
4008 return Location::RequiresFpuRegister();
4009 }
4010}
4011
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004012Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4013 Opcode opcode) {
4014 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4015 if (constant->IsConstant() &&
4016 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4017 return Location::ConstantLocation(constant->AsConstant());
4018 }
4019 return Location::RequiresRegister();
4020}
4021
4022bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4023 Opcode opcode) {
4024 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4025 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004026 Opcode high_opcode = opcode;
4027 SetCc low_set_cc = kCcDontCare;
4028 switch (opcode) {
4029 case SUB:
4030 // Flip the operation to an ADD.
4031 value = -value;
4032 opcode = ADD;
4033 FALLTHROUGH_INTENDED;
4034 case ADD:
4035 if (Low32Bits(value) == 0u) {
4036 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4037 }
4038 high_opcode = ADC;
4039 low_set_cc = kCcSet;
4040 break;
4041 default:
4042 break;
4043 }
4044 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4045 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004046 } else {
4047 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4048 }
4049}
4050
Vladimir Marko59751a72016-08-05 14:37:27 +01004051bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4052 Opcode opcode,
4053 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004054 ShifterOperand so;
4055 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004056 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004057 return true;
4058 }
4059 Opcode neg_opcode = kNoOperand;
4060 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004061 case AND: neg_opcode = BIC; value = ~value; break;
4062 case ORR: neg_opcode = ORN; value = ~value; break;
4063 case ADD: neg_opcode = SUB; value = -value; break;
4064 case ADC: neg_opcode = SBC; value = ~value; break;
4065 case SUB: neg_opcode = ADD; value = -value; break;
4066 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004067 default:
4068 return false;
4069 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004070 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004071}
4072
Calin Juravle52c48962014-12-16 17:02:57 +00004073void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4074 const FieldInfo& field_info) {
4075 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004076
Calin Juravle52c48962014-12-16 17:02:57 +00004077 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004078 Location base_loc = locations->InAt(0);
4079 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004080 Location out = locations->Out();
4081 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004082 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004083 Primitive::Type field_type = field_info.GetFieldType();
4084 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4085
4086 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004087 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004088 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004089 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004090
Roland Levillainc9285912015-12-18 10:38:42 +00004091 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004092 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004093 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004094
Roland Levillainc9285912015-12-18 10:38:42 +00004095 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004096 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004097 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004098
Roland Levillainc9285912015-12-18 10:38:42 +00004099 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004100 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004101 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004102
4103 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004104 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004105 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004106
4107 case Primitive::kPrimNot: {
4108 // /* HeapReference<Object> */ out = *(base + offset)
4109 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4110 Location temp_loc = locations->GetTemp(0);
4111 // Note that a potential implicit null check is handled in this
4112 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4113 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4114 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4115 if (is_volatile) {
4116 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4117 }
4118 } else {
4119 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4120 codegen_->MaybeRecordImplicitNullCheck(instruction);
4121 if (is_volatile) {
4122 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4123 }
4124 // If read barriers are enabled, emit read barriers other than
4125 // Baker's using a slow path (and also unpoison the loaded
4126 // reference, if heap poisoning is enabled).
4127 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4128 }
4129 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004130 }
4131
Roland Levillainc9285912015-12-18 10:38:42 +00004132 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004133 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004134 GenerateWideAtomicLoad(base, offset,
4135 out.AsRegisterPairLow<Register>(),
4136 out.AsRegisterPairHigh<Register>());
4137 } else {
4138 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4139 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004140 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004141
Roland Levillainc9285912015-12-18 10:38:42 +00004142 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004143 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004144 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004145
4146 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004147 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004148 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004149 Register lo = locations->GetTemp(0).AsRegister<Register>();
4150 Register hi = locations->GetTemp(1).AsRegister<Register>();
4151 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004152 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004153 __ vmovdrr(out_reg, lo, hi);
4154 } else {
4155 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004156 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004157 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004158 break;
4159 }
4160
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004161 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004162 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004163 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004164 }
Calin Juravle52c48962014-12-16 17:02:57 +00004165
Roland Levillainc9285912015-12-18 10:38:42 +00004166 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4167 // Potential implicit null checks, in the case of reference or
4168 // double fields, are handled in the previous switch statement.
4169 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004170 codegen_->MaybeRecordImplicitNullCheck(instruction);
4171 }
4172
Calin Juravle52c48962014-12-16 17:02:57 +00004173 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004174 if (field_type == Primitive::kPrimNot) {
4175 // Memory barriers, in the case of references, are also handled
4176 // in the previous switch statement.
4177 } else {
4178 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4179 }
Roland Levillain4d027112015-07-01 15:41:14 +01004180 }
Calin Juravle52c48962014-12-16 17:02:57 +00004181}
4182
4183void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4184 HandleFieldSet(instruction, instruction->GetFieldInfo());
4185}
4186
4187void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004188 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004189}
4190
4191void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4192 HandleFieldGet(instruction, instruction->GetFieldInfo());
4193}
4194
4195void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4196 HandleFieldGet(instruction, instruction->GetFieldInfo());
4197}
4198
4199void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4200 HandleFieldGet(instruction, instruction->GetFieldInfo());
4201}
4202
4203void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4204 HandleFieldGet(instruction, instruction->GetFieldInfo());
4205}
4206
4207void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4208 HandleFieldSet(instruction, instruction->GetFieldInfo());
4209}
4210
4211void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004212 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004213}
4214
Calin Juravlee460d1d2015-09-29 04:52:17 +01004215void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4216 HUnresolvedInstanceFieldGet* instruction) {
4217 FieldAccessCallingConventionARM calling_convention;
4218 codegen_->CreateUnresolvedFieldLocationSummary(
4219 instruction, instruction->GetFieldType(), calling_convention);
4220}
4221
4222void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4223 HUnresolvedInstanceFieldGet* instruction) {
4224 FieldAccessCallingConventionARM calling_convention;
4225 codegen_->GenerateUnresolvedFieldAccess(instruction,
4226 instruction->GetFieldType(),
4227 instruction->GetFieldIndex(),
4228 instruction->GetDexPc(),
4229 calling_convention);
4230}
4231
4232void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4233 HUnresolvedInstanceFieldSet* instruction) {
4234 FieldAccessCallingConventionARM calling_convention;
4235 codegen_->CreateUnresolvedFieldLocationSummary(
4236 instruction, instruction->GetFieldType(), calling_convention);
4237}
4238
4239void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4240 HUnresolvedInstanceFieldSet* instruction) {
4241 FieldAccessCallingConventionARM calling_convention;
4242 codegen_->GenerateUnresolvedFieldAccess(instruction,
4243 instruction->GetFieldType(),
4244 instruction->GetFieldIndex(),
4245 instruction->GetDexPc(),
4246 calling_convention);
4247}
4248
4249void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4250 HUnresolvedStaticFieldGet* instruction) {
4251 FieldAccessCallingConventionARM calling_convention;
4252 codegen_->CreateUnresolvedFieldLocationSummary(
4253 instruction, instruction->GetFieldType(), calling_convention);
4254}
4255
4256void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4257 HUnresolvedStaticFieldGet* instruction) {
4258 FieldAccessCallingConventionARM calling_convention;
4259 codegen_->GenerateUnresolvedFieldAccess(instruction,
4260 instruction->GetFieldType(),
4261 instruction->GetFieldIndex(),
4262 instruction->GetDexPc(),
4263 calling_convention);
4264}
4265
4266void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4267 HUnresolvedStaticFieldSet* instruction) {
4268 FieldAccessCallingConventionARM calling_convention;
4269 codegen_->CreateUnresolvedFieldLocationSummary(
4270 instruction, instruction->GetFieldType(), calling_convention);
4271}
4272
4273void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4274 HUnresolvedStaticFieldSet* instruction) {
4275 FieldAccessCallingConventionARM calling_convention;
4276 codegen_->GenerateUnresolvedFieldAccess(instruction,
4277 instruction->GetFieldType(),
4278 instruction->GetFieldIndex(),
4279 instruction->GetDexPc(),
4280 calling_convention);
4281}
4282
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004283void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004284 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4285 ? LocationSummary::kCallOnSlowPath
4286 : LocationSummary::kNoCall;
4287 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00004288 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004289 if (instruction->HasUses()) {
4290 locations->SetOut(Location::SameAsFirstInput());
4291 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004292}
4293
Calin Juravle2ae48182016-03-16 14:05:09 +00004294void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4295 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004296 return;
4297 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004298 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004299
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004300 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004301 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004302}
4303
Calin Juravle2ae48182016-03-16 14:05:09 +00004304void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004305 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004306 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004307
4308 LocationSummary* locations = instruction->GetLocations();
4309 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004310
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004311 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004312}
4313
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004314void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004315 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004316}
4317
Artem Serov6c916792016-07-11 14:02:34 +01004318static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4319 switch (type) {
4320 case Primitive::kPrimNot:
4321 return kLoadWord;
4322 case Primitive::kPrimBoolean:
4323 return kLoadUnsignedByte;
4324 case Primitive::kPrimByte:
4325 return kLoadSignedByte;
4326 case Primitive::kPrimChar:
4327 return kLoadUnsignedHalfword;
4328 case Primitive::kPrimShort:
4329 return kLoadSignedHalfword;
4330 case Primitive::kPrimInt:
4331 return kLoadWord;
4332 case Primitive::kPrimLong:
4333 return kLoadWordPair;
4334 case Primitive::kPrimFloat:
4335 return kLoadSWord;
4336 case Primitive::kPrimDouble:
4337 return kLoadDWord;
4338 default:
4339 LOG(FATAL) << "Unreachable type " << type;
4340 UNREACHABLE();
4341 }
4342}
4343
4344static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4345 switch (type) {
4346 case Primitive::kPrimNot:
4347 return kStoreWord;
4348 case Primitive::kPrimBoolean:
4349 case Primitive::kPrimByte:
4350 return kStoreByte;
4351 case Primitive::kPrimChar:
4352 case Primitive::kPrimShort:
4353 return kStoreHalfword;
4354 case Primitive::kPrimInt:
4355 return kStoreWord;
4356 case Primitive::kPrimLong:
4357 return kStoreWordPair;
4358 case Primitive::kPrimFloat:
4359 return kStoreSWord;
4360 case Primitive::kPrimDouble:
4361 return kStoreDWord;
4362 default:
4363 LOG(FATAL) << "Unreachable type " << type;
4364 UNREACHABLE();
4365 }
4366}
4367
4368void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4369 Location out_loc,
4370 Register base,
4371 Register reg_offset,
4372 Condition cond) {
4373 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4374 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4375
4376 switch (type) {
4377 case Primitive::kPrimByte:
4378 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4379 break;
4380 case Primitive::kPrimBoolean:
4381 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4382 break;
4383 case Primitive::kPrimShort:
4384 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4385 break;
4386 case Primitive::kPrimChar:
4387 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4388 break;
4389 case Primitive::kPrimNot:
4390 case Primitive::kPrimInt:
4391 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4392 break;
4393 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4394 case Primitive::kPrimLong:
4395 case Primitive::kPrimFloat:
4396 case Primitive::kPrimDouble:
4397 default:
4398 LOG(FATAL) << "Unreachable type " << type;
4399 UNREACHABLE();
4400 }
4401}
4402
4403void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4404 Location loc,
4405 Register base,
4406 Register reg_offset,
4407 Condition cond) {
4408 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4409 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4410
4411 switch (type) {
4412 case Primitive::kPrimByte:
4413 case Primitive::kPrimBoolean:
4414 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4415 break;
4416 case Primitive::kPrimShort:
4417 case Primitive::kPrimChar:
4418 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4419 break;
4420 case Primitive::kPrimNot:
4421 case Primitive::kPrimInt:
4422 __ str(loc.AsRegister<Register>(), mem_address, cond);
4423 break;
4424 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4425 case Primitive::kPrimLong:
4426 case Primitive::kPrimFloat:
4427 case Primitive::kPrimDouble:
4428 default:
4429 LOG(FATAL) << "Unreachable type " << type;
4430 UNREACHABLE();
4431 }
4432}
4433
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004434void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004435 bool object_array_get_with_read_barrier =
4436 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004437 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004438 new (GetGraph()->GetArena()) LocationSummary(instruction,
4439 object_array_get_with_read_barrier ?
4440 LocationSummary::kCallOnSlowPath :
4441 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004442 locations->SetInAt(0, Location::RequiresRegister());
4443 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004444 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4445 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4446 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004447 // The output overlaps in the case of an object array get with
4448 // read barriers enabled: we do not want the move to overwrite the
4449 // array's location, as we need it to emit the read barrier.
4450 locations->SetOut(
4451 Location::RequiresRegister(),
4452 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004453 }
Roland Levillainc9285912015-12-18 10:38:42 +00004454 // We need a temporary register for the read barrier marking slow
4455 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
4456 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4457 locations->AddTemp(Location::RequiresRegister());
4458 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004459}
4460
4461void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4462 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004463 Location obj_loc = locations->InAt(0);
4464 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004465 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004466 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004467 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004468 Primitive::Type type = instruction->GetType();
Artem Serov328429f2016-07-06 16:23:04 +01004469 HInstruction* array_instr = instruction->GetArray();
4470 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004471 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4472 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Artem Serov6c916792016-07-11 14:02:34 +01004473
Roland Levillain4d027112015-07-01 15:41:14 +01004474 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004475 case Primitive::kPrimBoolean:
4476 case Primitive::kPrimByte:
4477 case Primitive::kPrimShort:
4478 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004479 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004480 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004481 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4482 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
4483
4484 LoadOperandType load_type = GetLoadOperandType(type);
4485 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004486 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004487 Register temp = IP;
4488
4489 if (has_intermediate_address) {
4490 // We do not need to compute the intermediate address from the array: the
4491 // input instruction has done it already. See the comment in
4492 // `TryExtractArrayAccessAddress()`.
4493 if (kIsDebugBuild) {
4494 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4495 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4496 }
4497 temp = obj;
4498 } else {
4499 __ add(temp, obj, ShifterOperand(data_offset));
4500 }
4501 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004502 }
4503 break;
4504 }
4505
Roland Levillainc9285912015-12-18 10:38:42 +00004506 case Primitive::kPrimNot: {
4507 static_assert(
4508 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4509 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004510 // /* HeapReference<Object> */ out =
4511 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4512 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4513 Location temp = locations->GetTemp(0);
4514 // Note that a potential implicit null check is handled in this
4515 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4516 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4517 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4518 } else {
4519 Register out = out_loc.AsRegister<Register>();
4520 if (index.IsConstant()) {
4521 size_t offset =
4522 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4523 __ LoadFromOffset(kLoadWord, out, obj, offset);
4524 codegen_->MaybeRecordImplicitNullCheck(instruction);
4525 // If read barriers are enabled, emit read barriers other than
4526 // Baker's using a slow path (and also unpoison the loaded
4527 // reference, if heap poisoning is enabled).
4528 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4529 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004530 Register temp = IP;
4531
4532 if (has_intermediate_address) {
4533 // We do not need to compute the intermediate address from the array: the
4534 // input instruction has done it already. See the comment in
4535 // `TryExtractArrayAccessAddress()`.
4536 if (kIsDebugBuild) {
4537 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4538 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4539 }
4540 temp = obj;
4541 } else {
4542 __ add(temp, obj, ShifterOperand(data_offset));
4543 }
4544 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004545
Roland Levillainc9285912015-12-18 10:38:42 +00004546 codegen_->MaybeRecordImplicitNullCheck(instruction);
4547 // If read barriers are enabled, emit read barriers other than
4548 // Baker's using a slow path (and also unpoison the loaded
4549 // reference, if heap poisoning is enabled).
4550 codegen_->MaybeGenerateReadBarrierSlow(
4551 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4552 }
4553 }
4554 break;
4555 }
4556
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004557 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004558 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004559 size_t offset =
4560 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004561 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004562 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004563 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004564 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004565 }
4566 break;
4567 }
4568
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004569 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004570 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004571 if (index.IsConstant()) {
4572 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004573 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004574 } else {
4575 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004576 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004577 }
4578 break;
4579 }
4580
4581 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004582 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004583 if (index.IsConstant()) {
4584 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004585 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004586 } else {
4587 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004588 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004589 }
4590 break;
4591 }
4592
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004593 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01004594 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004595 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004596 }
Roland Levillain4d027112015-07-01 15:41:14 +01004597
4598 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00004599 // Potential implicit null checks, in the case of reference
4600 // arrays, are handled in the previous switch statement.
4601 } else {
4602 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01004603 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004604}
4605
4606void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004607 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004608
4609 bool needs_write_barrier =
4610 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00004611 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004612
Nicolas Geoffray39468442014-09-02 15:17:15 +01004613 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004614 instruction,
Vladimir Marko8d49fd72016-08-25 15:20:47 +01004615 may_need_runtime_call_for_type_check ?
Roland Levillain3b359c72015-11-17 19:35:12 +00004616 LocationSummary::kCallOnSlowPath :
4617 LocationSummary::kNoCall);
4618
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004619 locations->SetInAt(0, Location::RequiresRegister());
4620 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
4621 if (Primitive::IsFloatingPointType(value_type)) {
4622 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004623 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004624 locations->SetInAt(2, Location::RequiresRegister());
4625 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004626 if (needs_write_barrier) {
4627 // Temporary registers for the write barrier.
Roland Levillain16d9f942016-08-25 17:27:56 +01004628 // These registers may be used for Baker read barriers too.
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004629 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00004630 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004631 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004632}
4633
4634void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4635 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004636 Location array_loc = locations->InAt(0);
4637 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004638 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004639 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00004640 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004641 bool needs_write_barrier =
4642 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01004643 uint32_t data_offset =
4644 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
4645 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01004646 HInstruction* array_instr = instruction->GetArray();
4647 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004648 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4649 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004650
4651 switch (value_type) {
4652 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01004653 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004654 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01004655 case Primitive::kPrimChar:
4656 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004657 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004658 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4659 uint32_t full_offset =
4660 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
4661 StoreOperandType store_type = GetStoreOperandType(value_type);
4662 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004663 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004664 Register temp = IP;
4665
4666 if (has_intermediate_address) {
4667 // We do not need to compute the intermediate address from the array: the
4668 // input instruction has done it already. See the comment in
4669 // `TryExtractArrayAccessAddress()`.
4670 if (kIsDebugBuild) {
4671 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4672 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
4673 }
4674 temp = array;
4675 } else {
4676 __ add(temp, array, ShifterOperand(data_offset));
4677 }
Artem Serov6c916792016-07-11 14:02:34 +01004678 codegen_->StoreToShiftedRegOffset(value_type,
4679 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01004680 temp,
Artem Serov6c916792016-07-11 14:02:34 +01004681 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004682 }
4683 break;
4684 }
4685
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004686 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00004687 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01004688 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
4689 // See the comment in instruction_simplifier_shared.cc.
4690 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004691
4692 if (instruction->InputAt(2)->IsNullConstant()) {
4693 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004694 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004695 size_t offset =
4696 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01004697 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004698 } else {
4699 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004700 __ add(IP, array, ShifterOperand(data_offset));
4701 codegen_->StoreToShiftedRegOffset(value_type,
4702 value_loc,
4703 IP,
4704 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004705 }
Roland Levillain1407ee72016-01-08 15:56:19 +00004706 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00004707 DCHECK(!needs_write_barrier);
4708 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004709 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004710 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004711
4712 DCHECK(needs_write_barrier);
Roland Levillain16d9f942016-08-25 17:27:56 +01004713 Location temp1_loc = locations->GetTemp(0);
4714 Register temp1 = temp1_loc.AsRegister<Register>();
4715 Location temp2_loc = locations->GetTemp(1);
4716 Register temp2 = temp2_loc.AsRegister<Register>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004717 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4718 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4719 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4720 Label done;
4721 SlowPathCode* slow_path = nullptr;
4722
Roland Levillain3b359c72015-11-17 19:35:12 +00004723 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004724 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4725 codegen_->AddSlowPath(slow_path);
4726 if (instruction->GetValueCanBeNull()) {
4727 Label non_zero;
4728 __ CompareAndBranchIfNonZero(value, &non_zero);
4729 if (index.IsConstant()) {
4730 size_t offset =
4731 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4732 __ StoreToOffset(kStoreWord, value, array, offset);
4733 } else {
4734 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004735 __ add(IP, array, ShifterOperand(data_offset));
4736 codegen_->StoreToShiftedRegOffset(value_type,
4737 value_loc,
4738 IP,
4739 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004740 }
4741 codegen_->MaybeRecordImplicitNullCheck(instruction);
4742 __ b(&done);
4743 __ Bind(&non_zero);
4744 }
4745
Roland Levillain3b359c72015-11-17 19:35:12 +00004746 if (kEmitCompilerReadBarrier) {
Roland Levillain16d9f942016-08-25 17:27:56 +01004747 if (!kUseBakerReadBarrier) {
4748 // When (non-Baker) read barriers are enabled, the type
4749 // checking instrumentation requires two read barriers
4750 // generated by CodeGeneratorARM::GenerateReadBarrierSlow:
4751 //
4752 // __ Mov(temp2, temp1);
4753 // // /* HeapReference<Class> */ temp1 = temp1->component_type_
4754 // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4755 // codegen_->GenerateReadBarrierSlow(
4756 // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset);
4757 //
4758 // // /* HeapReference<Class> */ temp2 = value->klass_
4759 // __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4760 // codegen_->GenerateReadBarrierSlow(
4761 // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc);
4762 //
4763 // __ cmp(temp1, ShifterOperand(temp2));
4764 //
4765 // However, the second read barrier may trash `temp`, as it
4766 // is a temporary register, and as such would not be saved
4767 // along with live registers before calling the runtime (nor
4768 // restored afterwards). So in this case, we bail out and
4769 // delegate the work to the array set slow path.
4770 //
4771 // TODO: Extend the register allocator to support a new
4772 // "(locally) live temp" location so as to avoid always
4773 // going into the slow path when read barriers are enabled?
4774 //
4775 // There is no such problem with Baker read barriers (see below).
4776 __ b(slow_path->GetEntryLabel());
4777 } else {
4778 Register temp3 = IP;
4779 Location temp3_loc = Location::RegisterLocation(temp3);
4780
4781 // Note: `temp3` (scratch register IP) cannot be used as
4782 // `ref` argument of GenerateFieldLoadWithBakerReadBarrier
4783 // calls below (see ReadBarrierMarkSlowPathARM for more
4784 // details).
4785
4786 // /* HeapReference<Class> */ temp1 = array->klass_
4787 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4788 temp1_loc,
4789 array,
4790 class_offset,
4791 temp3_loc,
4792 /* needs_null_check */ true);
4793
4794 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4795 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4796 temp1_loc,
4797 temp1,
4798 component_offset,
4799 temp3_loc,
4800 /* needs_null_check */ false);
4801 // Register `temp1` is not trashed by the read barrier
4802 // emitted by GenerateFieldLoadWithBakerReadBarrier below,
4803 // as that method produces a call to a ReadBarrierMarkRegX
4804 // entry point, which saves all potentially live registers,
4805 // including temporaries such a `temp1`.
4806 // /* HeapReference<Class> */ temp2 = value->klass_
4807 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4808 temp2_loc,
4809 value,
4810 class_offset,
4811 temp3_loc,
4812 /* needs_null_check */ false);
4813 // If heap poisoning is enabled, `temp1` and `temp2` have
4814 // been unpoisoned by the the previous calls to
4815 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4816 __ cmp(temp1, ShifterOperand(temp2));
4817
4818 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4819 Label do_put;
4820 __ b(&do_put, EQ);
4821 // We do not need to emit a read barrier for the
4822 // following heap reference load, as `temp1` is only used
4823 // in a comparison with null below, and this reference
4824 // is not kept afterwards.
4825 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4826 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4827 // If heap poisoning is enabled, no need to unpoison
4828 // `temp`, as we are comparing against null below.
4829 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4830 __ Bind(&do_put);
4831 } else {
4832 __ b(slow_path->GetEntryLabel(), NE);
4833 }
4834 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004835 } else {
Roland Levillain16d9f942016-08-25 17:27:56 +01004836 // Non read barrier code.
4837
Roland Levillain3b359c72015-11-17 19:35:12 +00004838 // /* HeapReference<Class> */ temp1 = array->klass_
4839 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4840 codegen_->MaybeRecordImplicitNullCheck(instruction);
4841 __ MaybeUnpoisonHeapReference(temp1);
4842
4843 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4844 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4845 // /* HeapReference<Class> */ temp2 = value->klass_
4846 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4847 // If heap poisoning is enabled, no need to unpoison `temp1`
4848 // nor `temp2`, as we are comparing two poisoned references.
4849 __ cmp(temp1, ShifterOperand(temp2));
4850
4851 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4852 Label do_put;
4853 __ b(&do_put, EQ);
4854 // If heap poisoning is enabled, the `temp1` reference has
4855 // not been unpoisoned yet; unpoison it now.
4856 __ MaybeUnpoisonHeapReference(temp1);
4857
4858 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4859 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4860 // If heap poisoning is enabled, no need to unpoison
4861 // `temp1`, as we are comparing against null below.
4862 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4863 __ Bind(&do_put);
4864 } else {
4865 __ b(slow_path->GetEntryLabel(), NE);
4866 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004867 }
4868 }
4869
Artem Serov6c916792016-07-11 14:02:34 +01004870 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004871 if (kPoisonHeapReferences) {
4872 // Note that in the case where `value` is a null reference,
4873 // we do not enter this block, as a null reference does not
4874 // need poisoning.
4875 DCHECK_EQ(value_type, Primitive::kPrimNot);
4876 __ Mov(temp1, value);
4877 __ PoisonHeapReference(temp1);
4878 source = temp1;
4879 }
4880
4881 if (index.IsConstant()) {
4882 size_t offset =
4883 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4884 __ StoreToOffset(kStoreWord, source, array, offset);
4885 } else {
4886 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004887
4888 __ add(IP, array, ShifterOperand(data_offset));
4889 codegen_->StoreToShiftedRegOffset(value_type,
4890 Location::RegisterLocation(source),
4891 IP,
4892 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004893 }
4894
Roland Levillain3b359c72015-11-17 19:35:12 +00004895 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004896 codegen_->MaybeRecordImplicitNullCheck(instruction);
4897 }
4898
4899 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4900
4901 if (done.IsLinked()) {
4902 __ Bind(&done);
4903 }
4904
4905 if (slow_path != nullptr) {
4906 __ Bind(slow_path->GetExitLabel());
4907 }
4908
4909 break;
4910 }
4911
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004912 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004913 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004914 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004915 size_t offset =
4916 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004917 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004918 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004919 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004920 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004921 }
4922 break;
4923 }
4924
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004925 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004926 Location value = locations->InAt(2);
4927 DCHECK(value.IsFpuRegister());
4928 if (index.IsConstant()) {
4929 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004930 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004931 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004932 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004933 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4934 }
4935 break;
4936 }
4937
4938 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004939 Location value = locations->InAt(2);
4940 DCHECK(value.IsFpuRegisterPair());
4941 if (index.IsConstant()) {
4942 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004943 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004944 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004945 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004946 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4947 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004948
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004949 break;
4950 }
4951
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004952 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004953 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004954 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004955 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004956
Roland Levillain80e67092016-01-08 16:04:55 +00004957 // Objects are handled in the switch.
4958 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004959 codegen_->MaybeRecordImplicitNullCheck(instruction);
4960 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004961}
4962
4963void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004964 LocationSummary* locations =
4965 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004966 locations->SetInAt(0, Location::RequiresRegister());
4967 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004968}
4969
4970void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4971 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01004972 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00004973 Register obj = locations->InAt(0).AsRegister<Register>();
4974 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004975 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004976 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004977}
4978
Artem Serov328429f2016-07-06 16:23:04 +01004979void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Roland Levillain4a3aa572016-08-15 13:17:06 +00004980 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4981 DCHECK(!kEmitCompilerReadBarrier);
Artem Serov328429f2016-07-06 16:23:04 +01004982 LocationSummary* locations =
4983 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4984
4985 locations->SetInAt(0, Location::RequiresRegister());
4986 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
4987 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4988}
4989
4990void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
4991 LocationSummary* locations = instruction->GetLocations();
4992 Location out = locations->Out();
4993 Location first = locations->InAt(0);
4994 Location second = locations->InAt(1);
4995
Roland Levillain4a3aa572016-08-15 13:17:06 +00004996 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4997 DCHECK(!kEmitCompilerReadBarrier);
4998
Artem Serov328429f2016-07-06 16:23:04 +01004999 if (second.IsRegister()) {
5000 __ add(out.AsRegister<Register>(),
5001 first.AsRegister<Register>(),
5002 ShifterOperand(second.AsRegister<Register>()));
5003 } else {
5004 __ AddConstant(out.AsRegister<Register>(),
5005 first.AsRegister<Register>(),
5006 second.GetConstant()->AsIntConstant()->GetValue());
5007 }
5008}
5009
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005010void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00005011 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
5012 ? LocationSummary::kCallOnSlowPath
5013 : LocationSummary::kNoCall;
5014 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005015 locations->SetInAt(0, Location::RequiresRegister());
5016 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01005017 if (instruction->HasUses()) {
5018 locations->SetOut(Location::SameAsFirstInput());
5019 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005020}
5021
5022void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
5023 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07005024 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005025 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005026 codegen_->AddSlowPath(slow_path);
5027
Roland Levillain271ab9c2014-11-27 15:23:57 +00005028 Register index = locations->InAt(0).AsRegister<Register>();
5029 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005030
5031 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01005032 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005033}
5034
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005035void CodeGeneratorARM::MarkGCCard(Register temp,
5036 Register card,
5037 Register object,
5038 Register value,
5039 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005040 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005041 if (can_be_null) {
5042 __ CompareAndBranchIfZero(value, &is_null);
5043 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005044 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005045 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5046 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005047 if (can_be_null) {
5048 __ Bind(&is_null);
5049 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005050}
5051
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005052void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005053 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005054}
5055
5056void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005057 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5058}
5059
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005060void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
5061 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5062}
5063
5064void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005065 HBasicBlock* block = instruction->GetBlock();
5066 if (block->GetLoopInformation() != nullptr) {
5067 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5068 // The back edge will generate the suspend check.
5069 return;
5070 }
5071 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5072 // The goto will generate the suspend check.
5073 return;
5074 }
5075 GenerateSuspendCheck(instruction, nullptr);
5076}
5077
5078void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5079 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005080 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005081 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5082 if (slow_path == nullptr) {
5083 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5084 instruction->SetSlowPath(slow_path);
5085 codegen_->AddSlowPath(slow_path);
5086 if (successor != nullptr) {
5087 DCHECK(successor->IsLoopHeader());
5088 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5089 }
5090 } else {
5091 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5092 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005093
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005094 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005095 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005096 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005097 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005098 __ Bind(slow_path->GetReturnLabel());
5099 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005100 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005101 __ b(slow_path->GetEntryLabel());
5102 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005103}
5104
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005105ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5106 return codegen_->GetAssembler();
5107}
5108
5109void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005110 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005111 Location source = move->GetSource();
5112 Location destination = move->GetDestination();
5113
5114 if (source.IsRegister()) {
5115 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005116 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005117 } else if (destination.IsFpuRegister()) {
5118 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005119 } else {
5120 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005121 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005122 SP, destination.GetStackIndex());
5123 }
5124 } else if (source.IsStackSlot()) {
5125 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005126 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005127 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005128 } else if (destination.IsFpuRegister()) {
5129 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005130 } else {
5131 DCHECK(destination.IsStackSlot());
5132 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5133 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5134 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005135 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005136 if (destination.IsRegister()) {
5137 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5138 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005139 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005140 } else {
5141 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005142 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5143 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005144 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005145 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005146 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5147 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005148 } else if (destination.IsRegisterPair()) {
5149 DCHECK(ExpectedPairLayout(destination));
5150 __ LoadFromOffset(
5151 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5152 } else {
5153 DCHECK(destination.IsFpuRegisterPair()) << destination;
5154 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5155 SP,
5156 source.GetStackIndex());
5157 }
5158 } else if (source.IsRegisterPair()) {
5159 if (destination.IsRegisterPair()) {
5160 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5161 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005162 } else if (destination.IsFpuRegisterPair()) {
5163 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5164 source.AsRegisterPairLow<Register>(),
5165 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005166 } else {
5167 DCHECK(destination.IsDoubleStackSlot()) << destination;
5168 DCHECK(ExpectedPairLayout(source));
5169 __ StoreToOffset(
5170 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5171 }
5172 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005173 if (destination.IsRegisterPair()) {
5174 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5175 destination.AsRegisterPairHigh<Register>(),
5176 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5177 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005178 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5179 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5180 } else {
5181 DCHECK(destination.IsDoubleStackSlot()) << destination;
5182 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5183 SP,
5184 destination.GetStackIndex());
5185 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005186 } else {
5187 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005188 HConstant* constant = source.GetConstant();
5189 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5190 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005191 if (destination.IsRegister()) {
5192 __ LoadImmediate(destination.AsRegister<Register>(), value);
5193 } else {
5194 DCHECK(destination.IsStackSlot());
5195 __ LoadImmediate(IP, value);
5196 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5197 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005198 } else if (constant->IsLongConstant()) {
5199 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005200 if (destination.IsRegisterPair()) {
5201 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5202 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005203 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005204 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005205 __ LoadImmediate(IP, Low32Bits(value));
5206 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5207 __ LoadImmediate(IP, High32Bits(value));
5208 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5209 }
5210 } else if (constant->IsDoubleConstant()) {
5211 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005212 if (destination.IsFpuRegisterPair()) {
5213 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005214 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005215 DCHECK(destination.IsDoubleStackSlot()) << destination;
5216 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005217 __ LoadImmediate(IP, Low32Bits(int_value));
5218 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5219 __ LoadImmediate(IP, High32Bits(int_value));
5220 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5221 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005222 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005223 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005224 float value = constant->AsFloatConstant()->GetValue();
5225 if (destination.IsFpuRegister()) {
5226 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5227 } else {
5228 DCHECK(destination.IsStackSlot());
5229 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5230 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5231 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005232 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005233 }
5234}
5235
5236void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5237 __ Mov(IP, reg);
5238 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5239 __ StoreToOffset(kStoreWord, IP, SP, mem);
5240}
5241
5242void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5243 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5244 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5245 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5246 SP, mem1 + stack_offset);
5247 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5248 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5249 SP, mem2 + stack_offset);
5250 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5251}
5252
5253void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005254 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005255 Location source = move->GetSource();
5256 Location destination = move->GetDestination();
5257
5258 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005259 DCHECK_NE(source.AsRegister<Register>(), IP);
5260 DCHECK_NE(destination.AsRegister<Register>(), IP);
5261 __ Mov(IP, source.AsRegister<Register>());
5262 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5263 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005264 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005265 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005266 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005267 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005268 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5269 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005270 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005271 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005272 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005273 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005274 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005275 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005276 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005277 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005278 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5279 destination.AsRegisterPairHigh<Register>(),
5280 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005281 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005282 Register low_reg = source.IsRegisterPair()
5283 ? source.AsRegisterPairLow<Register>()
5284 : destination.AsRegisterPairLow<Register>();
5285 int mem = source.IsRegisterPair()
5286 ? destination.GetStackIndex()
5287 : source.GetStackIndex();
5288 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005289 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005290 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005291 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005292 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005293 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5294 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005295 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005296 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005297 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005298 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5299 DRegister reg = source.IsFpuRegisterPair()
5300 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5301 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5302 int mem = source.IsFpuRegisterPair()
5303 ? destination.GetStackIndex()
5304 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005305 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005306 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005307 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005308 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5309 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5310 : destination.AsFpuRegister<SRegister>();
5311 int mem = source.IsFpuRegister()
5312 ? destination.GetStackIndex()
5313 : source.GetStackIndex();
5314
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005315 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005316 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005317 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005318 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005319 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5320 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005321 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005322 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005323 }
5324}
5325
5326void ParallelMoveResolverARM::SpillScratch(int reg) {
5327 __ Push(static_cast<Register>(reg));
5328}
5329
5330void ParallelMoveResolverARM::RestoreScratch(int reg) {
5331 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005332}
5333
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005334HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5335 HLoadClass::LoadKind desired_class_load_kind) {
5336 if (kEmitCompilerReadBarrier) {
5337 switch (desired_class_load_kind) {
5338 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5339 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5340 case HLoadClass::LoadKind::kBootImageAddress:
5341 // TODO: Implement for read barrier.
5342 return HLoadClass::LoadKind::kDexCacheViaMethod;
5343 default:
5344 break;
5345 }
5346 }
5347 switch (desired_class_load_kind) {
5348 case HLoadClass::LoadKind::kReferrersClass:
5349 break;
5350 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5351 DCHECK(!GetCompilerOptions().GetCompilePic());
5352 break;
5353 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5354 DCHECK(GetCompilerOptions().GetCompilePic());
5355 break;
5356 case HLoadClass::LoadKind::kBootImageAddress:
5357 break;
5358 case HLoadClass::LoadKind::kDexCacheAddress:
5359 DCHECK(Runtime::Current()->UseJitCompilation());
5360 break;
5361 case HLoadClass::LoadKind::kDexCachePcRelative:
5362 DCHECK(!Runtime::Current()->UseJitCompilation());
5363 // We disable pc-relative load when there is an irreducible loop, as the optimization
5364 // is incompatible with it.
5365 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5366 // with irreducible loops.
5367 if (GetGraph()->HasIrreducibleLoops()) {
5368 return HLoadClass::LoadKind::kDexCacheViaMethod;
5369 }
5370 break;
5371 case HLoadClass::LoadKind::kDexCacheViaMethod:
5372 break;
5373 }
5374 return desired_class_load_kind;
5375}
5376
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005377void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005378 if (cls->NeedsAccessCheck()) {
5379 InvokeRuntimeCallingConvention calling_convention;
5380 CodeGenerator::CreateLoadClassLocationSummary(
5381 cls,
5382 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5383 Location::RegisterLocation(R0),
5384 /* code_generator_supports_read_barrier */ true);
5385 return;
5386 }
5387
5388 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5389 ? LocationSummary::kCallOnSlowPath
5390 : LocationSummary::kNoCall;
5391 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
5392 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5393 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5394 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5395 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5396 locations->SetInAt(0, Location::RequiresRegister());
5397 }
5398 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005399}
5400
5401void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005402 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005403 if (cls->NeedsAccessCheck()) {
5404 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01005405 codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005406 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005407 return;
5408 }
5409
Roland Levillain3b359c72015-11-17 19:35:12 +00005410 Location out_loc = locations->Out();
5411 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005412
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005413 bool generate_null_check = false;
5414 switch (cls->GetLoadKind()) {
5415 case HLoadClass::LoadKind::kReferrersClass: {
5416 DCHECK(!cls->CanCallRuntime());
5417 DCHECK(!cls->MustGenerateClinitCheck());
5418 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5419 Register current_method = locations->InAt(0).AsRegister<Register>();
5420 GenerateGcRootFieldLoad(
5421 cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5422 break;
5423 }
5424 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
5425 DCHECK(!kEmitCompilerReadBarrier);
5426 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5427 cls->GetTypeIndex()));
5428 break;
5429 }
5430 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
5431 DCHECK(!kEmitCompilerReadBarrier);
5432 CodeGeneratorARM::PcRelativePatchInfo* labels =
5433 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5434 __ BindTrackedLabel(&labels->movw_label);
5435 __ movw(out, /* placeholder */ 0u);
5436 __ BindTrackedLabel(&labels->movt_label);
5437 __ movt(out, /* placeholder */ 0u);
5438 __ BindTrackedLabel(&labels->add_pc_label);
5439 __ add(out, out, ShifterOperand(PC));
5440 break;
5441 }
5442 case HLoadClass::LoadKind::kBootImageAddress: {
5443 DCHECK(!kEmitCompilerReadBarrier);
5444 DCHECK_NE(cls->GetAddress(), 0u);
5445 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5446 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5447 break;
5448 }
5449 case HLoadClass::LoadKind::kDexCacheAddress: {
5450 DCHECK_NE(cls->GetAddress(), 0u);
5451 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5452 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5453 // a 128B range. To try and reduce the number of literals if we load multiple types,
5454 // simply split the dex cache address to a 128B aligned base loaded from a literal
5455 // and the remaining offset embedded in the load.
5456 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5457 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5458 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5459 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5460 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5461 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5462 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
5463 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5464 generate_null_check = !cls->IsInDexCache();
5465 break;
5466 }
5467 case HLoadClass::LoadKind::kDexCachePcRelative: {
5468 Register base_reg = locations->InAt(0).AsRegister<Register>();
5469 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5470 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5471 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
5472 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset);
5473 generate_null_check = !cls->IsInDexCache();
5474 break;
5475 }
5476 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5477 // /* GcRoot<mirror::Class>[] */ out =
5478 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5479 Register current_method = locations->InAt(0).AsRegister<Register>();
5480 __ LoadFromOffset(kLoadWord,
5481 out,
5482 current_method,
5483 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5484 // /* GcRoot<mirror::Class> */ out = out[type_index]
5485 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
5486 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5487 generate_null_check = !cls->IsInDexCache();
5488 }
5489 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005490
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005491 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5492 DCHECK(cls->CanCallRuntime());
5493 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
5494 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5495 codegen_->AddSlowPath(slow_path);
5496 if (generate_null_check) {
5497 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5498 }
5499 if (cls->MustGenerateClinitCheck()) {
5500 GenerateClassInitializationCheck(slow_path, out);
5501 } else {
5502 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005503 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005504 }
5505}
5506
5507void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5508 LocationSummary* locations =
5509 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5510 locations->SetInAt(0, Location::RequiresRegister());
5511 if (check->HasUses()) {
5512 locations->SetOut(Location::SameAsFirstInput());
5513 }
5514}
5515
5516void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005517 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07005518 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005519 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005520 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005521 GenerateClassInitializationCheck(slow_path,
5522 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005523}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005524
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005525void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07005526 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005527 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5528 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5529 __ b(slow_path->GetEntryLabel(), LT);
5530 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5531 // properly. Therefore, we do a memory fence.
5532 __ dmb(ISH);
5533 __ Bind(slow_path->GetExitLabel());
5534}
5535
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005536HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5537 HLoadString::LoadKind desired_string_load_kind) {
5538 if (kEmitCompilerReadBarrier) {
5539 switch (desired_string_load_kind) {
5540 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5541 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5542 case HLoadString::LoadKind::kBootImageAddress:
5543 // TODO: Implement for read barrier.
5544 return HLoadString::LoadKind::kDexCacheViaMethod;
5545 default:
5546 break;
5547 }
5548 }
5549 switch (desired_string_load_kind) {
5550 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5551 DCHECK(!GetCompilerOptions().GetCompilePic());
5552 break;
5553 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5554 DCHECK(GetCompilerOptions().GetCompilePic());
5555 break;
5556 case HLoadString::LoadKind::kBootImageAddress:
5557 break;
5558 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005559 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005560 break;
5561 case HLoadString::LoadKind::kDexCachePcRelative:
Calin Juravleffc87072016-04-20 14:22:09 +01005562 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005563 // We disable pc-relative load when there is an irreducible loop, as the optimization
5564 // is incompatible with it.
5565 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5566 // with irreducible loops.
5567 if (GetGraph()->HasIrreducibleLoops()) {
5568 return HLoadString::LoadKind::kDexCacheViaMethod;
5569 }
5570 break;
5571 case HLoadString::LoadKind::kDexCacheViaMethod:
5572 break;
5573 }
5574 return desired_string_load_kind;
5575}
5576
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005577void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005578 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005579 ? LocationSummary::kCallOnSlowPath
5580 : LocationSummary::kNoCall;
5581 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005582 HLoadString::LoadKind load_kind = load->GetLoadKind();
5583 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod ||
5584 load_kind == HLoadString::LoadKind::kDexCachePcRelative) {
5585 locations->SetInAt(0, Location::RequiresRegister());
5586 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005587 locations->SetOut(Location::RequiresRegister());
5588}
5589
5590void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005591 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005592 Location out_loc = locations->Out();
5593 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005594
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005595 switch (load->GetLoadKind()) {
5596 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
5597 DCHECK(!kEmitCompilerReadBarrier);
5598 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5599 load->GetStringIndex()));
5600 return; // No dex cache slow path.
5601 }
5602 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
5603 DCHECK(!kEmitCompilerReadBarrier);
5604 CodeGeneratorARM::PcRelativePatchInfo* labels =
5605 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5606 __ BindTrackedLabel(&labels->movw_label);
5607 __ movw(out, /* placeholder */ 0u);
5608 __ BindTrackedLabel(&labels->movt_label);
5609 __ movt(out, /* placeholder */ 0u);
5610 __ BindTrackedLabel(&labels->add_pc_label);
5611 __ add(out, out, ShifterOperand(PC));
5612 return; // No dex cache slow path.
5613 }
5614 case HLoadString::LoadKind::kBootImageAddress: {
5615 DCHECK(!kEmitCompilerReadBarrier);
5616 DCHECK_NE(load->GetAddress(), 0u);
5617 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5618 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5619 return; // No dex cache slow path.
5620 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005621 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005622 break;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005623 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005624
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005625 // TODO: Re-add the compiler code to do string dex cache lookup again.
5626 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5627 codegen_->AddSlowPath(slow_path);
5628 __ b(slow_path->GetEntryLabel());
5629 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005630}
5631
David Brazdilcb1c0552015-08-04 16:22:25 +01005632static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005633 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005634}
5635
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005636void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5637 LocationSummary* locations =
5638 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5639 locations->SetOut(Location::RequiresRegister());
5640}
5641
5642void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005643 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005644 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5645}
5646
5647void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5648 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5649}
5650
5651void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005652 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005653 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005654}
5655
5656void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5657 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005658 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005659 InvokeRuntimeCallingConvention calling_convention;
5660 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5661}
5662
5663void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01005664 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005665 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005666}
5667
Roland Levillainc9285912015-12-18 10:38:42 +00005668static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
5669 return kEmitCompilerReadBarrier &&
5670 (kUseBakerReadBarrier ||
5671 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5672 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5673 type_check_kind == TypeCheckKind::kArrayObjectCheck);
5674}
5675
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005676void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005677 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00005678 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5679 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005680 case TypeCheckKind::kExactCheck:
5681 case TypeCheckKind::kAbstractClassCheck:
5682 case TypeCheckKind::kClassHierarchyCheck:
5683 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005684 call_kind =
5685 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005686 break;
5687 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005688 case TypeCheckKind::kUnresolvedCheck:
5689 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005690 call_kind = LocationSummary::kCallOnSlowPath;
5691 break;
5692 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005693
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005694 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Roland Levillain3b359c72015-11-17 19:35:12 +00005695 locations->SetInAt(0, Location::RequiresRegister());
5696 locations->SetInAt(1, Location::RequiresRegister());
5697 // The "out" register is used as a temporary, so it overlaps with the inputs.
5698 // Note that TypeCheckSlowPathARM uses this register too.
5699 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5700 // When read barriers are enabled, we need a temporary register for
5701 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005702 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00005703 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005704 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005705}
5706
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005707void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005708 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005709 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005710 Location obj_loc = locations->InAt(0);
5711 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005712 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005713 Location out_loc = locations->Out();
5714 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005715 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005716 locations->GetTemp(0) :
5717 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005718 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005719 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5720 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5721 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005722 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07005723 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005724
5725 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005726 // avoid null check if we know obj is not null.
5727 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00005728 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005729 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005730
Roland Levillain3b359c72015-11-17 19:35:12 +00005731 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005732 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005733
Roland Levillainc9285912015-12-18 10:38:42 +00005734 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005735 case TypeCheckKind::kExactCheck: {
5736 __ cmp(out, ShifterOperand(cls));
5737 // Classes must be equal for the instanceof to succeed.
5738 __ b(&zero, NE);
5739 __ LoadImmediate(out, 1);
5740 __ b(&done);
5741 break;
5742 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005743
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005744 case TypeCheckKind::kAbstractClassCheck: {
5745 // If the class is abstract, we eagerly fetch the super class of the
5746 // object to avoid doing a comparison we know will fail.
5747 Label loop;
5748 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005749 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005750 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005751 // If `out` is null, we use it for the result, and jump to `done`.
5752 __ CompareAndBranchIfZero(out, &done);
5753 __ cmp(out, ShifterOperand(cls));
5754 __ b(&loop, NE);
5755 __ LoadImmediate(out, 1);
5756 if (zero.IsLinked()) {
5757 __ b(&done);
5758 }
5759 break;
5760 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005761
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005762 case TypeCheckKind::kClassHierarchyCheck: {
5763 // Walk over the class hierarchy to find a match.
5764 Label loop, success;
5765 __ Bind(&loop);
5766 __ cmp(out, ShifterOperand(cls));
5767 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005768 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005769 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005770 __ CompareAndBranchIfNonZero(out, &loop);
5771 // If `out` is null, we use it for the result, and jump to `done`.
5772 __ b(&done);
5773 __ Bind(&success);
5774 __ LoadImmediate(out, 1);
5775 if (zero.IsLinked()) {
5776 __ b(&done);
5777 }
5778 break;
5779 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005780
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005781 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005782 // Do an exact check.
5783 Label exact_check;
5784 __ cmp(out, ShifterOperand(cls));
5785 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005786 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005787 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005788 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005789 // If `out` is null, we use it for the result, and jump to `done`.
5790 __ CompareAndBranchIfZero(out, &done);
5791 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5792 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5793 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005794 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005795 __ LoadImmediate(out, 1);
5796 __ b(&done);
5797 break;
5798 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005799
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005800 case TypeCheckKind::kArrayCheck: {
5801 __ cmp(out, ShifterOperand(cls));
5802 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00005803 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5804 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005805 codegen_->AddSlowPath(slow_path);
5806 __ b(slow_path->GetEntryLabel(), NE);
5807 __ LoadImmediate(out, 1);
5808 if (zero.IsLinked()) {
5809 __ b(&done);
5810 }
5811 break;
5812 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005813
Calin Juravle98893e12015-10-02 21:05:03 +01005814 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005815 case TypeCheckKind::kInterfaceCheck: {
5816 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00005817 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00005818 // cases.
5819 //
5820 // We cannot directly call the InstanceofNonTrivial runtime
5821 // entry point without resorting to a type checking slow path
5822 // here (i.e. by calling InvokeRuntime directly), as it would
5823 // require to assign fixed registers for the inputs of this
5824 // HInstanceOf instruction (following the runtime calling
5825 // convention), which might be cluttered by the potential first
5826 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00005827 //
5828 // TODO: Introduce a new runtime entry point taking the object
5829 // to test (instead of its class) as argument, and let it deal
5830 // with the read barrier issues. This will let us refactor this
5831 // case of the `switch` code as it was previously (with a direct
5832 // call to the runtime not using a type checking slow path).
5833 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00005834 DCHECK(locations->OnlyCallsOnSlowPath());
5835 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5836 /* is_fatal */ false);
5837 codegen_->AddSlowPath(slow_path);
5838 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005839 if (zero.IsLinked()) {
5840 __ b(&done);
5841 }
5842 break;
5843 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005844 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005845
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005846 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005847 __ Bind(&zero);
5848 __ LoadImmediate(out, 0);
5849 }
5850
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005851 if (done.IsLinked()) {
5852 __ Bind(&done);
5853 }
5854
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005855 if (slow_path != nullptr) {
5856 __ Bind(slow_path->GetExitLabel());
5857 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005858}
5859
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005860void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005861 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5862 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
5863
Roland Levillain3b359c72015-11-17 19:35:12 +00005864 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5865 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005866 case TypeCheckKind::kExactCheck:
5867 case TypeCheckKind::kAbstractClassCheck:
5868 case TypeCheckKind::kClassHierarchyCheck:
5869 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005870 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
5871 LocationSummary::kCallOnSlowPath :
5872 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005873 break;
5874 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005875 case TypeCheckKind::kUnresolvedCheck:
5876 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005877 call_kind = LocationSummary::kCallOnSlowPath;
5878 break;
5879 }
5880
Roland Levillain3b359c72015-11-17 19:35:12 +00005881 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
5882 locations->SetInAt(0, Location::RequiresRegister());
5883 locations->SetInAt(1, Location::RequiresRegister());
5884 // Note that TypeCheckSlowPathARM uses this "temp" register too.
5885 locations->AddTemp(Location::RequiresRegister());
5886 // When read barriers are enabled, we need an additional temporary
5887 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005888 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005889 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005890 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005891}
5892
5893void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005894 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005895 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005896 Location obj_loc = locations->InAt(0);
5897 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005898 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005899 Location temp_loc = locations->GetTemp(0);
5900 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005901 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005902 locations->GetTemp(1) :
5903 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005904 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005905 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5906 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5907 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005908
Roland Levillain3b359c72015-11-17 19:35:12 +00005909 bool is_type_check_slow_path_fatal =
5910 (type_check_kind == TypeCheckKind::kExactCheck ||
5911 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5912 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5913 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
5914 !instruction->CanThrowIntoCatchBlock();
5915 SlowPathCode* type_check_slow_path =
5916 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5917 is_type_check_slow_path_fatal);
5918 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005919
5920 Label done;
5921 // Avoid null check if we know obj is not null.
5922 if (instruction->MustDoNullCheck()) {
5923 __ CompareAndBranchIfZero(obj, &done);
5924 }
5925
Roland Levillain3b359c72015-11-17 19:35:12 +00005926 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005927 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005928
Roland Levillain3b359c72015-11-17 19:35:12 +00005929 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005930 case TypeCheckKind::kExactCheck:
5931 case TypeCheckKind::kArrayCheck: {
5932 __ cmp(temp, ShifterOperand(cls));
5933 // Jump to slow path for throwing the exception or doing a
5934 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005935 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005936 break;
5937 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005938
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005939 case TypeCheckKind::kAbstractClassCheck: {
5940 // If the class is abstract, we eagerly fetch the super class of the
5941 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00005942 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005943 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005944 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005945 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005946
5947 // If the class reference currently in `temp` is not null, jump
5948 // to the `compare_classes` label to compare it with the checked
5949 // class.
5950 __ CompareAndBranchIfNonZero(temp, &compare_classes);
5951 // Otherwise, jump to the slow path to throw the exception.
5952 //
5953 // But before, move back the object's class into `temp` before
5954 // going into the slow path, as it has been overwritten in the
5955 // meantime.
5956 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005957 GenerateReferenceLoadTwoRegisters(
5958 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005959 __ b(type_check_slow_path->GetEntryLabel());
5960
5961 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005962 __ cmp(temp, ShifterOperand(cls));
5963 __ b(&loop, NE);
5964 break;
5965 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005966
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005967 case TypeCheckKind::kClassHierarchyCheck: {
5968 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005969 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005970 __ Bind(&loop);
5971 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005972 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005973
Roland Levillain3b359c72015-11-17 19:35:12 +00005974 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005975 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005976
5977 // If the class reference currently in `temp` is not null, jump
5978 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005979 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005980 // Otherwise, jump to the slow path to throw the exception.
5981 //
5982 // But before, move back the object's class into `temp` before
5983 // going into the slow path, as it has been overwritten in the
5984 // meantime.
5985 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005986 GenerateReferenceLoadTwoRegisters(
5987 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005988 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005989 break;
5990 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005991
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005992 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005993 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005994 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005995 __ cmp(temp, ShifterOperand(cls));
5996 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005997
5998 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005999 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006000 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006001
6002 // If the component type is not null (i.e. the object is indeed
6003 // an array), jump to label `check_non_primitive_component_type`
6004 // to further check that this component type is not a primitive
6005 // type.
6006 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6007 // Otherwise, jump to the slow path to throw the exception.
6008 //
6009 // But before, move back the object's class into `temp` before
6010 // going into the slow path, as it has been overwritten in the
6011 // meantime.
6012 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006013 GenerateReferenceLoadTwoRegisters(
6014 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006015 __ b(type_check_slow_path->GetEntryLabel());
6016
6017 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006018 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006019 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6020 __ CompareAndBranchIfZero(temp, &done);
6021 // Same comment as above regarding `temp` and the slow path.
6022 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006023 GenerateReferenceLoadTwoRegisters(
6024 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006025 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006026 break;
6027 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006028
Calin Juravle98893e12015-10-02 21:05:03 +01006029 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006030 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006031 // We always go into the type check slow path for the unresolved
6032 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006033 //
6034 // We cannot directly call the CheckCast runtime entry point
6035 // without resorting to a type checking slow path here (i.e. by
6036 // calling InvokeRuntime directly), as it would require to
6037 // assign fixed registers for the inputs of this HInstanceOf
6038 // instruction (following the runtime calling convention), which
6039 // might be cluttered by the potential first read barrier
6040 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006041 //
6042 // TODO: Introduce a new runtime entry point taking the object
6043 // to test (instead of its class) as argument, and let it deal
6044 // with the read barrier issues. This will let us refactor this
6045 // case of the `switch` code as it was previously (with a direct
6046 // call to the runtime not using a type checking slow path).
6047 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006048 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006049 break;
6050 }
6051 __ Bind(&done);
6052
Roland Levillain3b359c72015-11-17 19:35:12 +00006053 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006054}
6055
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006056void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6057 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006058 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006059 InvokeRuntimeCallingConvention calling_convention;
6060 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6061}
6062
6063void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01006064 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject,
6065 instruction,
6066 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00006067 if (instruction->IsEnter()) {
6068 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6069 } else {
6070 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6071 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006072}
6073
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006074void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6075void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6076void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006077
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006078void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006079 LocationSummary* locations =
6080 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6081 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6082 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006083 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006084 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006085 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006086 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006087}
6088
6089void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6090 HandleBitwiseOperation(instruction);
6091}
6092
6093void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6094 HandleBitwiseOperation(instruction);
6095}
6096
6097void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6098 HandleBitwiseOperation(instruction);
6099}
6100
Artem Serov7fc63502016-02-09 17:15:29 +00006101
6102void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6103 LocationSummary* locations =
6104 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6105 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6106 || instruction->GetResultType() == Primitive::kPrimLong);
6107
6108 locations->SetInAt(0, Location::RequiresRegister());
6109 locations->SetInAt(1, Location::RequiresRegister());
6110 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6111}
6112
6113void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6114 LocationSummary* locations = instruction->GetLocations();
6115 Location first = locations->InAt(0);
6116 Location second = locations->InAt(1);
6117 Location out = locations->Out();
6118
6119 if (instruction->GetResultType() == Primitive::kPrimInt) {
6120 Register first_reg = first.AsRegister<Register>();
6121 ShifterOperand second_reg(second.AsRegister<Register>());
6122 Register out_reg = out.AsRegister<Register>();
6123
6124 switch (instruction->GetOpKind()) {
6125 case HInstruction::kAnd:
6126 __ bic(out_reg, first_reg, second_reg);
6127 break;
6128 case HInstruction::kOr:
6129 __ orn(out_reg, first_reg, second_reg);
6130 break;
6131 // There is no EON on arm.
6132 case HInstruction::kXor:
6133 default:
6134 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6135 UNREACHABLE();
6136 }
6137 return;
6138
6139 } else {
6140 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6141 Register first_low = first.AsRegisterPairLow<Register>();
6142 Register first_high = first.AsRegisterPairHigh<Register>();
6143 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6144 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6145 Register out_low = out.AsRegisterPairLow<Register>();
6146 Register out_high = out.AsRegisterPairHigh<Register>();
6147
6148 switch (instruction->GetOpKind()) {
6149 case HInstruction::kAnd:
6150 __ bic(out_low, first_low, second_low);
6151 __ bic(out_high, first_high, second_high);
6152 break;
6153 case HInstruction::kOr:
6154 __ orn(out_low, first_low, second_low);
6155 __ orn(out_high, first_high, second_high);
6156 break;
6157 // There is no EON on arm.
6158 case HInstruction::kXor:
6159 default:
6160 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6161 UNREACHABLE();
6162 }
6163 }
6164}
6165
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006166void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6167 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6168 if (value == 0xffffffffu) {
6169 if (out != first) {
6170 __ mov(out, ShifterOperand(first));
6171 }
6172 return;
6173 }
6174 if (value == 0u) {
6175 __ mov(out, ShifterOperand(0));
6176 return;
6177 }
6178 ShifterOperand so;
6179 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6180 __ and_(out, first, so);
6181 } else {
6182 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6183 __ bic(out, first, ShifterOperand(~value));
6184 }
6185}
6186
6187void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6188 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6189 if (value == 0u) {
6190 if (out != first) {
6191 __ mov(out, ShifterOperand(first));
6192 }
6193 return;
6194 }
6195 if (value == 0xffffffffu) {
6196 __ mvn(out, ShifterOperand(0));
6197 return;
6198 }
6199 ShifterOperand so;
6200 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6201 __ orr(out, first, so);
6202 } else {
6203 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6204 __ orn(out, first, ShifterOperand(~value));
6205 }
6206}
6207
6208void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6209 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6210 if (value == 0u) {
6211 if (out != first) {
6212 __ mov(out, ShifterOperand(first));
6213 }
6214 return;
6215 }
6216 __ eor(out, first, ShifterOperand(value));
6217}
6218
Vladimir Marko59751a72016-08-05 14:37:27 +01006219void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6220 Location first,
6221 uint64_t value) {
6222 Register out_low = out.AsRegisterPairLow<Register>();
6223 Register out_high = out.AsRegisterPairHigh<Register>();
6224 Register first_low = first.AsRegisterPairLow<Register>();
6225 Register first_high = first.AsRegisterPairHigh<Register>();
6226 uint32_t value_low = Low32Bits(value);
6227 uint32_t value_high = High32Bits(value);
6228 if (value_low == 0u) {
6229 if (out_low != first_low) {
6230 __ mov(out_low, ShifterOperand(first_low));
6231 }
6232 __ AddConstant(out_high, first_high, value_high);
6233 return;
6234 }
6235 __ AddConstantSetFlags(out_low, first_low, value_low);
6236 ShifterOperand so;
6237 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6238 __ adc(out_high, first_high, so);
6239 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6240 __ sbc(out_high, first_high, so);
6241 } else {
6242 LOG(FATAL) << "Unexpected constant " << value_high;
6243 UNREACHABLE();
6244 }
6245}
6246
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006247void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6248 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006249 Location first = locations->InAt(0);
6250 Location second = locations->InAt(1);
6251 Location out = locations->Out();
6252
6253 if (second.IsConstant()) {
6254 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6255 uint32_t value_low = Low32Bits(value);
6256 if (instruction->GetResultType() == Primitive::kPrimInt) {
6257 Register first_reg = first.AsRegister<Register>();
6258 Register out_reg = out.AsRegister<Register>();
6259 if (instruction->IsAnd()) {
6260 GenerateAndConst(out_reg, first_reg, value_low);
6261 } else if (instruction->IsOr()) {
6262 GenerateOrrConst(out_reg, first_reg, value_low);
6263 } else {
6264 DCHECK(instruction->IsXor());
6265 GenerateEorConst(out_reg, first_reg, value_low);
6266 }
6267 } else {
6268 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6269 uint32_t value_high = High32Bits(value);
6270 Register first_low = first.AsRegisterPairLow<Register>();
6271 Register first_high = first.AsRegisterPairHigh<Register>();
6272 Register out_low = out.AsRegisterPairLow<Register>();
6273 Register out_high = out.AsRegisterPairHigh<Register>();
6274 if (instruction->IsAnd()) {
6275 GenerateAndConst(out_low, first_low, value_low);
6276 GenerateAndConst(out_high, first_high, value_high);
6277 } else if (instruction->IsOr()) {
6278 GenerateOrrConst(out_low, first_low, value_low);
6279 GenerateOrrConst(out_high, first_high, value_high);
6280 } else {
6281 DCHECK(instruction->IsXor());
6282 GenerateEorConst(out_low, first_low, value_low);
6283 GenerateEorConst(out_high, first_high, value_high);
6284 }
6285 }
6286 return;
6287 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006288
6289 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006290 Register first_reg = first.AsRegister<Register>();
6291 ShifterOperand second_reg(second.AsRegister<Register>());
6292 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006293 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006294 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006295 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006296 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006297 } else {
6298 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006299 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006300 }
6301 } else {
6302 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006303 Register first_low = first.AsRegisterPairLow<Register>();
6304 Register first_high = first.AsRegisterPairHigh<Register>();
6305 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6306 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6307 Register out_low = out.AsRegisterPairLow<Register>();
6308 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006309 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006310 __ and_(out_low, first_low, second_low);
6311 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006312 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006313 __ orr(out_low, first_low, second_low);
6314 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006315 } else {
6316 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006317 __ eor(out_low, first_low, second_low);
6318 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006319 }
6320 }
6321}
6322
Roland Levillainc9285912015-12-18 10:38:42 +00006323void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6324 Location out,
6325 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006326 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006327 Register out_reg = out.AsRegister<Register>();
6328 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006329 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006330 if (kUseBakerReadBarrier) {
6331 // Load with fast path based Baker's read barrier.
6332 // /* HeapReference<Object> */ out = *(out + offset)
6333 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006334 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006335 } else {
6336 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006337 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006338 // in the following move operation, as we will need it for the
6339 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006340 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006341 // /* HeapReference<Object> */ out = *(out + offset)
6342 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006343 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006344 }
6345 } else {
6346 // Plain load with no read barrier.
6347 // /* HeapReference<Object> */ out = *(out + offset)
6348 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6349 __ MaybeUnpoisonHeapReference(out_reg);
6350 }
6351}
6352
6353void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6354 Location out,
6355 Location obj,
6356 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006357 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006358 Register out_reg = out.AsRegister<Register>();
6359 Register obj_reg = obj.AsRegister<Register>();
6360 if (kEmitCompilerReadBarrier) {
6361 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006362 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006363 // Load with fast path based Baker's read barrier.
6364 // /* HeapReference<Object> */ out = *(obj + offset)
6365 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006366 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006367 } else {
6368 // Load with slow path based read barrier.
6369 // /* HeapReference<Object> */ out = *(obj + offset)
6370 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6371 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6372 }
6373 } else {
6374 // Plain load with no read barrier.
6375 // /* HeapReference<Object> */ out = *(obj + offset)
6376 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6377 __ MaybeUnpoisonHeapReference(out_reg);
6378 }
6379}
6380
6381void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6382 Location root,
6383 Register obj,
6384 uint32_t offset) {
6385 Register root_reg = root.AsRegister<Register>();
6386 if (kEmitCompilerReadBarrier) {
6387 if (kUseBakerReadBarrier) {
6388 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6389 // Baker's read barrier are used:
6390 //
6391 // root = obj.field;
6392 // if (Thread::Current()->GetIsGcMarking()) {
6393 // root = ReadBarrier::Mark(root)
6394 // }
6395
6396 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6397 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6398 static_assert(
6399 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6400 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6401 "have different sizes.");
6402 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6403 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6404 "have different sizes.");
6405
Vladimir Marko953437b2016-08-24 08:30:46 +00006406 // Slow path marking the GC root `root`.
Roland Levillainc9285912015-12-18 10:38:42 +00006407 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006408 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006409 codegen_->AddSlowPath(slow_path);
6410
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006411 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006412 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006413 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006414 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6415 __ Bind(slow_path->GetExitLabel());
6416 } else {
6417 // GC root loaded through a slow path for read barriers other
6418 // than Baker's.
6419 // /* GcRoot<mirror::Object>* */ root = obj + offset
6420 __ AddConstant(root_reg, obj, offset);
6421 // /* mirror::Object* */ root = root->Read()
6422 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6423 }
6424 } else {
6425 // Plain GC root load with no read barrier.
6426 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6427 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6428 // Note that GC roots are not affected by heap poisoning, thus we
6429 // do not have to unpoison `root_reg` here.
6430 }
6431}
6432
6433void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6434 Location ref,
6435 Register obj,
6436 uint32_t offset,
6437 Location temp,
6438 bool needs_null_check) {
6439 DCHECK(kEmitCompilerReadBarrier);
6440 DCHECK(kUseBakerReadBarrier);
6441
6442 // /* HeapReference<Object> */ ref = *(obj + offset)
6443 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006444 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006445 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006446 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006447}
6448
6449void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6450 Location ref,
6451 Register obj,
6452 uint32_t data_offset,
6453 Location index,
6454 Location temp,
6455 bool needs_null_check) {
6456 DCHECK(kEmitCompilerReadBarrier);
6457 DCHECK(kUseBakerReadBarrier);
6458
Roland Levillainbfea3352016-06-23 13:48:47 +01006459 static_assert(
6460 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6461 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006462 // /* HeapReference<Object> */ ref =
6463 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006464 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006465 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006466 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006467}
6468
6469void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6470 Location ref,
6471 Register obj,
6472 uint32_t offset,
6473 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006474 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006475 Location temp,
6476 bool needs_null_check) {
6477 DCHECK(kEmitCompilerReadBarrier);
6478 DCHECK(kUseBakerReadBarrier);
6479
6480 // In slow path based read barriers, the read barrier call is
6481 // inserted after the original load. However, in fast path based
6482 // Baker's read barriers, we need to perform the load of
6483 // mirror::Object::monitor_ *before* the original reference load.
6484 // This load-load ordering is required by the read barrier.
6485 // The fast path/slow path (for Baker's algorithm) should look like:
6486 //
6487 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6488 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6489 // HeapReference<Object> ref = *src; // Original reference load.
6490 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6491 // if (is_gray) {
6492 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6493 // }
6494 //
6495 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006496 // slightly more complex as it performs additional checks that we do
6497 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006498
6499 Register ref_reg = ref.AsRegister<Register>();
6500 Register temp_reg = temp.AsRegister<Register>();
6501 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6502
6503 // /* int32_t */ monitor = obj->monitor_
6504 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6505 if (needs_null_check) {
6506 MaybeRecordImplicitNullCheck(instruction);
6507 }
6508 // /* LockWord */ lock_word = LockWord(monitor)
6509 static_assert(sizeof(LockWord) == sizeof(int32_t),
6510 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006511
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006512 // Introduce a dependency on the lock_word including the rb_state,
6513 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006514 // a memory barrier (which would be more expensive).
Roland Levillain0b671c02016-08-19 12:02:34 +01006515 // `obj` is unchanged by this operation, but its value now depends
6516 // on `temp_reg`.
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006517 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006518
6519 // The actual reference load.
6520 if (index.IsValid()) {
Roland Levillainbfea3352016-06-23 13:48:47 +01006521 // Load types involving an "index": ArrayGet and
6522 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
6523 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006524 if (index.IsConstant()) {
6525 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006526 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006527 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6528 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006529 // Handle the special case of the
6530 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use
6531 // a register pair as index ("long offset"), of which only the low
6532 // part contains data.
6533 Register index_reg = index.IsRegisterPair()
6534 ? index.AsRegisterPairLow<Register>()
6535 : index.AsRegister<Register>();
6536 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006537 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6538 }
6539 } else {
6540 // /* HeapReference<Object> */ ref = *(obj + offset)
6541 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6542 }
6543
6544 // Object* ref = ref_addr->AsMirrorPtr()
6545 __ MaybeUnpoisonHeapReference(ref_reg);
6546
Vladimir Marko953437b2016-08-24 08:30:46 +00006547 // Slow path marking the object `ref` when it is gray.
Roland Levillainc9285912015-12-18 10:38:42 +00006548 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006549 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
Roland Levillainc9285912015-12-18 10:38:42 +00006550 AddSlowPath(slow_path);
6551
6552 // if (rb_state == ReadBarrier::gray_ptr_)
6553 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006554 // Given the numeric representation, it's enough to check the low bit of the
6555 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6556 // which can be a 16-bit instruction unlike the TST immediate.
6557 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6558 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6559 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6560 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6561 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006562 __ Bind(slow_path->GetExitLabel());
6563}
6564
6565void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6566 Location out,
6567 Location ref,
6568 Location obj,
6569 uint32_t offset,
6570 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006571 DCHECK(kEmitCompilerReadBarrier);
6572
Roland Levillainc9285912015-12-18 10:38:42 +00006573 // Insert a slow path based read barrier *after* the reference load.
6574 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006575 // If heap poisoning is enabled, the unpoisoning of the loaded
6576 // reference will be carried out by the runtime within the slow
6577 // path.
6578 //
6579 // Note that `ref` currently does not get unpoisoned (when heap
6580 // poisoning is enabled), which is alright as the `ref` argument is
6581 // not used by the artReadBarrierSlow entry point.
6582 //
6583 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
6584 SlowPathCode* slow_path = new (GetGraph()->GetArena())
6585 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6586 AddSlowPath(slow_path);
6587
Roland Levillain3b359c72015-11-17 19:35:12 +00006588 __ b(slow_path->GetEntryLabel());
6589 __ Bind(slow_path->GetExitLabel());
6590}
6591
Roland Levillainc9285912015-12-18 10:38:42 +00006592void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6593 Location out,
6594 Location ref,
6595 Location obj,
6596 uint32_t offset,
6597 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006598 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006599 // Baker's read barriers shall be handled by the fast path
6600 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6601 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006602 // If heap poisoning is enabled, unpoisoning will be taken care of
6603 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006604 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006605 } else if (kPoisonHeapReferences) {
6606 __ UnpoisonHeapReference(out.AsRegister<Register>());
6607 }
6608}
6609
Roland Levillainc9285912015-12-18 10:38:42 +00006610void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6611 Location out,
6612 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006613 DCHECK(kEmitCompilerReadBarrier);
6614
Roland Levillainc9285912015-12-18 10:38:42 +00006615 // Insert a slow path based read barrier *after* the GC root load.
6616 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006617 // Note that GC roots are not affected by heap poisoning, so we do
6618 // not need to do anything special for this here.
6619 SlowPathCode* slow_path =
6620 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6621 AddSlowPath(slow_path);
6622
Roland Levillain3b359c72015-11-17 19:35:12 +00006623 __ b(slow_path->GetEntryLabel());
6624 __ Bind(slow_path->GetExitLabel());
6625}
6626
Vladimir Markodc151b22015-10-15 18:02:30 +01006627HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6628 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
6629 MethodReference target_method) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006630 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6631 // We disable pc-relative load when there is an irreducible loop, as the optimization
6632 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006633 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6634 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006635 if (GetGraph()->HasIrreducibleLoops() &&
6636 (dispatch_info.method_load_kind ==
6637 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
6638 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
6639 }
6640
6641 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01006642 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
6643 if (&outer_dex_file != target_method.dex_file) {
6644 // Calls across dex files are more likely to exceed the available BL range,
6645 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
6646 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
6647 (desired_dispatch_info.method_load_kind ==
6648 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
6649 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
6650 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
6651 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006652 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01006653 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006654 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01006655 0u
6656 };
6657 }
6658 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006659 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006660}
6661
Vladimir Markob4536b72015-11-24 13:45:23 +00006662Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
6663 Register temp) {
6664 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
6665 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
6666 if (!invoke->GetLocations()->Intrinsified()) {
6667 return location.AsRegister<Register>();
6668 }
6669 // For intrinsics we allow any location, so it may be on the stack.
6670 if (!location.IsRegister()) {
6671 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
6672 return temp;
6673 }
6674 // For register locations, check if the register was saved. If so, get it from the stack.
6675 // Note: There is a chance that the register was saved but not overwritten, so we could
6676 // save one load. However, since this is just an intrinsic slow path we prefer this
6677 // simple and more robust approach rather that trying to determine if that's the case.
6678 SlowPathCode* slow_path = GetCurrentSlowPath();
6679 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
6680 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
6681 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
6682 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
6683 return temp;
6684 }
6685 return location.AsRegister<Register>();
6686}
6687
Nicolas Geoffray38207af2015-06-01 15:46:22 +01006688void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00006689 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00006690 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00006691 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6692 // LR = code address from literal pool with link-time patch.
6693 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00006694 break;
6695 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6696 // LR = invoke->GetDirectCodePtr();
6697 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00006698 break;
6699 default:
6700 break;
6701 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006702
Vladimir Marko58155012015-08-19 12:49:41 +00006703 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
6704 switch (invoke->GetMethodLoadKind()) {
6705 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
6706 // temp = thread->string_init_entrypoint
6707 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
6708 break;
6709 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006710 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006711 break;
6712 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
6713 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
6714 break;
6715 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
6716 __ LoadLiteral(temp.AsRegister<Register>(),
6717 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
6718 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00006719 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
6720 HArmDexCacheArraysBase* base =
6721 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
6722 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
6723 temp.AsRegister<Register>());
6724 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
6725 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
6726 break;
6727 }
Vladimir Marko58155012015-08-19 12:49:41 +00006728 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00006729 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006730 Register method_reg;
6731 Register reg = temp.AsRegister<Register>();
6732 if (current_method.IsRegister()) {
6733 method_reg = current_method.AsRegister<Register>();
6734 } else {
6735 DCHECK(invoke->GetLocations()->Intrinsified());
6736 DCHECK(!current_method.IsValid());
6737 method_reg = reg;
6738 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
6739 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006740 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
6741 __ LoadFromOffset(kLoadWord,
6742 reg,
6743 method_reg,
6744 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01006745 // temp = temp[index_in_cache];
6746 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
6747 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00006748 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
6749 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01006750 }
Vladimir Marko58155012015-08-19 12:49:41 +00006751 }
6752
6753 switch (invoke->GetCodePtrLocation()) {
6754 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
6755 __ bl(GetFrameEntryLabel());
6756 break;
6757 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01006758 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07006759 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01006760 // Arbitrarily branch to the BL itself, override at link time.
6761 __ bl(&relative_call_patches_.back().label);
6762 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006763 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6764 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6765 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00006766 // LR()
6767 __ blx(LR);
6768 break;
6769 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6770 // LR = callee_method->entry_point_from_quick_compiled_code_
6771 __ LoadFromOffset(
6772 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07006773 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006774 // LR()
6775 __ blx(LR);
6776 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006777 }
6778
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006779 DCHECK(!IsLeafMethod());
6780}
6781
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006782void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
6783 Register temp = temp_location.AsRegister<Register>();
6784 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6785 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006786
6787 // Use the calling convention instead of the location of the receiver, as
6788 // intrinsics may have put the receiver in a different register. In the intrinsics
6789 // slow path, the arguments have been moved to the right place, so here we are
6790 // guaranteed that the receiver is the first register of the calling convention.
6791 InvokeDexCallingConvention calling_convention;
6792 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006793 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00006794 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006795 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006796 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00006797 // Instead of simply (possibly) unpoisoning `temp` here, we should
6798 // emit a read barrier for the previous class reference load.
6799 // However this is not required in practice, as this is an
6800 // intermediate/temporary reference and because the current
6801 // concurrent copying collector keeps the from-space memory
6802 // intact/accessible until the end of the marking phase (the
6803 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006804 __ MaybeUnpoisonHeapReference(temp);
6805 // temp = temp->GetMethodAt(method_offset);
6806 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006807 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006808 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
6809 // LR = temp->GetEntryPoint();
6810 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
6811 // LR();
6812 __ blx(LR);
6813}
6814
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006815CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
6816 const DexFile& dex_file, uint32_t string_index) {
6817 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
6818}
6819
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006820CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
6821 const DexFile& dex_file, uint32_t type_index) {
6822 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
6823}
6824
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006825CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
6826 const DexFile& dex_file, uint32_t element_offset) {
6827 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
6828}
6829
6830CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
6831 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
6832 patches->emplace_back(dex_file, offset_or_index);
6833 return &patches->back();
6834}
6835
6836Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
6837 uint32_t string_index) {
6838 return boot_image_string_patches_.GetOrCreate(
6839 StringReference(&dex_file, string_index),
6840 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6841}
6842
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006843Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
6844 uint32_t type_index) {
6845 return boot_image_type_patches_.GetOrCreate(
6846 TypeReference(&dex_file, type_index),
6847 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6848}
6849
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006850Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
6851 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
6852 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
6853 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
6854}
6855
6856Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
6857 return DeduplicateUint32Literal(address, &uint32_literals_);
6858}
6859
Vladimir Marko58155012015-08-19 12:49:41 +00006860void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
6861 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00006862 size_t size =
6863 method_patches_.size() +
6864 call_patches_.size() +
6865 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006866 /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() +
6867 boot_image_string_patches_.size() +
6868 /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006869 boot_image_type_patches_.size() +
6870 /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006871 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00006872 linker_patches->reserve(size);
6873 for (const auto& entry : method_patches_) {
6874 const MethodReference& target_method = entry.first;
6875 Literal* literal = entry.second;
6876 DCHECK(literal->GetLabel()->IsBound());
6877 uint32_t literal_offset = literal->GetLabel()->Position();
6878 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
6879 target_method.dex_file,
6880 target_method.dex_method_index));
6881 }
6882 for (const auto& entry : call_patches_) {
6883 const MethodReference& target_method = entry.first;
6884 Literal* literal = entry.second;
6885 DCHECK(literal->GetLabel()->IsBound());
6886 uint32_t literal_offset = literal->GetLabel()->Position();
6887 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
6888 target_method.dex_file,
6889 target_method.dex_method_index));
6890 }
6891 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
6892 uint32_t literal_offset = info.label.Position();
6893 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
6894 info.target_method.dex_file,
6895 info.target_method.dex_method_index));
6896 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006897 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
6898 const DexFile& dex_file = info.target_dex_file;
6899 size_t base_element_offset = info.offset_or_index;
6900 DCHECK(info.add_pc_label.IsBound());
6901 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006902 // Add MOVW patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006903 DCHECK(info.movw_label.IsBound());
6904 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006905 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset,
6906 &dex_file,
6907 add_pc_offset,
6908 base_element_offset));
6909 // Add MOVT patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006910 DCHECK(info.movt_label.IsBound());
6911 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006912 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset,
6913 &dex_file,
6914 add_pc_offset,
6915 base_element_offset));
6916 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006917 for (const auto& entry : boot_image_string_patches_) {
6918 const StringReference& target_string = entry.first;
6919 Literal* literal = entry.second;
6920 DCHECK(literal->GetLabel()->IsBound());
6921 uint32_t literal_offset = literal->GetLabel()->Position();
6922 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
6923 target_string.dex_file,
6924 target_string.string_index));
6925 }
6926 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
6927 const DexFile& dex_file = info.target_dex_file;
6928 uint32_t string_index = info.offset_or_index;
6929 DCHECK(info.add_pc_label.IsBound());
6930 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6931 // Add MOVW patch.
6932 DCHECK(info.movw_label.IsBound());
6933 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6934 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset,
6935 &dex_file,
6936 add_pc_offset,
6937 string_index));
6938 // Add MOVT patch.
6939 DCHECK(info.movt_label.IsBound());
6940 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6941 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset,
6942 &dex_file,
6943 add_pc_offset,
6944 string_index));
6945 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006946 for (const auto& entry : boot_image_type_patches_) {
6947 const TypeReference& target_type = entry.first;
6948 Literal* literal = entry.second;
6949 DCHECK(literal->GetLabel()->IsBound());
6950 uint32_t literal_offset = literal->GetLabel()->Position();
6951 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
6952 target_type.dex_file,
6953 target_type.type_index));
6954 }
6955 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
6956 const DexFile& dex_file = info.target_dex_file;
6957 uint32_t type_index = info.offset_or_index;
6958 DCHECK(info.add_pc_label.IsBound());
6959 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6960 // Add MOVW patch.
6961 DCHECK(info.movw_label.IsBound());
6962 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6963 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset,
6964 &dex_file,
6965 add_pc_offset,
6966 type_index));
6967 // Add MOVT patch.
6968 DCHECK(info.movt_label.IsBound());
6969 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6970 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset,
6971 &dex_file,
6972 add_pc_offset,
6973 type_index));
6974 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006975 for (const auto& entry : boot_image_address_patches_) {
6976 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
6977 Literal* literal = entry.second;
6978 DCHECK(literal->GetLabel()->IsBound());
6979 uint32_t literal_offset = literal->GetLabel()->Position();
6980 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
6981 }
6982}
6983
6984Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
6985 return map->GetOrCreate(
6986 value,
6987 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00006988}
6989
6990Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
6991 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006992 return map->GetOrCreate(
6993 target_method,
6994 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00006995}
6996
6997Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
6998 return DeduplicateMethodLiteral(target_method, &method_patches_);
6999}
7000
7001Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
7002 return DeduplicateMethodLiteral(target_method, &call_patches_);
7003}
7004
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03007005void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7006 LocationSummary* locations =
7007 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7008 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7009 Location::RequiresRegister());
7010 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7011 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7012 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7013}
7014
7015void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7016 LocationSummary* locations = instr->GetLocations();
7017 Register res = locations->Out().AsRegister<Register>();
7018 Register accumulator =
7019 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7020 Register mul_left =
7021 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7022 Register mul_right =
7023 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7024
7025 if (instr->GetOpKind() == HInstruction::kAdd) {
7026 __ mla(res, mul_left, mul_right, accumulator);
7027 } else {
7028 __ mls(res, mul_left, mul_right, accumulator);
7029 }
7030}
7031
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007032void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007033 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007034 LOG(FATAL) << "Unreachable";
7035}
7036
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007037void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007038 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007039 LOG(FATAL) << "Unreachable";
7040}
7041
Mark Mendellfe57faa2015-09-18 09:26:15 -04007042// Simple implementation of packed switch - generate cascaded compare/jumps.
7043void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7044 LocationSummary* locations =
7045 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7046 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007047 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007048 codegen_->GetAssembler()->IsThumb()) {
7049 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7050 if (switch_instr->GetStartValue() != 0) {
7051 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7052 }
7053 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007054}
7055
7056void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7057 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007058 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007059 LocationSummary* locations = switch_instr->GetLocations();
7060 Register value_reg = locations->InAt(0).AsRegister<Register>();
7061 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7062
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007063 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007064 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007065 Register temp_reg = IP;
7066 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7067 // the immediate, because IP is used as the destination register. For the other
7068 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7069 // and they can be encoded in the instruction without making use of IP register.
7070 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7071
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007072 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007073 // Jump to successors[0] if value == lower_bound.
7074 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7075 int32_t last_index = 0;
7076 for (; num_entries - last_index > 2; last_index += 2) {
7077 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7078 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7079 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7080 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7081 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7082 }
7083 if (num_entries - last_index == 2) {
7084 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007085 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007086 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007087 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007088
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007089 // And the default for any other value.
7090 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7091 __ b(codegen_->GetLabelOf(default_block));
7092 }
7093 } else {
7094 // Create a table lookup.
7095 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7096
7097 // Materialize a pointer to the switch table
7098 std::vector<Label*> labels(num_entries);
7099 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7100 for (uint32_t i = 0; i < num_entries; i++) {
7101 labels[i] = codegen_->GetLabelOf(successors[i]);
7102 }
7103 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7104
7105 // Remove the bias.
7106 Register key_reg;
7107 if (lower_bound != 0) {
7108 key_reg = locations->GetTemp(1).AsRegister<Register>();
7109 __ AddConstant(key_reg, value_reg, -lower_bound);
7110 } else {
7111 key_reg = value_reg;
7112 }
7113
7114 // Check whether the value is in the table, jump to default block if not.
7115 __ CmpConstant(key_reg, num_entries - 1);
7116 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7117
7118 // Load the displacement from the table.
7119 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7120
7121 // Dispatch is a direct add to the PC (for Thumb2).
7122 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007123 }
7124}
7125
Vladimir Markob4536b72015-11-24 13:45:23 +00007126void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7127 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7128 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007129}
7130
7131void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7132 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007133 CodeGeneratorARM::PcRelativePatchInfo* labels =
7134 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007135 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007136 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007137 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007138 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007139 __ BindTrackedLabel(&labels->add_pc_label);
7140 __ add(base_reg, base_reg, ShifterOperand(PC));
7141}
7142
Andreas Gampe85b62f22015-09-09 13:15:38 -07007143void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7144 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007145 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007146 return;
7147 }
7148
7149 DCHECK_NE(type, Primitive::kPrimVoid);
7150
7151 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7152 if (return_loc.Equals(trg)) {
7153 return;
7154 }
7155
7156 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7157 // with the last branch.
7158 if (type == Primitive::kPrimLong) {
7159 HParallelMove parallel_move(GetGraph()->GetArena());
7160 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7161 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7162 GetMoveResolver()->EmitNativeCode(&parallel_move);
7163 } else if (type == Primitive::kPrimDouble) {
7164 HParallelMove parallel_move(GetGraph()->GetArena());
7165 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7166 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7167 GetMoveResolver()->EmitNativeCode(&parallel_move);
7168 } else {
7169 // Let the parallel move resolver take care of all of this.
7170 HParallelMove parallel_move(GetGraph()->GetArena());
7171 parallel_move.AddMove(return_loc, trg, type, nullptr);
7172 GetMoveResolver()->EmitNativeCode(&parallel_move);
7173 }
7174}
7175
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007176void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7177 LocationSummary* locations =
7178 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7179 locations->SetInAt(0, Location::RequiresRegister());
7180 locations->SetOut(Location::RequiresRegister());
7181}
7182
7183void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7184 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007185 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007186 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007187 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007188 __ LoadFromOffset(kLoadWord,
7189 locations->Out().AsRegister<Register>(),
7190 locations->InAt(0).AsRegister<Register>(),
7191 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007192 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007193 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007194 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007195 __ LoadFromOffset(kLoadWord,
7196 locations->Out().AsRegister<Register>(),
7197 locations->InAt(0).AsRegister<Register>(),
7198 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7199 __ LoadFromOffset(kLoadWord,
7200 locations->Out().AsRegister<Register>(),
7201 locations->Out().AsRegister<Register>(),
7202 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007203 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007204}
7205
Roland Levillain4d027112015-07-01 15:41:14 +01007206#undef __
7207#undef QUICK_ENTRY_POINT
7208
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007209} // namespace arm
7210} // namespace art