blob: 4ea17a9271ddb6471938da76ee90c409c280ee30 [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 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010077 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000078 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +000079 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080 }
81
Alexandre Rames8158f282015-08-07 10:26:17 +010082 bool IsFatal() const OVERRIDE { return true; }
83
Alexandre Rames9931f312015-06-19 14:47:01 +010084 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
85
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086 private:
Nicolas Geoffraye5038322014-07-04 09:41:32 +010087 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
88};
89
Andreas Gampe85b62f22015-09-09 13:15:38 -070090class DivZeroCheckSlowPathARM : public SlowPathCode {
Calin Juravled0d48522014-11-04 16:40:20 +000091 public:
David Srbecky9cd6d372016-02-09 15:24:47 +000092 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {}
Calin Juravled0d48522014-11-04 16:40:20 +000093
Alexandre Rames67555f72014-11-18 10:55:16 +000094 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000095 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
96 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000097 if (instruction_->CanThrowIntoCatchBlock()) {
98 // Live registers will be restored in the catch block if caught.
99 SaveLiveRegisters(codegen, instruction_->GetLocations());
100 }
Calin Juravled0d48522014-11-04 16:40:20 +0000101 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000102 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000103 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Calin Juravled0d48522014-11-04 16:40:20 +0000104 }
105
Alexandre Rames8158f282015-08-07 10:26:17 +0100106 bool IsFatal() const OVERRIDE { return true; }
107
Alexandre Rames9931f312015-06-19 14:47:01 +0100108 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
109
Calin Juravled0d48522014-11-04 16:40:20 +0000110 private:
Calin Juravled0d48522014-11-04 16:40:20 +0000111 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
112};
113
Andreas Gampe85b62f22015-09-09 13:15:38 -0700114class SuspendCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000115 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000116 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000117 : SlowPathCode(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000118
Alexandre Rames67555f72014-11-18 10:55:16 +0000119 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100120 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000121 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100122 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000123 QUICK_ENTRY_POINT(pTestSuspend), 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);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100177 uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt()
178 ? QUICK_ENTRY_POINT(pThrowStringBounds)
179 : QUICK_ENTRY_POINT(pThrowArrayBounds);
180 arm_codegen->InvokeRuntime(entry_point_offset, instruction_, instruction_->GetDexPc(), this);
181 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());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 int32_t entry_point_offset = do_clinit_
213 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
214 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000215 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Roland Levillain888d0672015-11-23 18:53:50 +0000216 if (do_clinit_) {
217 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
218 } else {
219 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
220 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000221
222 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000223 Location out = locations->Out();
224 if (out.IsValid()) {
225 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000226 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
227 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000228 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100229 __ b(GetExitLabel());
230 }
231
Alexandre Rames9931f312015-06-19 14:47:01 +0100232 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
233
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100234 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000235 // The class this slow path will load.
236 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100237
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000238 // The instruction where this slow path is happening.
239 // (Might be the load class or an initialization check).
240 HInstruction* const at_;
241
242 // The dex PC of `at_`.
243 const uint32_t dex_pc_;
244
245 // Whether to initialize the class.
246 const bool do_clinit_;
247
248 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100249};
250
Andreas Gampe85b62f22015-09-09 13:15:38 -0700251class LoadStringSlowPathARM : public SlowPathCode {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000252 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000253 explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000254
Alexandre Rames67555f72014-11-18 10:55:16 +0000255 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000256 LocationSummary* locations = instruction_->GetLocations();
257 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
258
259 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
260 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000261 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000262
263 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000264 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
265 __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000266 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000267 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000268 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000269 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
270
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000271 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000272 __ b(GetExitLabel());
273 }
274
Alexandre Rames9931f312015-06-19 14:47:01 +0100275 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
276
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000277 private:
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000278 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
279};
280
Andreas Gampe85b62f22015-09-09 13:15:38 -0700281class TypeCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000282 public:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000283 TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal)
David Srbecky9cd6d372016-02-09 15:24:47 +0000284 : SlowPathCode(instruction), is_fatal_(is_fatal) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
Alexandre Rames67555f72014-11-18 10:55:16 +0000286 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000287 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100288 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
289 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000290 DCHECK(instruction_->IsCheckCast()
291 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000292
293 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
294 __ Bind(GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000295
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000296 if (!is_fatal_) {
297 SaveLiveRegisters(codegen, locations);
298 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000299
300 // We're moving two locations to locations that could overlap, so we need a parallel
301 // move resolver.
302 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000303 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100304 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000305 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100306 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100307 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100308 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
309 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000310
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000311 if (instruction_->IsInstanceOf()) {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100312 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
313 instruction_,
314 instruction_->GetDexPc(),
315 this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000316 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700317 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000318 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
319 } else {
320 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100321 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
322 instruction_,
323 instruction_->GetDexPc(),
324 this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000325 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000326 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000327
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000328 if (!is_fatal_) {
329 RestoreLiveRegisters(codegen, locations);
330 __ b(GetExitLabel());
331 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000332 }
333
Alexandre Rames9931f312015-06-19 14:47:01 +0100334 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
335
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000336 bool IsFatal() const OVERRIDE { return is_fatal_; }
337
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000338 private:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000339 const bool is_fatal_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000340
341 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
342};
343
Andreas Gampe85b62f22015-09-09 13:15:38 -0700344class DeoptimizationSlowPathARM : public SlowPathCode {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700345 public:
Aart Bik42249c32016-01-07 15:33:50 -0800346 explicit DeoptimizationSlowPathARM(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000347 : SlowPathCode(instruction) {}
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700348
349 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800350 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700351 __ Bind(GetEntryLabel());
352 SaveLiveRegisters(codegen, instruction_->GetLocations());
Aart Bik42249c32016-01-07 15:33:50 -0800353 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize),
354 instruction_,
355 instruction_->GetDexPc(),
356 this);
Roland Levillain888d0672015-11-23 18:53:50 +0000357 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700358 }
359
Alexandre Rames9931f312015-06-19 14:47:01 +0100360 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
361
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700362 private:
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700363 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
364};
365
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100366class ArraySetSlowPathARM : public SlowPathCode {
367 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000368 explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100369
370 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
371 LocationSummary* locations = instruction_->GetLocations();
372 __ Bind(GetEntryLabel());
373 SaveLiveRegisters(codegen, locations);
374
375 InvokeRuntimeCallingConvention calling_convention;
376 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
377 parallel_move.AddMove(
378 locations->InAt(0),
379 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
380 Primitive::kPrimNot,
381 nullptr);
382 parallel_move.AddMove(
383 locations->InAt(1),
384 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
385 Primitive::kPrimInt,
386 nullptr);
387 parallel_move.AddMove(
388 locations->InAt(2),
389 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
390 Primitive::kPrimNot,
391 nullptr);
392 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
393
394 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
395 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
396 instruction_,
397 instruction_->GetDexPc(),
398 this);
Roland Levillain888d0672015-11-23 18:53:50 +0000399 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100400 RestoreLiveRegisters(codegen, locations);
401 __ b(GetExitLabel());
402 }
403
404 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; }
405
406 private:
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100407 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM);
408};
409
Roland Levillainc9285912015-12-18 10:38:42 +0000410// Slow path marking an object during a read barrier.
411class ReadBarrierMarkSlowPathARM : public SlowPathCode {
412 public:
Roland Levillain02b75802016-07-13 11:54:35 +0100413 ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj)
414 : SlowPathCode(instruction), obj_(obj) {
Roland Levillainc9285912015-12-18 10:38:42 +0000415 DCHECK(kEmitCompilerReadBarrier);
416 }
417
418 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; }
419
420 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
421 LocationSummary* locations = instruction_->GetLocations();
Roland Levillain02b75802016-07-13 11:54:35 +0100422 Register reg = obj_.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +0000423 DCHECK(locations->CanCall());
Roland Levillain02b75802016-07-13 11:54:35 +0100424 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg));
Roland Levillainc9285912015-12-18 10:38:42 +0000425 DCHECK(instruction_->IsInstanceFieldGet() ||
426 instruction_->IsStaticFieldGet() ||
427 instruction_->IsArrayGet() ||
Roland Levillain16d9f942016-08-25 17:27:56 +0100428 instruction_->IsArraySet() ||
Roland Levillainc9285912015-12-18 10:38:42 +0000429 instruction_->IsLoadClass() ||
430 instruction_->IsLoadString() ||
431 instruction_->IsInstanceOf() ||
Roland Levillain3d312422016-06-23 13:53:42 +0100432 instruction_->IsCheckCast() ||
Roland Levillain0b671c02016-08-19 12:02:34 +0100433 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
434 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
Roland Levillainc9285912015-12-18 10:38:42 +0000435 << "Unexpected instruction in read barrier marking slow path: "
436 << instruction_->DebugName();
437
438 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100439 // No need to save live registers; it's taken care of by the
440 // entrypoint. Also, there is no need to update the stack mask,
441 // as this runtime call will not trigger a garbage collection.
Roland Levillainc9285912015-12-18 10:38:42 +0000442 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Roland Levillain02b75802016-07-13 11:54:35 +0100443 DCHECK_NE(reg, SP);
444 DCHECK_NE(reg, LR);
445 DCHECK_NE(reg, PC);
Roland Levillain0b671c02016-08-19 12:02:34 +0100446 // IP is used internally by the ReadBarrierMarkRegX entry point
447 // as a temporary, it cannot be the entry point's input/output.
448 DCHECK_NE(reg, IP);
Roland Levillain02b75802016-07-13 11:54:35 +0100449 DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg;
450 // "Compact" slow path, saving two moves.
451 //
452 // Instead of using the standard runtime calling convention (input
453 // and output in R0):
454 //
455 // R0 <- obj
456 // R0 <- ReadBarrierMark(R0)
457 // obj <- R0
458 //
459 // we just use rX (the register holding `obj`) as input and output
460 // of a dedicated entrypoint:
461 //
462 // rX <- ReadBarrierMarkRegX(rX)
463 //
464 int32_t entry_point_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -0700465 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg);
Roland Levillaindec8f632016-07-22 17:10:06 +0100466 // This runtime call does not require a stack map.
467 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
Roland Levillainc9285912015-12-18 10:38:42 +0000468 __ b(GetExitLabel());
469 }
470
471 private:
Roland Levillainc9285912015-12-18 10:38:42 +0000472 const Location obj_;
473
474 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM);
475};
476
Roland Levillain3b359c72015-11-17 19:35:12 +0000477// Slow path generating a read barrier for a heap reference.
478class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode {
479 public:
480 ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction,
481 Location out,
482 Location ref,
483 Location obj,
484 uint32_t offset,
485 Location index)
David Srbecky9cd6d372016-02-09 15:24:47 +0000486 : SlowPathCode(instruction),
Roland Levillain3b359c72015-11-17 19:35:12 +0000487 out_(out),
488 ref_(ref),
489 obj_(obj),
490 offset_(offset),
491 index_(index) {
492 DCHECK(kEmitCompilerReadBarrier);
493 // If `obj` is equal to `out` or `ref`, it means the initial object
494 // has been overwritten by (or after) the heap object reference load
495 // to be instrumented, e.g.:
496 //
497 // __ LoadFromOffset(kLoadWord, out, out, offset);
Roland Levillainc9285912015-12-18 10:38:42 +0000498 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
Roland Levillain3b359c72015-11-17 19:35:12 +0000499 //
500 // In that case, we have lost the information about the original
501 // object, and the emitted read barrier cannot work properly.
502 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
503 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
504 }
505
506 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
507 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
508 LocationSummary* locations = instruction_->GetLocations();
509 Register reg_out = out_.AsRegister<Register>();
510 DCHECK(locations->CanCall());
511 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillain3d312422016-06-23 13:53:42 +0100512 DCHECK(instruction_->IsInstanceFieldGet() ||
513 instruction_->IsStaticFieldGet() ||
514 instruction_->IsArrayGet() ||
515 instruction_->IsInstanceOf() ||
516 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100517 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillainc9285912015-12-18 10:38:42 +0000518 << "Unexpected instruction in read barrier for heap reference slow path: "
519 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000520
521 __ Bind(GetEntryLabel());
522 SaveLiveRegisters(codegen, locations);
523
524 // We may have to change the index's value, but as `index_` is a
525 // constant member (like other "inputs" of this slow path),
526 // introduce a copy of it, `index`.
527 Location index = index_;
528 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100529 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain3b359c72015-11-17 19:35:12 +0000530 if (instruction_->IsArrayGet()) {
531 // Compute the actual memory offset and store it in `index`.
532 Register index_reg = index_.AsRegister<Register>();
533 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
534 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
535 // We are about to change the value of `index_reg` (see the
536 // calls to art::arm::Thumb2Assembler::Lsl and
537 // art::arm::Thumb2Assembler::AddConstant below), but it has
538 // not been saved by the previous call to
539 // art::SlowPathCode::SaveLiveRegisters, as it is a
540 // callee-save register --
541 // art::SlowPathCode::SaveLiveRegisters does not consider
542 // callee-save registers, as it has been designed with the
543 // assumption that callee-save registers are supposed to be
544 // handled by the called function. So, as a callee-save
545 // register, `index_reg` _would_ eventually be saved onto
546 // the stack, but it would be too late: we would have
547 // changed its value earlier. Therefore, we manually save
548 // it here into another freely available register,
549 // `free_reg`, chosen of course among the caller-save
550 // registers (as a callee-save `free_reg` register would
551 // exhibit the same problem).
552 //
553 // Note we could have requested a temporary register from
554 // the register allocator instead; but we prefer not to, as
555 // this is a slow path, and we know we can find a
556 // caller-save register that is available.
557 Register free_reg = FindAvailableCallerSaveRegister(codegen);
558 __ Mov(free_reg, index_reg);
559 index_reg = free_reg;
560 index = Location::RegisterLocation(index_reg);
561 } else {
562 // The initial register stored in `index_` has already been
563 // saved in the call to art::SlowPathCode::SaveLiveRegisters
564 // (as it is not a callee-save register), so we can freely
565 // use it.
566 }
567 // Shifting the index value contained in `index_reg` by the scale
568 // factor (2) cannot overflow in practice, as the runtime is
569 // unable to allocate object arrays with a size larger than
570 // 2^26 - 1 (that is, 2^28 - 4 bytes).
571 __ Lsl(index_reg, index_reg, TIMES_4);
572 static_assert(
573 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
574 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
575 __ AddConstant(index_reg, index_reg, offset_);
576 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100577 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
578 // intrinsics, `index_` is not shifted by a scale factor of 2
579 // (as in the case of ArrayGet), as it is actually an offset
580 // to an object field within an object.
581 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000582 DCHECK(instruction_->GetLocations()->Intrinsified());
583 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
584 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
585 << instruction_->AsInvoke()->GetIntrinsic();
586 DCHECK_EQ(offset_, 0U);
587 DCHECK(index_.IsRegisterPair());
588 // UnsafeGet's offset location is a register pair, the low
589 // part contains the correct offset.
590 index = index_.ToLow();
591 }
592 }
593
594 // We're moving two or three locations to locations that could
595 // overlap, so we need a parallel move resolver.
596 InvokeRuntimeCallingConvention calling_convention;
597 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
598 parallel_move.AddMove(ref_,
599 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
600 Primitive::kPrimNot,
601 nullptr);
602 parallel_move.AddMove(obj_,
603 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
604 Primitive::kPrimNot,
605 nullptr);
606 if (index.IsValid()) {
607 parallel_move.AddMove(index,
608 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
609 Primitive::kPrimInt,
610 nullptr);
611 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
612 } else {
613 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
614 __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_);
615 }
616 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow),
617 instruction_,
618 instruction_->GetDexPc(),
619 this);
620 CheckEntrypointTypes<
621 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
622 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
623
624 RestoreLiveRegisters(codegen, locations);
625 __ b(GetExitLabel());
626 }
627
628 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; }
629
630 private:
631 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
632 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
633 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
634 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
635 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
636 return static_cast<Register>(i);
637 }
638 }
639 // We shall never fail to find a free caller-save register, as
640 // there are more than two core caller-save registers on ARM
641 // (meaning it is possible to find one which is different from
642 // `ref` and `obj`).
643 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
644 LOG(FATAL) << "Could not find a free caller-save register";
645 UNREACHABLE();
646 }
647
Roland Levillain3b359c72015-11-17 19:35:12 +0000648 const Location out_;
649 const Location ref_;
650 const Location obj_;
651 const uint32_t offset_;
652 // An additional location containing an index to an array.
653 // Only used for HArrayGet and the UnsafeGetObject &
654 // UnsafeGetObjectVolatile intrinsics.
655 const Location index_;
656
657 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM);
658};
659
660// Slow path generating a read barrier for a GC root.
661class ReadBarrierForRootSlowPathARM : public SlowPathCode {
662 public:
663 ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root)
David Srbecky9cd6d372016-02-09 15:24:47 +0000664 : SlowPathCode(instruction), out_(out), root_(root) {
Roland Levillainc9285912015-12-18 10:38:42 +0000665 DCHECK(kEmitCompilerReadBarrier);
666 }
Roland Levillain3b359c72015-11-17 19:35:12 +0000667
668 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
669 LocationSummary* locations = instruction_->GetLocations();
670 Register reg_out = out_.AsRegister<Register>();
671 DCHECK(locations->CanCall());
672 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillainc9285912015-12-18 10:38:42 +0000673 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
674 << "Unexpected instruction in read barrier for GC root slow path: "
675 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000676
677 __ Bind(GetEntryLabel());
678 SaveLiveRegisters(codegen, locations);
679
680 InvokeRuntimeCallingConvention calling_convention;
681 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
682 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_);
683 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow),
684 instruction_,
685 instruction_->GetDexPc(),
686 this);
687 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
688 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
689
690 RestoreLiveRegisters(codegen, locations);
691 __ b(GetExitLabel());
692 }
693
694 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; }
695
696 private:
Roland Levillain3b359c72015-11-17 19:35:12 +0000697 const Location out_;
698 const Location root_;
699
700 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM);
701};
702
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000703#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100704// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
705#define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT
Dave Allison20dfc792014-06-16 20:44:29 -0700706
Aart Bike9f37602015-10-09 11:15:55 -0700707inline Condition ARMCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700708 switch (cond) {
709 case kCondEQ: return EQ;
710 case kCondNE: return NE;
711 case kCondLT: return LT;
712 case kCondLE: return LE;
713 case kCondGT: return GT;
714 case kCondGE: return GE;
Aart Bike9f37602015-10-09 11:15:55 -0700715 case kCondB: return LO;
716 case kCondBE: return LS;
717 case kCondA: return HI;
718 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700719 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100720 LOG(FATAL) << "Unreachable";
721 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700722}
723
Aart Bike9f37602015-10-09 11:15:55 -0700724// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100725inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700726 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100727 case kCondEQ: return EQ;
728 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -0700729 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100730 case kCondLT: return LO;
731 case kCondLE: return LS;
732 case kCondGT: return HI;
733 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -0700734 // Unsigned remain unchanged.
735 case kCondB: return LO;
736 case kCondBE: return LS;
737 case kCondA: return HI;
738 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700739 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100740 LOG(FATAL) << "Unreachable";
741 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700742}
743
Vladimir Markod6e069b2016-01-18 11:11:01 +0000744inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) {
745 // The ARM condition codes can express all the necessary branches, see the
746 // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual.
747 // There is no dex instruction or HIR that would need the missing conditions
748 // "equal or unordered" or "not equal".
749 switch (cond) {
750 case kCondEQ: return EQ;
751 case kCondNE: return NE /* unordered */;
752 case kCondLT: return gt_bias ? CC : LT /* unordered */;
753 case kCondLE: return gt_bias ? LS : LE /* unordered */;
754 case kCondGT: return gt_bias ? HI /* unordered */ : GT;
755 case kCondGE: return gt_bias ? CS /* unordered */ : GE;
756 default:
757 LOG(FATAL) << "UNREACHABLE";
758 UNREACHABLE();
759 }
760}
761
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100762void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100763 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100764}
765
766void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100767 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100768}
769
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100770size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
771 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
772 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100773}
774
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100775size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
776 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
777 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100778}
779
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000780size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
781 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
782 return kArmWordSize;
783}
784
785size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
786 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
787 return kArmWordSize;
788}
789
Calin Juravle34166012014-12-19 17:22:29 +0000790CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000791 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100792 const CompilerOptions& compiler_options,
793 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000794 : CodeGenerator(graph,
795 kNumberOfCoreRegisters,
796 kNumberOfSRegisters,
797 kNumberOfRegisterPairs,
798 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
799 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +0000800 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
801 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100802 compiler_options,
803 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100804 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100805 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100806 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100807 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100808 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +0000809 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000810 uint32_literals_(std::less<uint32_t>(),
811 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +0100812 method_patches_(MethodReferenceComparator(),
813 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
814 call_patches_(MethodReferenceComparator(),
815 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markob4536b72015-11-24 13:45:23 +0000816 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000817 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
818 boot_image_string_patches_(StringReferenceValueComparator(),
819 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
820 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100821 boot_image_type_patches_(TypeReferenceValueComparator(),
822 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
823 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000824 boot_image_address_patches_(std::less<uint32_t>(),
825 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700826 // Always save the LR register to mimic Quick.
827 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100828}
829
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000830void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
831 // Ensure that we fix up branches and literal loads and emit the literal pool.
832 __ FinalizeCode();
833
834 // Adjust native pc offsets in stack maps.
835 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
836 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
837 uint32_t new_position = __ GetAdjustedPosition(old_position);
838 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
839 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100840 // Adjust pc offsets for the disassembly information.
841 if (disasm_info_ != nullptr) {
842 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
843 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
844 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
845 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
846 it.second.start = __ GetAdjustedPosition(it.second.start);
847 it.second.end = __ GetAdjustedPosition(it.second.end);
848 }
849 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
850 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
851 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
852 }
853 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000854
855 CodeGenerator::Finalize(allocator);
856}
857
David Brazdil58282f42016-01-14 12:45:10 +0000858void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100859 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100860 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100861
862 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100863 blocked_core_registers_[SP] = true;
864 blocked_core_registers_[LR] = true;
865 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100866
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100867 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100868 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100869
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100870 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100871 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100872
David Brazdil58282f42016-01-14 12:45:10 +0000873 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100874 // Stubs do not save callee-save floating point registers. If the graph
875 // is debuggable, we need to deal with these registers differently. For
876 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000877 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
878 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
879 }
880 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100881
882 UpdateBlockedPairRegisters();
883}
884
885void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
886 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
887 ArmManagedRegister current =
888 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
889 if (blocked_core_registers_[current.AsRegisterPairLow()]
890 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
891 blocked_register_pairs_[i] = true;
892 }
893 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100894}
895
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100896InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
Aart Bik42249c32016-01-07 15:33:50 -0800897 : InstructionCodeGenerator(graph, codegen),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100898 assembler_(codegen->GetAssembler()),
899 codegen_(codegen) {}
900
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000901void CodeGeneratorARM::ComputeSpillMask() {
902 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
903 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
David Brazdil58282f42016-01-14 12:45:10 +0000904 // There is no easy instruction to restore just the PC on thumb2. We spill and
905 // restore another arbitrary register.
906 core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000907 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
908 // We use vpush and vpop for saving and restoring floating point registers, which take
909 // a SRegister and the number of registers to save/restore after that SRegister. We
910 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
911 // but in the range.
912 if (fpu_spill_mask_ != 0) {
913 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
914 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
915 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
916 fpu_spill_mask_ |= (1 << i);
917 }
918 }
919}
920
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100921static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100922 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100923}
924
925static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100926 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100927}
928
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000929void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000930 bool skip_overflow_check =
931 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000932 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000933 __ Bind(&frame_entry_label_);
934
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000935 if (HasEmptyFrame()) {
936 return;
937 }
938
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100939 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000940 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
941 __ LoadFromOffset(kLoadWord, IP, IP, 0);
942 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100943 }
944
Andreas Gampe501fd632015-09-10 16:11:06 -0700945 __ PushList(core_spill_mask_);
946 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
947 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000948 if (fpu_spill_mask_ != 0) {
949 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
950 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100951 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100952 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000953 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100954 int adjust = GetFrameSize() - FrameEntrySpillSize();
955 __ AddConstant(SP, -adjust);
956 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100957 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000958}
959
960void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000961 if (HasEmptyFrame()) {
962 __ bx(LR);
963 return;
964 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100965 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100966 int adjust = GetFrameSize() - FrameEntrySpillSize();
967 __ AddConstant(SP, adjust);
968 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000969 if (fpu_spill_mask_ != 0) {
970 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
971 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
Andreas Gampe542451c2016-07-26 09:02:02 -0700972 __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100973 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000974 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700975 // Pop LR into PC to return.
976 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
977 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
978 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100979 __ cfi().RestoreState();
980 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000981}
982
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100983void CodeGeneratorARM::Bind(HBasicBlock* block) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700984 Label* label = GetLabelOf(block);
985 __ BindTrackedLabel(label);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000986}
987
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100988Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100989 switch (type) {
990 case Primitive::kPrimBoolean:
991 case Primitive::kPrimByte:
992 case Primitive::kPrimChar:
993 case Primitive::kPrimShort:
994 case Primitive::kPrimInt:
995 case Primitive::kPrimNot: {
996 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000997 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100998 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100999 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001000 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001001 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001002 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001003 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001004
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001005 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001006 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001007 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001008 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001009 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001010 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001011 if (calling_convention.GetRegisterAt(index) == R1) {
1012 // Skip R1, and use R2_R3 instead.
1013 gp_index_++;
1014 index++;
1015 }
1016 }
1017 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
1018 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001019 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +01001020
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001021 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001022 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001023 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001024 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
1025 }
1026 }
1027
1028 case Primitive::kPrimFloat: {
1029 uint32_t stack_index = stack_index_++;
1030 if (float_index_ % 2 == 0) {
1031 float_index_ = std::max(double_index_, float_index_);
1032 }
1033 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
1034 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
1035 } else {
1036 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
1037 }
1038 }
1039
1040 case Primitive::kPrimDouble: {
1041 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
1042 uint32_t stack_index = stack_index_;
1043 stack_index_ += 2;
1044 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
1045 uint32_t index = double_index_;
1046 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001047 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001048 calling_convention.GetFpuRegisterAt(index),
1049 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001050 DCHECK(ExpectedPairLayout(result));
1051 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001052 } else {
1053 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001054 }
1055 }
1056
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001057 case Primitive::kPrimVoid:
1058 LOG(FATAL) << "Unexpected parameter type " << type;
1059 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001060 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001061 return Location::NoLocation();
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001062}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001063
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001064Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001065 switch (type) {
1066 case Primitive::kPrimBoolean:
1067 case Primitive::kPrimByte:
1068 case Primitive::kPrimChar:
1069 case Primitive::kPrimShort:
1070 case Primitive::kPrimInt:
1071 case Primitive::kPrimNot: {
1072 return Location::RegisterLocation(R0);
1073 }
1074
1075 case Primitive::kPrimFloat: {
1076 return Location::FpuRegisterLocation(S0);
1077 }
1078
1079 case Primitive::kPrimLong: {
1080 return Location::RegisterPairLocation(R0, R1);
1081 }
1082
1083 case Primitive::kPrimDouble: {
1084 return Location::FpuRegisterPairLocation(S0, S1);
1085 }
1086
1087 case Primitive::kPrimVoid:
Roland Levillain3b359c72015-11-17 19:35:12 +00001088 return Location::NoLocation();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001089 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +01001090
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001091 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001092}
1093
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001094Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
1095 return Location::RegisterLocation(kMethodRegisterArgument);
1096}
1097
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001098void CodeGeneratorARM::Move32(Location destination, Location source) {
1099 if (source.Equals(destination)) {
1100 return;
1101 }
1102 if (destination.IsRegister()) {
1103 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001104 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001105 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001106 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001107 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001108 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001109 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001110 } else if (destination.IsFpuRegister()) {
1111 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001112 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001113 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001114 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001115 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001116 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001117 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001118 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001119 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001120 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001121 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001122 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001123 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001124 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001125 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001126 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1127 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001128 }
1129 }
1130}
1131
1132void CodeGeneratorARM::Move64(Location destination, Location source) {
1133 if (source.Equals(destination)) {
1134 return;
1135 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001136 if (destination.IsRegisterPair()) {
1137 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001138 EmitParallelMoves(
1139 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
1140 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001141 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001142 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001143 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
1144 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001145 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001146 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001147 } else if (source.IsFpuRegisterPair()) {
1148 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
1149 destination.AsRegisterPairHigh<Register>(),
1150 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001151 } else {
1152 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001153 DCHECK(ExpectedPairLayout(destination));
1154 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
1155 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001156 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001157 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001158 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001159 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1160 SP,
1161 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001162 } else if (source.IsRegisterPair()) {
1163 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1164 source.AsRegisterPairLow<Register>(),
1165 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001166 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001167 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001168 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001169 } else {
1170 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001171 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001172 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001173 if (source.AsRegisterPairLow<Register>() == R1) {
1174 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001175 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
1176 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001177 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001178 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001179 SP, destination.GetStackIndex());
1180 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001181 } else if (source.IsFpuRegisterPair()) {
1182 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
1183 SP,
1184 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001185 } else {
1186 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001187 EmitParallelMoves(
1188 Location::StackSlot(source.GetStackIndex()),
1189 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001190 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001191 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001192 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
1193 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001194 }
1195 }
1196}
1197
Calin Juravle175dc732015-08-25 15:42:32 +01001198void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1199 DCHECK(location.IsRegister());
1200 __ LoadImmediate(location.AsRegister<Register>(), value);
1201}
1202
Calin Juravlee460d1d2015-09-29 04:52:17 +01001203void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001204 HParallelMove move(GetGraph()->GetArena());
1205 move.AddMove(src, dst, dst_type, nullptr);
1206 GetMoveResolver()->EmitNativeCode(&move);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001207}
1208
1209void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1210 if (location.IsRegister()) {
1211 locations->AddTemp(location);
1212 } else if (location.IsRegisterPair()) {
1213 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1214 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1215 } else {
1216 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1217 }
1218}
1219
Calin Juravle175dc732015-08-25 15:42:32 +01001220void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1221 HInstruction* instruction,
1222 uint32_t dex_pc,
1223 SlowPathCode* slow_path) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001224 InvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value(),
Calin Juravle175dc732015-08-25 15:42:32 +01001225 instruction,
1226 dex_pc,
1227 slow_path);
1228}
1229
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001230void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
1231 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001232 uint32_t dex_pc,
1233 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001234 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001235 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1236 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001237 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001238}
1239
Roland Levillaindec8f632016-07-22 17:10:06 +01001240void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1241 HInstruction* instruction,
1242 SlowPathCode* slow_path) {
1243 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1244 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1245 __ blx(LR);
1246}
1247
David Brazdilfc6a86a2015-06-26 10:33:45 +00001248void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001249 DCHECK(!successor->IsExitBlock());
1250
1251 HBasicBlock* block = got->GetBlock();
1252 HInstruction* previous = got->GetPrevious();
1253
1254 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001255 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001256 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1257 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1258 return;
1259 }
1260
1261 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1262 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1263 }
1264 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001265 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001266 }
1267}
1268
David Brazdilfc6a86a2015-06-26 10:33:45 +00001269void LocationsBuilderARM::VisitGoto(HGoto* got) {
1270 got->SetLocations(nullptr);
1271}
1272
1273void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1274 HandleGoto(got, got->GetSuccessor());
1275}
1276
1277void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1278 try_boundary->SetLocations(nullptr);
1279}
1280
1281void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1282 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1283 if (!successor->IsExitBlock()) {
1284 HandleGoto(try_boundary, successor);
1285 }
1286}
1287
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001288void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001289 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001290}
1291
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001292void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001293}
1294
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001295void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1296 Primitive::Type type = instruction->InputAt(0)->GetType();
1297 Location lhs_loc = instruction->GetLocations()->InAt(0);
1298 Location rhs_loc = instruction->GetLocations()->InAt(1);
1299 if (rhs_loc.IsConstant()) {
1300 // 0.0 is the only immediate that can be encoded directly in
1301 // a VCMP instruction.
1302 //
1303 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1304 // specify that in a floating-point comparison, positive zero
1305 // and negative zero are considered equal, so we can use the
1306 // literal 0.0 for both cases here.
1307 //
1308 // Note however that some methods (Float.equal, Float.compare,
1309 // Float.compareTo, Double.equal, Double.compare,
1310 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1311 // StrictMath.min) consider 0.0 to be (strictly) greater than
1312 // -0.0. So if we ever translate calls to these methods into a
1313 // HCompare instruction, we must handle the -0.0 case with
1314 // care here.
1315 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1316 if (type == Primitive::kPrimFloat) {
1317 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1318 } else {
1319 DCHECK_EQ(type, Primitive::kPrimDouble);
1320 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1321 }
1322 } else {
1323 if (type == Primitive::kPrimFloat) {
1324 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1325 } else {
1326 DCHECK_EQ(type, Primitive::kPrimDouble);
1327 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1328 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1329 }
1330 }
1331}
1332
Roland Levillain4fa13f62015-07-06 18:11:54 +01001333void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1334 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001335 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001336 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001337 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001338}
1339
1340void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1341 Label* true_label,
1342 Label* false_label) {
1343 LocationSummary* locations = cond->GetLocations();
1344 Location left = locations->InAt(0);
1345 Location right = locations->InAt(1);
1346 IfCondition if_cond = cond->GetCondition();
1347
1348 Register left_high = left.AsRegisterPairHigh<Register>();
1349 Register left_low = left.AsRegisterPairLow<Register>();
1350 IfCondition true_high_cond = if_cond;
1351 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001352 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001353
1354 // Set the conditions for the test, remembering that == needs to be
1355 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001356 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001357 switch (if_cond) {
1358 case kCondEQ:
1359 case kCondNE:
1360 // Nothing to do.
1361 break;
1362 case kCondLT:
1363 false_high_cond = kCondGT;
1364 break;
1365 case kCondLE:
1366 true_high_cond = kCondLT;
1367 break;
1368 case kCondGT:
1369 false_high_cond = kCondLT;
1370 break;
1371 case kCondGE:
1372 true_high_cond = kCondGT;
1373 break;
Aart Bike9f37602015-10-09 11:15:55 -07001374 case kCondB:
1375 false_high_cond = kCondA;
1376 break;
1377 case kCondBE:
1378 true_high_cond = kCondB;
1379 break;
1380 case kCondA:
1381 false_high_cond = kCondB;
1382 break;
1383 case kCondAE:
1384 true_high_cond = kCondA;
1385 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001386 }
1387 if (right.IsConstant()) {
1388 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1389 int32_t val_low = Low32Bits(value);
1390 int32_t val_high = High32Bits(value);
1391
Vladimir Markoac6ac102015-12-17 12:14:00 +00001392 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001393 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001394 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001395 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001396 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001397 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001398 __ b(true_label, ARMCondition(true_high_cond));
1399 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001400 }
1401 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001402 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001403 } else {
1404 Register right_high = right.AsRegisterPairHigh<Register>();
1405 Register right_low = right.AsRegisterPairLow<Register>();
1406
1407 __ cmp(left_high, ShifterOperand(right_high));
1408 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001409 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001410 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001411 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001412 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001413 __ b(true_label, ARMCondition(true_high_cond));
1414 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001415 }
1416 // Must be equal high, so compare the lows.
1417 __ cmp(left_low, ShifterOperand(right_low));
1418 }
1419 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001420 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001421 __ b(true_label, final_condition);
1422}
1423
David Brazdil0debae72015-11-12 18:37:00 +00001424void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1425 Label* true_target_in,
1426 Label* false_target_in) {
1427 // Generated branching requires both targets to be explicit. If either of the
1428 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1429 Label fallthrough_target;
1430 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1431 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1432
Roland Levillain4fa13f62015-07-06 18:11:54 +01001433 Primitive::Type type = condition->InputAt(0)->GetType();
1434 switch (type) {
1435 case Primitive::kPrimLong:
1436 GenerateLongComparesAndJumps(condition, true_target, false_target);
1437 break;
1438 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001439 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001440 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001441 GenerateFPJumps(condition, true_target, false_target);
1442 break;
1443 default:
1444 LOG(FATAL) << "Unexpected compare type " << type;
1445 }
1446
David Brazdil0debae72015-11-12 18:37:00 +00001447 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001448 __ b(false_target);
1449 }
David Brazdil0debae72015-11-12 18:37:00 +00001450
1451 if (fallthrough_target.IsLinked()) {
1452 __ Bind(&fallthrough_target);
1453 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001454}
1455
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001456void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001457 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001458 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001459 Label* false_target) {
1460 HInstruction* cond = instruction->InputAt(condition_input_index);
1461
1462 if (true_target == nullptr && false_target == nullptr) {
1463 // Nothing to do. The code always falls through.
1464 return;
1465 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001466 // Constant condition, statically compared against "true" (integer value 1).
1467 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001468 if (true_target != nullptr) {
1469 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001470 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001471 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001472 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001473 if (false_target != nullptr) {
1474 __ b(false_target);
1475 }
1476 }
1477 return;
1478 }
1479
1480 // The following code generates these patterns:
1481 // (1) true_target == nullptr && false_target != nullptr
1482 // - opposite condition true => branch to false_target
1483 // (2) true_target != nullptr && false_target == nullptr
1484 // - condition true => branch to true_target
1485 // (3) true_target != nullptr && false_target != nullptr
1486 // - condition true => branch to true_target
1487 // - branch to false_target
1488 if (IsBooleanValueOrMaterializedCondition(cond)) {
1489 // Condition has been materialized, compare the output to 0.
1490 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1491 DCHECK(cond_val.IsRegister());
1492 if (true_target == nullptr) {
1493 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1494 } else {
1495 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001496 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001497 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001498 // Condition has not been materialized. Use its inputs as the comparison and
1499 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001500 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001501
1502 // If this is a long or FP comparison that has been folded into
1503 // the HCondition, generate the comparison directly.
1504 Primitive::Type type = condition->InputAt(0)->GetType();
1505 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1506 GenerateCompareTestAndBranch(condition, true_target, false_target);
1507 return;
1508 }
1509
1510 LocationSummary* locations = cond->GetLocations();
1511 DCHECK(locations->InAt(0).IsRegister());
1512 Register left = locations->InAt(0).AsRegister<Register>();
1513 Location right = locations->InAt(1);
1514 if (right.IsRegister()) {
1515 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001516 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001517 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001518 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001519 }
1520 if (true_target == nullptr) {
1521 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1522 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001523 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001524 }
Dave Allison20dfc792014-06-16 20:44:29 -07001525 }
David Brazdil0debae72015-11-12 18:37:00 +00001526
1527 // If neither branch falls through (case 3), the conditional branch to `true_target`
1528 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1529 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001530 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001531 }
1532}
1533
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001534void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001535 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1536 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001537 locations->SetInAt(0, Location::RequiresRegister());
1538 }
1539}
1540
1541void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001542 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1543 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1544 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1545 nullptr : codegen_->GetLabelOf(true_successor);
1546 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1547 nullptr : codegen_->GetLabelOf(false_successor);
1548 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001549}
1550
1551void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1552 LocationSummary* locations = new (GetGraph()->GetArena())
1553 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00001554 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001555 locations->SetInAt(0, Location::RequiresRegister());
1556 }
1557}
1558
1559void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08001560 SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001561 GenerateTestAndBranch(deoptimize,
1562 /* condition_input_index */ 0,
1563 slow_path->GetEntryLabel(),
1564 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001565}
Dave Allison20dfc792014-06-16 20:44:29 -07001566
David Brazdil74eb1b22015-12-14 11:44:01 +00001567void LocationsBuilderARM::VisitSelect(HSelect* select) {
1568 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1569 if (Primitive::IsFloatingPointType(select->GetType())) {
1570 locations->SetInAt(0, Location::RequiresFpuRegister());
1571 locations->SetInAt(1, Location::RequiresFpuRegister());
1572 } else {
1573 locations->SetInAt(0, Location::RequiresRegister());
1574 locations->SetInAt(1, Location::RequiresRegister());
1575 }
1576 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1577 locations->SetInAt(2, Location::RequiresRegister());
1578 }
1579 locations->SetOut(Location::SameAsFirstInput());
1580}
1581
1582void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1583 LocationSummary* locations = select->GetLocations();
1584 Label false_target;
1585 GenerateTestAndBranch(select,
1586 /* condition_input_index */ 2,
1587 /* true_target */ nullptr,
1588 &false_target);
1589 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1590 __ Bind(&false_target);
1591}
1592
David Srbecky0cf44932015-12-09 14:09:59 +00001593void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1594 new (GetGraph()->GetArena()) LocationSummary(info);
1595}
1596
David Srbeckyd28f4a02016-03-14 17:14:24 +00001597void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1598 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001599}
1600
1601void CodeGeneratorARM::GenerateNop() {
1602 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001603}
1604
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001605void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001606 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001607 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001608 // Handle the long/FP comparisons made in instruction simplification.
1609 switch (cond->InputAt(0)->GetType()) {
1610 case Primitive::kPrimLong:
1611 locations->SetInAt(0, Location::RequiresRegister());
1612 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001613 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001614 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1615 }
1616 break;
1617
1618 case Primitive::kPrimFloat:
1619 case Primitive::kPrimDouble:
1620 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001621 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001622 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001623 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1624 }
1625 break;
1626
1627 default:
1628 locations->SetInAt(0, Location::RequiresRegister());
1629 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001630 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001631 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1632 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001633 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001634}
1635
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001636void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001637 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001638 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001639 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001640
1641 LocationSummary* locations = cond->GetLocations();
1642 Location left = locations->InAt(0);
1643 Location right = locations->InAt(1);
1644 Register out = locations->Out().AsRegister<Register>();
1645 Label true_label, false_label;
1646
1647 switch (cond->InputAt(0)->GetType()) {
1648 default: {
1649 // Integer case.
1650 if (right.IsRegister()) {
1651 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1652 } else {
1653 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001654 __ CmpConstant(left.AsRegister<Register>(),
1655 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001656 }
Aart Bike9f37602015-10-09 11:15:55 -07001657 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001658 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001659 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001660 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001661 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001662 return;
1663 }
1664 case Primitive::kPrimLong:
1665 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1666 break;
1667 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001668 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001669 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001670 GenerateFPJumps(cond, &true_label, &false_label);
1671 break;
1672 }
1673
1674 // Convert the jumps into the result.
1675 Label done_label;
1676
1677 // False case: result = 0.
1678 __ Bind(&false_label);
1679 __ LoadImmediate(out, 0);
1680 __ b(&done_label);
1681
1682 // True case: result = 1.
1683 __ Bind(&true_label);
1684 __ LoadImmediate(out, 1);
1685 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001686}
1687
1688void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001689 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001690}
1691
1692void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001693 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001694}
1695
1696void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001697 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001698}
1699
1700void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001701 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001702}
1703
1704void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001705 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001706}
1707
1708void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001709 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001710}
1711
1712void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001713 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001714}
1715
1716void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001717 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001718}
1719
1720void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001721 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001722}
1723
1724void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001725 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001726}
1727
1728void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001729 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001730}
1731
1732void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001733 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001734}
1735
Aart Bike9f37602015-10-09 11:15:55 -07001736void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001737 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001738}
1739
1740void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001741 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001742}
1743
1744void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001745 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001746}
1747
1748void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001749 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001750}
1751
1752void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001753 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001754}
1755
1756void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001757 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001758}
1759
1760void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001761 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001762}
1763
1764void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001765 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001766}
1767
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001768void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001769 LocationSummary* locations =
1770 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001771 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001772}
1773
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001774void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001775 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001776}
1777
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001778void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1779 LocationSummary* locations =
1780 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1781 locations->SetOut(Location::ConstantLocation(constant));
1782}
1783
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001784void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001785 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001786}
1787
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001788void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001789 LocationSummary* locations =
1790 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001791 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001792}
1793
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001794void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001795 // Will be generated at use site.
1796}
1797
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001798void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1799 LocationSummary* locations =
1800 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1801 locations->SetOut(Location::ConstantLocation(constant));
1802}
1803
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001804void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001805 // Will be generated at use site.
1806}
1807
1808void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1809 LocationSummary* locations =
1810 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1811 locations->SetOut(Location::ConstantLocation(constant));
1812}
1813
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001814void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001815 // Will be generated at use site.
1816}
1817
Calin Juravle27df7582015-04-17 19:12:31 +01001818void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1819 memory_barrier->SetLocations(nullptr);
1820}
1821
1822void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00001823 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01001824}
1825
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001826void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001827 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001828}
1829
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001830void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001831 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001832}
1833
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001834void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001835 LocationSummary* locations =
1836 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001837 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001838}
1839
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001840void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001841 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001842}
1843
Calin Juravle175dc732015-08-25 15:42:32 +01001844void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1845 // The trampoline uses the same calling convention as dex calling conventions,
1846 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1847 // the method_idx.
1848 HandleInvoke(invoke);
1849}
1850
1851void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1852 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1853}
1854
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001855void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001856 // Explicit clinit checks triggered by static invokes must have been pruned by
1857 // art::PrepareForRegisterAllocation.
1858 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001859
Vladimir Marko68c981f2016-08-26 13:13:33 +01001860 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001861 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00001862 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
1863 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
1864 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001865 return;
1866 }
1867
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001868 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00001869
1870 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
1871 if (invoke->HasPcRelativeDexCache()) {
1872 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
1873 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001874}
1875
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001876static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1877 if (invoke->GetLocations()->Intrinsified()) {
1878 IntrinsicCodeGeneratorARM intrinsic(codegen);
1879 intrinsic.Dispatch(invoke);
1880 return true;
1881 }
1882 return false;
1883}
1884
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001885void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001886 // Explicit clinit checks triggered by static invokes must have been pruned by
1887 // art::PrepareForRegisterAllocation.
1888 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001889
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001890 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1891 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001892 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001893
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001894 LocationSummary* locations = invoke->GetLocations();
1895 codegen_->GenerateStaticOrDirectCall(
1896 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001897 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001898}
1899
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001900void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001901 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001902 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001903}
1904
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001905void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Vladimir Marko68c981f2016-08-26 13:13:33 +01001906 IntrinsicLocationsBuilderARM intrinsic(codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001907 if (intrinsic.TryDispatch(invoke)) {
1908 return;
1909 }
1910
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001911 HandleInvoke(invoke);
1912}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001913
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001914void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001915 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1916 return;
1917 }
1918
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001919 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001920 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001921 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001922}
1923
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001924void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1925 HandleInvoke(invoke);
1926 // Add the hidden argument.
1927 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1928}
1929
1930void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1931 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00001932 LocationSummary* locations = invoke->GetLocations();
1933 Register temp = locations->GetTemp(0).AsRegister<Register>();
1934 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001935 Location receiver = locations->InAt(0);
1936 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1937
Roland Levillain3b359c72015-11-17 19:35:12 +00001938 // Set the hidden argument. This is safe to do this here, as R12
1939 // won't be modified thereafter, before the `blx` (call) instruction.
1940 DCHECK_EQ(R12, hidden_reg);
1941 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001942
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001943 if (receiver.IsStackSlot()) {
1944 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00001945 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001946 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1947 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00001948 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00001949 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001950 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001951 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00001952 // Instead of simply (possibly) unpoisoning `temp` here, we should
1953 // emit a read barrier for the previous class reference load.
1954 // However this is not required in practice, as this is an
1955 // intermediate/temporary reference and because the current
1956 // concurrent copying collector keeps the from-space memory
1957 // intact/accessible until the end of the marking phase (the
1958 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01001959 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001960 __ LoadFromOffset(kLoadWord, temp, temp,
1961 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
1962 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00001963 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001964 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001965 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00001966 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07001967 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001968 // LR = temp->GetEntryPoint();
1969 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1970 // LR();
1971 __ blx(LR);
1972 DCHECK(!codegen_->IsLeafMethod());
1973 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1974}
1975
Roland Levillain88cb1752014-10-20 16:36:47 +01001976void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1977 LocationSummary* locations =
1978 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1979 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001980 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001981 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001982 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1983 break;
1984 }
1985 case Primitive::kPrimLong: {
1986 locations->SetInAt(0, Location::RequiresRegister());
1987 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001988 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001989 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001990
Roland Levillain88cb1752014-10-20 16:36:47 +01001991 case Primitive::kPrimFloat:
1992 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001993 locations->SetInAt(0, Location::RequiresFpuRegister());
1994 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001995 break;
1996
1997 default:
1998 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1999 }
2000}
2001
2002void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
2003 LocationSummary* locations = neg->GetLocations();
2004 Location out = locations->Out();
2005 Location in = locations->InAt(0);
2006 switch (neg->GetResultType()) {
2007 case Primitive::kPrimInt:
2008 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002009 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01002010 break;
2011
2012 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002013 DCHECK(in.IsRegisterPair());
2014 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
2015 __ rsbs(out.AsRegisterPairLow<Register>(),
2016 in.AsRegisterPairLow<Register>(),
2017 ShifterOperand(0));
2018 // We cannot emit an RSC (Reverse Subtract with Carry)
2019 // instruction here, as it does not exist in the Thumb-2
2020 // instruction set. We use the following approach
2021 // using SBC and SUB instead.
2022 //
2023 // out.hi = -C
2024 __ sbc(out.AsRegisterPairHigh<Register>(),
2025 out.AsRegisterPairHigh<Register>(),
2026 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2027 // out.hi = out.hi - in.hi
2028 __ sub(out.AsRegisterPairHigh<Register>(),
2029 out.AsRegisterPairHigh<Register>(),
2030 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2031 break;
2032
Roland Levillain88cb1752014-10-20 16:36:47 +01002033 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002034 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002035 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002036 break;
2037
Roland Levillain88cb1752014-10-20 16:36:47 +01002038 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002039 DCHECK(in.IsFpuRegisterPair());
2040 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2041 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002042 break;
2043
2044 default:
2045 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2046 }
2047}
2048
Roland Levillaindff1f282014-11-05 14:15:05 +00002049void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002050 Primitive::Type result_type = conversion->GetResultType();
2051 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002052 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002053
Roland Levillain5b3ee562015-04-14 16:02:41 +01002054 // The float-to-long, double-to-long and long-to-float type conversions
2055 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002056 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002057 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2058 && result_type == Primitive::kPrimLong)
2059 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002060 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002061 : LocationSummary::kNoCall;
2062 LocationSummary* locations =
2063 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2064
David Brazdilb2bd1c52015-03-25 11:17:37 +00002065 // The Java language does not allow treating boolean as an integral type but
2066 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002067
Roland Levillaindff1f282014-11-05 14:15:05 +00002068 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002069 case Primitive::kPrimByte:
2070 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002071 case Primitive::kPrimLong:
2072 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002073 case Primitive::kPrimBoolean:
2074 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002075 case Primitive::kPrimShort:
2076 case Primitive::kPrimInt:
2077 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002078 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002079 locations->SetInAt(0, Location::RequiresRegister());
2080 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2081 break;
2082
2083 default:
2084 LOG(FATAL) << "Unexpected type conversion from " << input_type
2085 << " to " << result_type;
2086 }
2087 break;
2088
Roland Levillain01a8d712014-11-14 16:27:39 +00002089 case Primitive::kPrimShort:
2090 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002091 case Primitive::kPrimLong:
2092 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002093 case Primitive::kPrimBoolean:
2094 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002095 case Primitive::kPrimByte:
2096 case Primitive::kPrimInt:
2097 case Primitive::kPrimChar:
2098 // Processing a Dex `int-to-short' instruction.
2099 locations->SetInAt(0, Location::RequiresRegister());
2100 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2101 break;
2102
2103 default:
2104 LOG(FATAL) << "Unexpected type conversion from " << input_type
2105 << " to " << result_type;
2106 }
2107 break;
2108
Roland Levillain946e1432014-11-11 17:35:19 +00002109 case Primitive::kPrimInt:
2110 switch (input_type) {
2111 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002112 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002113 locations->SetInAt(0, Location::Any());
2114 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2115 break;
2116
2117 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002118 // Processing a Dex `float-to-int' instruction.
2119 locations->SetInAt(0, Location::RequiresFpuRegister());
2120 locations->SetOut(Location::RequiresRegister());
2121 locations->AddTemp(Location::RequiresFpuRegister());
2122 break;
2123
Roland Levillain946e1432014-11-11 17:35:19 +00002124 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002125 // Processing a Dex `double-to-int' instruction.
2126 locations->SetInAt(0, Location::RequiresFpuRegister());
2127 locations->SetOut(Location::RequiresRegister());
2128 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002129 break;
2130
2131 default:
2132 LOG(FATAL) << "Unexpected type conversion from " << input_type
2133 << " to " << result_type;
2134 }
2135 break;
2136
Roland Levillaindff1f282014-11-05 14:15:05 +00002137 case Primitive::kPrimLong:
2138 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002139 case Primitive::kPrimBoolean:
2140 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002141 case Primitive::kPrimByte:
2142 case Primitive::kPrimShort:
2143 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002144 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002145 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002146 locations->SetInAt(0, Location::RequiresRegister());
2147 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2148 break;
2149
Roland Levillain624279f2014-12-04 11:54:28 +00002150 case Primitive::kPrimFloat: {
2151 // Processing a Dex `float-to-long' instruction.
2152 InvokeRuntimeCallingConvention calling_convention;
2153 locations->SetInAt(0, Location::FpuRegisterLocation(
2154 calling_convention.GetFpuRegisterAt(0)));
2155 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2156 break;
2157 }
2158
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002159 case Primitive::kPrimDouble: {
2160 // Processing a Dex `double-to-long' instruction.
2161 InvokeRuntimeCallingConvention calling_convention;
2162 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2163 calling_convention.GetFpuRegisterAt(0),
2164 calling_convention.GetFpuRegisterAt(1)));
2165 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002166 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002167 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002168
2169 default:
2170 LOG(FATAL) << "Unexpected type conversion from " << input_type
2171 << " to " << result_type;
2172 }
2173 break;
2174
Roland Levillain981e4542014-11-14 11:47:14 +00002175 case Primitive::kPrimChar:
2176 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002177 case Primitive::kPrimLong:
2178 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002179 case Primitive::kPrimBoolean:
2180 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002181 case Primitive::kPrimByte:
2182 case Primitive::kPrimShort:
2183 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002184 // Processing a Dex `int-to-char' instruction.
2185 locations->SetInAt(0, Location::RequiresRegister());
2186 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2187 break;
2188
2189 default:
2190 LOG(FATAL) << "Unexpected type conversion from " << input_type
2191 << " to " << result_type;
2192 }
2193 break;
2194
Roland Levillaindff1f282014-11-05 14:15:05 +00002195 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002196 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002197 case Primitive::kPrimBoolean:
2198 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002199 case Primitive::kPrimByte:
2200 case Primitive::kPrimShort:
2201 case Primitive::kPrimInt:
2202 case Primitive::kPrimChar:
2203 // Processing a Dex `int-to-float' instruction.
2204 locations->SetInAt(0, Location::RequiresRegister());
2205 locations->SetOut(Location::RequiresFpuRegister());
2206 break;
2207
Roland Levillain5b3ee562015-04-14 16:02:41 +01002208 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002209 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002210 InvokeRuntimeCallingConvention calling_convention;
2211 locations->SetInAt(0, Location::RegisterPairLocation(
2212 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2213 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002214 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002215 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002216
Roland Levillaincff13742014-11-17 14:32:17 +00002217 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002218 // Processing a Dex `double-to-float' instruction.
2219 locations->SetInAt(0, Location::RequiresFpuRegister());
2220 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002221 break;
2222
2223 default:
2224 LOG(FATAL) << "Unexpected type conversion from " << input_type
2225 << " to " << result_type;
2226 };
2227 break;
2228
Roland Levillaindff1f282014-11-05 14:15:05 +00002229 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002230 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002231 case Primitive::kPrimBoolean:
2232 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002233 case Primitive::kPrimByte:
2234 case Primitive::kPrimShort:
2235 case Primitive::kPrimInt:
2236 case Primitive::kPrimChar:
2237 // Processing a Dex `int-to-double' instruction.
2238 locations->SetInAt(0, Location::RequiresRegister());
2239 locations->SetOut(Location::RequiresFpuRegister());
2240 break;
2241
2242 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002243 // Processing a Dex `long-to-double' instruction.
2244 locations->SetInAt(0, Location::RequiresRegister());
2245 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002246 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002247 locations->AddTemp(Location::RequiresFpuRegister());
2248 break;
2249
Roland Levillaincff13742014-11-17 14:32:17 +00002250 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002251 // Processing a Dex `float-to-double' instruction.
2252 locations->SetInAt(0, Location::RequiresFpuRegister());
2253 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002254 break;
2255
2256 default:
2257 LOG(FATAL) << "Unexpected type conversion from " << input_type
2258 << " to " << result_type;
2259 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002260 break;
2261
2262 default:
2263 LOG(FATAL) << "Unexpected type conversion from " << input_type
2264 << " to " << result_type;
2265 }
2266}
2267
2268void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2269 LocationSummary* locations = conversion->GetLocations();
2270 Location out = locations->Out();
2271 Location in = locations->InAt(0);
2272 Primitive::Type result_type = conversion->GetResultType();
2273 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002274 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002275 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002276 case Primitive::kPrimByte:
2277 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002278 case Primitive::kPrimLong:
2279 // Type conversion from long to byte is a result of code transformations.
2280 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2281 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002282 case Primitive::kPrimBoolean:
2283 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002284 case Primitive::kPrimShort:
2285 case Primitive::kPrimInt:
2286 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002287 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002288 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002289 break;
2290
2291 default:
2292 LOG(FATAL) << "Unexpected type conversion from " << input_type
2293 << " to " << result_type;
2294 }
2295 break;
2296
Roland Levillain01a8d712014-11-14 16:27:39 +00002297 case Primitive::kPrimShort:
2298 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002299 case Primitive::kPrimLong:
2300 // Type conversion from long to short is a result of code transformations.
2301 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2302 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002303 case Primitive::kPrimBoolean:
2304 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002305 case Primitive::kPrimByte:
2306 case Primitive::kPrimInt:
2307 case Primitive::kPrimChar:
2308 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002309 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002310 break;
2311
2312 default:
2313 LOG(FATAL) << "Unexpected type conversion from " << input_type
2314 << " to " << result_type;
2315 }
2316 break;
2317
Roland Levillain946e1432014-11-11 17:35:19 +00002318 case Primitive::kPrimInt:
2319 switch (input_type) {
2320 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002321 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002322 DCHECK(out.IsRegister());
2323 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002324 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002325 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002326 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002327 } else {
2328 DCHECK(in.IsConstant());
2329 DCHECK(in.GetConstant()->IsLongConstant());
2330 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002331 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002332 }
2333 break;
2334
Roland Levillain3f8f9362014-12-02 17:45:01 +00002335 case Primitive::kPrimFloat: {
2336 // Processing a Dex `float-to-int' instruction.
2337 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002338 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002339 __ vmovrs(out.AsRegister<Register>(), temp);
2340 break;
2341 }
2342
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002343 case Primitive::kPrimDouble: {
2344 // Processing a Dex `double-to-int' instruction.
2345 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002346 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002347 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002348 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002349 }
Roland Levillain946e1432014-11-11 17:35:19 +00002350
2351 default:
2352 LOG(FATAL) << "Unexpected type conversion from " << input_type
2353 << " to " << result_type;
2354 }
2355 break;
2356
Roland Levillaindff1f282014-11-05 14:15:05 +00002357 case Primitive::kPrimLong:
2358 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002359 case Primitive::kPrimBoolean:
2360 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002361 case Primitive::kPrimByte:
2362 case Primitive::kPrimShort:
2363 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002364 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002365 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002366 DCHECK(out.IsRegisterPair());
2367 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002368 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002369 // Sign extension.
2370 __ Asr(out.AsRegisterPairHigh<Register>(),
2371 out.AsRegisterPairLow<Register>(),
2372 31);
2373 break;
2374
2375 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002376 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002377 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2378 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002379 conversion->GetDexPc(),
2380 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002381 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002382 break;
2383
Roland Levillaindff1f282014-11-05 14:15:05 +00002384 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002385 // Processing a Dex `double-to-long' instruction.
2386 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2387 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002388 conversion->GetDexPc(),
2389 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002390 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002391 break;
2392
2393 default:
2394 LOG(FATAL) << "Unexpected type conversion from " << input_type
2395 << " to " << result_type;
2396 }
2397 break;
2398
Roland Levillain981e4542014-11-14 11:47:14 +00002399 case Primitive::kPrimChar:
2400 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002401 case Primitive::kPrimLong:
2402 // Type conversion from long to char is a result of code transformations.
2403 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2404 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002405 case Primitive::kPrimBoolean:
2406 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002407 case Primitive::kPrimByte:
2408 case Primitive::kPrimShort:
2409 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002410 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002411 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002412 break;
2413
2414 default:
2415 LOG(FATAL) << "Unexpected type conversion from " << input_type
2416 << " to " << result_type;
2417 }
2418 break;
2419
Roland Levillaindff1f282014-11-05 14:15:05 +00002420 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002421 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002422 case Primitive::kPrimBoolean:
2423 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002424 case Primitive::kPrimByte:
2425 case Primitive::kPrimShort:
2426 case Primitive::kPrimInt:
2427 case Primitive::kPrimChar: {
2428 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002429 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2430 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002431 break;
2432 }
2433
Roland Levillain5b3ee562015-04-14 16:02:41 +01002434 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002435 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002436 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2437 conversion,
2438 conversion->GetDexPc(),
2439 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002440 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002441 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002442
Roland Levillaincff13742014-11-17 14:32:17 +00002443 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002444 // Processing a Dex `double-to-float' instruction.
2445 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2446 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002447 break;
2448
2449 default:
2450 LOG(FATAL) << "Unexpected type conversion from " << input_type
2451 << " to " << result_type;
2452 };
2453 break;
2454
Roland Levillaindff1f282014-11-05 14:15:05 +00002455 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002456 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002457 case Primitive::kPrimBoolean:
2458 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002459 case Primitive::kPrimByte:
2460 case Primitive::kPrimShort:
2461 case Primitive::kPrimInt:
2462 case Primitive::kPrimChar: {
2463 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002464 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002465 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2466 out.AsFpuRegisterPairLow<SRegister>());
2467 break;
2468 }
2469
Roland Levillain647b9ed2014-11-27 12:06:00 +00002470 case Primitive::kPrimLong: {
2471 // Processing a Dex `long-to-double' instruction.
2472 Register low = in.AsRegisterPairLow<Register>();
2473 Register high = in.AsRegisterPairHigh<Register>();
2474 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2475 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002476 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002477 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002478 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2479 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002480
Roland Levillain682393c2015-04-14 15:57:52 +01002481 // temp_d = int-to-double(high)
2482 __ vmovsr(temp_s, high);
2483 __ vcvtdi(temp_d, temp_s);
2484 // constant_d = k2Pow32EncodingForDouble
2485 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2486 // out_d = unsigned-to-double(low)
2487 __ vmovsr(out_s, low);
2488 __ vcvtdu(out_d, out_s);
2489 // out_d += temp_d * constant_d
2490 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002491 break;
2492 }
2493
Roland Levillaincff13742014-11-17 14:32:17 +00002494 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002495 // Processing a Dex `float-to-double' instruction.
2496 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2497 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002498 break;
2499
2500 default:
2501 LOG(FATAL) << "Unexpected type conversion from " << input_type
2502 << " to " << result_type;
2503 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002504 break;
2505
2506 default:
2507 LOG(FATAL) << "Unexpected type conversion from " << input_type
2508 << " to " << result_type;
2509 }
2510}
2511
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002512void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002513 LocationSummary* locations =
2514 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002515 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002516 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002517 locations->SetInAt(0, Location::RequiresRegister());
2518 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002519 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2520 break;
2521 }
2522
2523 case Primitive::kPrimLong: {
2524 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002525 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002526 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002527 break;
2528 }
2529
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002530 case Primitive::kPrimFloat:
2531 case Primitive::kPrimDouble: {
2532 locations->SetInAt(0, Location::RequiresFpuRegister());
2533 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002534 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002535 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002536 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002537
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002538 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002539 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002540 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002541}
2542
2543void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2544 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002545 Location out = locations->Out();
2546 Location first = locations->InAt(0);
2547 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002548 switch (add->GetResultType()) {
2549 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002550 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002551 __ add(out.AsRegister<Register>(),
2552 first.AsRegister<Register>(),
2553 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002554 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002555 __ AddConstant(out.AsRegister<Register>(),
2556 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002557 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002558 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002559 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002560
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002561 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002562 if (second.IsConstant()) {
2563 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2564 GenerateAddLongConst(out, first, value);
2565 } else {
2566 DCHECK(second.IsRegisterPair());
2567 __ adds(out.AsRegisterPairLow<Register>(),
2568 first.AsRegisterPairLow<Register>(),
2569 ShifterOperand(second.AsRegisterPairLow<Register>()));
2570 __ adc(out.AsRegisterPairHigh<Register>(),
2571 first.AsRegisterPairHigh<Register>(),
2572 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2573 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002574 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002575 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002576
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002577 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002578 __ vadds(out.AsFpuRegister<SRegister>(),
2579 first.AsFpuRegister<SRegister>(),
2580 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002581 break;
2582
2583 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002584 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2585 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2586 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002587 break;
2588
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002589 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002590 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002591 }
2592}
2593
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002594void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002595 LocationSummary* locations =
2596 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002597 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002598 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002599 locations->SetInAt(0, Location::RequiresRegister());
2600 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002601 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2602 break;
2603 }
2604
2605 case Primitive::kPrimLong: {
2606 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002607 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002608 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002609 break;
2610 }
Calin Juravle11351682014-10-23 15:38:15 +01002611 case Primitive::kPrimFloat:
2612 case Primitive::kPrimDouble: {
2613 locations->SetInAt(0, Location::RequiresFpuRegister());
2614 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002615 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002616 break;
Calin Juravle11351682014-10-23 15:38:15 +01002617 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002618 default:
Calin Juravle11351682014-10-23 15:38:15 +01002619 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002620 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002621}
2622
2623void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2624 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002625 Location out = locations->Out();
2626 Location first = locations->InAt(0);
2627 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002628 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002629 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002630 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002631 __ sub(out.AsRegister<Register>(),
2632 first.AsRegister<Register>(),
2633 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002634 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002635 __ AddConstant(out.AsRegister<Register>(),
2636 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002637 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002638 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002639 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002640 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002641
Calin Juravle11351682014-10-23 15:38:15 +01002642 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002643 if (second.IsConstant()) {
2644 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2645 GenerateAddLongConst(out, first, -value);
2646 } else {
2647 DCHECK(second.IsRegisterPair());
2648 __ subs(out.AsRegisterPairLow<Register>(),
2649 first.AsRegisterPairLow<Register>(),
2650 ShifterOperand(second.AsRegisterPairLow<Register>()));
2651 __ sbc(out.AsRegisterPairHigh<Register>(),
2652 first.AsRegisterPairHigh<Register>(),
2653 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2654 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002655 break;
Calin Juravle11351682014-10-23 15:38:15 +01002656 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002657
Calin Juravle11351682014-10-23 15:38:15 +01002658 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002659 __ vsubs(out.AsFpuRegister<SRegister>(),
2660 first.AsFpuRegister<SRegister>(),
2661 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002662 break;
Calin Juravle11351682014-10-23 15:38:15 +01002663 }
2664
2665 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002666 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2667 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2668 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002669 break;
2670 }
2671
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002672
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002673 default:
Calin Juravle11351682014-10-23 15:38:15 +01002674 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002675 }
2676}
2677
Calin Juravle34bacdf2014-10-07 20:23:36 +01002678void LocationsBuilderARM::VisitMul(HMul* mul) {
2679 LocationSummary* locations =
2680 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2681 switch (mul->GetResultType()) {
2682 case Primitive::kPrimInt:
2683 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002684 locations->SetInAt(0, Location::RequiresRegister());
2685 locations->SetInAt(1, Location::RequiresRegister());
2686 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002687 break;
2688 }
2689
Calin Juravleb5bfa962014-10-21 18:02:24 +01002690 case Primitive::kPrimFloat:
2691 case Primitive::kPrimDouble: {
2692 locations->SetInAt(0, Location::RequiresFpuRegister());
2693 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002694 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002695 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002696 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002697
2698 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002699 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002700 }
2701}
2702
2703void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2704 LocationSummary* locations = mul->GetLocations();
2705 Location out = locations->Out();
2706 Location first = locations->InAt(0);
2707 Location second = locations->InAt(1);
2708 switch (mul->GetResultType()) {
2709 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002710 __ mul(out.AsRegister<Register>(),
2711 first.AsRegister<Register>(),
2712 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002713 break;
2714 }
2715 case Primitive::kPrimLong: {
2716 Register out_hi = out.AsRegisterPairHigh<Register>();
2717 Register out_lo = out.AsRegisterPairLow<Register>();
2718 Register in1_hi = first.AsRegisterPairHigh<Register>();
2719 Register in1_lo = first.AsRegisterPairLow<Register>();
2720 Register in2_hi = second.AsRegisterPairHigh<Register>();
2721 Register in2_lo = second.AsRegisterPairLow<Register>();
2722
2723 // Extra checks to protect caused by the existence of R1_R2.
2724 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2725 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2726 DCHECK_NE(out_hi, in1_lo);
2727 DCHECK_NE(out_hi, in2_lo);
2728
2729 // input: in1 - 64 bits, in2 - 64 bits
2730 // output: out
2731 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2732 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2733 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2734
2735 // IP <- in1.lo * in2.hi
2736 __ mul(IP, in1_lo, in2_hi);
2737 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2738 __ mla(out_hi, in1_hi, in2_lo, IP);
2739 // out.lo <- (in1.lo * in2.lo)[31:0];
2740 __ umull(out_lo, IP, in1_lo, in2_lo);
2741 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2742 __ add(out_hi, out_hi, ShifterOperand(IP));
2743 break;
2744 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002745
2746 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002747 __ vmuls(out.AsFpuRegister<SRegister>(),
2748 first.AsFpuRegister<SRegister>(),
2749 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002750 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002751 }
2752
2753 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002754 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2755 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2756 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002757 break;
2758 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002759
2760 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002761 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002762 }
2763}
2764
Zheng Xuc6667102015-05-15 16:08:45 +08002765void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(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 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2776 DCHECK(imm == 1 || imm == -1);
2777
2778 if (instruction->IsRem()) {
2779 __ LoadImmediate(out, 0);
2780 } else {
2781 if (imm == 1) {
2782 __ Mov(out, dividend);
2783 } else {
2784 __ rsb(out, dividend, ShifterOperand(0));
2785 }
2786 }
2787}
2788
2789void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2790 DCHECK(instruction->IsDiv() || instruction->IsRem());
2791 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2792
2793 LocationSummary* locations = instruction->GetLocations();
2794 Location second = locations->InAt(1);
2795 DCHECK(second.IsConstant());
2796
2797 Register out = locations->Out().AsRegister<Register>();
2798 Register dividend = locations->InAt(0).AsRegister<Register>();
2799 Register temp = locations->GetTemp(0).AsRegister<Register>();
2800 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002801 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002802 int ctz_imm = CTZ(abs_imm);
2803
2804 if (ctz_imm == 1) {
2805 __ Lsr(temp, dividend, 32 - ctz_imm);
2806 } else {
2807 __ Asr(temp, dividend, 31);
2808 __ Lsr(temp, temp, 32 - ctz_imm);
2809 }
2810 __ add(out, temp, ShifterOperand(dividend));
2811
2812 if (instruction->IsDiv()) {
2813 __ Asr(out, out, ctz_imm);
2814 if (imm < 0) {
2815 __ rsb(out, out, ShifterOperand(0));
2816 }
2817 } else {
2818 __ ubfx(out, out, 0, ctz_imm);
2819 __ sub(out, out, ShifterOperand(temp));
2820 }
2821}
2822
2823void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2824 DCHECK(instruction->IsDiv() || instruction->IsRem());
2825 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2826
2827 LocationSummary* locations = instruction->GetLocations();
2828 Location second = locations->InAt(1);
2829 DCHECK(second.IsConstant());
2830
2831 Register out = locations->Out().AsRegister<Register>();
2832 Register dividend = locations->InAt(0).AsRegister<Register>();
2833 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2834 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2835 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2836
2837 int64_t magic;
2838 int shift;
2839 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2840
2841 __ LoadImmediate(temp1, magic);
2842 __ smull(temp2, temp1, dividend, temp1);
2843
2844 if (imm > 0 && magic < 0) {
2845 __ add(temp1, temp1, ShifterOperand(dividend));
2846 } else if (imm < 0 && magic > 0) {
2847 __ sub(temp1, temp1, ShifterOperand(dividend));
2848 }
2849
2850 if (shift != 0) {
2851 __ Asr(temp1, temp1, shift);
2852 }
2853
2854 if (instruction->IsDiv()) {
2855 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2856 } else {
2857 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2858 // TODO: Strength reduction for mls.
2859 __ LoadImmediate(temp2, imm);
2860 __ mls(out, temp1, temp2, dividend);
2861 }
2862}
2863
2864void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2865 DCHECK(instruction->IsDiv() || instruction->IsRem());
2866 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2867
2868 LocationSummary* locations = instruction->GetLocations();
2869 Location second = locations->InAt(1);
2870 DCHECK(second.IsConstant());
2871
2872 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2873 if (imm == 0) {
2874 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2875 } else if (imm == 1 || imm == -1) {
2876 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002877 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002878 DivRemByPowerOfTwo(instruction);
2879 } else {
2880 DCHECK(imm <= -2 || imm >= 2);
2881 GenerateDivRemWithAnyConstant(instruction);
2882 }
2883}
2884
Calin Juravle7c4954d2014-10-28 16:57:40 +00002885void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002886 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2887 if (div->GetResultType() == Primitive::kPrimLong) {
2888 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002889 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002890 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2891 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002892 } else if (div->GetResultType() == Primitive::kPrimInt &&
2893 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2894 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002895 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002896 }
2897
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002898 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2899
Calin Juravle7c4954d2014-10-28 16:57:40 +00002900 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002901 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002902 if (div->InputAt(1)->IsConstant()) {
2903 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00002904 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08002905 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002906 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
2907 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08002908 // No temp register required.
2909 } else {
2910 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002911 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002912 locations->AddTemp(Location::RequiresRegister());
2913 }
2914 }
2915 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002916 locations->SetInAt(0, Location::RequiresRegister());
2917 locations->SetInAt(1, Location::RequiresRegister());
2918 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2919 } else {
2920 InvokeRuntimeCallingConvention calling_convention;
2921 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2922 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2923 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2924 // we only need the former.
2925 locations->SetOut(Location::RegisterLocation(R0));
2926 }
Calin Juravled0d48522014-11-04 16:40:20 +00002927 break;
2928 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002929 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002930 InvokeRuntimeCallingConvention calling_convention;
2931 locations->SetInAt(0, Location::RegisterPairLocation(
2932 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2933 locations->SetInAt(1, Location::RegisterPairLocation(
2934 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002935 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002936 break;
2937 }
2938 case Primitive::kPrimFloat:
2939 case Primitive::kPrimDouble: {
2940 locations->SetInAt(0, Location::RequiresFpuRegister());
2941 locations->SetInAt(1, Location::RequiresFpuRegister());
2942 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2943 break;
2944 }
2945
2946 default:
2947 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2948 }
2949}
2950
2951void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2952 LocationSummary* locations = div->GetLocations();
2953 Location out = locations->Out();
2954 Location first = locations->InAt(0);
2955 Location second = locations->InAt(1);
2956
2957 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002958 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002959 if (second.IsConstant()) {
2960 GenerateDivRemConstantIntegral(div);
2961 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002962 __ sdiv(out.AsRegister<Register>(),
2963 first.AsRegister<Register>(),
2964 second.AsRegister<Register>());
2965 } else {
2966 InvokeRuntimeCallingConvention calling_convention;
2967 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2968 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2969 DCHECK_EQ(R0, out.AsRegister<Register>());
2970
2971 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002972 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002973 }
Calin Juravled0d48522014-11-04 16:40:20 +00002974 break;
2975 }
2976
Calin Juravle7c4954d2014-10-28 16:57:40 +00002977 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002978 InvokeRuntimeCallingConvention calling_convention;
2979 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2980 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2981 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2982 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2983 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002984 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002985
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002986 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002987 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002988 break;
2989 }
2990
2991 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002992 __ vdivs(out.AsFpuRegister<SRegister>(),
2993 first.AsFpuRegister<SRegister>(),
2994 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002995 break;
2996 }
2997
2998 case Primitive::kPrimDouble: {
2999 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
3000 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
3001 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
3002 break;
3003 }
3004
3005 default:
3006 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3007 }
3008}
3009
Calin Juravlebacfec32014-11-14 15:54:36 +00003010void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003011 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003012
3013 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003014 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08003015 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
3016 // sdiv will be replaced by other instruction sequence.
3017 call_kind = LocationSummary::kNoCall;
3018 } else if ((rem->GetResultType() == Primitive::kPrimInt)
3019 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003020 // Have hardware divide instruction for int, do it with three instructions.
3021 call_kind = LocationSummary::kNoCall;
3022 }
3023
Calin Juravlebacfec32014-11-14 15:54:36 +00003024 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3025
Calin Juravled2ec87d2014-12-08 14:24:46 +00003026 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003027 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003028 if (rem->InputAt(1)->IsConstant()) {
3029 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003030 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003031 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003032 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3033 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003034 // No temp register required.
3035 } else {
3036 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003037 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003038 locations->AddTemp(Location::RequiresRegister());
3039 }
3040 }
3041 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003042 locations->SetInAt(0, Location::RequiresRegister());
3043 locations->SetInAt(1, Location::RequiresRegister());
3044 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3045 locations->AddTemp(Location::RequiresRegister());
3046 } else {
3047 InvokeRuntimeCallingConvention calling_convention;
3048 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3049 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3050 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3051 // we only need the latter.
3052 locations->SetOut(Location::RegisterLocation(R1));
3053 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003054 break;
3055 }
3056 case Primitive::kPrimLong: {
3057 InvokeRuntimeCallingConvention calling_convention;
3058 locations->SetInAt(0, Location::RegisterPairLocation(
3059 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3060 locations->SetInAt(1, Location::RegisterPairLocation(
3061 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3062 // The runtime helper puts the output in R2,R3.
3063 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3064 break;
3065 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003066 case Primitive::kPrimFloat: {
3067 InvokeRuntimeCallingConvention calling_convention;
3068 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3069 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3070 locations->SetOut(Location::FpuRegisterLocation(S0));
3071 break;
3072 }
3073
Calin Juravlebacfec32014-11-14 15:54:36 +00003074 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003075 InvokeRuntimeCallingConvention calling_convention;
3076 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3077 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3078 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3079 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3080 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003081 break;
3082 }
3083
3084 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003085 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003086 }
3087}
3088
3089void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3090 LocationSummary* locations = rem->GetLocations();
3091 Location out = locations->Out();
3092 Location first = locations->InAt(0);
3093 Location second = locations->InAt(1);
3094
Calin Juravled2ec87d2014-12-08 14:24:46 +00003095 Primitive::Type type = rem->GetResultType();
3096 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003097 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003098 if (second.IsConstant()) {
3099 GenerateDivRemConstantIntegral(rem);
3100 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003101 Register reg1 = first.AsRegister<Register>();
3102 Register reg2 = second.AsRegister<Register>();
3103 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003104
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003105 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003106 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003107 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003108 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003109 } else {
3110 InvokeRuntimeCallingConvention calling_convention;
3111 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3112 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3113 DCHECK_EQ(R1, out.AsRegister<Register>());
3114
3115 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003116 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003117 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003118 break;
3119 }
3120
3121 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003122 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003123 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003124 break;
3125 }
3126
Calin Juravled2ec87d2014-12-08 14:24:46 +00003127 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003128 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003129 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003130 break;
3131 }
3132
Calin Juravlebacfec32014-11-14 15:54:36 +00003133 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003134 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003135 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003136 break;
3137 }
3138
3139 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003140 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003141 }
3142}
3143
Calin Juravled0d48522014-11-04 16:40:20 +00003144void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003145 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3146 ? LocationSummary::kCallOnSlowPath
3147 : LocationSummary::kNoCall;
3148 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003149 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003150 if (instruction->HasUses()) {
3151 locations->SetOut(Location::SameAsFirstInput());
3152 }
3153}
3154
3155void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003156 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003157 codegen_->AddSlowPath(slow_path);
3158
3159 LocationSummary* locations = instruction->GetLocations();
3160 Location value = locations->InAt(0);
3161
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003162 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003163 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003164 case Primitive::kPrimByte:
3165 case Primitive::kPrimChar:
3166 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003167 case Primitive::kPrimInt: {
3168 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003169 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003170 } else {
3171 DCHECK(value.IsConstant()) << value;
3172 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3173 __ b(slow_path->GetEntryLabel());
3174 }
3175 }
3176 break;
3177 }
3178 case Primitive::kPrimLong: {
3179 if (value.IsRegisterPair()) {
3180 __ orrs(IP,
3181 value.AsRegisterPairLow<Register>(),
3182 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3183 __ b(slow_path->GetEntryLabel(), EQ);
3184 } else {
3185 DCHECK(value.IsConstant()) << value;
3186 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3187 __ b(slow_path->GetEntryLabel());
3188 }
3189 }
3190 break;
3191 default:
3192 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3193 }
3194 }
Calin Juravled0d48522014-11-04 16:40:20 +00003195}
3196
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003197void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3198 Register in = locations->InAt(0).AsRegister<Register>();
3199 Location rhs = locations->InAt(1);
3200 Register out = locations->Out().AsRegister<Register>();
3201
3202 if (rhs.IsConstant()) {
3203 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3204 // so map all rotations to a +ve. equivalent in that range.
3205 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3206 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3207 if (rot) {
3208 // Rotate, mapping left rotations to right equivalents if necessary.
3209 // (e.g. left by 2 bits == right by 30.)
3210 __ Ror(out, in, rot);
3211 } else if (out != in) {
3212 __ Mov(out, in);
3213 }
3214 } else {
3215 __ Ror(out, in, rhs.AsRegister<Register>());
3216 }
3217}
3218
3219// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3220// rotates by swapping input regs (effectively rotating by the first 32-bits of
3221// a larger rotation) or flipping direction (thus treating larger right/left
3222// rotations as sub-word sized rotations in the other direction) as appropriate.
3223void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3224 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3225 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3226 Location rhs = locations->InAt(1);
3227 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3228 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3229
3230 if (rhs.IsConstant()) {
3231 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3232 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003233 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003234 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3235 // logic below to a simple pair of binary orr.
3236 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3237 if (rot >= kArmBitsPerWord) {
3238 rot -= kArmBitsPerWord;
3239 std::swap(in_reg_hi, in_reg_lo);
3240 }
3241 // Rotate, or mov to out for zero or word size rotations.
3242 if (rot != 0u) {
3243 __ Lsr(out_reg_hi, in_reg_hi, rot);
3244 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3245 __ Lsr(out_reg_lo, in_reg_lo, rot);
3246 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3247 } else {
3248 __ Mov(out_reg_lo, in_reg_lo);
3249 __ Mov(out_reg_hi, in_reg_hi);
3250 }
3251 } else {
3252 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3253 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3254 Label end;
3255 Label shift_by_32_plus_shift_right;
3256
3257 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3258 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3259 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3260 __ b(&shift_by_32_plus_shift_right, CC);
3261
3262 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3263 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3264 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3265 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3266 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3267 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3268 __ Lsr(shift_left, in_reg_hi, shift_right);
3269 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3270 __ b(&end);
3271
3272 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3273 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3274 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3275 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3276 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3277 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3278 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3279 __ Lsl(shift_right, in_reg_hi, shift_left);
3280 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3281
3282 __ Bind(&end);
3283 }
3284}
Roland Levillain22c49222016-03-18 14:04:28 +00003285
3286void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003287 LocationSummary* locations =
3288 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3289 switch (ror->GetResultType()) {
3290 case Primitive::kPrimInt: {
3291 locations->SetInAt(0, Location::RequiresRegister());
3292 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3293 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3294 break;
3295 }
3296 case Primitive::kPrimLong: {
3297 locations->SetInAt(0, Location::RequiresRegister());
3298 if (ror->InputAt(1)->IsConstant()) {
3299 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3300 } else {
3301 locations->SetInAt(1, Location::RequiresRegister());
3302 locations->AddTemp(Location::RequiresRegister());
3303 locations->AddTemp(Location::RequiresRegister());
3304 }
3305 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3306 break;
3307 }
3308 default:
3309 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3310 }
3311}
3312
Roland Levillain22c49222016-03-18 14:04:28 +00003313void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003314 LocationSummary* locations = ror->GetLocations();
3315 Primitive::Type type = ror->GetResultType();
3316 switch (type) {
3317 case Primitive::kPrimInt: {
3318 HandleIntegerRotate(locations);
3319 break;
3320 }
3321 case Primitive::kPrimLong: {
3322 HandleLongRotate(locations);
3323 break;
3324 }
3325 default:
3326 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003327 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003328 }
3329}
3330
Calin Juravle9aec02f2014-11-18 23:06:35 +00003331void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3332 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3333
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003334 LocationSummary* locations =
3335 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003336
3337 switch (op->GetResultType()) {
3338 case Primitive::kPrimInt: {
3339 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003340 if (op->InputAt(1)->IsConstant()) {
3341 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3342 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3343 } else {
3344 locations->SetInAt(1, Location::RequiresRegister());
3345 // Make the output overlap, as it will be used to hold the masked
3346 // second input.
3347 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3348 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003349 break;
3350 }
3351 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003352 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003353 if (op->InputAt(1)->IsConstant()) {
3354 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3355 // For simplicity, use kOutputOverlap even though we only require that low registers
3356 // don't clash with high registers which the register allocator currently guarantees.
3357 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3358 } else {
3359 locations->SetInAt(1, Location::RequiresRegister());
3360 locations->AddTemp(Location::RequiresRegister());
3361 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3362 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003363 break;
3364 }
3365 default:
3366 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3367 }
3368}
3369
3370void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3371 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3372
3373 LocationSummary* locations = op->GetLocations();
3374 Location out = locations->Out();
3375 Location first = locations->InAt(0);
3376 Location second = locations->InAt(1);
3377
3378 Primitive::Type type = op->GetResultType();
3379 switch (type) {
3380 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003381 Register out_reg = out.AsRegister<Register>();
3382 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003383 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003384 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003385 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003386 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003387 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003388 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003389 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003390 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003391 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003392 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003393 }
3394 } else {
3395 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003396 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003397 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003398 __ Mov(out_reg, first_reg);
3399 } else if (op->IsShl()) {
3400 __ Lsl(out_reg, first_reg, shift_value);
3401 } else if (op->IsShr()) {
3402 __ Asr(out_reg, first_reg, shift_value);
3403 } else {
3404 __ Lsr(out_reg, first_reg, shift_value);
3405 }
3406 }
3407 break;
3408 }
3409 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003410 Register o_h = out.AsRegisterPairHigh<Register>();
3411 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003412
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003413 Register high = first.AsRegisterPairHigh<Register>();
3414 Register low = first.AsRegisterPairLow<Register>();
3415
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003416 if (second.IsRegister()) {
3417 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003418
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003419 Register second_reg = second.AsRegister<Register>();
3420
3421 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003422 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003423 // Shift the high part
3424 __ Lsl(o_h, high, o_l);
3425 // Shift the low part and `or` what overflew on the high part
3426 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3427 __ Lsr(temp, low, temp);
3428 __ orr(o_h, o_h, ShifterOperand(temp));
3429 // If the shift is > 32 bits, override the high part
3430 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3431 __ it(PL);
3432 __ Lsl(o_h, low, temp, PL);
3433 // Shift the low part
3434 __ Lsl(o_l, low, o_l);
3435 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003436 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003437 // Shift the low part
3438 __ Lsr(o_l, low, o_h);
3439 // Shift the high part and `or` what underflew on the low part
3440 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3441 __ Lsl(temp, high, temp);
3442 __ orr(o_l, o_l, ShifterOperand(temp));
3443 // If the shift is > 32 bits, override the low part
3444 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3445 __ it(PL);
3446 __ Asr(o_l, high, temp, PL);
3447 // Shift the high part
3448 __ Asr(o_h, high, o_h);
3449 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003450 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003451 // same as Shr except we use `Lsr`s and not `Asr`s
3452 __ Lsr(o_l, low, o_h);
3453 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3454 __ Lsl(temp, high, temp);
3455 __ orr(o_l, o_l, ShifterOperand(temp));
3456 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3457 __ it(PL);
3458 __ Lsr(o_l, high, temp, PL);
3459 __ Lsr(o_h, high, o_h);
3460 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003461 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003462 // Register allocator doesn't create partial overlap.
3463 DCHECK_NE(o_l, high);
3464 DCHECK_NE(o_h, low);
3465 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003466 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003467 if (shift_value > 32) {
3468 if (op->IsShl()) {
3469 __ Lsl(o_h, low, shift_value - 32);
3470 __ LoadImmediate(o_l, 0);
3471 } else if (op->IsShr()) {
3472 __ Asr(o_l, high, shift_value - 32);
3473 __ Asr(o_h, high, 31);
3474 } else {
3475 __ Lsr(o_l, high, shift_value - 32);
3476 __ LoadImmediate(o_h, 0);
3477 }
3478 } else if (shift_value == 32) {
3479 if (op->IsShl()) {
3480 __ mov(o_h, ShifterOperand(low));
3481 __ LoadImmediate(o_l, 0);
3482 } else if (op->IsShr()) {
3483 __ mov(o_l, ShifterOperand(high));
3484 __ Asr(o_h, high, 31);
3485 } else {
3486 __ mov(o_l, ShifterOperand(high));
3487 __ LoadImmediate(o_h, 0);
3488 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003489 } else if (shift_value == 1) {
3490 if (op->IsShl()) {
3491 __ Lsls(o_l, low, 1);
3492 __ adc(o_h, high, ShifterOperand(high));
3493 } else if (op->IsShr()) {
3494 __ Asrs(o_h, high, 1);
3495 __ Rrx(o_l, low);
3496 } else {
3497 __ Lsrs(o_h, high, 1);
3498 __ Rrx(o_l, low);
3499 }
3500 } else {
3501 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003502 if (op->IsShl()) {
3503 __ Lsl(o_h, high, shift_value);
3504 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3505 __ Lsl(o_l, low, shift_value);
3506 } else if (op->IsShr()) {
3507 __ Lsr(o_l, low, shift_value);
3508 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3509 __ Asr(o_h, high, shift_value);
3510 } else {
3511 __ Lsr(o_l, low, shift_value);
3512 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3513 __ Lsr(o_h, high, shift_value);
3514 }
3515 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003516 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003517 break;
3518 }
3519 default:
3520 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003521 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003522 }
3523}
3524
3525void LocationsBuilderARM::VisitShl(HShl* shl) {
3526 HandleShift(shl);
3527}
3528
3529void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3530 HandleShift(shl);
3531}
3532
3533void LocationsBuilderARM::VisitShr(HShr* shr) {
3534 HandleShift(shr);
3535}
3536
3537void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3538 HandleShift(shr);
3539}
3540
3541void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3542 HandleShift(ushr);
3543}
3544
3545void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3546 HandleShift(ushr);
3547}
3548
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003549void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003550 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003551 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003552 if (instruction->IsStringAlloc()) {
3553 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3554 } else {
3555 InvokeRuntimeCallingConvention calling_convention;
3556 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3557 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3558 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003559 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003560}
3561
3562void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003563 // Note: if heap poisoning is enabled, the entry point takes cares
3564 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003565 if (instruction->IsStringAlloc()) {
3566 // String is allocated through StringFactory. Call NewEmptyString entry point.
3567 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003568 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003569 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3570 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3571 __ blx(LR);
3572 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3573 } else {
3574 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
3575 instruction,
3576 instruction->GetDexPc(),
3577 nullptr);
3578 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3579 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003580}
3581
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003582void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3583 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003584 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003585 InvokeRuntimeCallingConvention calling_convention;
3586 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003587 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003588 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003589 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003590}
3591
3592void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3593 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003594 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003595 // Note: if heap poisoning is enabled, the entry point takes cares
3596 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003597 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003598 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003599 instruction->GetDexPc(),
3600 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003601 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003602}
3603
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003604void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003605 LocationSummary* locations =
3606 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003607 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3608 if (location.IsStackSlot()) {
3609 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3610 } else if (location.IsDoubleStackSlot()) {
3611 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003612 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003613 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003614}
3615
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003616void InstructionCodeGeneratorARM::VisitParameterValue(
3617 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003618 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003619}
3620
3621void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3622 LocationSummary* locations =
3623 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3624 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3625}
3626
3627void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3628 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003629}
3630
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003631void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003632 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003633 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003634 locations->SetInAt(0, Location::RequiresRegister());
3635 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003636}
3637
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003638void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3639 LocationSummary* locations = not_->GetLocations();
3640 Location out = locations->Out();
3641 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003642 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003643 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003644 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003645 break;
3646
3647 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003648 __ mvn(out.AsRegisterPairLow<Register>(),
3649 ShifterOperand(in.AsRegisterPairLow<Register>()));
3650 __ mvn(out.AsRegisterPairHigh<Register>(),
3651 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003652 break;
3653
3654 default:
3655 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3656 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003657}
3658
David Brazdil66d126e2015-04-03 16:02:44 +01003659void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3660 LocationSummary* locations =
3661 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3662 locations->SetInAt(0, Location::RequiresRegister());
3663 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3664}
3665
3666void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003667 LocationSummary* locations = bool_not->GetLocations();
3668 Location out = locations->Out();
3669 Location in = locations->InAt(0);
3670 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3671}
3672
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003673void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003674 LocationSummary* locations =
3675 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003676 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003677 case Primitive::kPrimBoolean:
3678 case Primitive::kPrimByte:
3679 case Primitive::kPrimShort:
3680 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003681 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00003682 case Primitive::kPrimLong: {
3683 locations->SetInAt(0, Location::RequiresRegister());
3684 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003685 // Output overlaps because it is written before doing the low comparison.
3686 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003687 break;
3688 }
3689 case Primitive::kPrimFloat:
3690 case Primitive::kPrimDouble: {
3691 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003692 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00003693 locations->SetOut(Location::RequiresRegister());
3694 break;
3695 }
3696 default:
3697 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3698 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003699}
3700
3701void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003702 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003703 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003704 Location left = locations->InAt(0);
3705 Location right = locations->InAt(1);
3706
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003707 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003708 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00003709 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00003710 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003711 case Primitive::kPrimBoolean:
3712 case Primitive::kPrimByte:
3713 case Primitive::kPrimShort:
3714 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003715 case Primitive::kPrimInt: {
3716 __ LoadImmediate(out, 0);
3717 __ cmp(left.AsRegister<Register>(),
3718 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
3719 less_cond = LT;
3720 break;
3721 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003722 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003723 __ cmp(left.AsRegisterPairHigh<Register>(),
3724 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003725 __ b(&less, LT);
3726 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003727 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003728 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003729 __ cmp(left.AsRegisterPairLow<Register>(),
3730 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003731 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00003732 break;
3733 }
3734 case Primitive::kPrimFloat:
3735 case Primitive::kPrimDouble: {
3736 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003737 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00003738 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003739 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003740 break;
3741 }
3742 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003743 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00003744 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003745 }
Aart Bika19616e2016-02-01 18:57:58 -08003746
Calin Juravleddb7df22014-11-25 20:56:51 +00003747 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00003748 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00003749
3750 __ Bind(&greater);
3751 __ LoadImmediate(out, 1);
3752 __ b(&done);
3753
3754 __ Bind(&less);
3755 __ LoadImmediate(out, -1);
3756
3757 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003758}
3759
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003760void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003761 LocationSummary* locations =
3762 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003763 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003764 locations->SetInAt(i, Location::Any());
3765 }
3766 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003767}
3768
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003769void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003770 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003771}
3772
Roland Levillainc9285912015-12-18 10:38:42 +00003773void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3774 // TODO (ported from quick): revisit ARM barrier kinds.
3775 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00003776 switch (kind) {
3777 case MemBarrierKind::kAnyStore:
3778 case MemBarrierKind::kLoadAny:
3779 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003780 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003781 break;
3782 }
3783 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003784 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003785 break;
3786 }
3787 default:
3788 LOG(FATAL) << "Unexpected memory barrier " << kind;
3789 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003790 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003791}
3792
3793void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3794 uint32_t offset,
3795 Register out_lo,
3796 Register out_hi) {
3797 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00003798 // Ensure `out_lo` is different from `addr`, so that loading
3799 // `offset` into `out_lo` does not clutter `addr`.
3800 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00003801 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003802 __ add(IP, addr, ShifterOperand(out_lo));
3803 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003804 }
3805 __ ldrexd(out_lo, out_hi, addr);
3806}
3807
3808void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3809 uint32_t offset,
3810 Register value_lo,
3811 Register value_hi,
3812 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003813 Register temp2,
3814 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003815 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003816 if (offset != 0) {
3817 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003818 __ add(IP, addr, ShifterOperand(temp1));
3819 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003820 }
3821 __ Bind(&fail);
3822 // We need a load followed by store. (The address used in a STREX instruction must
3823 // be the same as the address in the most recently executed LDREX instruction.)
3824 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003825 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003826 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003827 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003828}
3829
3830void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3831 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3832
Nicolas Geoffray39468442014-09-02 15:17:15 +01003833 LocationSummary* locations =
3834 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003835 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003836
Calin Juravle52c48962014-12-16 17:02:57 +00003837 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003838 if (Primitive::IsFloatingPointType(field_type)) {
3839 locations->SetInAt(1, Location::RequiresFpuRegister());
3840 } else {
3841 locations->SetInAt(1, Location::RequiresRegister());
3842 }
3843
Calin Juravle52c48962014-12-16 17:02:57 +00003844 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003845 bool generate_volatile = field_info.IsVolatile()
3846 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003847 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003848 bool needs_write_barrier =
3849 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003850 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003851 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003852 if (needs_write_barrier) {
3853 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003854 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003855 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003856 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003857 // - registers need to be consecutive
3858 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003859 // We don't test for ARM yet, and the assertion makes sure that we
3860 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003861 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3862
3863 locations->AddTemp(Location::RequiresRegister());
3864 locations->AddTemp(Location::RequiresRegister());
3865 if (field_type == Primitive::kPrimDouble) {
3866 // For doubles we need two more registers to copy the value.
3867 locations->AddTemp(Location::RegisterLocation(R2));
3868 locations->AddTemp(Location::RegisterLocation(R3));
3869 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003870 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003871}
3872
Calin Juravle52c48962014-12-16 17:02:57 +00003873void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003874 const FieldInfo& field_info,
3875 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003876 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3877
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003878 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003879 Register base = locations->InAt(0).AsRegister<Register>();
3880 Location value = locations->InAt(1);
3881
3882 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003883 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003884 Primitive::Type field_type = field_info.GetFieldType();
3885 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003886 bool needs_write_barrier =
3887 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003888
3889 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003890 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00003891 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003892
3893 switch (field_type) {
3894 case Primitive::kPrimBoolean:
3895 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003896 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003897 break;
3898 }
3899
3900 case Primitive::kPrimShort:
3901 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003902 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003903 break;
3904 }
3905
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003906 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003907 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003908 if (kPoisonHeapReferences && needs_write_barrier) {
3909 // Note that in the case where `value` is a null reference,
3910 // we do not enter this block, as a null reference does not
3911 // need poisoning.
3912 DCHECK_EQ(field_type, Primitive::kPrimNot);
3913 Register temp = locations->GetTemp(0).AsRegister<Register>();
3914 __ Mov(temp, value.AsRegister<Register>());
3915 __ PoisonHeapReference(temp);
3916 __ StoreToOffset(kStoreWord, temp, base, offset);
3917 } else {
3918 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3919 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003920 break;
3921 }
3922
3923 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003924 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003925 GenerateWideAtomicStore(base, offset,
3926 value.AsRegisterPairLow<Register>(),
3927 value.AsRegisterPairHigh<Register>(),
3928 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003929 locations->GetTemp(1).AsRegister<Register>(),
3930 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003931 } else {
3932 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003933 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003934 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003935 break;
3936 }
3937
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003938 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003939 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003940 break;
3941 }
3942
3943 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003944 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003945 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003946 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3947 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3948
3949 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3950
3951 GenerateWideAtomicStore(base, offset,
3952 value_reg_lo,
3953 value_reg_hi,
3954 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003955 locations->GetTemp(3).AsRegister<Register>(),
3956 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003957 } else {
3958 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003959 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003960 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003961 break;
3962 }
3963
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003964 case Primitive::kPrimVoid:
3965 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003966 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003967 }
Calin Juravle52c48962014-12-16 17:02:57 +00003968
Calin Juravle77520bc2015-01-12 18:45:46 +00003969 // Longs and doubles are handled in the switch.
3970 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3971 codegen_->MaybeRecordImplicitNullCheck(instruction);
3972 }
3973
3974 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3975 Register temp = locations->GetTemp(0).AsRegister<Register>();
3976 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003977 codegen_->MarkGCCard(
3978 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003979 }
3980
Calin Juravle52c48962014-12-16 17:02:57 +00003981 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003982 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00003983 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003984}
3985
Calin Juravle52c48962014-12-16 17:02:57 +00003986void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3987 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00003988
3989 bool object_field_get_with_read_barrier =
3990 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003991 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00003992 new (GetGraph()->GetArena()) LocationSummary(instruction,
3993 object_field_get_with_read_barrier ?
3994 LocationSummary::kCallOnSlowPath :
3995 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003996 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003997
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003998 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003999 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004000 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00004001 // The output overlaps in case of volatile long: we don't want the
4002 // code generated by GenerateWideAtomicLoad to overwrite the
4003 // object's location. Likewise, in the case of an object field get
4004 // with read barriers enabled, we do not want the load to overwrite
4005 // the object's location, as we need it to emit the read barrier.
4006 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
4007 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01004008
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004009 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4010 locations->SetOut(Location::RequiresFpuRegister());
4011 } else {
4012 locations->SetOut(Location::RequiresRegister(),
4013 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
4014 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004015 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00004016 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00004017 // - registers need to be consecutive
4018 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00004019 // We don't test for ARM yet, and the assertion makes sure that we
4020 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00004021 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
4022 locations->AddTemp(Location::RequiresRegister());
4023 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00004024 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4025 // We need a temporary register for the read barrier marking slow
4026 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4027 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004028 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004029}
4030
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004031Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
4032 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
4033 << input->GetType();
4034 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
4035 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4036 return Location::ConstantLocation(input->AsConstant());
4037 } else {
4038 return Location::RequiresFpuRegister();
4039 }
4040}
4041
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004042Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4043 Opcode opcode) {
4044 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4045 if (constant->IsConstant() &&
4046 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4047 return Location::ConstantLocation(constant->AsConstant());
4048 }
4049 return Location::RequiresRegister();
4050}
4051
4052bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4053 Opcode opcode) {
4054 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4055 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004056 Opcode high_opcode = opcode;
4057 SetCc low_set_cc = kCcDontCare;
4058 switch (opcode) {
4059 case SUB:
4060 // Flip the operation to an ADD.
4061 value = -value;
4062 opcode = ADD;
4063 FALLTHROUGH_INTENDED;
4064 case ADD:
4065 if (Low32Bits(value) == 0u) {
4066 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4067 }
4068 high_opcode = ADC;
4069 low_set_cc = kCcSet;
4070 break;
4071 default:
4072 break;
4073 }
4074 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4075 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004076 } else {
4077 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4078 }
4079}
4080
Vladimir Marko59751a72016-08-05 14:37:27 +01004081bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4082 Opcode opcode,
4083 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004084 ShifterOperand so;
4085 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004086 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004087 return true;
4088 }
4089 Opcode neg_opcode = kNoOperand;
4090 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004091 case AND: neg_opcode = BIC; value = ~value; break;
4092 case ORR: neg_opcode = ORN; value = ~value; break;
4093 case ADD: neg_opcode = SUB; value = -value; break;
4094 case ADC: neg_opcode = SBC; value = ~value; break;
4095 case SUB: neg_opcode = ADD; value = -value; break;
4096 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004097 default:
4098 return false;
4099 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004100 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004101}
4102
Calin Juravle52c48962014-12-16 17:02:57 +00004103void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4104 const FieldInfo& field_info) {
4105 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004106
Calin Juravle52c48962014-12-16 17:02:57 +00004107 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004108 Location base_loc = locations->InAt(0);
4109 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004110 Location out = locations->Out();
4111 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004112 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004113 Primitive::Type field_type = field_info.GetFieldType();
4114 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4115
4116 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004117 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004118 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004119 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004120
Roland Levillainc9285912015-12-18 10:38:42 +00004121 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004122 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004123 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004124
Roland Levillainc9285912015-12-18 10:38:42 +00004125 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004126 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004127 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004128
Roland Levillainc9285912015-12-18 10:38:42 +00004129 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004130 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004131 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004132
4133 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004134 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004135 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004136
4137 case Primitive::kPrimNot: {
4138 // /* HeapReference<Object> */ out = *(base + offset)
4139 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4140 Location temp_loc = locations->GetTemp(0);
4141 // Note that a potential implicit null check is handled in this
4142 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4143 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4144 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4145 if (is_volatile) {
4146 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4147 }
4148 } else {
4149 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4150 codegen_->MaybeRecordImplicitNullCheck(instruction);
4151 if (is_volatile) {
4152 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4153 }
4154 // If read barriers are enabled, emit read barriers other than
4155 // Baker's using a slow path (and also unpoison the loaded
4156 // reference, if heap poisoning is enabled).
4157 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4158 }
4159 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004160 }
4161
Roland Levillainc9285912015-12-18 10:38:42 +00004162 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004163 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004164 GenerateWideAtomicLoad(base, offset,
4165 out.AsRegisterPairLow<Register>(),
4166 out.AsRegisterPairHigh<Register>());
4167 } else {
4168 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4169 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004170 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004171
Roland Levillainc9285912015-12-18 10:38:42 +00004172 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004173 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004174 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004175
4176 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004177 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004178 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004179 Register lo = locations->GetTemp(0).AsRegister<Register>();
4180 Register hi = locations->GetTemp(1).AsRegister<Register>();
4181 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004182 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004183 __ vmovdrr(out_reg, lo, hi);
4184 } else {
4185 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004186 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004187 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004188 break;
4189 }
4190
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004191 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004192 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004193 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004194 }
Calin Juravle52c48962014-12-16 17:02:57 +00004195
Roland Levillainc9285912015-12-18 10:38:42 +00004196 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4197 // Potential implicit null checks, in the case of reference or
4198 // double fields, are handled in the previous switch statement.
4199 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004200 codegen_->MaybeRecordImplicitNullCheck(instruction);
4201 }
4202
Calin Juravle52c48962014-12-16 17:02:57 +00004203 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004204 if (field_type == Primitive::kPrimNot) {
4205 // Memory barriers, in the case of references, are also handled
4206 // in the previous switch statement.
4207 } else {
4208 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4209 }
Roland Levillain4d027112015-07-01 15:41:14 +01004210 }
Calin Juravle52c48962014-12-16 17:02:57 +00004211}
4212
4213void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4214 HandleFieldSet(instruction, instruction->GetFieldInfo());
4215}
4216
4217void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004218 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004219}
4220
4221void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4222 HandleFieldGet(instruction, instruction->GetFieldInfo());
4223}
4224
4225void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4226 HandleFieldGet(instruction, instruction->GetFieldInfo());
4227}
4228
4229void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4230 HandleFieldGet(instruction, instruction->GetFieldInfo());
4231}
4232
4233void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4234 HandleFieldGet(instruction, instruction->GetFieldInfo());
4235}
4236
4237void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4238 HandleFieldSet(instruction, instruction->GetFieldInfo());
4239}
4240
4241void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004242 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004243}
4244
Calin Juravlee460d1d2015-09-29 04:52:17 +01004245void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4246 HUnresolvedInstanceFieldGet* instruction) {
4247 FieldAccessCallingConventionARM calling_convention;
4248 codegen_->CreateUnresolvedFieldLocationSummary(
4249 instruction, instruction->GetFieldType(), calling_convention);
4250}
4251
4252void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4253 HUnresolvedInstanceFieldGet* instruction) {
4254 FieldAccessCallingConventionARM calling_convention;
4255 codegen_->GenerateUnresolvedFieldAccess(instruction,
4256 instruction->GetFieldType(),
4257 instruction->GetFieldIndex(),
4258 instruction->GetDexPc(),
4259 calling_convention);
4260}
4261
4262void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4263 HUnresolvedInstanceFieldSet* instruction) {
4264 FieldAccessCallingConventionARM calling_convention;
4265 codegen_->CreateUnresolvedFieldLocationSummary(
4266 instruction, instruction->GetFieldType(), calling_convention);
4267}
4268
4269void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4270 HUnresolvedInstanceFieldSet* instruction) {
4271 FieldAccessCallingConventionARM calling_convention;
4272 codegen_->GenerateUnresolvedFieldAccess(instruction,
4273 instruction->GetFieldType(),
4274 instruction->GetFieldIndex(),
4275 instruction->GetDexPc(),
4276 calling_convention);
4277}
4278
4279void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4280 HUnresolvedStaticFieldGet* instruction) {
4281 FieldAccessCallingConventionARM calling_convention;
4282 codegen_->CreateUnresolvedFieldLocationSummary(
4283 instruction, instruction->GetFieldType(), calling_convention);
4284}
4285
4286void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4287 HUnresolvedStaticFieldGet* instruction) {
4288 FieldAccessCallingConventionARM calling_convention;
4289 codegen_->GenerateUnresolvedFieldAccess(instruction,
4290 instruction->GetFieldType(),
4291 instruction->GetFieldIndex(),
4292 instruction->GetDexPc(),
4293 calling_convention);
4294}
4295
4296void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4297 HUnresolvedStaticFieldSet* instruction) {
4298 FieldAccessCallingConventionARM calling_convention;
4299 codegen_->CreateUnresolvedFieldLocationSummary(
4300 instruction, instruction->GetFieldType(), calling_convention);
4301}
4302
4303void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4304 HUnresolvedStaticFieldSet* instruction) {
4305 FieldAccessCallingConventionARM calling_convention;
4306 codegen_->GenerateUnresolvedFieldAccess(instruction,
4307 instruction->GetFieldType(),
4308 instruction->GetFieldIndex(),
4309 instruction->GetDexPc(),
4310 calling_convention);
4311}
4312
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004313void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004314 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4315 ? LocationSummary::kCallOnSlowPath
4316 : LocationSummary::kNoCall;
4317 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00004318 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004319 if (instruction->HasUses()) {
4320 locations->SetOut(Location::SameAsFirstInput());
4321 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004322}
4323
Calin Juravle2ae48182016-03-16 14:05:09 +00004324void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4325 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004326 return;
4327 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004328 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004329
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004330 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004331 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004332}
4333
Calin Juravle2ae48182016-03-16 14:05:09 +00004334void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004335 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004336 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004337
4338 LocationSummary* locations = instruction->GetLocations();
4339 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004340
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004341 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004342}
4343
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004344void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004345 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004346}
4347
Artem Serov6c916792016-07-11 14:02:34 +01004348static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4349 switch (type) {
4350 case Primitive::kPrimNot:
4351 return kLoadWord;
4352 case Primitive::kPrimBoolean:
4353 return kLoadUnsignedByte;
4354 case Primitive::kPrimByte:
4355 return kLoadSignedByte;
4356 case Primitive::kPrimChar:
4357 return kLoadUnsignedHalfword;
4358 case Primitive::kPrimShort:
4359 return kLoadSignedHalfword;
4360 case Primitive::kPrimInt:
4361 return kLoadWord;
4362 case Primitive::kPrimLong:
4363 return kLoadWordPair;
4364 case Primitive::kPrimFloat:
4365 return kLoadSWord;
4366 case Primitive::kPrimDouble:
4367 return kLoadDWord;
4368 default:
4369 LOG(FATAL) << "Unreachable type " << type;
4370 UNREACHABLE();
4371 }
4372}
4373
4374static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4375 switch (type) {
4376 case Primitive::kPrimNot:
4377 return kStoreWord;
4378 case Primitive::kPrimBoolean:
4379 case Primitive::kPrimByte:
4380 return kStoreByte;
4381 case Primitive::kPrimChar:
4382 case Primitive::kPrimShort:
4383 return kStoreHalfword;
4384 case Primitive::kPrimInt:
4385 return kStoreWord;
4386 case Primitive::kPrimLong:
4387 return kStoreWordPair;
4388 case Primitive::kPrimFloat:
4389 return kStoreSWord;
4390 case Primitive::kPrimDouble:
4391 return kStoreDWord;
4392 default:
4393 LOG(FATAL) << "Unreachable type " << type;
4394 UNREACHABLE();
4395 }
4396}
4397
4398void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4399 Location out_loc,
4400 Register base,
4401 Register reg_offset,
4402 Condition cond) {
4403 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4404 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4405
4406 switch (type) {
4407 case Primitive::kPrimByte:
4408 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4409 break;
4410 case Primitive::kPrimBoolean:
4411 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4412 break;
4413 case Primitive::kPrimShort:
4414 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4415 break;
4416 case Primitive::kPrimChar:
4417 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4418 break;
4419 case Primitive::kPrimNot:
4420 case Primitive::kPrimInt:
4421 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4422 break;
4423 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4424 case Primitive::kPrimLong:
4425 case Primitive::kPrimFloat:
4426 case Primitive::kPrimDouble:
4427 default:
4428 LOG(FATAL) << "Unreachable type " << type;
4429 UNREACHABLE();
4430 }
4431}
4432
4433void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4434 Location loc,
4435 Register base,
4436 Register reg_offset,
4437 Condition cond) {
4438 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4439 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4440
4441 switch (type) {
4442 case Primitive::kPrimByte:
4443 case Primitive::kPrimBoolean:
4444 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4445 break;
4446 case Primitive::kPrimShort:
4447 case Primitive::kPrimChar:
4448 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4449 break;
4450 case Primitive::kPrimNot:
4451 case Primitive::kPrimInt:
4452 __ str(loc.AsRegister<Register>(), mem_address, cond);
4453 break;
4454 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4455 case Primitive::kPrimLong:
4456 case Primitive::kPrimFloat:
4457 case Primitive::kPrimDouble:
4458 default:
4459 LOG(FATAL) << "Unreachable type " << type;
4460 UNREACHABLE();
4461 }
4462}
4463
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004464void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004465 bool object_array_get_with_read_barrier =
4466 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004467 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004468 new (GetGraph()->GetArena()) LocationSummary(instruction,
4469 object_array_get_with_read_barrier ?
4470 LocationSummary::kCallOnSlowPath :
4471 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004472 locations->SetInAt(0, Location::RequiresRegister());
4473 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004474 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4475 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4476 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004477 // The output overlaps in the case of an object array get with
4478 // read barriers enabled: we do not want the move to overwrite the
4479 // array's location, as we need it to emit the read barrier.
4480 locations->SetOut(
4481 Location::RequiresRegister(),
4482 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004483 }
Roland Levillainc9285912015-12-18 10:38:42 +00004484 // We need a temporary register for the read barrier marking slow
4485 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
4486 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4487 locations->AddTemp(Location::RequiresRegister());
4488 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004489}
4490
4491void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4492 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004493 Location obj_loc = locations->InAt(0);
4494 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004495 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004496 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004497 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004498 Primitive::Type type = instruction->GetType();
Artem Serov328429f2016-07-06 16:23:04 +01004499 HInstruction* array_instr = instruction->GetArray();
4500 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004501 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4502 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Artem Serov6c916792016-07-11 14:02:34 +01004503
Roland Levillain4d027112015-07-01 15:41:14 +01004504 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004505 case Primitive::kPrimBoolean:
4506 case Primitive::kPrimByte:
4507 case Primitive::kPrimShort:
4508 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004509 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004510 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004511 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4512 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
4513
4514 LoadOperandType load_type = GetLoadOperandType(type);
4515 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004516 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004517 Register temp = IP;
4518
4519 if (has_intermediate_address) {
4520 // We do not need to compute the intermediate address from the array: the
4521 // input instruction has done it already. See the comment in
4522 // `TryExtractArrayAccessAddress()`.
4523 if (kIsDebugBuild) {
4524 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4525 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4526 }
4527 temp = obj;
4528 } else {
4529 __ add(temp, obj, ShifterOperand(data_offset));
4530 }
4531 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004532 }
4533 break;
4534 }
4535
Roland Levillainc9285912015-12-18 10:38:42 +00004536 case Primitive::kPrimNot: {
4537 static_assert(
4538 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4539 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004540 // /* HeapReference<Object> */ out =
4541 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4542 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4543 Location temp = locations->GetTemp(0);
4544 // Note that a potential implicit null check is handled in this
4545 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4546 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4547 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4548 } else {
4549 Register out = out_loc.AsRegister<Register>();
4550 if (index.IsConstant()) {
4551 size_t offset =
4552 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4553 __ LoadFromOffset(kLoadWord, out, obj, offset);
4554 codegen_->MaybeRecordImplicitNullCheck(instruction);
4555 // If read barriers are enabled, emit read barriers other than
4556 // Baker's using a slow path (and also unpoison the loaded
4557 // reference, if heap poisoning is enabled).
4558 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4559 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004560 Register temp = IP;
4561
4562 if (has_intermediate_address) {
4563 // We do not need to compute the intermediate address from the array: the
4564 // input instruction has done it already. See the comment in
4565 // `TryExtractArrayAccessAddress()`.
4566 if (kIsDebugBuild) {
4567 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4568 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4569 }
4570 temp = obj;
4571 } else {
4572 __ add(temp, obj, ShifterOperand(data_offset));
4573 }
4574 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004575
Roland Levillainc9285912015-12-18 10:38:42 +00004576 codegen_->MaybeRecordImplicitNullCheck(instruction);
4577 // If read barriers are enabled, emit read barriers other than
4578 // Baker's using a slow path (and also unpoison the loaded
4579 // reference, if heap poisoning is enabled).
4580 codegen_->MaybeGenerateReadBarrierSlow(
4581 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4582 }
4583 }
4584 break;
4585 }
4586
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004587 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004588 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004589 size_t offset =
4590 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004591 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004592 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004593 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004594 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004595 }
4596 break;
4597 }
4598
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004599 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004600 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004601 if (index.IsConstant()) {
4602 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004603 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004604 } else {
4605 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004606 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004607 }
4608 break;
4609 }
4610
4611 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004612 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004613 if (index.IsConstant()) {
4614 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004615 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004616 } else {
4617 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004618 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004619 }
4620 break;
4621 }
4622
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004623 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01004624 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004625 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004626 }
Roland Levillain4d027112015-07-01 15:41:14 +01004627
4628 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00004629 // Potential implicit null checks, in the case of reference
4630 // arrays, are handled in the previous switch statement.
4631 } else {
4632 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01004633 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004634}
4635
4636void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004637 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004638
4639 bool needs_write_barrier =
4640 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00004641 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004642
Nicolas Geoffray39468442014-09-02 15:17:15 +01004643 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004644 instruction,
Vladimir Marko8d49fd72016-08-25 15:20:47 +01004645 may_need_runtime_call_for_type_check ?
Roland Levillain3b359c72015-11-17 19:35:12 +00004646 LocationSummary::kCallOnSlowPath :
4647 LocationSummary::kNoCall);
4648
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004649 locations->SetInAt(0, Location::RequiresRegister());
4650 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
4651 if (Primitive::IsFloatingPointType(value_type)) {
4652 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004653 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004654 locations->SetInAt(2, Location::RequiresRegister());
4655 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004656 if (needs_write_barrier) {
4657 // Temporary registers for the write barrier.
Roland Levillain16d9f942016-08-25 17:27:56 +01004658 // These registers may be used for Baker read barriers too.
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004659 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00004660 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004661 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004662}
4663
4664void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4665 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004666 Location array_loc = locations->InAt(0);
4667 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004668 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004669 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00004670 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004671 bool needs_write_barrier =
4672 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01004673 uint32_t data_offset =
4674 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
4675 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01004676 HInstruction* array_instr = instruction->GetArray();
4677 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004678 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4679 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004680
4681 switch (value_type) {
4682 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01004683 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004684 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01004685 case Primitive::kPrimChar:
4686 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004687 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004688 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4689 uint32_t full_offset =
4690 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
4691 StoreOperandType store_type = GetStoreOperandType(value_type);
4692 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004693 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004694 Register temp = IP;
4695
4696 if (has_intermediate_address) {
4697 // We do not need to compute the intermediate address from the array: the
4698 // input instruction has done it already. See the comment in
4699 // `TryExtractArrayAccessAddress()`.
4700 if (kIsDebugBuild) {
4701 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4702 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
4703 }
4704 temp = array;
4705 } else {
4706 __ add(temp, array, ShifterOperand(data_offset));
4707 }
Artem Serov6c916792016-07-11 14:02:34 +01004708 codegen_->StoreToShiftedRegOffset(value_type,
4709 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01004710 temp,
Artem Serov6c916792016-07-11 14:02:34 +01004711 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004712 }
4713 break;
4714 }
4715
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004716 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00004717 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01004718 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
4719 // See the comment in instruction_simplifier_shared.cc.
4720 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004721
4722 if (instruction->InputAt(2)->IsNullConstant()) {
4723 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004724 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004725 size_t offset =
4726 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01004727 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004728 } else {
4729 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004730 __ add(IP, array, ShifterOperand(data_offset));
4731 codegen_->StoreToShiftedRegOffset(value_type,
4732 value_loc,
4733 IP,
4734 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004735 }
Roland Levillain1407ee72016-01-08 15:56:19 +00004736 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00004737 DCHECK(!needs_write_barrier);
4738 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004739 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004740 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004741
4742 DCHECK(needs_write_barrier);
Roland Levillain16d9f942016-08-25 17:27:56 +01004743 Location temp1_loc = locations->GetTemp(0);
4744 Register temp1 = temp1_loc.AsRegister<Register>();
4745 Location temp2_loc = locations->GetTemp(1);
4746 Register temp2 = temp2_loc.AsRegister<Register>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004747 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4748 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4749 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4750 Label done;
4751 SlowPathCode* slow_path = nullptr;
4752
Roland Levillain3b359c72015-11-17 19:35:12 +00004753 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004754 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4755 codegen_->AddSlowPath(slow_path);
4756 if (instruction->GetValueCanBeNull()) {
4757 Label non_zero;
4758 __ CompareAndBranchIfNonZero(value, &non_zero);
4759 if (index.IsConstant()) {
4760 size_t offset =
4761 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4762 __ StoreToOffset(kStoreWord, value, array, offset);
4763 } else {
4764 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004765 __ add(IP, array, ShifterOperand(data_offset));
4766 codegen_->StoreToShiftedRegOffset(value_type,
4767 value_loc,
4768 IP,
4769 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004770 }
4771 codegen_->MaybeRecordImplicitNullCheck(instruction);
4772 __ b(&done);
4773 __ Bind(&non_zero);
4774 }
4775
Roland Levillain3b359c72015-11-17 19:35:12 +00004776 if (kEmitCompilerReadBarrier) {
Roland Levillain16d9f942016-08-25 17:27:56 +01004777 if (!kUseBakerReadBarrier) {
4778 // When (non-Baker) read barriers are enabled, the type
4779 // checking instrumentation requires two read barriers
4780 // generated by CodeGeneratorARM::GenerateReadBarrierSlow:
4781 //
4782 // __ Mov(temp2, temp1);
4783 // // /* HeapReference<Class> */ temp1 = temp1->component_type_
4784 // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4785 // codegen_->GenerateReadBarrierSlow(
4786 // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset);
4787 //
4788 // // /* HeapReference<Class> */ temp2 = value->klass_
4789 // __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4790 // codegen_->GenerateReadBarrierSlow(
4791 // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc);
4792 //
4793 // __ cmp(temp1, ShifterOperand(temp2));
4794 //
4795 // However, the second read barrier may trash `temp`, as it
4796 // is a temporary register, and as such would not be saved
4797 // along with live registers before calling the runtime (nor
4798 // restored afterwards). So in this case, we bail out and
4799 // delegate the work to the array set slow path.
4800 //
4801 // TODO: Extend the register allocator to support a new
4802 // "(locally) live temp" location so as to avoid always
4803 // going into the slow path when read barriers are enabled?
4804 //
4805 // There is no such problem with Baker read barriers (see below).
4806 __ b(slow_path->GetEntryLabel());
4807 } else {
4808 Register temp3 = IP;
4809 Location temp3_loc = Location::RegisterLocation(temp3);
4810
4811 // Note: `temp3` (scratch register IP) cannot be used as
4812 // `ref` argument of GenerateFieldLoadWithBakerReadBarrier
4813 // calls below (see ReadBarrierMarkSlowPathARM for more
4814 // details).
4815
4816 // /* HeapReference<Class> */ temp1 = array->klass_
4817 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4818 temp1_loc,
4819 array,
4820 class_offset,
4821 temp3_loc,
4822 /* needs_null_check */ true);
4823
4824 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4825 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4826 temp1_loc,
4827 temp1,
4828 component_offset,
4829 temp3_loc,
4830 /* needs_null_check */ false);
4831 // Register `temp1` is not trashed by the read barrier
4832 // emitted by GenerateFieldLoadWithBakerReadBarrier below,
4833 // as that method produces a call to a ReadBarrierMarkRegX
4834 // entry point, which saves all potentially live registers,
4835 // including temporaries such a `temp1`.
4836 // /* HeapReference<Class> */ temp2 = value->klass_
4837 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
4838 temp2_loc,
4839 value,
4840 class_offset,
4841 temp3_loc,
4842 /* needs_null_check */ false);
4843 // If heap poisoning is enabled, `temp1` and `temp2` have
4844 // been unpoisoned by the the previous calls to
4845 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4846 __ cmp(temp1, ShifterOperand(temp2));
4847
4848 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4849 Label do_put;
4850 __ b(&do_put, EQ);
4851 // We do not need to emit a read barrier for the
4852 // following heap reference load, as `temp1` is only used
4853 // in a comparison with null below, and this reference
4854 // is not kept afterwards.
4855 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4856 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4857 // If heap poisoning is enabled, no need to unpoison
4858 // `temp`, as we are comparing against null below.
4859 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4860 __ Bind(&do_put);
4861 } else {
4862 __ b(slow_path->GetEntryLabel(), NE);
4863 }
4864 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004865 } else {
Roland Levillain16d9f942016-08-25 17:27:56 +01004866 // Non read barrier code.
4867
Roland Levillain3b359c72015-11-17 19:35:12 +00004868 // /* HeapReference<Class> */ temp1 = array->klass_
4869 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4870 codegen_->MaybeRecordImplicitNullCheck(instruction);
4871 __ MaybeUnpoisonHeapReference(temp1);
4872
4873 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4874 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4875 // /* HeapReference<Class> */ temp2 = value->klass_
4876 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4877 // If heap poisoning is enabled, no need to unpoison `temp1`
4878 // nor `temp2`, as we are comparing two poisoned references.
4879 __ cmp(temp1, ShifterOperand(temp2));
4880
4881 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4882 Label do_put;
4883 __ b(&do_put, EQ);
4884 // If heap poisoning is enabled, the `temp1` reference has
4885 // not been unpoisoned yet; unpoison it now.
4886 __ MaybeUnpoisonHeapReference(temp1);
4887
4888 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4889 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4890 // If heap poisoning is enabled, no need to unpoison
4891 // `temp1`, as we are comparing against null below.
4892 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4893 __ Bind(&do_put);
4894 } else {
4895 __ b(slow_path->GetEntryLabel(), NE);
4896 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004897 }
4898 }
4899
Artem Serov6c916792016-07-11 14:02:34 +01004900 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004901 if (kPoisonHeapReferences) {
4902 // Note that in the case where `value` is a null reference,
4903 // we do not enter this block, as a null reference does not
4904 // need poisoning.
4905 DCHECK_EQ(value_type, Primitive::kPrimNot);
4906 __ Mov(temp1, value);
4907 __ PoisonHeapReference(temp1);
4908 source = temp1;
4909 }
4910
4911 if (index.IsConstant()) {
4912 size_t offset =
4913 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4914 __ StoreToOffset(kStoreWord, source, array, offset);
4915 } else {
4916 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004917
4918 __ add(IP, array, ShifterOperand(data_offset));
4919 codegen_->StoreToShiftedRegOffset(value_type,
4920 Location::RegisterLocation(source),
4921 IP,
4922 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004923 }
4924
Roland Levillain3b359c72015-11-17 19:35:12 +00004925 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004926 codegen_->MaybeRecordImplicitNullCheck(instruction);
4927 }
4928
4929 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4930
4931 if (done.IsLinked()) {
4932 __ Bind(&done);
4933 }
4934
4935 if (slow_path != nullptr) {
4936 __ Bind(slow_path->GetExitLabel());
4937 }
4938
4939 break;
4940 }
4941
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004942 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004943 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004944 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004945 size_t offset =
4946 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004947 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004948 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004949 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004950 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004951 }
4952 break;
4953 }
4954
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004955 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004956 Location value = locations->InAt(2);
4957 DCHECK(value.IsFpuRegister());
4958 if (index.IsConstant()) {
4959 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004960 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004961 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004962 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004963 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4964 }
4965 break;
4966 }
4967
4968 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004969 Location value = locations->InAt(2);
4970 DCHECK(value.IsFpuRegisterPair());
4971 if (index.IsConstant()) {
4972 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004973 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004974 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004975 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004976 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4977 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004978
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004979 break;
4980 }
4981
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004982 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004983 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004984 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004985 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004986
Roland Levillain80e67092016-01-08 16:04:55 +00004987 // Objects are handled in the switch.
4988 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004989 codegen_->MaybeRecordImplicitNullCheck(instruction);
4990 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004991}
4992
4993void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004994 LocationSummary* locations =
4995 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004996 locations->SetInAt(0, Location::RequiresRegister());
4997 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004998}
4999
5000void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
5001 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01005002 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00005003 Register obj = locations->InAt(0).AsRegister<Register>();
5004 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005005 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00005006 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005007}
5008
Artem Serov328429f2016-07-06 16:23:04 +01005009void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Roland Levillain4a3aa572016-08-15 13:17:06 +00005010 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
5011 DCHECK(!kEmitCompilerReadBarrier);
Artem Serov328429f2016-07-06 16:23:04 +01005012 LocationSummary* locations =
5013 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5014
5015 locations->SetInAt(0, Location::RequiresRegister());
5016 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
5017 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5018}
5019
5020void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
5021 LocationSummary* locations = instruction->GetLocations();
5022 Location out = locations->Out();
5023 Location first = locations->InAt(0);
5024 Location second = locations->InAt(1);
5025
Roland Levillain4a3aa572016-08-15 13:17:06 +00005026 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
5027 DCHECK(!kEmitCompilerReadBarrier);
5028
Artem Serov328429f2016-07-06 16:23:04 +01005029 if (second.IsRegister()) {
5030 __ add(out.AsRegister<Register>(),
5031 first.AsRegister<Register>(),
5032 ShifterOperand(second.AsRegister<Register>()));
5033 } else {
5034 __ AddConstant(out.AsRegister<Register>(),
5035 first.AsRegister<Register>(),
5036 second.GetConstant()->AsIntConstant()->GetValue());
5037 }
5038}
5039
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005040void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00005041 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
5042 ? LocationSummary::kCallOnSlowPath
5043 : LocationSummary::kNoCall;
5044 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005045 locations->SetInAt(0, Location::RequiresRegister());
5046 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01005047 if (instruction->HasUses()) {
5048 locations->SetOut(Location::SameAsFirstInput());
5049 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005050}
5051
5052void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
5053 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07005054 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01005055 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005056 codegen_->AddSlowPath(slow_path);
5057
Roland Levillain271ab9c2014-11-27 15:23:57 +00005058 Register index = locations->InAt(0).AsRegister<Register>();
5059 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005060
5061 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01005062 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005063}
5064
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005065void CodeGeneratorARM::MarkGCCard(Register temp,
5066 Register card,
5067 Register object,
5068 Register value,
5069 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005070 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005071 if (can_be_null) {
5072 __ CompareAndBranchIfZero(value, &is_null);
5073 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005074 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005075 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5076 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005077 if (can_be_null) {
5078 __ Bind(&is_null);
5079 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005080}
5081
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005082void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005083 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005084}
5085
5086void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005087 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5088}
5089
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005090void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
5091 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5092}
5093
5094void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005095 HBasicBlock* block = instruction->GetBlock();
5096 if (block->GetLoopInformation() != nullptr) {
5097 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5098 // The back edge will generate the suspend check.
5099 return;
5100 }
5101 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5102 // The goto will generate the suspend check.
5103 return;
5104 }
5105 GenerateSuspendCheck(instruction, nullptr);
5106}
5107
5108void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5109 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005110 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005111 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5112 if (slow_path == nullptr) {
5113 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5114 instruction->SetSlowPath(slow_path);
5115 codegen_->AddSlowPath(slow_path);
5116 if (successor != nullptr) {
5117 DCHECK(successor->IsLoopHeader());
5118 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5119 }
5120 } else {
5121 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5122 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005123
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005124 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005125 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005126 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005127 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005128 __ Bind(slow_path->GetReturnLabel());
5129 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005130 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005131 __ b(slow_path->GetEntryLabel());
5132 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005133}
5134
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005135ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5136 return codegen_->GetAssembler();
5137}
5138
5139void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005140 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005141 Location source = move->GetSource();
5142 Location destination = move->GetDestination();
5143
5144 if (source.IsRegister()) {
5145 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005146 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005147 } else if (destination.IsFpuRegister()) {
5148 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005149 } else {
5150 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005151 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005152 SP, destination.GetStackIndex());
5153 }
5154 } else if (source.IsStackSlot()) {
5155 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005156 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005157 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005158 } else if (destination.IsFpuRegister()) {
5159 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005160 } else {
5161 DCHECK(destination.IsStackSlot());
5162 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5163 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5164 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005165 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005166 if (destination.IsRegister()) {
5167 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5168 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005169 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005170 } else {
5171 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005172 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5173 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005174 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005175 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005176 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5177 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005178 } else if (destination.IsRegisterPair()) {
5179 DCHECK(ExpectedPairLayout(destination));
5180 __ LoadFromOffset(
5181 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5182 } else {
5183 DCHECK(destination.IsFpuRegisterPair()) << destination;
5184 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5185 SP,
5186 source.GetStackIndex());
5187 }
5188 } else if (source.IsRegisterPair()) {
5189 if (destination.IsRegisterPair()) {
5190 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5191 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005192 } else if (destination.IsFpuRegisterPair()) {
5193 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5194 source.AsRegisterPairLow<Register>(),
5195 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005196 } else {
5197 DCHECK(destination.IsDoubleStackSlot()) << destination;
5198 DCHECK(ExpectedPairLayout(source));
5199 __ StoreToOffset(
5200 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5201 }
5202 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005203 if (destination.IsRegisterPair()) {
5204 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5205 destination.AsRegisterPairHigh<Register>(),
5206 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5207 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005208 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5209 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5210 } else {
5211 DCHECK(destination.IsDoubleStackSlot()) << destination;
5212 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5213 SP,
5214 destination.GetStackIndex());
5215 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005216 } else {
5217 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005218 HConstant* constant = source.GetConstant();
5219 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5220 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005221 if (destination.IsRegister()) {
5222 __ LoadImmediate(destination.AsRegister<Register>(), value);
5223 } else {
5224 DCHECK(destination.IsStackSlot());
5225 __ LoadImmediate(IP, value);
5226 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5227 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005228 } else if (constant->IsLongConstant()) {
5229 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005230 if (destination.IsRegisterPair()) {
5231 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5232 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005233 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005234 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005235 __ LoadImmediate(IP, Low32Bits(value));
5236 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5237 __ LoadImmediate(IP, High32Bits(value));
5238 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5239 }
5240 } else if (constant->IsDoubleConstant()) {
5241 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005242 if (destination.IsFpuRegisterPair()) {
5243 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005244 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005245 DCHECK(destination.IsDoubleStackSlot()) << destination;
5246 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005247 __ LoadImmediate(IP, Low32Bits(int_value));
5248 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5249 __ LoadImmediate(IP, High32Bits(int_value));
5250 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5251 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005252 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005253 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005254 float value = constant->AsFloatConstant()->GetValue();
5255 if (destination.IsFpuRegister()) {
5256 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5257 } else {
5258 DCHECK(destination.IsStackSlot());
5259 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5260 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5261 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005262 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005263 }
5264}
5265
5266void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5267 __ Mov(IP, reg);
5268 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5269 __ StoreToOffset(kStoreWord, IP, SP, mem);
5270}
5271
5272void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5273 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5274 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5275 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5276 SP, mem1 + stack_offset);
5277 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5278 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5279 SP, mem2 + stack_offset);
5280 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5281}
5282
5283void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005284 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005285 Location source = move->GetSource();
5286 Location destination = move->GetDestination();
5287
5288 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005289 DCHECK_NE(source.AsRegister<Register>(), IP);
5290 DCHECK_NE(destination.AsRegister<Register>(), IP);
5291 __ Mov(IP, source.AsRegister<Register>());
5292 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5293 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005294 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005295 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005296 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005297 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005298 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5299 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005300 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005301 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005302 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005303 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005304 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005305 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005306 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005307 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005308 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5309 destination.AsRegisterPairHigh<Register>(),
5310 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005311 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005312 Register low_reg = source.IsRegisterPair()
5313 ? source.AsRegisterPairLow<Register>()
5314 : destination.AsRegisterPairLow<Register>();
5315 int mem = source.IsRegisterPair()
5316 ? destination.GetStackIndex()
5317 : source.GetStackIndex();
5318 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005319 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005320 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005321 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005322 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005323 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5324 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005325 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005326 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005327 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005328 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5329 DRegister reg = source.IsFpuRegisterPair()
5330 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5331 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5332 int mem = source.IsFpuRegisterPair()
5333 ? destination.GetStackIndex()
5334 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005335 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005336 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005337 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005338 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5339 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5340 : destination.AsFpuRegister<SRegister>();
5341 int mem = source.IsFpuRegister()
5342 ? destination.GetStackIndex()
5343 : source.GetStackIndex();
5344
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005345 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005346 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005347 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005348 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005349 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5350 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005351 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005352 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005353 }
5354}
5355
5356void ParallelMoveResolverARM::SpillScratch(int reg) {
5357 __ Push(static_cast<Register>(reg));
5358}
5359
5360void ParallelMoveResolverARM::RestoreScratch(int reg) {
5361 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005362}
5363
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005364HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5365 HLoadClass::LoadKind desired_class_load_kind) {
5366 if (kEmitCompilerReadBarrier) {
5367 switch (desired_class_load_kind) {
5368 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5369 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5370 case HLoadClass::LoadKind::kBootImageAddress:
5371 // TODO: Implement for read barrier.
5372 return HLoadClass::LoadKind::kDexCacheViaMethod;
5373 default:
5374 break;
5375 }
5376 }
5377 switch (desired_class_load_kind) {
5378 case HLoadClass::LoadKind::kReferrersClass:
5379 break;
5380 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5381 DCHECK(!GetCompilerOptions().GetCompilePic());
5382 break;
5383 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5384 DCHECK(GetCompilerOptions().GetCompilePic());
5385 break;
5386 case HLoadClass::LoadKind::kBootImageAddress:
5387 break;
5388 case HLoadClass::LoadKind::kDexCacheAddress:
5389 DCHECK(Runtime::Current()->UseJitCompilation());
5390 break;
5391 case HLoadClass::LoadKind::kDexCachePcRelative:
5392 DCHECK(!Runtime::Current()->UseJitCompilation());
5393 // We disable pc-relative load when there is an irreducible loop, as the optimization
5394 // is incompatible with it.
5395 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5396 // with irreducible loops.
5397 if (GetGraph()->HasIrreducibleLoops()) {
5398 return HLoadClass::LoadKind::kDexCacheViaMethod;
5399 }
5400 break;
5401 case HLoadClass::LoadKind::kDexCacheViaMethod:
5402 break;
5403 }
5404 return desired_class_load_kind;
5405}
5406
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005407void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005408 if (cls->NeedsAccessCheck()) {
5409 InvokeRuntimeCallingConvention calling_convention;
5410 CodeGenerator::CreateLoadClassLocationSummary(
5411 cls,
5412 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5413 Location::RegisterLocation(R0),
5414 /* code_generator_supports_read_barrier */ true);
5415 return;
5416 }
5417
5418 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5419 ? LocationSummary::kCallOnSlowPath
5420 : LocationSummary::kNoCall;
5421 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
5422 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5423 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5424 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5425 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5426 locations->SetInAt(0, Location::RequiresRegister());
5427 }
5428 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005429}
5430
5431void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005432 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005433 if (cls->NeedsAccessCheck()) {
5434 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
5435 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
5436 cls,
5437 cls->GetDexPc(),
5438 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005439 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005440 return;
5441 }
5442
Roland Levillain3b359c72015-11-17 19:35:12 +00005443 Location out_loc = locations->Out();
5444 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005445
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005446 bool generate_null_check = false;
5447 switch (cls->GetLoadKind()) {
5448 case HLoadClass::LoadKind::kReferrersClass: {
5449 DCHECK(!cls->CanCallRuntime());
5450 DCHECK(!cls->MustGenerateClinitCheck());
5451 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5452 Register current_method = locations->InAt(0).AsRegister<Register>();
5453 GenerateGcRootFieldLoad(
5454 cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5455 break;
5456 }
5457 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
5458 DCHECK(!kEmitCompilerReadBarrier);
5459 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5460 cls->GetTypeIndex()));
5461 break;
5462 }
5463 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
5464 DCHECK(!kEmitCompilerReadBarrier);
5465 CodeGeneratorARM::PcRelativePatchInfo* labels =
5466 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5467 __ BindTrackedLabel(&labels->movw_label);
5468 __ movw(out, /* placeholder */ 0u);
5469 __ BindTrackedLabel(&labels->movt_label);
5470 __ movt(out, /* placeholder */ 0u);
5471 __ BindTrackedLabel(&labels->add_pc_label);
5472 __ add(out, out, ShifterOperand(PC));
5473 break;
5474 }
5475 case HLoadClass::LoadKind::kBootImageAddress: {
5476 DCHECK(!kEmitCompilerReadBarrier);
5477 DCHECK_NE(cls->GetAddress(), 0u);
5478 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5479 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5480 break;
5481 }
5482 case HLoadClass::LoadKind::kDexCacheAddress: {
5483 DCHECK_NE(cls->GetAddress(), 0u);
5484 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5485 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5486 // a 128B range. To try and reduce the number of literals if we load multiple types,
5487 // simply split the dex cache address to a 128B aligned base loaded from a literal
5488 // and the remaining offset embedded in the load.
5489 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5490 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5491 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5492 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5493 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5494 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5495 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
5496 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5497 generate_null_check = !cls->IsInDexCache();
5498 break;
5499 }
5500 case HLoadClass::LoadKind::kDexCachePcRelative: {
5501 Register base_reg = locations->InAt(0).AsRegister<Register>();
5502 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5503 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5504 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
5505 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset);
5506 generate_null_check = !cls->IsInDexCache();
5507 break;
5508 }
5509 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5510 // /* GcRoot<mirror::Class>[] */ out =
5511 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5512 Register current_method = locations->InAt(0).AsRegister<Register>();
5513 __ LoadFromOffset(kLoadWord,
5514 out,
5515 current_method,
5516 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5517 // /* GcRoot<mirror::Class> */ out = out[type_index]
5518 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
5519 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5520 generate_null_check = !cls->IsInDexCache();
5521 }
5522 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005523
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005524 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5525 DCHECK(cls->CanCallRuntime());
5526 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
5527 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5528 codegen_->AddSlowPath(slow_path);
5529 if (generate_null_check) {
5530 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5531 }
5532 if (cls->MustGenerateClinitCheck()) {
5533 GenerateClassInitializationCheck(slow_path, out);
5534 } else {
5535 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005536 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005537 }
5538}
5539
5540void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5541 LocationSummary* locations =
5542 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5543 locations->SetInAt(0, Location::RequiresRegister());
5544 if (check->HasUses()) {
5545 locations->SetOut(Location::SameAsFirstInput());
5546 }
5547}
5548
5549void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005550 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07005551 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005552 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005553 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005554 GenerateClassInitializationCheck(slow_path,
5555 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005556}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005557
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005558void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07005559 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005560 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5561 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5562 __ b(slow_path->GetEntryLabel(), LT);
5563 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5564 // properly. Therefore, we do a memory fence.
5565 __ dmb(ISH);
5566 __ Bind(slow_path->GetExitLabel());
5567}
5568
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005569HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5570 HLoadString::LoadKind desired_string_load_kind) {
5571 if (kEmitCompilerReadBarrier) {
5572 switch (desired_string_load_kind) {
5573 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5574 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5575 case HLoadString::LoadKind::kBootImageAddress:
5576 // TODO: Implement for read barrier.
5577 return HLoadString::LoadKind::kDexCacheViaMethod;
5578 default:
5579 break;
5580 }
5581 }
5582 switch (desired_string_load_kind) {
5583 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5584 DCHECK(!GetCompilerOptions().GetCompilePic());
5585 break;
5586 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5587 DCHECK(GetCompilerOptions().GetCompilePic());
5588 break;
5589 case HLoadString::LoadKind::kBootImageAddress:
5590 break;
5591 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005592 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005593 break;
5594 case HLoadString::LoadKind::kDexCachePcRelative:
Calin Juravleffc87072016-04-20 14:22:09 +01005595 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005596 // We disable pc-relative load when there is an irreducible loop, as the optimization
5597 // is incompatible with it.
5598 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5599 // with irreducible loops.
5600 if (GetGraph()->HasIrreducibleLoops()) {
5601 return HLoadString::LoadKind::kDexCacheViaMethod;
5602 }
5603 break;
5604 case HLoadString::LoadKind::kDexCacheViaMethod:
5605 break;
5606 }
5607 return desired_string_load_kind;
5608}
5609
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005610void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005611 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005612 ? LocationSummary::kCallOnSlowPath
5613 : LocationSummary::kNoCall;
5614 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005615 HLoadString::LoadKind load_kind = load->GetLoadKind();
5616 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod ||
5617 load_kind == HLoadString::LoadKind::kDexCachePcRelative) {
5618 locations->SetInAt(0, Location::RequiresRegister());
5619 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005620 locations->SetOut(Location::RequiresRegister());
5621}
5622
5623void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005624 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005625 Location out_loc = locations->Out();
5626 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005627
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005628 switch (load->GetLoadKind()) {
5629 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
5630 DCHECK(!kEmitCompilerReadBarrier);
5631 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5632 load->GetStringIndex()));
5633 return; // No dex cache slow path.
5634 }
5635 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
5636 DCHECK(!kEmitCompilerReadBarrier);
5637 CodeGeneratorARM::PcRelativePatchInfo* labels =
5638 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5639 __ BindTrackedLabel(&labels->movw_label);
5640 __ movw(out, /* placeholder */ 0u);
5641 __ BindTrackedLabel(&labels->movt_label);
5642 __ movt(out, /* placeholder */ 0u);
5643 __ BindTrackedLabel(&labels->add_pc_label);
5644 __ add(out, out, ShifterOperand(PC));
5645 return; // No dex cache slow path.
5646 }
5647 case HLoadString::LoadKind::kBootImageAddress: {
5648 DCHECK(!kEmitCompilerReadBarrier);
5649 DCHECK_NE(load->GetAddress(), 0u);
5650 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5651 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5652 return; // No dex cache slow path.
5653 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005654 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005655 break;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005656 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005657
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005658 // TODO: Re-add the compiler code to do string dex cache lookup again.
5659 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5660 codegen_->AddSlowPath(slow_path);
5661 __ b(slow_path->GetEntryLabel());
5662 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005663}
5664
David Brazdilcb1c0552015-08-04 16:22:25 +01005665static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005666 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005667}
5668
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005669void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5670 LocationSummary* locations =
5671 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5672 locations->SetOut(Location::RequiresRegister());
5673}
5674
5675void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005676 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005677 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5678}
5679
5680void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5681 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5682}
5683
5684void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005685 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005686 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005687}
5688
5689void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5690 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005691 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005692 InvokeRuntimeCallingConvention calling_convention;
5693 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5694}
5695
5696void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
5697 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00005698 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005699 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005700}
5701
Roland Levillainc9285912015-12-18 10:38:42 +00005702static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
5703 return kEmitCompilerReadBarrier &&
5704 (kUseBakerReadBarrier ||
5705 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5706 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5707 type_check_kind == TypeCheckKind::kArrayObjectCheck);
5708}
5709
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005710void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005711 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00005712 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5713 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005714 case TypeCheckKind::kExactCheck:
5715 case TypeCheckKind::kAbstractClassCheck:
5716 case TypeCheckKind::kClassHierarchyCheck:
5717 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005718 call_kind =
5719 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005720 break;
5721 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005722 case TypeCheckKind::kUnresolvedCheck:
5723 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005724 call_kind = LocationSummary::kCallOnSlowPath;
5725 break;
5726 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005727
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005728 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Roland Levillain3b359c72015-11-17 19:35:12 +00005729 locations->SetInAt(0, Location::RequiresRegister());
5730 locations->SetInAt(1, Location::RequiresRegister());
5731 // The "out" register is used as a temporary, so it overlaps with the inputs.
5732 // Note that TypeCheckSlowPathARM uses this register too.
5733 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5734 // When read barriers are enabled, we need a temporary register for
5735 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005736 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00005737 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005738 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005739}
5740
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005741void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005742 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005743 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005744 Location obj_loc = locations->InAt(0);
5745 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005746 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005747 Location out_loc = locations->Out();
5748 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005749 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005750 locations->GetTemp(0) :
5751 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005752 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005753 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5754 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5755 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005756 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07005757 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005758
5759 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005760 // avoid null check if we know obj is not null.
5761 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00005762 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005763 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005764
Roland Levillain3b359c72015-11-17 19:35:12 +00005765 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005766 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005767
Roland Levillainc9285912015-12-18 10:38:42 +00005768 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005769 case TypeCheckKind::kExactCheck: {
5770 __ cmp(out, ShifterOperand(cls));
5771 // Classes must be equal for the instanceof to succeed.
5772 __ b(&zero, NE);
5773 __ LoadImmediate(out, 1);
5774 __ b(&done);
5775 break;
5776 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005777
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005778 case TypeCheckKind::kAbstractClassCheck: {
5779 // If the class is abstract, we eagerly fetch the super class of the
5780 // object to avoid doing a comparison we know will fail.
5781 Label loop;
5782 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005783 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005784 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005785 // If `out` is null, we use it for the result, and jump to `done`.
5786 __ CompareAndBranchIfZero(out, &done);
5787 __ cmp(out, ShifterOperand(cls));
5788 __ b(&loop, NE);
5789 __ LoadImmediate(out, 1);
5790 if (zero.IsLinked()) {
5791 __ b(&done);
5792 }
5793 break;
5794 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005795
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005796 case TypeCheckKind::kClassHierarchyCheck: {
5797 // Walk over the class hierarchy to find a match.
5798 Label loop, success;
5799 __ Bind(&loop);
5800 __ cmp(out, ShifterOperand(cls));
5801 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005802 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005803 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005804 __ CompareAndBranchIfNonZero(out, &loop);
5805 // If `out` is null, we use it for the result, and jump to `done`.
5806 __ b(&done);
5807 __ Bind(&success);
5808 __ LoadImmediate(out, 1);
5809 if (zero.IsLinked()) {
5810 __ b(&done);
5811 }
5812 break;
5813 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005814
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005815 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005816 // Do an exact check.
5817 Label exact_check;
5818 __ cmp(out, ShifterOperand(cls));
5819 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005820 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005821 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005822 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005823 // If `out` is null, we use it for the result, and jump to `done`.
5824 __ CompareAndBranchIfZero(out, &done);
5825 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5826 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5827 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005828 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005829 __ LoadImmediate(out, 1);
5830 __ b(&done);
5831 break;
5832 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005833
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005834 case TypeCheckKind::kArrayCheck: {
5835 __ cmp(out, ShifterOperand(cls));
5836 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00005837 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5838 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005839 codegen_->AddSlowPath(slow_path);
5840 __ b(slow_path->GetEntryLabel(), NE);
5841 __ LoadImmediate(out, 1);
5842 if (zero.IsLinked()) {
5843 __ b(&done);
5844 }
5845 break;
5846 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005847
Calin Juravle98893e12015-10-02 21:05:03 +01005848 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005849 case TypeCheckKind::kInterfaceCheck: {
5850 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00005851 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00005852 // cases.
5853 //
5854 // We cannot directly call the InstanceofNonTrivial runtime
5855 // entry point without resorting to a type checking slow path
5856 // here (i.e. by calling InvokeRuntime directly), as it would
5857 // require to assign fixed registers for the inputs of this
5858 // HInstanceOf instruction (following the runtime calling
5859 // convention), which might be cluttered by the potential first
5860 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00005861 //
5862 // TODO: Introduce a new runtime entry point taking the object
5863 // to test (instead of its class) as argument, and let it deal
5864 // with the read barrier issues. This will let us refactor this
5865 // case of the `switch` code as it was previously (with a direct
5866 // call to the runtime not using a type checking slow path).
5867 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00005868 DCHECK(locations->OnlyCallsOnSlowPath());
5869 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5870 /* is_fatal */ false);
5871 codegen_->AddSlowPath(slow_path);
5872 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005873 if (zero.IsLinked()) {
5874 __ b(&done);
5875 }
5876 break;
5877 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005878 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005879
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005880 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005881 __ Bind(&zero);
5882 __ LoadImmediate(out, 0);
5883 }
5884
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005885 if (done.IsLinked()) {
5886 __ Bind(&done);
5887 }
5888
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005889 if (slow_path != nullptr) {
5890 __ Bind(slow_path->GetExitLabel());
5891 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005892}
5893
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005894void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005895 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5896 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
5897
Roland Levillain3b359c72015-11-17 19:35:12 +00005898 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5899 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005900 case TypeCheckKind::kExactCheck:
5901 case TypeCheckKind::kAbstractClassCheck:
5902 case TypeCheckKind::kClassHierarchyCheck:
5903 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005904 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
5905 LocationSummary::kCallOnSlowPath :
5906 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005907 break;
5908 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005909 case TypeCheckKind::kUnresolvedCheck:
5910 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005911 call_kind = LocationSummary::kCallOnSlowPath;
5912 break;
5913 }
5914
Roland Levillain3b359c72015-11-17 19:35:12 +00005915 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
5916 locations->SetInAt(0, Location::RequiresRegister());
5917 locations->SetInAt(1, Location::RequiresRegister());
5918 // Note that TypeCheckSlowPathARM uses this "temp" register too.
5919 locations->AddTemp(Location::RequiresRegister());
5920 // When read barriers are enabled, we need an additional temporary
5921 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005922 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005923 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005924 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005925}
5926
5927void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005928 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005929 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005930 Location obj_loc = locations->InAt(0);
5931 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005932 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005933 Location temp_loc = locations->GetTemp(0);
5934 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005935 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005936 locations->GetTemp(1) :
5937 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005938 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005939 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5940 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5941 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005942
Roland Levillain3b359c72015-11-17 19:35:12 +00005943 bool is_type_check_slow_path_fatal =
5944 (type_check_kind == TypeCheckKind::kExactCheck ||
5945 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5946 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5947 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
5948 !instruction->CanThrowIntoCatchBlock();
5949 SlowPathCode* type_check_slow_path =
5950 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5951 is_type_check_slow_path_fatal);
5952 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005953
5954 Label done;
5955 // Avoid null check if we know obj is not null.
5956 if (instruction->MustDoNullCheck()) {
5957 __ CompareAndBranchIfZero(obj, &done);
5958 }
5959
Roland Levillain3b359c72015-11-17 19:35:12 +00005960 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005961 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005962
Roland Levillain3b359c72015-11-17 19:35:12 +00005963 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005964 case TypeCheckKind::kExactCheck:
5965 case TypeCheckKind::kArrayCheck: {
5966 __ cmp(temp, ShifterOperand(cls));
5967 // Jump to slow path for throwing the exception or doing a
5968 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005969 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005970 break;
5971 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005972
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005973 case TypeCheckKind::kAbstractClassCheck: {
5974 // If the class is abstract, we eagerly fetch the super class of the
5975 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00005976 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005977 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005978 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005979 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005980
5981 // If the class reference currently in `temp` is not null, jump
5982 // to the `compare_classes` label to compare it with the checked
5983 // class.
5984 __ CompareAndBranchIfNonZero(temp, &compare_classes);
5985 // Otherwise, jump to the slow path to throw the exception.
5986 //
5987 // But before, move back the object's class into `temp` before
5988 // going into the slow path, as it has been overwritten in the
5989 // meantime.
5990 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005991 GenerateReferenceLoadTwoRegisters(
5992 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005993 __ b(type_check_slow_path->GetEntryLabel());
5994
5995 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005996 __ cmp(temp, ShifterOperand(cls));
5997 __ b(&loop, NE);
5998 break;
5999 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006000
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006001 case TypeCheckKind::kClassHierarchyCheck: {
6002 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006003 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006004 __ Bind(&loop);
6005 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006006 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006007
Roland Levillain3b359c72015-11-17 19:35:12 +00006008 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006009 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006010
6011 // If the class reference currently in `temp` is not null, jump
6012 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006013 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00006014 // Otherwise, jump to the slow path to throw the exception.
6015 //
6016 // But before, move back the object's class into `temp` before
6017 // going into the slow path, as it has been overwritten in the
6018 // meantime.
6019 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006020 GenerateReferenceLoadTwoRegisters(
6021 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006022 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006023 break;
6024 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006025
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006026 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006027 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00006028 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006029 __ cmp(temp, ShifterOperand(cls));
6030 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006031
6032 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00006033 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006034 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006035
6036 // If the component type is not null (i.e. the object is indeed
6037 // an array), jump to label `check_non_primitive_component_type`
6038 // to further check that this component type is not a primitive
6039 // type.
6040 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6041 // Otherwise, jump to the slow path to throw the exception.
6042 //
6043 // But before, move back the object's class into `temp` before
6044 // going into the slow path, as it has been overwritten in the
6045 // meantime.
6046 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006047 GenerateReferenceLoadTwoRegisters(
6048 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006049 __ b(type_check_slow_path->GetEntryLabel());
6050
6051 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006052 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006053 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6054 __ CompareAndBranchIfZero(temp, &done);
6055 // Same comment as above regarding `temp` and the slow path.
6056 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006057 GenerateReferenceLoadTwoRegisters(
6058 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006059 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006060 break;
6061 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006062
Calin Juravle98893e12015-10-02 21:05:03 +01006063 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006064 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006065 // We always go into the type check slow path for the unresolved
6066 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006067 //
6068 // We cannot directly call the CheckCast runtime entry point
6069 // without resorting to a type checking slow path here (i.e. by
6070 // calling InvokeRuntime directly), as it would require to
6071 // assign fixed registers for the inputs of this HInstanceOf
6072 // instruction (following the runtime calling convention), which
6073 // might be cluttered by the potential first read barrier
6074 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006075 //
6076 // TODO: Introduce a new runtime entry point taking the object
6077 // to test (instead of its class) as argument, and let it deal
6078 // with the read barrier issues. This will let us refactor this
6079 // case of the `switch` code as it was previously (with a direct
6080 // call to the runtime not using a type checking slow path).
6081 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006082 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006083 break;
6084 }
6085 __ Bind(&done);
6086
Roland Levillain3b359c72015-11-17 19:35:12 +00006087 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006088}
6089
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006090void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6091 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006092 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006093 InvokeRuntimeCallingConvention calling_convention;
6094 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6095}
6096
6097void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6098 codegen_->InvokeRuntime(instruction->IsEnter()
6099 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
6100 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00006101 instruction->GetDexPc(),
6102 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00006103 if (instruction->IsEnter()) {
6104 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6105 } else {
6106 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6107 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006108}
6109
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006110void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6111void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6112void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006113
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006114void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006115 LocationSummary* locations =
6116 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6117 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6118 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006119 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006120 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006121 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006122 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006123}
6124
6125void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6126 HandleBitwiseOperation(instruction);
6127}
6128
6129void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6130 HandleBitwiseOperation(instruction);
6131}
6132
6133void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6134 HandleBitwiseOperation(instruction);
6135}
6136
Artem Serov7fc63502016-02-09 17:15:29 +00006137
6138void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6139 LocationSummary* locations =
6140 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6141 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6142 || instruction->GetResultType() == Primitive::kPrimLong);
6143
6144 locations->SetInAt(0, Location::RequiresRegister());
6145 locations->SetInAt(1, Location::RequiresRegister());
6146 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6147}
6148
6149void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6150 LocationSummary* locations = instruction->GetLocations();
6151 Location first = locations->InAt(0);
6152 Location second = locations->InAt(1);
6153 Location out = locations->Out();
6154
6155 if (instruction->GetResultType() == Primitive::kPrimInt) {
6156 Register first_reg = first.AsRegister<Register>();
6157 ShifterOperand second_reg(second.AsRegister<Register>());
6158 Register out_reg = out.AsRegister<Register>();
6159
6160 switch (instruction->GetOpKind()) {
6161 case HInstruction::kAnd:
6162 __ bic(out_reg, first_reg, second_reg);
6163 break;
6164 case HInstruction::kOr:
6165 __ orn(out_reg, first_reg, second_reg);
6166 break;
6167 // There is no EON on arm.
6168 case HInstruction::kXor:
6169 default:
6170 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6171 UNREACHABLE();
6172 }
6173 return;
6174
6175 } else {
6176 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6177 Register first_low = first.AsRegisterPairLow<Register>();
6178 Register first_high = first.AsRegisterPairHigh<Register>();
6179 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6180 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6181 Register out_low = out.AsRegisterPairLow<Register>();
6182 Register out_high = out.AsRegisterPairHigh<Register>();
6183
6184 switch (instruction->GetOpKind()) {
6185 case HInstruction::kAnd:
6186 __ bic(out_low, first_low, second_low);
6187 __ bic(out_high, first_high, second_high);
6188 break;
6189 case HInstruction::kOr:
6190 __ orn(out_low, first_low, second_low);
6191 __ orn(out_high, first_high, second_high);
6192 break;
6193 // There is no EON on arm.
6194 case HInstruction::kXor:
6195 default:
6196 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6197 UNREACHABLE();
6198 }
6199 }
6200}
6201
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006202void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6203 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6204 if (value == 0xffffffffu) {
6205 if (out != first) {
6206 __ mov(out, ShifterOperand(first));
6207 }
6208 return;
6209 }
6210 if (value == 0u) {
6211 __ mov(out, ShifterOperand(0));
6212 return;
6213 }
6214 ShifterOperand so;
6215 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6216 __ and_(out, first, so);
6217 } else {
6218 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6219 __ bic(out, first, ShifterOperand(~value));
6220 }
6221}
6222
6223void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6224 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6225 if (value == 0u) {
6226 if (out != first) {
6227 __ mov(out, ShifterOperand(first));
6228 }
6229 return;
6230 }
6231 if (value == 0xffffffffu) {
6232 __ mvn(out, ShifterOperand(0));
6233 return;
6234 }
6235 ShifterOperand so;
6236 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6237 __ orr(out, first, so);
6238 } else {
6239 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6240 __ orn(out, first, ShifterOperand(~value));
6241 }
6242}
6243
6244void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6245 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6246 if (value == 0u) {
6247 if (out != first) {
6248 __ mov(out, ShifterOperand(first));
6249 }
6250 return;
6251 }
6252 __ eor(out, first, ShifterOperand(value));
6253}
6254
Vladimir Marko59751a72016-08-05 14:37:27 +01006255void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6256 Location first,
6257 uint64_t value) {
6258 Register out_low = out.AsRegisterPairLow<Register>();
6259 Register out_high = out.AsRegisterPairHigh<Register>();
6260 Register first_low = first.AsRegisterPairLow<Register>();
6261 Register first_high = first.AsRegisterPairHigh<Register>();
6262 uint32_t value_low = Low32Bits(value);
6263 uint32_t value_high = High32Bits(value);
6264 if (value_low == 0u) {
6265 if (out_low != first_low) {
6266 __ mov(out_low, ShifterOperand(first_low));
6267 }
6268 __ AddConstant(out_high, first_high, value_high);
6269 return;
6270 }
6271 __ AddConstantSetFlags(out_low, first_low, value_low);
6272 ShifterOperand so;
6273 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6274 __ adc(out_high, first_high, so);
6275 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6276 __ sbc(out_high, first_high, so);
6277 } else {
6278 LOG(FATAL) << "Unexpected constant " << value_high;
6279 UNREACHABLE();
6280 }
6281}
6282
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006283void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6284 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006285 Location first = locations->InAt(0);
6286 Location second = locations->InAt(1);
6287 Location out = locations->Out();
6288
6289 if (second.IsConstant()) {
6290 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6291 uint32_t value_low = Low32Bits(value);
6292 if (instruction->GetResultType() == Primitive::kPrimInt) {
6293 Register first_reg = first.AsRegister<Register>();
6294 Register out_reg = out.AsRegister<Register>();
6295 if (instruction->IsAnd()) {
6296 GenerateAndConst(out_reg, first_reg, value_low);
6297 } else if (instruction->IsOr()) {
6298 GenerateOrrConst(out_reg, first_reg, value_low);
6299 } else {
6300 DCHECK(instruction->IsXor());
6301 GenerateEorConst(out_reg, first_reg, value_low);
6302 }
6303 } else {
6304 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6305 uint32_t value_high = High32Bits(value);
6306 Register first_low = first.AsRegisterPairLow<Register>();
6307 Register first_high = first.AsRegisterPairHigh<Register>();
6308 Register out_low = out.AsRegisterPairLow<Register>();
6309 Register out_high = out.AsRegisterPairHigh<Register>();
6310 if (instruction->IsAnd()) {
6311 GenerateAndConst(out_low, first_low, value_low);
6312 GenerateAndConst(out_high, first_high, value_high);
6313 } else if (instruction->IsOr()) {
6314 GenerateOrrConst(out_low, first_low, value_low);
6315 GenerateOrrConst(out_high, first_high, value_high);
6316 } else {
6317 DCHECK(instruction->IsXor());
6318 GenerateEorConst(out_low, first_low, value_low);
6319 GenerateEorConst(out_high, first_high, value_high);
6320 }
6321 }
6322 return;
6323 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006324
6325 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006326 Register first_reg = first.AsRegister<Register>();
6327 ShifterOperand second_reg(second.AsRegister<Register>());
6328 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006329 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006330 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006331 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006332 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006333 } else {
6334 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006335 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006336 }
6337 } else {
6338 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006339 Register first_low = first.AsRegisterPairLow<Register>();
6340 Register first_high = first.AsRegisterPairHigh<Register>();
6341 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6342 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6343 Register out_low = out.AsRegisterPairLow<Register>();
6344 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006345 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006346 __ and_(out_low, first_low, second_low);
6347 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006348 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006349 __ orr(out_low, first_low, second_low);
6350 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006351 } else {
6352 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006353 __ eor(out_low, first_low, second_low);
6354 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006355 }
6356 }
6357}
6358
Roland Levillainc9285912015-12-18 10:38:42 +00006359void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6360 Location out,
6361 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006362 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006363 Register out_reg = out.AsRegister<Register>();
6364 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006365 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006366 if (kUseBakerReadBarrier) {
6367 // Load with fast path based Baker's read barrier.
6368 // /* HeapReference<Object> */ out = *(out + offset)
6369 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006370 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006371 } else {
6372 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006373 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006374 // in the following move operation, as we will need it for the
6375 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006376 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006377 // /* HeapReference<Object> */ out = *(out + offset)
6378 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006379 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006380 }
6381 } else {
6382 // Plain load with no read barrier.
6383 // /* HeapReference<Object> */ out = *(out + offset)
6384 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6385 __ MaybeUnpoisonHeapReference(out_reg);
6386 }
6387}
6388
6389void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6390 Location out,
6391 Location obj,
6392 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006393 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006394 Register out_reg = out.AsRegister<Register>();
6395 Register obj_reg = obj.AsRegister<Register>();
6396 if (kEmitCompilerReadBarrier) {
6397 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006398 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006399 // Load with fast path based Baker's read barrier.
6400 // /* HeapReference<Object> */ out = *(obj + offset)
6401 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006402 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006403 } else {
6404 // Load with slow path based read barrier.
6405 // /* HeapReference<Object> */ out = *(obj + offset)
6406 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6407 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6408 }
6409 } else {
6410 // Plain load with no read barrier.
6411 // /* HeapReference<Object> */ out = *(obj + offset)
6412 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6413 __ MaybeUnpoisonHeapReference(out_reg);
6414 }
6415}
6416
6417void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6418 Location root,
6419 Register obj,
6420 uint32_t offset) {
6421 Register root_reg = root.AsRegister<Register>();
6422 if (kEmitCompilerReadBarrier) {
6423 if (kUseBakerReadBarrier) {
6424 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6425 // Baker's read barrier are used:
6426 //
6427 // root = obj.field;
6428 // if (Thread::Current()->GetIsGcMarking()) {
6429 // root = ReadBarrier::Mark(root)
6430 // }
6431
6432 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6433 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6434 static_assert(
6435 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6436 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6437 "have different sizes.");
6438 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6439 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6440 "have different sizes.");
6441
Vladimir Marko953437b2016-08-24 08:30:46 +00006442 // Slow path marking the GC root `root`.
Roland Levillainc9285912015-12-18 10:38:42 +00006443 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006444 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006445 codegen_->AddSlowPath(slow_path);
6446
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006447 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006448 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006449 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006450 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6451 __ Bind(slow_path->GetExitLabel());
6452 } else {
6453 // GC root loaded through a slow path for read barriers other
6454 // than Baker's.
6455 // /* GcRoot<mirror::Object>* */ root = obj + offset
6456 __ AddConstant(root_reg, obj, offset);
6457 // /* mirror::Object* */ root = root->Read()
6458 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6459 }
6460 } else {
6461 // Plain GC root load with no read barrier.
6462 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6463 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6464 // Note that GC roots are not affected by heap poisoning, thus we
6465 // do not have to unpoison `root_reg` here.
6466 }
6467}
6468
6469void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6470 Location ref,
6471 Register obj,
6472 uint32_t offset,
6473 Location temp,
6474 bool needs_null_check) {
6475 DCHECK(kEmitCompilerReadBarrier);
6476 DCHECK(kUseBakerReadBarrier);
6477
6478 // /* HeapReference<Object> */ ref = *(obj + offset)
6479 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006480 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006481 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006482 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006483}
6484
6485void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6486 Location ref,
6487 Register obj,
6488 uint32_t data_offset,
6489 Location index,
6490 Location temp,
6491 bool needs_null_check) {
6492 DCHECK(kEmitCompilerReadBarrier);
6493 DCHECK(kUseBakerReadBarrier);
6494
Roland Levillainbfea3352016-06-23 13:48:47 +01006495 static_assert(
6496 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6497 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006498 // /* HeapReference<Object> */ ref =
6499 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006500 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006501 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006502 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006503}
6504
6505void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6506 Location ref,
6507 Register obj,
6508 uint32_t offset,
6509 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006510 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006511 Location temp,
6512 bool needs_null_check) {
6513 DCHECK(kEmitCompilerReadBarrier);
6514 DCHECK(kUseBakerReadBarrier);
6515
6516 // In slow path based read barriers, the read barrier call is
6517 // inserted after the original load. However, in fast path based
6518 // Baker's read barriers, we need to perform the load of
6519 // mirror::Object::monitor_ *before* the original reference load.
6520 // This load-load ordering is required by the read barrier.
6521 // The fast path/slow path (for Baker's algorithm) should look like:
6522 //
6523 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6524 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6525 // HeapReference<Object> ref = *src; // Original reference load.
6526 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6527 // if (is_gray) {
6528 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6529 // }
6530 //
6531 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006532 // slightly more complex as it performs additional checks that we do
6533 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006534
6535 Register ref_reg = ref.AsRegister<Register>();
6536 Register temp_reg = temp.AsRegister<Register>();
6537 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6538
6539 // /* int32_t */ monitor = obj->monitor_
6540 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6541 if (needs_null_check) {
6542 MaybeRecordImplicitNullCheck(instruction);
6543 }
6544 // /* LockWord */ lock_word = LockWord(monitor)
6545 static_assert(sizeof(LockWord) == sizeof(int32_t),
6546 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006547
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006548 // Introduce a dependency on the lock_word including the rb_state,
6549 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006550 // a memory barrier (which would be more expensive).
Roland Levillain0b671c02016-08-19 12:02:34 +01006551 // `obj` is unchanged by this operation, but its value now depends
6552 // on `temp_reg`.
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006553 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006554
6555 // The actual reference load.
6556 if (index.IsValid()) {
Roland Levillainbfea3352016-06-23 13:48:47 +01006557 // Load types involving an "index": ArrayGet and
6558 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
6559 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006560 if (index.IsConstant()) {
6561 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006562 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006563 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6564 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006565 // Handle the special case of the
6566 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use
6567 // a register pair as index ("long offset"), of which only the low
6568 // part contains data.
6569 Register index_reg = index.IsRegisterPair()
6570 ? index.AsRegisterPairLow<Register>()
6571 : index.AsRegister<Register>();
6572 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006573 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6574 }
6575 } else {
6576 // /* HeapReference<Object> */ ref = *(obj + offset)
6577 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6578 }
6579
6580 // Object* ref = ref_addr->AsMirrorPtr()
6581 __ MaybeUnpoisonHeapReference(ref_reg);
6582
Vladimir Marko953437b2016-08-24 08:30:46 +00006583 // Slow path marking the object `ref` when it is gray.
Roland Levillainc9285912015-12-18 10:38:42 +00006584 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006585 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
Roland Levillainc9285912015-12-18 10:38:42 +00006586 AddSlowPath(slow_path);
6587
6588 // if (rb_state == ReadBarrier::gray_ptr_)
6589 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006590 // Given the numeric representation, it's enough to check the low bit of the
6591 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6592 // which can be a 16-bit instruction unlike the TST immediate.
6593 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6594 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6595 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6596 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6597 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006598 __ Bind(slow_path->GetExitLabel());
6599}
6600
6601void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6602 Location out,
6603 Location ref,
6604 Location obj,
6605 uint32_t offset,
6606 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006607 DCHECK(kEmitCompilerReadBarrier);
6608
Roland Levillainc9285912015-12-18 10:38:42 +00006609 // Insert a slow path based read barrier *after* the reference load.
6610 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006611 // If heap poisoning is enabled, the unpoisoning of the loaded
6612 // reference will be carried out by the runtime within the slow
6613 // path.
6614 //
6615 // Note that `ref` currently does not get unpoisoned (when heap
6616 // poisoning is enabled), which is alright as the `ref` argument is
6617 // not used by the artReadBarrierSlow entry point.
6618 //
6619 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
6620 SlowPathCode* slow_path = new (GetGraph()->GetArena())
6621 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6622 AddSlowPath(slow_path);
6623
Roland Levillain3b359c72015-11-17 19:35:12 +00006624 __ b(slow_path->GetEntryLabel());
6625 __ Bind(slow_path->GetExitLabel());
6626}
6627
Roland Levillainc9285912015-12-18 10:38:42 +00006628void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6629 Location out,
6630 Location ref,
6631 Location obj,
6632 uint32_t offset,
6633 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006634 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006635 // Baker's read barriers shall be handled by the fast path
6636 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6637 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006638 // If heap poisoning is enabled, unpoisoning will be taken care of
6639 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006640 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006641 } else if (kPoisonHeapReferences) {
6642 __ UnpoisonHeapReference(out.AsRegister<Register>());
6643 }
6644}
6645
Roland Levillainc9285912015-12-18 10:38:42 +00006646void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6647 Location out,
6648 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006649 DCHECK(kEmitCompilerReadBarrier);
6650
Roland Levillainc9285912015-12-18 10:38:42 +00006651 // Insert a slow path based read barrier *after* the GC root load.
6652 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006653 // Note that GC roots are not affected by heap poisoning, so we do
6654 // not need to do anything special for this here.
6655 SlowPathCode* slow_path =
6656 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6657 AddSlowPath(slow_path);
6658
Roland Levillain3b359c72015-11-17 19:35:12 +00006659 __ b(slow_path->GetEntryLabel());
6660 __ Bind(slow_path->GetExitLabel());
6661}
6662
Vladimir Markodc151b22015-10-15 18:02:30 +01006663HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6664 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
6665 MethodReference target_method) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006666 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6667 // We disable pc-relative load when there is an irreducible loop, as the optimization
6668 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006669 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6670 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006671 if (GetGraph()->HasIrreducibleLoops() &&
6672 (dispatch_info.method_load_kind ==
6673 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
6674 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
6675 }
6676
6677 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01006678 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
6679 if (&outer_dex_file != target_method.dex_file) {
6680 // Calls across dex files are more likely to exceed the available BL range,
6681 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
6682 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
6683 (desired_dispatch_info.method_load_kind ==
6684 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
6685 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
6686 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
6687 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006688 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01006689 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006690 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01006691 0u
6692 };
6693 }
6694 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006695 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006696}
6697
Vladimir Markob4536b72015-11-24 13:45:23 +00006698Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
6699 Register temp) {
6700 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
6701 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
6702 if (!invoke->GetLocations()->Intrinsified()) {
6703 return location.AsRegister<Register>();
6704 }
6705 // For intrinsics we allow any location, so it may be on the stack.
6706 if (!location.IsRegister()) {
6707 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
6708 return temp;
6709 }
6710 // For register locations, check if the register was saved. If so, get it from the stack.
6711 // Note: There is a chance that the register was saved but not overwritten, so we could
6712 // save one load. However, since this is just an intrinsic slow path we prefer this
6713 // simple and more robust approach rather that trying to determine if that's the case.
6714 SlowPathCode* slow_path = GetCurrentSlowPath();
6715 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
6716 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
6717 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
6718 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
6719 return temp;
6720 }
6721 return location.AsRegister<Register>();
6722}
6723
Nicolas Geoffray38207af2015-06-01 15:46:22 +01006724void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00006725 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00006726 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00006727 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6728 // LR = code address from literal pool with link-time patch.
6729 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00006730 break;
6731 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6732 // LR = invoke->GetDirectCodePtr();
6733 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00006734 break;
6735 default:
6736 break;
6737 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006738
Vladimir Marko58155012015-08-19 12:49:41 +00006739 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
6740 switch (invoke->GetMethodLoadKind()) {
6741 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
6742 // temp = thread->string_init_entrypoint
6743 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
6744 break;
6745 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006746 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006747 break;
6748 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
6749 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
6750 break;
6751 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
6752 __ LoadLiteral(temp.AsRegister<Register>(),
6753 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
6754 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00006755 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
6756 HArmDexCacheArraysBase* base =
6757 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
6758 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
6759 temp.AsRegister<Register>());
6760 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
6761 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
6762 break;
6763 }
Vladimir Marko58155012015-08-19 12:49:41 +00006764 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00006765 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006766 Register method_reg;
6767 Register reg = temp.AsRegister<Register>();
6768 if (current_method.IsRegister()) {
6769 method_reg = current_method.AsRegister<Register>();
6770 } else {
6771 DCHECK(invoke->GetLocations()->Intrinsified());
6772 DCHECK(!current_method.IsValid());
6773 method_reg = reg;
6774 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
6775 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006776 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
6777 __ LoadFromOffset(kLoadWord,
6778 reg,
6779 method_reg,
6780 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01006781 // temp = temp[index_in_cache];
6782 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
6783 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00006784 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
6785 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01006786 }
Vladimir Marko58155012015-08-19 12:49:41 +00006787 }
6788
6789 switch (invoke->GetCodePtrLocation()) {
6790 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
6791 __ bl(GetFrameEntryLabel());
6792 break;
6793 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01006794 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07006795 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01006796 // Arbitrarily branch to the BL itself, override at link time.
6797 __ bl(&relative_call_patches_.back().label);
6798 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006799 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6800 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6801 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00006802 // LR()
6803 __ blx(LR);
6804 break;
6805 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6806 // LR = callee_method->entry_point_from_quick_compiled_code_
6807 __ LoadFromOffset(
6808 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07006809 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006810 // LR()
6811 __ blx(LR);
6812 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006813 }
6814
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006815 DCHECK(!IsLeafMethod());
6816}
6817
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006818void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
6819 Register temp = temp_location.AsRegister<Register>();
6820 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6821 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006822
6823 // Use the calling convention instead of the location of the receiver, as
6824 // intrinsics may have put the receiver in a different register. In the intrinsics
6825 // slow path, the arguments have been moved to the right place, so here we are
6826 // guaranteed that the receiver is the first register of the calling convention.
6827 InvokeDexCallingConvention calling_convention;
6828 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006829 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00006830 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006831 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006832 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00006833 // Instead of simply (possibly) unpoisoning `temp` here, we should
6834 // emit a read barrier for the previous class reference load.
6835 // However this is not required in practice, as this is an
6836 // intermediate/temporary reference and because the current
6837 // concurrent copying collector keeps the from-space memory
6838 // intact/accessible until the end of the marking phase (the
6839 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006840 __ MaybeUnpoisonHeapReference(temp);
6841 // temp = temp->GetMethodAt(method_offset);
6842 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006843 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006844 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
6845 // LR = temp->GetEntryPoint();
6846 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
6847 // LR();
6848 __ blx(LR);
6849}
6850
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006851CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
6852 const DexFile& dex_file, uint32_t string_index) {
6853 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
6854}
6855
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006856CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
6857 const DexFile& dex_file, uint32_t type_index) {
6858 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
6859}
6860
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006861CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
6862 const DexFile& dex_file, uint32_t element_offset) {
6863 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
6864}
6865
6866CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
6867 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
6868 patches->emplace_back(dex_file, offset_or_index);
6869 return &patches->back();
6870}
6871
6872Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
6873 uint32_t string_index) {
6874 return boot_image_string_patches_.GetOrCreate(
6875 StringReference(&dex_file, string_index),
6876 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6877}
6878
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006879Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
6880 uint32_t type_index) {
6881 return boot_image_type_patches_.GetOrCreate(
6882 TypeReference(&dex_file, type_index),
6883 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6884}
6885
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006886Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
6887 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
6888 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
6889 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
6890}
6891
6892Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
6893 return DeduplicateUint32Literal(address, &uint32_literals_);
6894}
6895
Vladimir Marko58155012015-08-19 12:49:41 +00006896void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
6897 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00006898 size_t size =
6899 method_patches_.size() +
6900 call_patches_.size() +
6901 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006902 /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() +
6903 boot_image_string_patches_.size() +
6904 /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006905 boot_image_type_patches_.size() +
6906 /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006907 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00006908 linker_patches->reserve(size);
6909 for (const auto& entry : method_patches_) {
6910 const MethodReference& target_method = entry.first;
6911 Literal* literal = entry.second;
6912 DCHECK(literal->GetLabel()->IsBound());
6913 uint32_t literal_offset = literal->GetLabel()->Position();
6914 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
6915 target_method.dex_file,
6916 target_method.dex_method_index));
6917 }
6918 for (const auto& entry : call_patches_) {
6919 const MethodReference& target_method = entry.first;
6920 Literal* literal = entry.second;
6921 DCHECK(literal->GetLabel()->IsBound());
6922 uint32_t literal_offset = literal->GetLabel()->Position();
6923 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
6924 target_method.dex_file,
6925 target_method.dex_method_index));
6926 }
6927 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
6928 uint32_t literal_offset = info.label.Position();
6929 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
6930 info.target_method.dex_file,
6931 info.target_method.dex_method_index));
6932 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006933 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
6934 const DexFile& dex_file = info.target_dex_file;
6935 size_t base_element_offset = info.offset_or_index;
6936 DCHECK(info.add_pc_label.IsBound());
6937 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006938 // Add MOVW patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006939 DCHECK(info.movw_label.IsBound());
6940 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006941 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset,
6942 &dex_file,
6943 add_pc_offset,
6944 base_element_offset));
6945 // Add MOVT patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006946 DCHECK(info.movt_label.IsBound());
6947 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006948 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset,
6949 &dex_file,
6950 add_pc_offset,
6951 base_element_offset));
6952 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006953 for (const auto& entry : boot_image_string_patches_) {
6954 const StringReference& target_string = entry.first;
6955 Literal* literal = entry.second;
6956 DCHECK(literal->GetLabel()->IsBound());
6957 uint32_t literal_offset = literal->GetLabel()->Position();
6958 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
6959 target_string.dex_file,
6960 target_string.string_index));
6961 }
6962 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
6963 const DexFile& dex_file = info.target_dex_file;
6964 uint32_t string_index = info.offset_or_index;
6965 DCHECK(info.add_pc_label.IsBound());
6966 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6967 // Add MOVW patch.
6968 DCHECK(info.movw_label.IsBound());
6969 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6970 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset,
6971 &dex_file,
6972 add_pc_offset,
6973 string_index));
6974 // Add MOVT patch.
6975 DCHECK(info.movt_label.IsBound());
6976 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6977 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset,
6978 &dex_file,
6979 add_pc_offset,
6980 string_index));
6981 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006982 for (const auto& entry : boot_image_type_patches_) {
6983 const TypeReference& target_type = entry.first;
6984 Literal* literal = entry.second;
6985 DCHECK(literal->GetLabel()->IsBound());
6986 uint32_t literal_offset = literal->GetLabel()->Position();
6987 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
6988 target_type.dex_file,
6989 target_type.type_index));
6990 }
6991 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
6992 const DexFile& dex_file = info.target_dex_file;
6993 uint32_t type_index = info.offset_or_index;
6994 DCHECK(info.add_pc_label.IsBound());
6995 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6996 // Add MOVW patch.
6997 DCHECK(info.movw_label.IsBound());
6998 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6999 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset,
7000 &dex_file,
7001 add_pc_offset,
7002 type_index));
7003 // Add MOVT patch.
7004 DCHECK(info.movt_label.IsBound());
7005 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
7006 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset,
7007 &dex_file,
7008 add_pc_offset,
7009 type_index));
7010 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007011 for (const auto& entry : boot_image_address_patches_) {
7012 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
7013 Literal* literal = entry.second;
7014 DCHECK(literal->GetLabel()->IsBound());
7015 uint32_t literal_offset = literal->GetLabel()->Position();
7016 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
7017 }
7018}
7019
7020Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
7021 return map->GetOrCreate(
7022 value,
7023 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00007024}
7025
7026Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
7027 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007028 return map->GetOrCreate(
7029 target_method,
7030 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00007031}
7032
7033Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
7034 return DeduplicateMethodLiteral(target_method, &method_patches_);
7035}
7036
7037Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
7038 return DeduplicateMethodLiteral(target_method, &call_patches_);
7039}
7040
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03007041void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7042 LocationSummary* locations =
7043 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7044 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7045 Location::RequiresRegister());
7046 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7047 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7048 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7049}
7050
7051void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7052 LocationSummary* locations = instr->GetLocations();
7053 Register res = locations->Out().AsRegister<Register>();
7054 Register accumulator =
7055 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7056 Register mul_left =
7057 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7058 Register mul_right =
7059 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7060
7061 if (instr->GetOpKind() == HInstruction::kAdd) {
7062 __ mla(res, mul_left, mul_right, accumulator);
7063 } else {
7064 __ mls(res, mul_left, mul_right, accumulator);
7065 }
7066}
7067
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007068void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007069 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007070 LOG(FATAL) << "Unreachable";
7071}
7072
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007073void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007074 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007075 LOG(FATAL) << "Unreachable";
7076}
7077
Mark Mendellfe57faa2015-09-18 09:26:15 -04007078// Simple implementation of packed switch - generate cascaded compare/jumps.
7079void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7080 LocationSummary* locations =
7081 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7082 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007083 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007084 codegen_->GetAssembler()->IsThumb()) {
7085 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7086 if (switch_instr->GetStartValue() != 0) {
7087 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7088 }
7089 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007090}
7091
7092void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7093 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007094 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007095 LocationSummary* locations = switch_instr->GetLocations();
7096 Register value_reg = locations->InAt(0).AsRegister<Register>();
7097 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7098
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007099 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007100 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007101 Register temp_reg = IP;
7102 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7103 // the immediate, because IP is used as the destination register. For the other
7104 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7105 // and they can be encoded in the instruction without making use of IP register.
7106 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7107
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007108 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007109 // Jump to successors[0] if value == lower_bound.
7110 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7111 int32_t last_index = 0;
7112 for (; num_entries - last_index > 2; last_index += 2) {
7113 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7114 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7115 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7116 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7117 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7118 }
7119 if (num_entries - last_index == 2) {
7120 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007121 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007122 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007123 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007124
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007125 // And the default for any other value.
7126 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7127 __ b(codegen_->GetLabelOf(default_block));
7128 }
7129 } else {
7130 // Create a table lookup.
7131 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7132
7133 // Materialize a pointer to the switch table
7134 std::vector<Label*> labels(num_entries);
7135 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7136 for (uint32_t i = 0; i < num_entries; i++) {
7137 labels[i] = codegen_->GetLabelOf(successors[i]);
7138 }
7139 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7140
7141 // Remove the bias.
7142 Register key_reg;
7143 if (lower_bound != 0) {
7144 key_reg = locations->GetTemp(1).AsRegister<Register>();
7145 __ AddConstant(key_reg, value_reg, -lower_bound);
7146 } else {
7147 key_reg = value_reg;
7148 }
7149
7150 // Check whether the value is in the table, jump to default block if not.
7151 __ CmpConstant(key_reg, num_entries - 1);
7152 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7153
7154 // Load the displacement from the table.
7155 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7156
7157 // Dispatch is a direct add to the PC (for Thumb2).
7158 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007159 }
7160}
7161
Vladimir Markob4536b72015-11-24 13:45:23 +00007162void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7163 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7164 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007165}
7166
7167void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7168 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007169 CodeGeneratorARM::PcRelativePatchInfo* labels =
7170 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007171 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007172 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007173 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007174 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007175 __ BindTrackedLabel(&labels->add_pc_label);
7176 __ add(base_reg, base_reg, ShifterOperand(PC));
7177}
7178
Andreas Gampe85b62f22015-09-09 13:15:38 -07007179void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7180 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007181 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007182 return;
7183 }
7184
7185 DCHECK_NE(type, Primitive::kPrimVoid);
7186
7187 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7188 if (return_loc.Equals(trg)) {
7189 return;
7190 }
7191
7192 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7193 // with the last branch.
7194 if (type == Primitive::kPrimLong) {
7195 HParallelMove parallel_move(GetGraph()->GetArena());
7196 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7197 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7198 GetMoveResolver()->EmitNativeCode(&parallel_move);
7199 } else if (type == Primitive::kPrimDouble) {
7200 HParallelMove parallel_move(GetGraph()->GetArena());
7201 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7202 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7203 GetMoveResolver()->EmitNativeCode(&parallel_move);
7204 } else {
7205 // Let the parallel move resolver take care of all of this.
7206 HParallelMove parallel_move(GetGraph()->GetArena());
7207 parallel_move.AddMove(return_loc, trg, type, nullptr);
7208 GetMoveResolver()->EmitNativeCode(&parallel_move);
7209 }
7210}
7211
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007212void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7213 LocationSummary* locations =
7214 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7215 locations->SetInAt(0, Location::RequiresRegister());
7216 locations->SetOut(Location::RequiresRegister());
7217}
7218
7219void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7220 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007221 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007222 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007223 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007224 __ LoadFromOffset(kLoadWord,
7225 locations->Out().AsRegister<Register>(),
7226 locations->InAt(0).AsRegister<Register>(),
7227 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007228 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007229 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007230 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007231 __ LoadFromOffset(kLoadWord,
7232 locations->Out().AsRegister<Register>(),
7233 locations->InAt(0).AsRegister<Register>(),
7234 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7235 __ LoadFromOffset(kLoadWord,
7236 locations->Out().AsRegister<Register>(),
7237 locations->Out().AsRegister<Register>(),
7238 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007239 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007240}
7241
Roland Levillain4d027112015-07-01 15:41:14 +01007242#undef __
7243#undef QUICK_ENTRY_POINT
7244
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007245} // namespace arm
7246} // namespace art