blob: ab85c12a1d106dcf4d009cd05063fd7f5ab87af6 [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
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -070062// NOLINT on __ macro to suppress wrong warning/fix 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() ||
428 instruction_->IsLoadClass() ||
429 instruction_->IsLoadString() ||
430 instruction_->IsInstanceOf() ||
Roland Levillain3d312422016-06-23 13:53:42 +0100431 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100432 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillainc9285912015-12-18 10:38:42 +0000433 << "Unexpected instruction in read barrier marking slow path: "
434 << instruction_->DebugName();
Roland Levillain12ecf082016-08-08 10:18:37 +0100435 // The read barrier instrumentation of object ArrayGet
436 // instructions does not support the HIntermediateAddress
437 // instruction.
438 DCHECK(!(instruction_->IsArrayGet() &&
439 instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress()));
Roland Levillainc9285912015-12-18 10:38:42 +0000440
441 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100442 // No need to save live registers; it's taken care of by the
443 // entrypoint. Also, there is no need to update the stack mask,
444 // as this runtime call will not trigger a garbage collection.
Roland Levillainc9285912015-12-18 10:38:42 +0000445 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Roland Levillain02b75802016-07-13 11:54:35 +0100446 DCHECK_NE(reg, SP);
447 DCHECK_NE(reg, LR);
448 DCHECK_NE(reg, PC);
449 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 Levillain12ecf082016-08-08 10:18:37 +0100520 // The read barrier instrumentation of object ArrayGet
521 // instructions does not support the HIntermediateAddress
522 // instruction.
523 DCHECK(!(instruction_->IsArrayGet() &&
524 instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress()));
Roland Levillain3b359c72015-11-17 19:35:12 +0000525
526 __ Bind(GetEntryLabel());
527 SaveLiveRegisters(codegen, locations);
528
529 // We may have to change the index's value, but as `index_` is a
530 // constant member (like other "inputs" of this slow path),
531 // introduce a copy of it, `index`.
532 Location index = index_;
533 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100534 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain3b359c72015-11-17 19:35:12 +0000535 if (instruction_->IsArrayGet()) {
536 // Compute the actual memory offset and store it in `index`.
537 Register index_reg = index_.AsRegister<Register>();
538 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
539 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
540 // We are about to change the value of `index_reg` (see the
541 // calls to art::arm::Thumb2Assembler::Lsl and
542 // art::arm::Thumb2Assembler::AddConstant below), but it has
543 // not been saved by the previous call to
544 // art::SlowPathCode::SaveLiveRegisters, as it is a
545 // callee-save register --
546 // art::SlowPathCode::SaveLiveRegisters does not consider
547 // callee-save registers, as it has been designed with the
548 // assumption that callee-save registers are supposed to be
549 // handled by the called function. So, as a callee-save
550 // register, `index_reg` _would_ eventually be saved onto
551 // the stack, but it would be too late: we would have
552 // changed its value earlier. Therefore, we manually save
553 // it here into another freely available register,
554 // `free_reg`, chosen of course among the caller-save
555 // registers (as a callee-save `free_reg` register would
556 // exhibit the same problem).
557 //
558 // Note we could have requested a temporary register from
559 // the register allocator instead; but we prefer not to, as
560 // this is a slow path, and we know we can find a
561 // caller-save register that is available.
562 Register free_reg = FindAvailableCallerSaveRegister(codegen);
563 __ Mov(free_reg, index_reg);
564 index_reg = free_reg;
565 index = Location::RegisterLocation(index_reg);
566 } else {
567 // The initial register stored in `index_` has already been
568 // saved in the call to art::SlowPathCode::SaveLiveRegisters
569 // (as it is not a callee-save register), so we can freely
570 // use it.
571 }
572 // Shifting the index value contained in `index_reg` by the scale
573 // factor (2) cannot overflow in practice, as the runtime is
574 // unable to allocate object arrays with a size larger than
575 // 2^26 - 1 (that is, 2^28 - 4 bytes).
576 __ Lsl(index_reg, index_reg, TIMES_4);
577 static_assert(
578 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
579 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
580 __ AddConstant(index_reg, index_reg, offset_);
581 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100582 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
583 // intrinsics, `index_` is not shifted by a scale factor of 2
584 // (as in the case of ArrayGet), as it is actually an offset
585 // to an object field within an object.
586 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000587 DCHECK(instruction_->GetLocations()->Intrinsified());
588 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
589 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
590 << instruction_->AsInvoke()->GetIntrinsic();
591 DCHECK_EQ(offset_, 0U);
592 DCHECK(index_.IsRegisterPair());
593 // UnsafeGet's offset location is a register pair, the low
594 // part contains the correct offset.
595 index = index_.ToLow();
596 }
597 }
598
599 // We're moving two or three locations to locations that could
600 // overlap, so we need a parallel move resolver.
601 InvokeRuntimeCallingConvention calling_convention;
602 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
603 parallel_move.AddMove(ref_,
604 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
605 Primitive::kPrimNot,
606 nullptr);
607 parallel_move.AddMove(obj_,
608 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
609 Primitive::kPrimNot,
610 nullptr);
611 if (index.IsValid()) {
612 parallel_move.AddMove(index,
613 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
614 Primitive::kPrimInt,
615 nullptr);
616 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
617 } else {
618 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
619 __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_);
620 }
621 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow),
622 instruction_,
623 instruction_->GetDexPc(),
624 this);
625 CheckEntrypointTypes<
626 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
627 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
628
629 RestoreLiveRegisters(codegen, locations);
630 __ b(GetExitLabel());
631 }
632
633 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; }
634
635 private:
636 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
637 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
638 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
639 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
640 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
641 return static_cast<Register>(i);
642 }
643 }
644 // We shall never fail to find a free caller-save register, as
645 // there are more than two core caller-save registers on ARM
646 // (meaning it is possible to find one which is different from
647 // `ref` and `obj`).
648 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
649 LOG(FATAL) << "Could not find a free caller-save register";
650 UNREACHABLE();
651 }
652
Roland Levillain3b359c72015-11-17 19:35:12 +0000653 const Location out_;
654 const Location ref_;
655 const Location obj_;
656 const uint32_t offset_;
657 // An additional location containing an index to an array.
658 // Only used for HArrayGet and the UnsafeGetObject &
659 // UnsafeGetObjectVolatile intrinsics.
660 const Location index_;
661
662 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM);
663};
664
665// Slow path generating a read barrier for a GC root.
666class ReadBarrierForRootSlowPathARM : public SlowPathCode {
667 public:
668 ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root)
David Srbecky9cd6d372016-02-09 15:24:47 +0000669 : SlowPathCode(instruction), out_(out), root_(root) {
Roland Levillainc9285912015-12-18 10:38:42 +0000670 DCHECK(kEmitCompilerReadBarrier);
671 }
Roland Levillain3b359c72015-11-17 19:35:12 +0000672
673 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
674 LocationSummary* locations = instruction_->GetLocations();
675 Register reg_out = out_.AsRegister<Register>();
676 DCHECK(locations->CanCall());
677 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillainc9285912015-12-18 10:38:42 +0000678 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
679 << "Unexpected instruction in read barrier for GC root slow path: "
680 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000681
682 __ Bind(GetEntryLabel());
683 SaveLiveRegisters(codegen, locations);
684
685 InvokeRuntimeCallingConvention calling_convention;
686 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
687 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_);
688 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow),
689 instruction_,
690 instruction_->GetDexPc(),
691 this);
692 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
693 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
694
695 RestoreLiveRegisters(codegen, locations);
696 __ b(GetExitLabel());
697 }
698
699 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; }
700
701 private:
Roland Levillain3b359c72015-11-17 19:35:12 +0000702 const Location out_;
703 const Location root_;
704
705 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM);
706};
707
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000708#undef __
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -0700709// NOLINT on __ macro to suppress wrong warning/fix from clang-tidy.
710#define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT
Dave Allison20dfc792014-06-16 20:44:29 -0700711
Aart Bike9f37602015-10-09 11:15:55 -0700712inline Condition ARMCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700713 switch (cond) {
714 case kCondEQ: return EQ;
715 case kCondNE: return NE;
716 case kCondLT: return LT;
717 case kCondLE: return LE;
718 case kCondGT: return GT;
719 case kCondGE: return GE;
Aart Bike9f37602015-10-09 11:15:55 -0700720 case kCondB: return LO;
721 case kCondBE: return LS;
722 case kCondA: return HI;
723 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700724 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100725 LOG(FATAL) << "Unreachable";
726 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700727}
728
Aart Bike9f37602015-10-09 11:15:55 -0700729// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100730inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700731 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100732 case kCondEQ: return EQ;
733 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -0700734 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100735 case kCondLT: return LO;
736 case kCondLE: return LS;
737 case kCondGT: return HI;
738 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -0700739 // Unsigned remain unchanged.
740 case kCondB: return LO;
741 case kCondBE: return LS;
742 case kCondA: return HI;
743 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700744 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100745 LOG(FATAL) << "Unreachable";
746 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700747}
748
Vladimir Markod6e069b2016-01-18 11:11:01 +0000749inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) {
750 // The ARM condition codes can express all the necessary branches, see the
751 // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual.
752 // There is no dex instruction or HIR that would need the missing conditions
753 // "equal or unordered" or "not equal".
754 switch (cond) {
755 case kCondEQ: return EQ;
756 case kCondNE: return NE /* unordered */;
757 case kCondLT: return gt_bias ? CC : LT /* unordered */;
758 case kCondLE: return gt_bias ? LS : LE /* unordered */;
759 case kCondGT: return gt_bias ? HI /* unordered */ : GT;
760 case kCondGE: return gt_bias ? CS /* unordered */ : GE;
761 default:
762 LOG(FATAL) << "UNREACHABLE";
763 UNREACHABLE();
764 }
765}
766
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100767void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100768 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100769}
770
771void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100772 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100773}
774
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100775size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
776 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
777 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100778}
779
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100780size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
781 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
782 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100783}
784
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000785size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
786 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
787 return kArmWordSize;
788}
789
790size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
791 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
792 return kArmWordSize;
793}
794
Calin Juravle34166012014-12-19 17:22:29 +0000795CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000796 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100797 const CompilerOptions& compiler_options,
798 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000799 : CodeGenerator(graph,
800 kNumberOfCoreRegisters,
801 kNumberOfSRegisters,
802 kNumberOfRegisterPairs,
803 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
804 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +0000805 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
806 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100807 compiler_options,
808 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100809 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100810 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100811 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100812 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100813 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +0000814 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000815 uint32_literals_(std::less<uint32_t>(),
816 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +0100817 method_patches_(MethodReferenceComparator(),
818 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
819 call_patches_(MethodReferenceComparator(),
820 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markob4536b72015-11-24 13:45:23 +0000821 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000822 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
823 boot_image_string_patches_(StringReferenceValueComparator(),
824 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
825 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100826 boot_image_type_patches_(TypeReferenceValueComparator(),
827 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
828 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000829 boot_image_address_patches_(std::less<uint32_t>(),
830 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700831 // Always save the LR register to mimic Quick.
832 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100833}
834
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000835void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
836 // Ensure that we fix up branches and literal loads and emit the literal pool.
837 __ FinalizeCode();
838
839 // Adjust native pc offsets in stack maps.
840 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
841 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
842 uint32_t new_position = __ GetAdjustedPosition(old_position);
843 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
844 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100845 // Adjust pc offsets for the disassembly information.
846 if (disasm_info_ != nullptr) {
847 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
848 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
849 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
850 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
851 it.second.start = __ GetAdjustedPosition(it.second.start);
852 it.second.end = __ GetAdjustedPosition(it.second.end);
853 }
854 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
855 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
856 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
857 }
858 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000859
860 CodeGenerator::Finalize(allocator);
861}
862
David Brazdil58282f42016-01-14 12:45:10 +0000863void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100864 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100865 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100866
867 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100868 blocked_core_registers_[SP] = true;
869 blocked_core_registers_[LR] = true;
870 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100871
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100872 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100873 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100874
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100875 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100876 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100877
David Brazdil58282f42016-01-14 12:45:10 +0000878 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100879 // Stubs do not save callee-save floating point registers. If the graph
880 // is debuggable, we need to deal with these registers differently. For
881 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000882 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
883 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
884 }
885 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100886
887 UpdateBlockedPairRegisters();
888}
889
890void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
891 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
892 ArmManagedRegister current =
893 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
894 if (blocked_core_registers_[current.AsRegisterPairLow()]
895 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
896 blocked_register_pairs_[i] = true;
897 }
898 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100899}
900
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100901InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
Aart Bik42249c32016-01-07 15:33:50 -0800902 : InstructionCodeGenerator(graph, codegen),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100903 assembler_(codegen->GetAssembler()),
904 codegen_(codegen) {}
905
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000906void CodeGeneratorARM::ComputeSpillMask() {
907 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
908 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
David Brazdil58282f42016-01-14 12:45:10 +0000909 // There is no easy instruction to restore just the PC on thumb2. We spill and
910 // restore another arbitrary register.
911 core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000912 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
913 // We use vpush and vpop for saving and restoring floating point registers, which take
914 // a SRegister and the number of registers to save/restore after that SRegister. We
915 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
916 // but in the range.
917 if (fpu_spill_mask_ != 0) {
918 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
919 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
920 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
921 fpu_spill_mask_ |= (1 << i);
922 }
923 }
924}
925
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100926static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100927 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100928}
929
930static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100931 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100932}
933
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000934void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000935 bool skip_overflow_check =
936 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000937 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000938 __ Bind(&frame_entry_label_);
939
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000940 if (HasEmptyFrame()) {
941 return;
942 }
943
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100944 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000945 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
946 __ LoadFromOffset(kLoadWord, IP, IP, 0);
947 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100948 }
949
Andreas Gampe501fd632015-09-10 16:11:06 -0700950 __ PushList(core_spill_mask_);
951 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
952 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000953 if (fpu_spill_mask_ != 0) {
954 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
955 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100956 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100957 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000958 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100959 int adjust = GetFrameSize() - FrameEntrySpillSize();
960 __ AddConstant(SP, -adjust);
961 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100962 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000963}
964
965void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000966 if (HasEmptyFrame()) {
967 __ bx(LR);
968 return;
969 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100970 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100971 int adjust = GetFrameSize() - FrameEntrySpillSize();
972 __ AddConstant(SP, adjust);
973 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000974 if (fpu_spill_mask_ != 0) {
975 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
976 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
Andreas Gampe542451c2016-07-26 09:02:02 -0700977 __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100978 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000979 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700980 // Pop LR into PC to return.
981 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
982 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
983 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100984 __ cfi().RestoreState();
985 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000986}
987
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100988void CodeGeneratorARM::Bind(HBasicBlock* block) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700989 Label* label = GetLabelOf(block);
990 __ BindTrackedLabel(label);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000991}
992
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100993Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100994 switch (type) {
995 case Primitive::kPrimBoolean:
996 case Primitive::kPrimByte:
997 case Primitive::kPrimChar:
998 case Primitive::kPrimShort:
999 case Primitive::kPrimInt:
1000 case Primitive::kPrimNot: {
1001 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001002 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001003 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001004 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001005 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001006 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001007 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001008 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001009
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001010 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001011 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001012 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001013 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001014 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001015 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001016 if (calling_convention.GetRegisterAt(index) == R1) {
1017 // Skip R1, and use R2_R3 instead.
1018 gp_index_++;
1019 index++;
1020 }
1021 }
1022 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
1023 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001024 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +01001025
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001026 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001027 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001028 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001029 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
1030 }
1031 }
1032
1033 case Primitive::kPrimFloat: {
1034 uint32_t stack_index = stack_index_++;
1035 if (float_index_ % 2 == 0) {
1036 float_index_ = std::max(double_index_, float_index_);
1037 }
1038 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
1039 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
1040 } else {
1041 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
1042 }
1043 }
1044
1045 case Primitive::kPrimDouble: {
1046 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
1047 uint32_t stack_index = stack_index_;
1048 stack_index_ += 2;
1049 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
1050 uint32_t index = double_index_;
1051 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001052 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001053 calling_convention.GetFpuRegisterAt(index),
1054 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001055 DCHECK(ExpectedPairLayout(result));
1056 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001057 } else {
1058 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001059 }
1060 }
1061
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001062 case Primitive::kPrimVoid:
1063 LOG(FATAL) << "Unexpected parameter type " << type;
1064 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001065 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001066 return Location::NoLocation();
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001067}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001068
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001069Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001070 switch (type) {
1071 case Primitive::kPrimBoolean:
1072 case Primitive::kPrimByte:
1073 case Primitive::kPrimChar:
1074 case Primitive::kPrimShort:
1075 case Primitive::kPrimInt:
1076 case Primitive::kPrimNot: {
1077 return Location::RegisterLocation(R0);
1078 }
1079
1080 case Primitive::kPrimFloat: {
1081 return Location::FpuRegisterLocation(S0);
1082 }
1083
1084 case Primitive::kPrimLong: {
1085 return Location::RegisterPairLocation(R0, R1);
1086 }
1087
1088 case Primitive::kPrimDouble: {
1089 return Location::FpuRegisterPairLocation(S0, S1);
1090 }
1091
1092 case Primitive::kPrimVoid:
Roland Levillain3b359c72015-11-17 19:35:12 +00001093 return Location::NoLocation();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001094 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +01001095
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001096 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001097}
1098
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001099Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
1100 return Location::RegisterLocation(kMethodRegisterArgument);
1101}
1102
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001103void CodeGeneratorARM::Move32(Location destination, Location source) {
1104 if (source.Equals(destination)) {
1105 return;
1106 }
1107 if (destination.IsRegister()) {
1108 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001109 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001110 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001111 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001112 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001113 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001114 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001115 } else if (destination.IsFpuRegister()) {
1116 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001117 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001118 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001119 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001120 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001121 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001122 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001123 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001124 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001125 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001126 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001127 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001128 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001129 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001130 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001131 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1132 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001133 }
1134 }
1135}
1136
1137void CodeGeneratorARM::Move64(Location destination, Location source) {
1138 if (source.Equals(destination)) {
1139 return;
1140 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001141 if (destination.IsRegisterPair()) {
1142 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001143 EmitParallelMoves(
1144 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
1145 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001146 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001147 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001148 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
1149 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001150 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001151 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001152 } else if (source.IsFpuRegisterPair()) {
1153 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
1154 destination.AsRegisterPairHigh<Register>(),
1155 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001156 } else {
1157 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001158 DCHECK(ExpectedPairLayout(destination));
1159 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
1160 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001161 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001162 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001163 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001164 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1165 SP,
1166 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001167 } else if (source.IsRegisterPair()) {
1168 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1169 source.AsRegisterPairLow<Register>(),
1170 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001171 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001172 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001173 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001174 } else {
1175 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001176 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001177 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001178 if (source.AsRegisterPairLow<Register>() == R1) {
1179 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001180 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
1181 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001182 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001183 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001184 SP, destination.GetStackIndex());
1185 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001186 } else if (source.IsFpuRegisterPair()) {
1187 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
1188 SP,
1189 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001190 } else {
1191 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001192 EmitParallelMoves(
1193 Location::StackSlot(source.GetStackIndex()),
1194 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001195 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001196 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001197 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
1198 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001199 }
1200 }
1201}
1202
Calin Juravle175dc732015-08-25 15:42:32 +01001203void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1204 DCHECK(location.IsRegister());
1205 __ LoadImmediate(location.AsRegister<Register>(), value);
1206}
1207
Calin Juravlee460d1d2015-09-29 04:52:17 +01001208void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001209 HParallelMove move(GetGraph()->GetArena());
1210 move.AddMove(src, dst, dst_type, nullptr);
1211 GetMoveResolver()->EmitNativeCode(&move);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001212}
1213
1214void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1215 if (location.IsRegister()) {
1216 locations->AddTemp(location);
1217 } else if (location.IsRegisterPair()) {
1218 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1219 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1220 } else {
1221 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1222 }
1223}
1224
Calin Juravle175dc732015-08-25 15:42:32 +01001225void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1226 HInstruction* instruction,
1227 uint32_t dex_pc,
1228 SlowPathCode* slow_path) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001229 InvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value(),
Calin Juravle175dc732015-08-25 15:42:32 +01001230 instruction,
1231 dex_pc,
1232 slow_path);
1233}
1234
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001235void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
1236 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001237 uint32_t dex_pc,
1238 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001239 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001240 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1241 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001242 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001243}
1244
Roland Levillaindec8f632016-07-22 17:10:06 +01001245void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1246 HInstruction* instruction,
1247 SlowPathCode* slow_path) {
1248 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1249 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1250 __ blx(LR);
1251}
1252
David Brazdilfc6a86a2015-06-26 10:33:45 +00001253void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001254 DCHECK(!successor->IsExitBlock());
1255
1256 HBasicBlock* block = got->GetBlock();
1257 HInstruction* previous = got->GetPrevious();
1258
1259 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001260 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001261 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1262 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1263 return;
1264 }
1265
1266 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1267 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1268 }
1269 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001270 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001271 }
1272}
1273
David Brazdilfc6a86a2015-06-26 10:33:45 +00001274void LocationsBuilderARM::VisitGoto(HGoto* got) {
1275 got->SetLocations(nullptr);
1276}
1277
1278void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1279 HandleGoto(got, got->GetSuccessor());
1280}
1281
1282void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1283 try_boundary->SetLocations(nullptr);
1284}
1285
1286void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1287 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1288 if (!successor->IsExitBlock()) {
1289 HandleGoto(try_boundary, successor);
1290 }
1291}
1292
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001293void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001294 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001295}
1296
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001297void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001298}
1299
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001300void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1301 Primitive::Type type = instruction->InputAt(0)->GetType();
1302 Location lhs_loc = instruction->GetLocations()->InAt(0);
1303 Location rhs_loc = instruction->GetLocations()->InAt(1);
1304 if (rhs_loc.IsConstant()) {
1305 // 0.0 is the only immediate that can be encoded directly in
1306 // a VCMP instruction.
1307 //
1308 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1309 // specify that in a floating-point comparison, positive zero
1310 // and negative zero are considered equal, so we can use the
1311 // literal 0.0 for both cases here.
1312 //
1313 // Note however that some methods (Float.equal, Float.compare,
1314 // Float.compareTo, Double.equal, Double.compare,
1315 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1316 // StrictMath.min) consider 0.0 to be (strictly) greater than
1317 // -0.0. So if we ever translate calls to these methods into a
1318 // HCompare instruction, we must handle the -0.0 case with
1319 // care here.
1320 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1321 if (type == Primitive::kPrimFloat) {
1322 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1323 } else {
1324 DCHECK_EQ(type, Primitive::kPrimDouble);
1325 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1326 }
1327 } else {
1328 if (type == Primitive::kPrimFloat) {
1329 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1330 } else {
1331 DCHECK_EQ(type, Primitive::kPrimDouble);
1332 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1333 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1334 }
1335 }
1336}
1337
Roland Levillain4fa13f62015-07-06 18:11:54 +01001338void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1339 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001340 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001341 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001342 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001343}
1344
1345void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1346 Label* true_label,
1347 Label* false_label) {
1348 LocationSummary* locations = cond->GetLocations();
1349 Location left = locations->InAt(0);
1350 Location right = locations->InAt(1);
1351 IfCondition if_cond = cond->GetCondition();
1352
1353 Register left_high = left.AsRegisterPairHigh<Register>();
1354 Register left_low = left.AsRegisterPairLow<Register>();
1355 IfCondition true_high_cond = if_cond;
1356 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001357 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001358
1359 // Set the conditions for the test, remembering that == needs to be
1360 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001361 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001362 switch (if_cond) {
1363 case kCondEQ:
1364 case kCondNE:
1365 // Nothing to do.
1366 break;
1367 case kCondLT:
1368 false_high_cond = kCondGT;
1369 break;
1370 case kCondLE:
1371 true_high_cond = kCondLT;
1372 break;
1373 case kCondGT:
1374 false_high_cond = kCondLT;
1375 break;
1376 case kCondGE:
1377 true_high_cond = kCondGT;
1378 break;
Aart Bike9f37602015-10-09 11:15:55 -07001379 case kCondB:
1380 false_high_cond = kCondA;
1381 break;
1382 case kCondBE:
1383 true_high_cond = kCondB;
1384 break;
1385 case kCondA:
1386 false_high_cond = kCondB;
1387 break;
1388 case kCondAE:
1389 true_high_cond = kCondA;
1390 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001391 }
1392 if (right.IsConstant()) {
1393 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1394 int32_t val_low = Low32Bits(value);
1395 int32_t val_high = High32Bits(value);
1396
Vladimir Markoac6ac102015-12-17 12:14:00 +00001397 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001398 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001399 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001400 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001401 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001402 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001403 __ b(true_label, ARMCondition(true_high_cond));
1404 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001405 }
1406 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001407 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001408 } else {
1409 Register right_high = right.AsRegisterPairHigh<Register>();
1410 Register right_low = right.AsRegisterPairLow<Register>();
1411
1412 __ cmp(left_high, ShifterOperand(right_high));
1413 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001414 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001415 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001416 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001417 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001418 __ b(true_label, ARMCondition(true_high_cond));
1419 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001420 }
1421 // Must be equal high, so compare the lows.
1422 __ cmp(left_low, ShifterOperand(right_low));
1423 }
1424 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001425 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001426 __ b(true_label, final_condition);
1427}
1428
David Brazdil0debae72015-11-12 18:37:00 +00001429void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1430 Label* true_target_in,
1431 Label* false_target_in) {
1432 // Generated branching requires both targets to be explicit. If either of the
1433 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1434 Label fallthrough_target;
1435 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1436 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1437
Roland Levillain4fa13f62015-07-06 18:11:54 +01001438 Primitive::Type type = condition->InputAt(0)->GetType();
1439 switch (type) {
1440 case Primitive::kPrimLong:
1441 GenerateLongComparesAndJumps(condition, true_target, false_target);
1442 break;
1443 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001444 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001445 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001446 GenerateFPJumps(condition, true_target, false_target);
1447 break;
1448 default:
1449 LOG(FATAL) << "Unexpected compare type " << type;
1450 }
1451
David Brazdil0debae72015-11-12 18:37:00 +00001452 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001453 __ b(false_target);
1454 }
David Brazdil0debae72015-11-12 18:37:00 +00001455
1456 if (fallthrough_target.IsLinked()) {
1457 __ Bind(&fallthrough_target);
1458 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001459}
1460
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001461void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001462 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001463 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001464 Label* false_target) {
1465 HInstruction* cond = instruction->InputAt(condition_input_index);
1466
1467 if (true_target == nullptr && false_target == nullptr) {
1468 // Nothing to do. The code always falls through.
1469 return;
1470 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001471 // Constant condition, statically compared against "true" (integer value 1).
1472 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001473 if (true_target != nullptr) {
1474 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001475 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001476 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001477 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001478 if (false_target != nullptr) {
1479 __ b(false_target);
1480 }
1481 }
1482 return;
1483 }
1484
1485 // The following code generates these patterns:
1486 // (1) true_target == nullptr && false_target != nullptr
1487 // - opposite condition true => branch to false_target
1488 // (2) true_target != nullptr && false_target == nullptr
1489 // - condition true => branch to true_target
1490 // (3) true_target != nullptr && false_target != nullptr
1491 // - condition true => branch to true_target
1492 // - branch to false_target
1493 if (IsBooleanValueOrMaterializedCondition(cond)) {
1494 // Condition has been materialized, compare the output to 0.
1495 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1496 DCHECK(cond_val.IsRegister());
1497 if (true_target == nullptr) {
1498 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1499 } else {
1500 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001501 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001502 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001503 // Condition has not been materialized. Use its inputs as the comparison and
1504 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001505 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001506
1507 // If this is a long or FP comparison that has been folded into
1508 // the HCondition, generate the comparison directly.
1509 Primitive::Type type = condition->InputAt(0)->GetType();
1510 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1511 GenerateCompareTestAndBranch(condition, true_target, false_target);
1512 return;
1513 }
1514
1515 LocationSummary* locations = cond->GetLocations();
1516 DCHECK(locations->InAt(0).IsRegister());
1517 Register left = locations->InAt(0).AsRegister<Register>();
1518 Location right = locations->InAt(1);
1519 if (right.IsRegister()) {
1520 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001521 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001522 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001523 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001524 }
1525 if (true_target == nullptr) {
1526 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1527 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001528 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001529 }
Dave Allison20dfc792014-06-16 20:44:29 -07001530 }
David Brazdil0debae72015-11-12 18:37:00 +00001531
1532 // If neither branch falls through (case 3), the conditional branch to `true_target`
1533 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1534 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001535 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001536 }
1537}
1538
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001539void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001540 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1541 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001542 locations->SetInAt(0, Location::RequiresRegister());
1543 }
1544}
1545
1546void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001547 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1548 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1549 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1550 nullptr : codegen_->GetLabelOf(true_successor);
1551 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1552 nullptr : codegen_->GetLabelOf(false_successor);
1553 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001554}
1555
1556void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1557 LocationSummary* locations = new (GetGraph()->GetArena())
1558 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00001559 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001560 locations->SetInAt(0, Location::RequiresRegister());
1561 }
1562}
1563
1564void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08001565 SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001566 GenerateTestAndBranch(deoptimize,
1567 /* condition_input_index */ 0,
1568 slow_path->GetEntryLabel(),
1569 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001570}
Dave Allison20dfc792014-06-16 20:44:29 -07001571
David Brazdil74eb1b22015-12-14 11:44:01 +00001572void LocationsBuilderARM::VisitSelect(HSelect* select) {
1573 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1574 if (Primitive::IsFloatingPointType(select->GetType())) {
1575 locations->SetInAt(0, Location::RequiresFpuRegister());
1576 locations->SetInAt(1, Location::RequiresFpuRegister());
1577 } else {
1578 locations->SetInAt(0, Location::RequiresRegister());
1579 locations->SetInAt(1, Location::RequiresRegister());
1580 }
1581 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1582 locations->SetInAt(2, Location::RequiresRegister());
1583 }
1584 locations->SetOut(Location::SameAsFirstInput());
1585}
1586
1587void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1588 LocationSummary* locations = select->GetLocations();
1589 Label false_target;
1590 GenerateTestAndBranch(select,
1591 /* condition_input_index */ 2,
1592 /* true_target */ nullptr,
1593 &false_target);
1594 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1595 __ Bind(&false_target);
1596}
1597
David Srbecky0cf44932015-12-09 14:09:59 +00001598void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1599 new (GetGraph()->GetArena()) LocationSummary(info);
1600}
1601
David Srbeckyd28f4a02016-03-14 17:14:24 +00001602void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1603 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001604}
1605
1606void CodeGeneratorARM::GenerateNop() {
1607 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001608}
1609
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001610void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001611 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001612 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001613 // Handle the long/FP comparisons made in instruction simplification.
1614 switch (cond->InputAt(0)->GetType()) {
1615 case Primitive::kPrimLong:
1616 locations->SetInAt(0, Location::RequiresRegister());
1617 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001618 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001619 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1620 }
1621 break;
1622
1623 case Primitive::kPrimFloat:
1624 case Primitive::kPrimDouble:
1625 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001626 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001627 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001628 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1629 }
1630 break;
1631
1632 default:
1633 locations->SetInAt(0, Location::RequiresRegister());
1634 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001635 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001636 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1637 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001638 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001639}
1640
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001641void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001642 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001643 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001644 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001645
1646 LocationSummary* locations = cond->GetLocations();
1647 Location left = locations->InAt(0);
1648 Location right = locations->InAt(1);
1649 Register out = locations->Out().AsRegister<Register>();
1650 Label true_label, false_label;
1651
1652 switch (cond->InputAt(0)->GetType()) {
1653 default: {
1654 // Integer case.
1655 if (right.IsRegister()) {
1656 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1657 } else {
1658 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001659 __ CmpConstant(left.AsRegister<Register>(),
1660 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001661 }
Aart Bike9f37602015-10-09 11:15:55 -07001662 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001663 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001664 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001665 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001666 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001667 return;
1668 }
1669 case Primitive::kPrimLong:
1670 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1671 break;
1672 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001673 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001674 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001675 GenerateFPJumps(cond, &true_label, &false_label);
1676 break;
1677 }
1678
1679 // Convert the jumps into the result.
1680 Label done_label;
1681
1682 // False case: result = 0.
1683 __ Bind(&false_label);
1684 __ LoadImmediate(out, 0);
1685 __ b(&done_label);
1686
1687 // True case: result = 1.
1688 __ Bind(&true_label);
1689 __ LoadImmediate(out, 1);
1690 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001691}
1692
1693void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001694 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001695}
1696
1697void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001698 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001699}
1700
1701void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001702 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001703}
1704
1705void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001706 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001707}
1708
1709void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001710 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001711}
1712
1713void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001714 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001715}
1716
1717void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001718 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001719}
1720
1721void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001722 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001723}
1724
1725void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001726 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001727}
1728
1729void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001730 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001731}
1732
1733void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001734 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001735}
1736
1737void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001738 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001739}
1740
Aart Bike9f37602015-10-09 11:15:55 -07001741void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001742 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001743}
1744
1745void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001746 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001747}
1748
1749void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001750 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001751}
1752
1753void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001754 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001755}
1756
1757void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001758 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001759}
1760
1761void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001762 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001763}
1764
1765void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001766 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001767}
1768
1769void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001770 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001771}
1772
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001773void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001774 LocationSummary* locations =
1775 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001776 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001777}
1778
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001779void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001780 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001781}
1782
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001783void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1784 LocationSummary* locations =
1785 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1786 locations->SetOut(Location::ConstantLocation(constant));
1787}
1788
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001789void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001790 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001791}
1792
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001793void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001794 LocationSummary* locations =
1795 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001796 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001797}
1798
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001799void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001800 // Will be generated at use site.
1801}
1802
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001803void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1804 LocationSummary* locations =
1805 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1806 locations->SetOut(Location::ConstantLocation(constant));
1807}
1808
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001809void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001810 // Will be generated at use site.
1811}
1812
1813void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1814 LocationSummary* locations =
1815 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1816 locations->SetOut(Location::ConstantLocation(constant));
1817}
1818
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001819void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001820 // Will be generated at use site.
1821}
1822
Calin Juravle27df7582015-04-17 19:12:31 +01001823void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1824 memory_barrier->SetLocations(nullptr);
1825}
1826
1827void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00001828 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01001829}
1830
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001831void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001832 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001833}
1834
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001835void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001836 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001837}
1838
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001839void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001840 LocationSummary* locations =
1841 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001842 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001843}
1844
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001845void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001846 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001847}
1848
Calin Juravle175dc732015-08-25 15:42:32 +01001849void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1850 // The trampoline uses the same calling convention as dex calling conventions,
1851 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1852 // the method_idx.
1853 HandleInvoke(invoke);
1854}
1855
1856void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1857 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1858}
1859
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001860void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001861 // Explicit clinit checks triggered by static invokes must have been pruned by
1862 // art::PrepareForRegisterAllocation.
1863 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001864
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001865 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001866 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001867 codegen_->GetInstructionSetFeatures());
1868 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00001869 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
1870 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
1871 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001872 return;
1873 }
1874
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001875 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00001876
1877 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
1878 if (invoke->HasPcRelativeDexCache()) {
1879 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
1880 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001881}
1882
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001883static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1884 if (invoke->GetLocations()->Intrinsified()) {
1885 IntrinsicCodeGeneratorARM intrinsic(codegen);
1886 intrinsic.Dispatch(invoke);
1887 return true;
1888 }
1889 return false;
1890}
1891
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001892void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001893 // Explicit clinit checks triggered by static invokes must have been pruned by
1894 // art::PrepareForRegisterAllocation.
1895 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001896
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001897 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1898 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001899 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001900
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001901 LocationSummary* locations = invoke->GetLocations();
1902 codegen_->GenerateStaticOrDirectCall(
1903 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001904 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001905}
1906
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001907void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001908 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001909 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001910}
1911
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001912void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001913 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001914 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001915 codegen_->GetInstructionSetFeatures());
1916 if (intrinsic.TryDispatch(invoke)) {
1917 return;
1918 }
1919
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001920 HandleInvoke(invoke);
1921}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001922
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001923void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001924 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1925 return;
1926 }
1927
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001928 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001929 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001930 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001931}
1932
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001933void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1934 HandleInvoke(invoke);
1935 // Add the hidden argument.
1936 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1937}
1938
1939void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1940 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00001941 LocationSummary* locations = invoke->GetLocations();
1942 Register temp = locations->GetTemp(0).AsRegister<Register>();
1943 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001944 Location receiver = locations->InAt(0);
1945 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1946
Roland Levillain3b359c72015-11-17 19:35:12 +00001947 // Set the hidden argument. This is safe to do this here, as R12
1948 // won't be modified thereafter, before the `blx` (call) instruction.
1949 DCHECK_EQ(R12, hidden_reg);
1950 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001951
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001952 if (receiver.IsStackSlot()) {
1953 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00001954 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001955 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1956 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00001957 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00001958 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001959 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001960 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00001961 // Instead of simply (possibly) unpoisoning `temp` here, we should
1962 // emit a read barrier for the previous class reference load.
1963 // However this is not required in practice, as this is an
1964 // intermediate/temporary reference and because the current
1965 // concurrent copying collector keeps the from-space memory
1966 // intact/accessible until the end of the marking phase (the
1967 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01001968 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001969 __ LoadFromOffset(kLoadWord, temp, temp,
1970 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
1971 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00001972 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001973 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001974 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00001975 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07001976 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001977 // LR = temp->GetEntryPoint();
1978 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1979 // LR();
1980 __ blx(LR);
1981 DCHECK(!codegen_->IsLeafMethod());
1982 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1983}
1984
Roland Levillain88cb1752014-10-20 16:36:47 +01001985void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1986 LocationSummary* locations =
1987 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1988 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001989 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001990 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001991 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1992 break;
1993 }
1994 case Primitive::kPrimLong: {
1995 locations->SetInAt(0, Location::RequiresRegister());
1996 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001997 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001998 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001999
Roland Levillain88cb1752014-10-20 16:36:47 +01002000 case Primitive::kPrimFloat:
2001 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002002 locations->SetInAt(0, Location::RequiresFpuRegister());
2003 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01002004 break;
2005
2006 default:
2007 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2008 }
2009}
2010
2011void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
2012 LocationSummary* locations = neg->GetLocations();
2013 Location out = locations->Out();
2014 Location in = locations->InAt(0);
2015 switch (neg->GetResultType()) {
2016 case Primitive::kPrimInt:
2017 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002018 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01002019 break;
2020
2021 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002022 DCHECK(in.IsRegisterPair());
2023 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
2024 __ rsbs(out.AsRegisterPairLow<Register>(),
2025 in.AsRegisterPairLow<Register>(),
2026 ShifterOperand(0));
2027 // We cannot emit an RSC (Reverse Subtract with Carry)
2028 // instruction here, as it does not exist in the Thumb-2
2029 // instruction set. We use the following approach
2030 // using SBC and SUB instead.
2031 //
2032 // out.hi = -C
2033 __ sbc(out.AsRegisterPairHigh<Register>(),
2034 out.AsRegisterPairHigh<Register>(),
2035 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2036 // out.hi = out.hi - in.hi
2037 __ sub(out.AsRegisterPairHigh<Register>(),
2038 out.AsRegisterPairHigh<Register>(),
2039 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2040 break;
2041
Roland Levillain88cb1752014-10-20 16:36:47 +01002042 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002043 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002044 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002045 break;
2046
Roland Levillain88cb1752014-10-20 16:36:47 +01002047 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002048 DCHECK(in.IsFpuRegisterPair());
2049 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2050 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002051 break;
2052
2053 default:
2054 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2055 }
2056}
2057
Roland Levillaindff1f282014-11-05 14:15:05 +00002058void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002059 Primitive::Type result_type = conversion->GetResultType();
2060 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002061 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002062
Roland Levillain5b3ee562015-04-14 16:02:41 +01002063 // The float-to-long, double-to-long and long-to-float type conversions
2064 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002065 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002066 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2067 && result_type == Primitive::kPrimLong)
2068 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002069 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002070 : LocationSummary::kNoCall;
2071 LocationSummary* locations =
2072 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2073
David Brazdilb2bd1c52015-03-25 11:17:37 +00002074 // The Java language does not allow treating boolean as an integral type but
2075 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002076
Roland Levillaindff1f282014-11-05 14:15:05 +00002077 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002078 case Primitive::kPrimByte:
2079 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002080 case Primitive::kPrimLong:
2081 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002082 case Primitive::kPrimBoolean:
2083 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002084 case Primitive::kPrimShort:
2085 case Primitive::kPrimInt:
2086 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002087 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002088 locations->SetInAt(0, Location::RequiresRegister());
2089 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2090 break;
2091
2092 default:
2093 LOG(FATAL) << "Unexpected type conversion from " << input_type
2094 << " to " << result_type;
2095 }
2096 break;
2097
Roland Levillain01a8d712014-11-14 16:27:39 +00002098 case Primitive::kPrimShort:
2099 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002100 case Primitive::kPrimLong:
2101 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002102 case Primitive::kPrimBoolean:
2103 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002104 case Primitive::kPrimByte:
2105 case Primitive::kPrimInt:
2106 case Primitive::kPrimChar:
2107 // Processing a Dex `int-to-short' instruction.
2108 locations->SetInAt(0, Location::RequiresRegister());
2109 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2110 break;
2111
2112 default:
2113 LOG(FATAL) << "Unexpected type conversion from " << input_type
2114 << " to " << result_type;
2115 }
2116 break;
2117
Roland Levillain946e1432014-11-11 17:35:19 +00002118 case Primitive::kPrimInt:
2119 switch (input_type) {
2120 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002121 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002122 locations->SetInAt(0, Location::Any());
2123 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2124 break;
2125
2126 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002127 // Processing a Dex `float-to-int' instruction.
2128 locations->SetInAt(0, Location::RequiresFpuRegister());
2129 locations->SetOut(Location::RequiresRegister());
2130 locations->AddTemp(Location::RequiresFpuRegister());
2131 break;
2132
Roland Levillain946e1432014-11-11 17:35:19 +00002133 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002134 // Processing a Dex `double-to-int' instruction.
2135 locations->SetInAt(0, Location::RequiresFpuRegister());
2136 locations->SetOut(Location::RequiresRegister());
2137 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002138 break;
2139
2140 default:
2141 LOG(FATAL) << "Unexpected type conversion from " << input_type
2142 << " to " << result_type;
2143 }
2144 break;
2145
Roland Levillaindff1f282014-11-05 14:15:05 +00002146 case Primitive::kPrimLong:
2147 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002148 case Primitive::kPrimBoolean:
2149 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002150 case Primitive::kPrimByte:
2151 case Primitive::kPrimShort:
2152 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002153 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002154 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002155 locations->SetInAt(0, Location::RequiresRegister());
2156 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2157 break;
2158
Roland Levillain624279f2014-12-04 11:54:28 +00002159 case Primitive::kPrimFloat: {
2160 // Processing a Dex `float-to-long' instruction.
2161 InvokeRuntimeCallingConvention calling_convention;
2162 locations->SetInAt(0, Location::FpuRegisterLocation(
2163 calling_convention.GetFpuRegisterAt(0)));
2164 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2165 break;
2166 }
2167
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002168 case Primitive::kPrimDouble: {
2169 // Processing a Dex `double-to-long' instruction.
2170 InvokeRuntimeCallingConvention calling_convention;
2171 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2172 calling_convention.GetFpuRegisterAt(0),
2173 calling_convention.GetFpuRegisterAt(1)));
2174 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002175 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002176 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002177
2178 default:
2179 LOG(FATAL) << "Unexpected type conversion from " << input_type
2180 << " to " << result_type;
2181 }
2182 break;
2183
Roland Levillain981e4542014-11-14 11:47:14 +00002184 case Primitive::kPrimChar:
2185 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002186 case Primitive::kPrimLong:
2187 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002188 case Primitive::kPrimBoolean:
2189 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002190 case Primitive::kPrimByte:
2191 case Primitive::kPrimShort:
2192 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002193 // Processing a Dex `int-to-char' instruction.
2194 locations->SetInAt(0, Location::RequiresRegister());
2195 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2196 break;
2197
2198 default:
2199 LOG(FATAL) << "Unexpected type conversion from " << input_type
2200 << " to " << result_type;
2201 }
2202 break;
2203
Roland Levillaindff1f282014-11-05 14:15:05 +00002204 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002205 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002206 case Primitive::kPrimBoolean:
2207 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002208 case Primitive::kPrimByte:
2209 case Primitive::kPrimShort:
2210 case Primitive::kPrimInt:
2211 case Primitive::kPrimChar:
2212 // Processing a Dex `int-to-float' instruction.
2213 locations->SetInAt(0, Location::RequiresRegister());
2214 locations->SetOut(Location::RequiresFpuRegister());
2215 break;
2216
Roland Levillain5b3ee562015-04-14 16:02:41 +01002217 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002218 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002219 InvokeRuntimeCallingConvention calling_convention;
2220 locations->SetInAt(0, Location::RegisterPairLocation(
2221 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2222 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002223 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002224 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002225
Roland Levillaincff13742014-11-17 14:32:17 +00002226 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002227 // Processing a Dex `double-to-float' instruction.
2228 locations->SetInAt(0, Location::RequiresFpuRegister());
2229 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002230 break;
2231
2232 default:
2233 LOG(FATAL) << "Unexpected type conversion from " << input_type
2234 << " to " << result_type;
2235 };
2236 break;
2237
Roland Levillaindff1f282014-11-05 14:15:05 +00002238 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002239 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002240 case Primitive::kPrimBoolean:
2241 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002242 case Primitive::kPrimByte:
2243 case Primitive::kPrimShort:
2244 case Primitive::kPrimInt:
2245 case Primitive::kPrimChar:
2246 // Processing a Dex `int-to-double' instruction.
2247 locations->SetInAt(0, Location::RequiresRegister());
2248 locations->SetOut(Location::RequiresFpuRegister());
2249 break;
2250
2251 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002252 // Processing a Dex `long-to-double' instruction.
2253 locations->SetInAt(0, Location::RequiresRegister());
2254 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002255 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002256 locations->AddTemp(Location::RequiresFpuRegister());
2257 break;
2258
Roland Levillaincff13742014-11-17 14:32:17 +00002259 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002260 // Processing a Dex `float-to-double' instruction.
2261 locations->SetInAt(0, Location::RequiresFpuRegister());
2262 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002263 break;
2264
2265 default:
2266 LOG(FATAL) << "Unexpected type conversion from " << input_type
2267 << " to " << result_type;
2268 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002269 break;
2270
2271 default:
2272 LOG(FATAL) << "Unexpected type conversion from " << input_type
2273 << " to " << result_type;
2274 }
2275}
2276
2277void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2278 LocationSummary* locations = conversion->GetLocations();
2279 Location out = locations->Out();
2280 Location in = locations->InAt(0);
2281 Primitive::Type result_type = conversion->GetResultType();
2282 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002283 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002284 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002285 case Primitive::kPrimByte:
2286 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002287 case Primitive::kPrimLong:
2288 // Type conversion from long to byte is a result of code transformations.
2289 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2290 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002291 case Primitive::kPrimBoolean:
2292 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002293 case Primitive::kPrimShort:
2294 case Primitive::kPrimInt:
2295 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002296 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002297 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002298 break;
2299
2300 default:
2301 LOG(FATAL) << "Unexpected type conversion from " << input_type
2302 << " to " << result_type;
2303 }
2304 break;
2305
Roland Levillain01a8d712014-11-14 16:27:39 +00002306 case Primitive::kPrimShort:
2307 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002308 case Primitive::kPrimLong:
2309 // Type conversion from long to short is a result of code transformations.
2310 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2311 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002312 case Primitive::kPrimBoolean:
2313 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002314 case Primitive::kPrimByte:
2315 case Primitive::kPrimInt:
2316 case Primitive::kPrimChar:
2317 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002318 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002319 break;
2320
2321 default:
2322 LOG(FATAL) << "Unexpected type conversion from " << input_type
2323 << " to " << result_type;
2324 }
2325 break;
2326
Roland Levillain946e1432014-11-11 17:35:19 +00002327 case Primitive::kPrimInt:
2328 switch (input_type) {
2329 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002330 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002331 DCHECK(out.IsRegister());
2332 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002333 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002334 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002335 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002336 } else {
2337 DCHECK(in.IsConstant());
2338 DCHECK(in.GetConstant()->IsLongConstant());
2339 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002340 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002341 }
2342 break;
2343
Roland Levillain3f8f9362014-12-02 17:45:01 +00002344 case Primitive::kPrimFloat: {
2345 // Processing a Dex `float-to-int' instruction.
2346 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002347 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002348 __ vmovrs(out.AsRegister<Register>(), temp);
2349 break;
2350 }
2351
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002352 case Primitive::kPrimDouble: {
2353 // Processing a Dex `double-to-int' instruction.
2354 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002355 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002356 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002357 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002358 }
Roland Levillain946e1432014-11-11 17:35:19 +00002359
2360 default:
2361 LOG(FATAL) << "Unexpected type conversion from " << input_type
2362 << " to " << result_type;
2363 }
2364 break;
2365
Roland Levillaindff1f282014-11-05 14:15:05 +00002366 case Primitive::kPrimLong:
2367 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002368 case Primitive::kPrimBoolean:
2369 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002370 case Primitive::kPrimByte:
2371 case Primitive::kPrimShort:
2372 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002373 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002374 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002375 DCHECK(out.IsRegisterPair());
2376 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002377 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002378 // Sign extension.
2379 __ Asr(out.AsRegisterPairHigh<Register>(),
2380 out.AsRegisterPairLow<Register>(),
2381 31);
2382 break;
2383
2384 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002385 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002386 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2387 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002388 conversion->GetDexPc(),
2389 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002390 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002391 break;
2392
Roland Levillaindff1f282014-11-05 14:15:05 +00002393 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002394 // Processing a Dex `double-to-long' instruction.
2395 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2396 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002397 conversion->GetDexPc(),
2398 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002399 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002400 break;
2401
2402 default:
2403 LOG(FATAL) << "Unexpected type conversion from " << input_type
2404 << " to " << result_type;
2405 }
2406 break;
2407
Roland Levillain981e4542014-11-14 11:47:14 +00002408 case Primitive::kPrimChar:
2409 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002410 case Primitive::kPrimLong:
2411 // Type conversion from long to char is a result of code transformations.
2412 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2413 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002414 case Primitive::kPrimBoolean:
2415 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002416 case Primitive::kPrimByte:
2417 case Primitive::kPrimShort:
2418 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002419 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002420 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002421 break;
2422
2423 default:
2424 LOG(FATAL) << "Unexpected type conversion from " << input_type
2425 << " to " << result_type;
2426 }
2427 break;
2428
Roland Levillaindff1f282014-11-05 14:15:05 +00002429 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002430 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002431 case Primitive::kPrimBoolean:
2432 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002433 case Primitive::kPrimByte:
2434 case Primitive::kPrimShort:
2435 case Primitive::kPrimInt:
2436 case Primitive::kPrimChar: {
2437 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002438 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2439 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002440 break;
2441 }
2442
Roland Levillain5b3ee562015-04-14 16:02:41 +01002443 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002444 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002445 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2446 conversion,
2447 conversion->GetDexPc(),
2448 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002449 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002450 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002451
Roland Levillaincff13742014-11-17 14:32:17 +00002452 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002453 // Processing a Dex `double-to-float' instruction.
2454 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2455 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002456 break;
2457
2458 default:
2459 LOG(FATAL) << "Unexpected type conversion from " << input_type
2460 << " to " << result_type;
2461 };
2462 break;
2463
Roland Levillaindff1f282014-11-05 14:15:05 +00002464 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002465 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002466 case Primitive::kPrimBoolean:
2467 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002468 case Primitive::kPrimByte:
2469 case Primitive::kPrimShort:
2470 case Primitive::kPrimInt:
2471 case Primitive::kPrimChar: {
2472 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002473 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002474 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2475 out.AsFpuRegisterPairLow<SRegister>());
2476 break;
2477 }
2478
Roland Levillain647b9ed2014-11-27 12:06:00 +00002479 case Primitive::kPrimLong: {
2480 // Processing a Dex `long-to-double' instruction.
2481 Register low = in.AsRegisterPairLow<Register>();
2482 Register high = in.AsRegisterPairHigh<Register>();
2483 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2484 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002485 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002486 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002487 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2488 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002489
Roland Levillain682393c2015-04-14 15:57:52 +01002490 // temp_d = int-to-double(high)
2491 __ vmovsr(temp_s, high);
2492 __ vcvtdi(temp_d, temp_s);
2493 // constant_d = k2Pow32EncodingForDouble
2494 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2495 // out_d = unsigned-to-double(low)
2496 __ vmovsr(out_s, low);
2497 __ vcvtdu(out_d, out_s);
2498 // out_d += temp_d * constant_d
2499 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002500 break;
2501 }
2502
Roland Levillaincff13742014-11-17 14:32:17 +00002503 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002504 // Processing a Dex `float-to-double' instruction.
2505 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2506 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002507 break;
2508
2509 default:
2510 LOG(FATAL) << "Unexpected type conversion from " << input_type
2511 << " to " << result_type;
2512 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002513 break;
2514
2515 default:
2516 LOG(FATAL) << "Unexpected type conversion from " << input_type
2517 << " to " << result_type;
2518 }
2519}
2520
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002521void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002522 LocationSummary* locations =
2523 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002524 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002525 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002526 locations->SetInAt(0, Location::RequiresRegister());
2527 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002528 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2529 break;
2530 }
2531
2532 case Primitive::kPrimLong: {
2533 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002534 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002535 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002536 break;
2537 }
2538
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002539 case Primitive::kPrimFloat:
2540 case Primitive::kPrimDouble: {
2541 locations->SetInAt(0, Location::RequiresFpuRegister());
2542 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002543 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002544 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002545 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002546
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002547 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002548 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002549 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002550}
2551
2552void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2553 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002554 Location out = locations->Out();
2555 Location first = locations->InAt(0);
2556 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002557 switch (add->GetResultType()) {
2558 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002559 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002560 __ add(out.AsRegister<Register>(),
2561 first.AsRegister<Register>(),
2562 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002563 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002564 __ AddConstant(out.AsRegister<Register>(),
2565 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002566 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002567 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002568 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002569
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002570 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002571 if (second.IsConstant()) {
2572 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2573 GenerateAddLongConst(out, first, value);
2574 } else {
2575 DCHECK(second.IsRegisterPair());
2576 __ adds(out.AsRegisterPairLow<Register>(),
2577 first.AsRegisterPairLow<Register>(),
2578 ShifterOperand(second.AsRegisterPairLow<Register>()));
2579 __ adc(out.AsRegisterPairHigh<Register>(),
2580 first.AsRegisterPairHigh<Register>(),
2581 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2582 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002583 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002584 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002585
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002586 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002587 __ vadds(out.AsFpuRegister<SRegister>(),
2588 first.AsFpuRegister<SRegister>(),
2589 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002590 break;
2591
2592 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002593 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2594 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2595 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002596 break;
2597
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002598 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002599 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002600 }
2601}
2602
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002603void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002604 LocationSummary* locations =
2605 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002606 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002607 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002608 locations->SetInAt(0, Location::RequiresRegister());
2609 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002610 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2611 break;
2612 }
2613
2614 case Primitive::kPrimLong: {
2615 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002616 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002617 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002618 break;
2619 }
Calin Juravle11351682014-10-23 15:38:15 +01002620 case Primitive::kPrimFloat:
2621 case Primitive::kPrimDouble: {
2622 locations->SetInAt(0, Location::RequiresFpuRegister());
2623 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002624 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002625 break;
Calin Juravle11351682014-10-23 15:38:15 +01002626 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002627 default:
Calin Juravle11351682014-10-23 15:38:15 +01002628 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002629 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002630}
2631
2632void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2633 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002634 Location out = locations->Out();
2635 Location first = locations->InAt(0);
2636 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002637 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002638 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002639 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002640 __ sub(out.AsRegister<Register>(),
2641 first.AsRegister<Register>(),
2642 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002643 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002644 __ AddConstant(out.AsRegister<Register>(),
2645 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002646 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002647 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002648 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002649 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002650
Calin Juravle11351682014-10-23 15:38:15 +01002651 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002652 if (second.IsConstant()) {
2653 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2654 GenerateAddLongConst(out, first, -value);
2655 } else {
2656 DCHECK(second.IsRegisterPair());
2657 __ subs(out.AsRegisterPairLow<Register>(),
2658 first.AsRegisterPairLow<Register>(),
2659 ShifterOperand(second.AsRegisterPairLow<Register>()));
2660 __ sbc(out.AsRegisterPairHigh<Register>(),
2661 first.AsRegisterPairHigh<Register>(),
2662 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2663 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002664 break;
Calin Juravle11351682014-10-23 15:38:15 +01002665 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002666
Calin Juravle11351682014-10-23 15:38:15 +01002667 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002668 __ vsubs(out.AsFpuRegister<SRegister>(),
2669 first.AsFpuRegister<SRegister>(),
2670 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002671 break;
Calin Juravle11351682014-10-23 15:38:15 +01002672 }
2673
2674 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002675 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2676 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2677 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002678 break;
2679 }
2680
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002681
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002682 default:
Calin Juravle11351682014-10-23 15:38:15 +01002683 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002684 }
2685}
2686
Calin Juravle34bacdf2014-10-07 20:23:36 +01002687void LocationsBuilderARM::VisitMul(HMul* mul) {
2688 LocationSummary* locations =
2689 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2690 switch (mul->GetResultType()) {
2691 case Primitive::kPrimInt:
2692 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002693 locations->SetInAt(0, Location::RequiresRegister());
2694 locations->SetInAt(1, Location::RequiresRegister());
2695 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002696 break;
2697 }
2698
Calin Juravleb5bfa962014-10-21 18:02:24 +01002699 case Primitive::kPrimFloat:
2700 case Primitive::kPrimDouble: {
2701 locations->SetInAt(0, Location::RequiresFpuRegister());
2702 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002703 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002704 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002705 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002706
2707 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002708 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002709 }
2710}
2711
2712void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2713 LocationSummary* locations = mul->GetLocations();
2714 Location out = locations->Out();
2715 Location first = locations->InAt(0);
2716 Location second = locations->InAt(1);
2717 switch (mul->GetResultType()) {
2718 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002719 __ mul(out.AsRegister<Register>(),
2720 first.AsRegister<Register>(),
2721 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002722 break;
2723 }
2724 case Primitive::kPrimLong: {
2725 Register out_hi = out.AsRegisterPairHigh<Register>();
2726 Register out_lo = out.AsRegisterPairLow<Register>();
2727 Register in1_hi = first.AsRegisterPairHigh<Register>();
2728 Register in1_lo = first.AsRegisterPairLow<Register>();
2729 Register in2_hi = second.AsRegisterPairHigh<Register>();
2730 Register in2_lo = second.AsRegisterPairLow<Register>();
2731
2732 // Extra checks to protect caused by the existence of R1_R2.
2733 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2734 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2735 DCHECK_NE(out_hi, in1_lo);
2736 DCHECK_NE(out_hi, in2_lo);
2737
2738 // input: in1 - 64 bits, in2 - 64 bits
2739 // output: out
2740 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2741 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2742 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2743
2744 // IP <- in1.lo * in2.hi
2745 __ mul(IP, in1_lo, in2_hi);
2746 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2747 __ mla(out_hi, in1_hi, in2_lo, IP);
2748 // out.lo <- (in1.lo * in2.lo)[31:0];
2749 __ umull(out_lo, IP, in1_lo, in2_lo);
2750 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2751 __ add(out_hi, out_hi, ShifterOperand(IP));
2752 break;
2753 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002754
2755 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002756 __ vmuls(out.AsFpuRegister<SRegister>(),
2757 first.AsFpuRegister<SRegister>(),
2758 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002759 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002760 }
2761
2762 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002763 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2764 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2765 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002766 break;
2767 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002768
2769 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002770 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002771 }
2772}
2773
Zheng Xuc6667102015-05-15 16:08:45 +08002774void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2775 DCHECK(instruction->IsDiv() || instruction->IsRem());
2776 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2777
2778 LocationSummary* locations = instruction->GetLocations();
2779 Location second = locations->InAt(1);
2780 DCHECK(second.IsConstant());
2781
2782 Register out = locations->Out().AsRegister<Register>();
2783 Register dividend = locations->InAt(0).AsRegister<Register>();
2784 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2785 DCHECK(imm == 1 || imm == -1);
2786
2787 if (instruction->IsRem()) {
2788 __ LoadImmediate(out, 0);
2789 } else {
2790 if (imm == 1) {
2791 __ Mov(out, dividend);
2792 } else {
2793 __ rsb(out, dividend, ShifterOperand(0));
2794 }
2795 }
2796}
2797
2798void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2799 DCHECK(instruction->IsDiv() || instruction->IsRem());
2800 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2801
2802 LocationSummary* locations = instruction->GetLocations();
2803 Location second = locations->InAt(1);
2804 DCHECK(second.IsConstant());
2805
2806 Register out = locations->Out().AsRegister<Register>();
2807 Register dividend = locations->InAt(0).AsRegister<Register>();
2808 Register temp = locations->GetTemp(0).AsRegister<Register>();
2809 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002810 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002811 int ctz_imm = CTZ(abs_imm);
2812
2813 if (ctz_imm == 1) {
2814 __ Lsr(temp, dividend, 32 - ctz_imm);
2815 } else {
2816 __ Asr(temp, dividend, 31);
2817 __ Lsr(temp, temp, 32 - ctz_imm);
2818 }
2819 __ add(out, temp, ShifterOperand(dividend));
2820
2821 if (instruction->IsDiv()) {
2822 __ Asr(out, out, ctz_imm);
2823 if (imm < 0) {
2824 __ rsb(out, out, ShifterOperand(0));
2825 }
2826 } else {
2827 __ ubfx(out, out, 0, ctz_imm);
2828 __ sub(out, out, ShifterOperand(temp));
2829 }
2830}
2831
2832void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2833 DCHECK(instruction->IsDiv() || instruction->IsRem());
2834 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2835
2836 LocationSummary* locations = instruction->GetLocations();
2837 Location second = locations->InAt(1);
2838 DCHECK(second.IsConstant());
2839
2840 Register out = locations->Out().AsRegister<Register>();
2841 Register dividend = locations->InAt(0).AsRegister<Register>();
2842 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2843 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2844 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2845
2846 int64_t magic;
2847 int shift;
2848 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2849
2850 __ LoadImmediate(temp1, magic);
2851 __ smull(temp2, temp1, dividend, temp1);
2852
2853 if (imm > 0 && magic < 0) {
2854 __ add(temp1, temp1, ShifterOperand(dividend));
2855 } else if (imm < 0 && magic > 0) {
2856 __ sub(temp1, temp1, ShifterOperand(dividend));
2857 }
2858
2859 if (shift != 0) {
2860 __ Asr(temp1, temp1, shift);
2861 }
2862
2863 if (instruction->IsDiv()) {
2864 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2865 } else {
2866 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2867 // TODO: Strength reduction for mls.
2868 __ LoadImmediate(temp2, imm);
2869 __ mls(out, temp1, temp2, dividend);
2870 }
2871}
2872
2873void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2874 DCHECK(instruction->IsDiv() || instruction->IsRem());
2875 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2876
2877 LocationSummary* locations = instruction->GetLocations();
2878 Location second = locations->InAt(1);
2879 DCHECK(second.IsConstant());
2880
2881 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2882 if (imm == 0) {
2883 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2884 } else if (imm == 1 || imm == -1) {
2885 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002886 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002887 DivRemByPowerOfTwo(instruction);
2888 } else {
2889 DCHECK(imm <= -2 || imm >= 2);
2890 GenerateDivRemWithAnyConstant(instruction);
2891 }
2892}
2893
Calin Juravle7c4954d2014-10-28 16:57:40 +00002894void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002895 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2896 if (div->GetResultType() == Primitive::kPrimLong) {
2897 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002898 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002899 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2900 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002901 } else if (div->GetResultType() == Primitive::kPrimInt &&
2902 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2903 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002904 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002905 }
2906
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002907 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2908
Calin Juravle7c4954d2014-10-28 16:57:40 +00002909 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002910 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002911 if (div->InputAt(1)->IsConstant()) {
2912 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00002913 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08002914 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002915 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
2916 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08002917 // No temp register required.
2918 } else {
2919 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002920 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002921 locations->AddTemp(Location::RequiresRegister());
2922 }
2923 }
2924 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002925 locations->SetInAt(0, Location::RequiresRegister());
2926 locations->SetInAt(1, Location::RequiresRegister());
2927 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2928 } else {
2929 InvokeRuntimeCallingConvention calling_convention;
2930 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2931 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2932 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2933 // we only need the former.
2934 locations->SetOut(Location::RegisterLocation(R0));
2935 }
Calin Juravled0d48522014-11-04 16:40:20 +00002936 break;
2937 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002938 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002939 InvokeRuntimeCallingConvention calling_convention;
2940 locations->SetInAt(0, Location::RegisterPairLocation(
2941 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2942 locations->SetInAt(1, Location::RegisterPairLocation(
2943 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002944 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002945 break;
2946 }
2947 case Primitive::kPrimFloat:
2948 case Primitive::kPrimDouble: {
2949 locations->SetInAt(0, Location::RequiresFpuRegister());
2950 locations->SetInAt(1, Location::RequiresFpuRegister());
2951 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2952 break;
2953 }
2954
2955 default:
2956 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2957 }
2958}
2959
2960void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2961 LocationSummary* locations = div->GetLocations();
2962 Location out = locations->Out();
2963 Location first = locations->InAt(0);
2964 Location second = locations->InAt(1);
2965
2966 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002967 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002968 if (second.IsConstant()) {
2969 GenerateDivRemConstantIntegral(div);
2970 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002971 __ sdiv(out.AsRegister<Register>(),
2972 first.AsRegister<Register>(),
2973 second.AsRegister<Register>());
2974 } else {
2975 InvokeRuntimeCallingConvention calling_convention;
2976 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2977 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2978 DCHECK_EQ(R0, out.AsRegister<Register>());
2979
2980 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002981 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002982 }
Calin Juravled0d48522014-11-04 16:40:20 +00002983 break;
2984 }
2985
Calin Juravle7c4954d2014-10-28 16:57:40 +00002986 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002987 InvokeRuntimeCallingConvention calling_convention;
2988 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2989 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2990 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2991 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2992 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002993 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002994
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002995 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002996 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002997 break;
2998 }
2999
3000 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00003001 __ vdivs(out.AsFpuRegister<SRegister>(),
3002 first.AsFpuRegister<SRegister>(),
3003 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00003004 break;
3005 }
3006
3007 case Primitive::kPrimDouble: {
3008 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
3009 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
3010 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
3011 break;
3012 }
3013
3014 default:
3015 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3016 }
3017}
3018
Calin Juravlebacfec32014-11-14 15:54:36 +00003019void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003020 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003021
3022 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003023 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08003024 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
3025 // sdiv will be replaced by other instruction sequence.
3026 call_kind = LocationSummary::kNoCall;
3027 } else if ((rem->GetResultType() == Primitive::kPrimInt)
3028 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003029 // Have hardware divide instruction for int, do it with three instructions.
3030 call_kind = LocationSummary::kNoCall;
3031 }
3032
Calin Juravlebacfec32014-11-14 15:54:36 +00003033 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3034
Calin Juravled2ec87d2014-12-08 14:24:46 +00003035 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003036 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003037 if (rem->InputAt(1)->IsConstant()) {
3038 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003039 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003040 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003041 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3042 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003043 // No temp register required.
3044 } else {
3045 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003046 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003047 locations->AddTemp(Location::RequiresRegister());
3048 }
3049 }
3050 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003051 locations->SetInAt(0, Location::RequiresRegister());
3052 locations->SetInAt(1, Location::RequiresRegister());
3053 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3054 locations->AddTemp(Location::RequiresRegister());
3055 } else {
3056 InvokeRuntimeCallingConvention calling_convention;
3057 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3058 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3059 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3060 // we only need the latter.
3061 locations->SetOut(Location::RegisterLocation(R1));
3062 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003063 break;
3064 }
3065 case Primitive::kPrimLong: {
3066 InvokeRuntimeCallingConvention calling_convention;
3067 locations->SetInAt(0, Location::RegisterPairLocation(
3068 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3069 locations->SetInAt(1, Location::RegisterPairLocation(
3070 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3071 // The runtime helper puts the output in R2,R3.
3072 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3073 break;
3074 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003075 case Primitive::kPrimFloat: {
3076 InvokeRuntimeCallingConvention calling_convention;
3077 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3078 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3079 locations->SetOut(Location::FpuRegisterLocation(S0));
3080 break;
3081 }
3082
Calin Juravlebacfec32014-11-14 15:54:36 +00003083 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003084 InvokeRuntimeCallingConvention calling_convention;
3085 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3086 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3087 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3088 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3089 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003090 break;
3091 }
3092
3093 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003094 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003095 }
3096}
3097
3098void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3099 LocationSummary* locations = rem->GetLocations();
3100 Location out = locations->Out();
3101 Location first = locations->InAt(0);
3102 Location second = locations->InAt(1);
3103
Calin Juravled2ec87d2014-12-08 14:24:46 +00003104 Primitive::Type type = rem->GetResultType();
3105 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003106 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003107 if (second.IsConstant()) {
3108 GenerateDivRemConstantIntegral(rem);
3109 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003110 Register reg1 = first.AsRegister<Register>();
3111 Register reg2 = second.AsRegister<Register>();
3112 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003113
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003114 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003115 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003116 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003117 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003118 } else {
3119 InvokeRuntimeCallingConvention calling_convention;
3120 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3121 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3122 DCHECK_EQ(R1, out.AsRegister<Register>());
3123
3124 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003125 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003126 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003127 break;
3128 }
3129
3130 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003131 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003132 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003133 break;
3134 }
3135
Calin Juravled2ec87d2014-12-08 14:24:46 +00003136 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003137 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003138 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003139 break;
3140 }
3141
Calin Juravlebacfec32014-11-14 15:54:36 +00003142 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003143 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003144 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003145 break;
3146 }
3147
3148 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003149 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003150 }
3151}
3152
Calin Juravled0d48522014-11-04 16:40:20 +00003153void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003154 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3155 ? LocationSummary::kCallOnSlowPath
3156 : LocationSummary::kNoCall;
3157 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003158 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003159 if (instruction->HasUses()) {
3160 locations->SetOut(Location::SameAsFirstInput());
3161 }
3162}
3163
3164void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003165 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003166 codegen_->AddSlowPath(slow_path);
3167
3168 LocationSummary* locations = instruction->GetLocations();
3169 Location value = locations->InAt(0);
3170
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003171 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003172 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003173 case Primitive::kPrimByte:
3174 case Primitive::kPrimChar:
3175 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003176 case Primitive::kPrimInt: {
3177 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003178 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003179 } else {
3180 DCHECK(value.IsConstant()) << value;
3181 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3182 __ b(slow_path->GetEntryLabel());
3183 }
3184 }
3185 break;
3186 }
3187 case Primitive::kPrimLong: {
3188 if (value.IsRegisterPair()) {
3189 __ orrs(IP,
3190 value.AsRegisterPairLow<Register>(),
3191 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3192 __ b(slow_path->GetEntryLabel(), EQ);
3193 } else {
3194 DCHECK(value.IsConstant()) << value;
3195 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3196 __ b(slow_path->GetEntryLabel());
3197 }
3198 }
3199 break;
3200 default:
3201 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3202 }
3203 }
Calin Juravled0d48522014-11-04 16:40:20 +00003204}
3205
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003206void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3207 Register in = locations->InAt(0).AsRegister<Register>();
3208 Location rhs = locations->InAt(1);
3209 Register out = locations->Out().AsRegister<Register>();
3210
3211 if (rhs.IsConstant()) {
3212 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3213 // so map all rotations to a +ve. equivalent in that range.
3214 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3215 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3216 if (rot) {
3217 // Rotate, mapping left rotations to right equivalents if necessary.
3218 // (e.g. left by 2 bits == right by 30.)
3219 __ Ror(out, in, rot);
3220 } else if (out != in) {
3221 __ Mov(out, in);
3222 }
3223 } else {
3224 __ Ror(out, in, rhs.AsRegister<Register>());
3225 }
3226}
3227
3228// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3229// rotates by swapping input regs (effectively rotating by the first 32-bits of
3230// a larger rotation) or flipping direction (thus treating larger right/left
3231// rotations as sub-word sized rotations in the other direction) as appropriate.
3232void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3233 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3234 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3235 Location rhs = locations->InAt(1);
3236 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3237 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3238
3239 if (rhs.IsConstant()) {
3240 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3241 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003242 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003243 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3244 // logic below to a simple pair of binary orr.
3245 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3246 if (rot >= kArmBitsPerWord) {
3247 rot -= kArmBitsPerWord;
3248 std::swap(in_reg_hi, in_reg_lo);
3249 }
3250 // Rotate, or mov to out for zero or word size rotations.
3251 if (rot != 0u) {
3252 __ Lsr(out_reg_hi, in_reg_hi, rot);
3253 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3254 __ Lsr(out_reg_lo, in_reg_lo, rot);
3255 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3256 } else {
3257 __ Mov(out_reg_lo, in_reg_lo);
3258 __ Mov(out_reg_hi, in_reg_hi);
3259 }
3260 } else {
3261 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3262 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3263 Label end;
3264 Label shift_by_32_plus_shift_right;
3265
3266 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3267 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3268 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3269 __ b(&shift_by_32_plus_shift_right, CC);
3270
3271 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3272 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3273 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3274 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3275 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3276 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3277 __ Lsr(shift_left, in_reg_hi, shift_right);
3278 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3279 __ b(&end);
3280
3281 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3282 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3283 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3284 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3285 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3286 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3287 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3288 __ Lsl(shift_right, in_reg_hi, shift_left);
3289 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3290
3291 __ Bind(&end);
3292 }
3293}
Roland Levillain22c49222016-03-18 14:04:28 +00003294
3295void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003296 LocationSummary* locations =
3297 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3298 switch (ror->GetResultType()) {
3299 case Primitive::kPrimInt: {
3300 locations->SetInAt(0, Location::RequiresRegister());
3301 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3302 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3303 break;
3304 }
3305 case Primitive::kPrimLong: {
3306 locations->SetInAt(0, Location::RequiresRegister());
3307 if (ror->InputAt(1)->IsConstant()) {
3308 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3309 } else {
3310 locations->SetInAt(1, Location::RequiresRegister());
3311 locations->AddTemp(Location::RequiresRegister());
3312 locations->AddTemp(Location::RequiresRegister());
3313 }
3314 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3315 break;
3316 }
3317 default:
3318 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3319 }
3320}
3321
Roland Levillain22c49222016-03-18 14:04:28 +00003322void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003323 LocationSummary* locations = ror->GetLocations();
3324 Primitive::Type type = ror->GetResultType();
3325 switch (type) {
3326 case Primitive::kPrimInt: {
3327 HandleIntegerRotate(locations);
3328 break;
3329 }
3330 case Primitive::kPrimLong: {
3331 HandleLongRotate(locations);
3332 break;
3333 }
3334 default:
3335 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003336 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003337 }
3338}
3339
Calin Juravle9aec02f2014-11-18 23:06:35 +00003340void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3341 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3342
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003343 LocationSummary* locations =
3344 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003345
3346 switch (op->GetResultType()) {
3347 case Primitive::kPrimInt: {
3348 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003349 if (op->InputAt(1)->IsConstant()) {
3350 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3351 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3352 } else {
3353 locations->SetInAt(1, Location::RequiresRegister());
3354 // Make the output overlap, as it will be used to hold the masked
3355 // second input.
3356 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3357 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003358 break;
3359 }
3360 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003361 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003362 if (op->InputAt(1)->IsConstant()) {
3363 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3364 // For simplicity, use kOutputOverlap even though we only require that low registers
3365 // don't clash with high registers which the register allocator currently guarantees.
3366 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3367 } else {
3368 locations->SetInAt(1, Location::RequiresRegister());
3369 locations->AddTemp(Location::RequiresRegister());
3370 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3371 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003372 break;
3373 }
3374 default:
3375 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3376 }
3377}
3378
3379void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3380 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3381
3382 LocationSummary* locations = op->GetLocations();
3383 Location out = locations->Out();
3384 Location first = locations->InAt(0);
3385 Location second = locations->InAt(1);
3386
3387 Primitive::Type type = op->GetResultType();
3388 switch (type) {
3389 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003390 Register out_reg = out.AsRegister<Register>();
3391 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003392 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003393 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003394 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003395 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003396 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003397 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003398 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003399 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003400 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003401 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003402 }
3403 } else {
3404 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003405 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003406 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003407 __ Mov(out_reg, first_reg);
3408 } else if (op->IsShl()) {
3409 __ Lsl(out_reg, first_reg, shift_value);
3410 } else if (op->IsShr()) {
3411 __ Asr(out_reg, first_reg, shift_value);
3412 } else {
3413 __ Lsr(out_reg, first_reg, shift_value);
3414 }
3415 }
3416 break;
3417 }
3418 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003419 Register o_h = out.AsRegisterPairHigh<Register>();
3420 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003421
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003422 Register high = first.AsRegisterPairHigh<Register>();
3423 Register low = first.AsRegisterPairLow<Register>();
3424
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003425 if (second.IsRegister()) {
3426 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003427
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003428 Register second_reg = second.AsRegister<Register>();
3429
3430 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003431 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003432 // Shift the high part
3433 __ Lsl(o_h, high, o_l);
3434 // Shift the low part and `or` what overflew on the high part
3435 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3436 __ Lsr(temp, low, temp);
3437 __ orr(o_h, o_h, ShifterOperand(temp));
3438 // If the shift is > 32 bits, override the high part
3439 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3440 __ it(PL);
3441 __ Lsl(o_h, low, temp, PL);
3442 // Shift the low part
3443 __ Lsl(o_l, low, o_l);
3444 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003445 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003446 // Shift the low part
3447 __ Lsr(o_l, low, o_h);
3448 // Shift the high part and `or` what underflew on the low part
3449 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3450 __ Lsl(temp, high, temp);
3451 __ orr(o_l, o_l, ShifterOperand(temp));
3452 // If the shift is > 32 bits, override the low part
3453 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3454 __ it(PL);
3455 __ Asr(o_l, high, temp, PL);
3456 // Shift the high part
3457 __ Asr(o_h, high, o_h);
3458 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003459 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003460 // same as Shr except we use `Lsr`s and not `Asr`s
3461 __ Lsr(o_l, low, o_h);
3462 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3463 __ Lsl(temp, high, temp);
3464 __ orr(o_l, o_l, ShifterOperand(temp));
3465 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3466 __ it(PL);
3467 __ Lsr(o_l, high, temp, PL);
3468 __ Lsr(o_h, high, o_h);
3469 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003470 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003471 // Register allocator doesn't create partial overlap.
3472 DCHECK_NE(o_l, high);
3473 DCHECK_NE(o_h, low);
3474 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003475 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003476 if (shift_value > 32) {
3477 if (op->IsShl()) {
3478 __ Lsl(o_h, low, shift_value - 32);
3479 __ LoadImmediate(o_l, 0);
3480 } else if (op->IsShr()) {
3481 __ Asr(o_l, high, shift_value - 32);
3482 __ Asr(o_h, high, 31);
3483 } else {
3484 __ Lsr(o_l, high, shift_value - 32);
3485 __ LoadImmediate(o_h, 0);
3486 }
3487 } else if (shift_value == 32) {
3488 if (op->IsShl()) {
3489 __ mov(o_h, ShifterOperand(low));
3490 __ LoadImmediate(o_l, 0);
3491 } else if (op->IsShr()) {
3492 __ mov(o_l, ShifterOperand(high));
3493 __ Asr(o_h, high, 31);
3494 } else {
3495 __ mov(o_l, ShifterOperand(high));
3496 __ LoadImmediate(o_h, 0);
3497 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003498 } else if (shift_value == 1) {
3499 if (op->IsShl()) {
3500 __ Lsls(o_l, low, 1);
3501 __ adc(o_h, high, ShifterOperand(high));
3502 } else if (op->IsShr()) {
3503 __ Asrs(o_h, high, 1);
3504 __ Rrx(o_l, low);
3505 } else {
3506 __ Lsrs(o_h, high, 1);
3507 __ Rrx(o_l, low);
3508 }
3509 } else {
3510 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003511 if (op->IsShl()) {
3512 __ Lsl(o_h, high, shift_value);
3513 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3514 __ Lsl(o_l, low, shift_value);
3515 } else if (op->IsShr()) {
3516 __ Lsr(o_l, low, shift_value);
3517 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3518 __ Asr(o_h, high, shift_value);
3519 } else {
3520 __ Lsr(o_l, low, shift_value);
3521 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3522 __ Lsr(o_h, high, shift_value);
3523 }
3524 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003525 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003526 break;
3527 }
3528 default:
3529 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003530 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003531 }
3532}
3533
3534void LocationsBuilderARM::VisitShl(HShl* shl) {
3535 HandleShift(shl);
3536}
3537
3538void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3539 HandleShift(shl);
3540}
3541
3542void LocationsBuilderARM::VisitShr(HShr* shr) {
3543 HandleShift(shr);
3544}
3545
3546void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3547 HandleShift(shr);
3548}
3549
3550void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3551 HandleShift(ushr);
3552}
3553
3554void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3555 HandleShift(ushr);
3556}
3557
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003558void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003559 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003560 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003561 if (instruction->IsStringAlloc()) {
3562 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3563 } else {
3564 InvokeRuntimeCallingConvention calling_convention;
3565 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3566 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3567 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003568 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003569}
3570
3571void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003572 // Note: if heap poisoning is enabled, the entry point takes cares
3573 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003574 if (instruction->IsStringAlloc()) {
3575 // String is allocated through StringFactory. Call NewEmptyString entry point.
3576 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003577 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003578 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3579 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3580 __ blx(LR);
3581 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3582 } else {
3583 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
3584 instruction,
3585 instruction->GetDexPc(),
3586 nullptr);
3587 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3588 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003589}
3590
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003591void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3592 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003593 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003594 InvokeRuntimeCallingConvention calling_convention;
3595 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003596 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003597 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003598 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003599}
3600
3601void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3602 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003603 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003604 // Note: if heap poisoning is enabled, the entry point takes cares
3605 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003606 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003607 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003608 instruction->GetDexPc(),
3609 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003610 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003611}
3612
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003613void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003614 LocationSummary* locations =
3615 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003616 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3617 if (location.IsStackSlot()) {
3618 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3619 } else if (location.IsDoubleStackSlot()) {
3620 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003621 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003622 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003623}
3624
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003625void InstructionCodeGeneratorARM::VisitParameterValue(
3626 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003627 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003628}
3629
3630void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3631 LocationSummary* locations =
3632 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3633 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3634}
3635
3636void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3637 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003638}
3639
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003640void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003641 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003642 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003643 locations->SetInAt(0, Location::RequiresRegister());
3644 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003645}
3646
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003647void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3648 LocationSummary* locations = not_->GetLocations();
3649 Location out = locations->Out();
3650 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003651 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003652 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003653 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003654 break;
3655
3656 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003657 __ mvn(out.AsRegisterPairLow<Register>(),
3658 ShifterOperand(in.AsRegisterPairLow<Register>()));
3659 __ mvn(out.AsRegisterPairHigh<Register>(),
3660 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003661 break;
3662
3663 default:
3664 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3665 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003666}
3667
David Brazdil66d126e2015-04-03 16:02:44 +01003668void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3669 LocationSummary* locations =
3670 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3671 locations->SetInAt(0, Location::RequiresRegister());
3672 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3673}
3674
3675void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003676 LocationSummary* locations = bool_not->GetLocations();
3677 Location out = locations->Out();
3678 Location in = locations->InAt(0);
3679 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3680}
3681
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003682void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003683 LocationSummary* locations =
3684 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003685 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003686 case Primitive::kPrimBoolean:
3687 case Primitive::kPrimByte:
3688 case Primitive::kPrimShort:
3689 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003690 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00003691 case Primitive::kPrimLong: {
3692 locations->SetInAt(0, Location::RequiresRegister());
3693 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003694 // Output overlaps because it is written before doing the low comparison.
3695 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003696 break;
3697 }
3698 case Primitive::kPrimFloat:
3699 case Primitive::kPrimDouble: {
3700 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003701 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00003702 locations->SetOut(Location::RequiresRegister());
3703 break;
3704 }
3705 default:
3706 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3707 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003708}
3709
3710void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003711 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003712 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003713 Location left = locations->InAt(0);
3714 Location right = locations->InAt(1);
3715
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003716 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003717 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00003718 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00003719 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003720 case Primitive::kPrimBoolean:
3721 case Primitive::kPrimByte:
3722 case Primitive::kPrimShort:
3723 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003724 case Primitive::kPrimInt: {
3725 __ LoadImmediate(out, 0);
3726 __ cmp(left.AsRegister<Register>(),
3727 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
3728 less_cond = LT;
3729 break;
3730 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003731 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003732 __ cmp(left.AsRegisterPairHigh<Register>(),
3733 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003734 __ b(&less, LT);
3735 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003736 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003737 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003738 __ cmp(left.AsRegisterPairLow<Register>(),
3739 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003740 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00003741 break;
3742 }
3743 case Primitive::kPrimFloat:
3744 case Primitive::kPrimDouble: {
3745 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003746 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00003747 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003748 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003749 break;
3750 }
3751 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003752 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00003753 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003754 }
Aart Bika19616e2016-02-01 18:57:58 -08003755
Calin Juravleddb7df22014-11-25 20:56:51 +00003756 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00003757 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00003758
3759 __ Bind(&greater);
3760 __ LoadImmediate(out, 1);
3761 __ b(&done);
3762
3763 __ Bind(&less);
3764 __ LoadImmediate(out, -1);
3765
3766 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003767}
3768
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003769void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003770 LocationSummary* locations =
3771 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003772 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003773 locations->SetInAt(i, Location::Any());
3774 }
3775 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003776}
3777
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003778void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003779 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003780}
3781
Roland Levillainc9285912015-12-18 10:38:42 +00003782void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3783 // TODO (ported from quick): revisit ARM barrier kinds.
3784 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00003785 switch (kind) {
3786 case MemBarrierKind::kAnyStore:
3787 case MemBarrierKind::kLoadAny:
3788 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003789 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003790 break;
3791 }
3792 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003793 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003794 break;
3795 }
3796 default:
3797 LOG(FATAL) << "Unexpected memory barrier " << kind;
3798 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003799 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003800}
3801
3802void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3803 uint32_t offset,
3804 Register out_lo,
3805 Register out_hi) {
3806 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00003807 // Ensure `out_lo` is different from `addr`, so that loading
3808 // `offset` into `out_lo` does not clutter `addr`.
3809 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00003810 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003811 __ add(IP, addr, ShifterOperand(out_lo));
3812 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003813 }
3814 __ ldrexd(out_lo, out_hi, addr);
3815}
3816
3817void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3818 uint32_t offset,
3819 Register value_lo,
3820 Register value_hi,
3821 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003822 Register temp2,
3823 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003824 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003825 if (offset != 0) {
3826 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003827 __ add(IP, addr, ShifterOperand(temp1));
3828 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003829 }
3830 __ Bind(&fail);
3831 // We need a load followed by store. (The address used in a STREX instruction must
3832 // be the same as the address in the most recently executed LDREX instruction.)
3833 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003834 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003835 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003836 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003837}
3838
3839void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3840 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3841
Nicolas Geoffray39468442014-09-02 15:17:15 +01003842 LocationSummary* locations =
3843 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003844 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003845
Calin Juravle52c48962014-12-16 17:02:57 +00003846 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003847 if (Primitive::IsFloatingPointType(field_type)) {
3848 locations->SetInAt(1, Location::RequiresFpuRegister());
3849 } else {
3850 locations->SetInAt(1, Location::RequiresRegister());
3851 }
3852
Calin Juravle52c48962014-12-16 17:02:57 +00003853 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003854 bool generate_volatile = field_info.IsVolatile()
3855 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003856 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003857 bool needs_write_barrier =
3858 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003859 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003860 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003861 if (needs_write_barrier) {
3862 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003863 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003864 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003865 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003866 // - registers need to be consecutive
3867 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003868 // We don't test for ARM yet, and the assertion makes sure that we
3869 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003870 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3871
3872 locations->AddTemp(Location::RequiresRegister());
3873 locations->AddTemp(Location::RequiresRegister());
3874 if (field_type == Primitive::kPrimDouble) {
3875 // For doubles we need two more registers to copy the value.
3876 locations->AddTemp(Location::RegisterLocation(R2));
3877 locations->AddTemp(Location::RegisterLocation(R3));
3878 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003879 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003880}
3881
Calin Juravle52c48962014-12-16 17:02:57 +00003882void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003883 const FieldInfo& field_info,
3884 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003885 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3886
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003887 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003888 Register base = locations->InAt(0).AsRegister<Register>();
3889 Location value = locations->InAt(1);
3890
3891 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003892 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003893 Primitive::Type field_type = field_info.GetFieldType();
3894 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003895 bool needs_write_barrier =
3896 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003897
3898 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003899 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00003900 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003901
3902 switch (field_type) {
3903 case Primitive::kPrimBoolean:
3904 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003905 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003906 break;
3907 }
3908
3909 case Primitive::kPrimShort:
3910 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003911 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003912 break;
3913 }
3914
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003915 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003916 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003917 if (kPoisonHeapReferences && needs_write_barrier) {
3918 // Note that in the case where `value` is a null reference,
3919 // we do not enter this block, as a null reference does not
3920 // need poisoning.
3921 DCHECK_EQ(field_type, Primitive::kPrimNot);
3922 Register temp = locations->GetTemp(0).AsRegister<Register>();
3923 __ Mov(temp, value.AsRegister<Register>());
3924 __ PoisonHeapReference(temp);
3925 __ StoreToOffset(kStoreWord, temp, base, offset);
3926 } else {
3927 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3928 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003929 break;
3930 }
3931
3932 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003933 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003934 GenerateWideAtomicStore(base, offset,
3935 value.AsRegisterPairLow<Register>(),
3936 value.AsRegisterPairHigh<Register>(),
3937 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003938 locations->GetTemp(1).AsRegister<Register>(),
3939 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003940 } else {
3941 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003942 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003943 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003944 break;
3945 }
3946
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003947 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003948 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003949 break;
3950 }
3951
3952 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003953 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003954 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003955 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3956 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3957
3958 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3959
3960 GenerateWideAtomicStore(base, offset,
3961 value_reg_lo,
3962 value_reg_hi,
3963 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003964 locations->GetTemp(3).AsRegister<Register>(),
3965 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003966 } else {
3967 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003968 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003969 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003970 break;
3971 }
3972
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003973 case Primitive::kPrimVoid:
3974 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003975 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003976 }
Calin Juravle52c48962014-12-16 17:02:57 +00003977
Calin Juravle77520bc2015-01-12 18:45:46 +00003978 // Longs and doubles are handled in the switch.
3979 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3980 codegen_->MaybeRecordImplicitNullCheck(instruction);
3981 }
3982
3983 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3984 Register temp = locations->GetTemp(0).AsRegister<Register>();
3985 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003986 codegen_->MarkGCCard(
3987 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003988 }
3989
Calin Juravle52c48962014-12-16 17:02:57 +00003990 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003991 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00003992 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003993}
3994
Calin Juravle52c48962014-12-16 17:02:57 +00003995void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3996 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00003997
3998 bool object_field_get_with_read_barrier =
3999 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004000 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004001 new (GetGraph()->GetArena()) LocationSummary(instruction,
4002 object_field_get_with_read_barrier ?
4003 LocationSummary::kCallOnSlowPath :
4004 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004005 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004006
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004007 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00004008 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004009 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00004010 // The output overlaps in case of volatile long: we don't want the
4011 // code generated by GenerateWideAtomicLoad to overwrite the
4012 // object's location. Likewise, in the case of an object field get
4013 // with read barriers enabled, we do not want the load to overwrite
4014 // the object's location, as we need it to emit the read barrier.
4015 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
4016 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01004017
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004018 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4019 locations->SetOut(Location::RequiresFpuRegister());
4020 } else {
4021 locations->SetOut(Location::RequiresRegister(),
4022 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
4023 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004024 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00004025 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00004026 // - registers need to be consecutive
4027 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00004028 // We don't test for ARM yet, and the assertion makes sure that we
4029 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00004030 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
4031 locations->AddTemp(Location::RequiresRegister());
4032 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00004033 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4034 // We need a temporary register for the read barrier marking slow
4035 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4036 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004037 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004038}
4039
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004040Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
4041 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
4042 << input->GetType();
4043 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
4044 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4045 return Location::ConstantLocation(input->AsConstant());
4046 } else {
4047 return Location::RequiresFpuRegister();
4048 }
4049}
4050
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004051Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4052 Opcode opcode) {
4053 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4054 if (constant->IsConstant() &&
4055 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4056 return Location::ConstantLocation(constant->AsConstant());
4057 }
4058 return Location::RequiresRegister();
4059}
4060
4061bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4062 Opcode opcode) {
4063 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4064 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004065 Opcode high_opcode = opcode;
4066 SetCc low_set_cc = kCcDontCare;
4067 switch (opcode) {
4068 case SUB:
4069 // Flip the operation to an ADD.
4070 value = -value;
4071 opcode = ADD;
4072 FALLTHROUGH_INTENDED;
4073 case ADD:
4074 if (Low32Bits(value) == 0u) {
4075 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4076 }
4077 high_opcode = ADC;
4078 low_set_cc = kCcSet;
4079 break;
4080 default:
4081 break;
4082 }
4083 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4084 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004085 } else {
4086 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4087 }
4088}
4089
Vladimir Marko59751a72016-08-05 14:37:27 +01004090bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4091 Opcode opcode,
4092 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004093 ShifterOperand so;
4094 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004095 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004096 return true;
4097 }
4098 Opcode neg_opcode = kNoOperand;
4099 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004100 case AND: neg_opcode = BIC; value = ~value; break;
4101 case ORR: neg_opcode = ORN; value = ~value; break;
4102 case ADD: neg_opcode = SUB; value = -value; break;
4103 case ADC: neg_opcode = SBC; value = ~value; break;
4104 case SUB: neg_opcode = ADD; value = -value; break;
4105 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004106 default:
4107 return false;
4108 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004109 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004110}
4111
Calin Juravle52c48962014-12-16 17:02:57 +00004112void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4113 const FieldInfo& field_info) {
4114 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004115
Calin Juravle52c48962014-12-16 17:02:57 +00004116 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004117 Location base_loc = locations->InAt(0);
4118 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004119 Location out = locations->Out();
4120 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004121 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004122 Primitive::Type field_type = field_info.GetFieldType();
4123 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4124
4125 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004126 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004127 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004128 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004129
Roland Levillainc9285912015-12-18 10:38:42 +00004130 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004131 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004132 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004133
Roland Levillainc9285912015-12-18 10:38:42 +00004134 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004135 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004136 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004137
Roland Levillainc9285912015-12-18 10:38:42 +00004138 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004139 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004140 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004141
4142 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004143 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004144 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004145
4146 case Primitive::kPrimNot: {
4147 // /* HeapReference<Object> */ out = *(base + offset)
4148 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4149 Location temp_loc = locations->GetTemp(0);
4150 // Note that a potential implicit null check is handled in this
4151 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4152 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4153 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4154 if (is_volatile) {
4155 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4156 }
4157 } else {
4158 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4159 codegen_->MaybeRecordImplicitNullCheck(instruction);
4160 if (is_volatile) {
4161 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4162 }
4163 // If read barriers are enabled, emit read barriers other than
4164 // Baker's using a slow path (and also unpoison the loaded
4165 // reference, if heap poisoning is enabled).
4166 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4167 }
4168 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004169 }
4170
Roland Levillainc9285912015-12-18 10:38:42 +00004171 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004172 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004173 GenerateWideAtomicLoad(base, offset,
4174 out.AsRegisterPairLow<Register>(),
4175 out.AsRegisterPairHigh<Register>());
4176 } else {
4177 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4178 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004179 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004180
Roland Levillainc9285912015-12-18 10:38:42 +00004181 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004182 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004183 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004184
4185 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004186 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004187 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004188 Register lo = locations->GetTemp(0).AsRegister<Register>();
4189 Register hi = locations->GetTemp(1).AsRegister<Register>();
4190 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004191 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004192 __ vmovdrr(out_reg, lo, hi);
4193 } else {
4194 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004195 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004196 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004197 break;
4198 }
4199
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004200 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004201 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004202 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004203 }
Calin Juravle52c48962014-12-16 17:02:57 +00004204
Roland Levillainc9285912015-12-18 10:38:42 +00004205 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4206 // Potential implicit null checks, in the case of reference or
4207 // double fields, are handled in the previous switch statement.
4208 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004209 codegen_->MaybeRecordImplicitNullCheck(instruction);
4210 }
4211
Calin Juravle52c48962014-12-16 17:02:57 +00004212 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004213 if (field_type == Primitive::kPrimNot) {
4214 // Memory barriers, in the case of references, are also handled
4215 // in the previous switch statement.
4216 } else {
4217 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4218 }
Roland Levillain4d027112015-07-01 15:41:14 +01004219 }
Calin Juravle52c48962014-12-16 17:02:57 +00004220}
4221
4222void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4223 HandleFieldSet(instruction, instruction->GetFieldInfo());
4224}
4225
4226void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004227 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004228}
4229
4230void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4231 HandleFieldGet(instruction, instruction->GetFieldInfo());
4232}
4233
4234void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4235 HandleFieldGet(instruction, instruction->GetFieldInfo());
4236}
4237
4238void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4239 HandleFieldGet(instruction, instruction->GetFieldInfo());
4240}
4241
4242void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4243 HandleFieldGet(instruction, instruction->GetFieldInfo());
4244}
4245
4246void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4247 HandleFieldSet(instruction, instruction->GetFieldInfo());
4248}
4249
4250void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004251 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004252}
4253
Calin Juravlee460d1d2015-09-29 04:52:17 +01004254void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4255 HUnresolvedInstanceFieldGet* instruction) {
4256 FieldAccessCallingConventionARM calling_convention;
4257 codegen_->CreateUnresolvedFieldLocationSummary(
4258 instruction, instruction->GetFieldType(), calling_convention);
4259}
4260
4261void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4262 HUnresolvedInstanceFieldGet* instruction) {
4263 FieldAccessCallingConventionARM calling_convention;
4264 codegen_->GenerateUnresolvedFieldAccess(instruction,
4265 instruction->GetFieldType(),
4266 instruction->GetFieldIndex(),
4267 instruction->GetDexPc(),
4268 calling_convention);
4269}
4270
4271void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4272 HUnresolvedInstanceFieldSet* instruction) {
4273 FieldAccessCallingConventionARM calling_convention;
4274 codegen_->CreateUnresolvedFieldLocationSummary(
4275 instruction, instruction->GetFieldType(), calling_convention);
4276}
4277
4278void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4279 HUnresolvedInstanceFieldSet* instruction) {
4280 FieldAccessCallingConventionARM calling_convention;
4281 codegen_->GenerateUnresolvedFieldAccess(instruction,
4282 instruction->GetFieldType(),
4283 instruction->GetFieldIndex(),
4284 instruction->GetDexPc(),
4285 calling_convention);
4286}
4287
4288void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4289 HUnresolvedStaticFieldGet* instruction) {
4290 FieldAccessCallingConventionARM calling_convention;
4291 codegen_->CreateUnresolvedFieldLocationSummary(
4292 instruction, instruction->GetFieldType(), calling_convention);
4293}
4294
4295void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4296 HUnresolvedStaticFieldGet* instruction) {
4297 FieldAccessCallingConventionARM calling_convention;
4298 codegen_->GenerateUnresolvedFieldAccess(instruction,
4299 instruction->GetFieldType(),
4300 instruction->GetFieldIndex(),
4301 instruction->GetDexPc(),
4302 calling_convention);
4303}
4304
4305void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4306 HUnresolvedStaticFieldSet* instruction) {
4307 FieldAccessCallingConventionARM calling_convention;
4308 codegen_->CreateUnresolvedFieldLocationSummary(
4309 instruction, instruction->GetFieldType(), calling_convention);
4310}
4311
4312void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4313 HUnresolvedStaticFieldSet* instruction) {
4314 FieldAccessCallingConventionARM calling_convention;
4315 codegen_->GenerateUnresolvedFieldAccess(instruction,
4316 instruction->GetFieldType(),
4317 instruction->GetFieldIndex(),
4318 instruction->GetDexPc(),
4319 calling_convention);
4320}
4321
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004322void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004323 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4324 ? LocationSummary::kCallOnSlowPath
4325 : LocationSummary::kNoCall;
4326 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00004327 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004328 if (instruction->HasUses()) {
4329 locations->SetOut(Location::SameAsFirstInput());
4330 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004331}
4332
Calin Juravle2ae48182016-03-16 14:05:09 +00004333void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4334 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004335 return;
4336 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004337 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004338
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004339 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004340 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004341}
4342
Calin Juravle2ae48182016-03-16 14:05:09 +00004343void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004344 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004345 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004346
4347 LocationSummary* locations = instruction->GetLocations();
4348 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004349
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004350 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004351}
4352
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004353void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004354 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004355}
4356
Artem Serov6c916792016-07-11 14:02:34 +01004357static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4358 switch (type) {
4359 case Primitive::kPrimNot:
4360 return kLoadWord;
4361 case Primitive::kPrimBoolean:
4362 return kLoadUnsignedByte;
4363 case Primitive::kPrimByte:
4364 return kLoadSignedByte;
4365 case Primitive::kPrimChar:
4366 return kLoadUnsignedHalfword;
4367 case Primitive::kPrimShort:
4368 return kLoadSignedHalfword;
4369 case Primitive::kPrimInt:
4370 return kLoadWord;
4371 case Primitive::kPrimLong:
4372 return kLoadWordPair;
4373 case Primitive::kPrimFloat:
4374 return kLoadSWord;
4375 case Primitive::kPrimDouble:
4376 return kLoadDWord;
4377 default:
4378 LOG(FATAL) << "Unreachable type " << type;
4379 UNREACHABLE();
4380 }
4381}
4382
4383static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4384 switch (type) {
4385 case Primitive::kPrimNot:
4386 return kStoreWord;
4387 case Primitive::kPrimBoolean:
4388 case Primitive::kPrimByte:
4389 return kStoreByte;
4390 case Primitive::kPrimChar:
4391 case Primitive::kPrimShort:
4392 return kStoreHalfword;
4393 case Primitive::kPrimInt:
4394 return kStoreWord;
4395 case Primitive::kPrimLong:
4396 return kStoreWordPair;
4397 case Primitive::kPrimFloat:
4398 return kStoreSWord;
4399 case Primitive::kPrimDouble:
4400 return kStoreDWord;
4401 default:
4402 LOG(FATAL) << "Unreachable type " << type;
4403 UNREACHABLE();
4404 }
4405}
4406
4407void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4408 Location out_loc,
4409 Register base,
4410 Register reg_offset,
4411 Condition cond) {
4412 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4413 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4414
4415 switch (type) {
4416 case Primitive::kPrimByte:
4417 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4418 break;
4419 case Primitive::kPrimBoolean:
4420 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4421 break;
4422 case Primitive::kPrimShort:
4423 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4424 break;
4425 case Primitive::kPrimChar:
4426 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4427 break;
4428 case Primitive::kPrimNot:
4429 case Primitive::kPrimInt:
4430 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4431 break;
4432 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4433 case Primitive::kPrimLong:
4434 case Primitive::kPrimFloat:
4435 case Primitive::kPrimDouble:
4436 default:
4437 LOG(FATAL) << "Unreachable type " << type;
4438 UNREACHABLE();
4439 }
4440}
4441
4442void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4443 Location loc,
4444 Register base,
4445 Register reg_offset,
4446 Condition cond) {
4447 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4448 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4449
4450 switch (type) {
4451 case Primitive::kPrimByte:
4452 case Primitive::kPrimBoolean:
4453 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4454 break;
4455 case Primitive::kPrimShort:
4456 case Primitive::kPrimChar:
4457 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4458 break;
4459 case Primitive::kPrimNot:
4460 case Primitive::kPrimInt:
4461 __ str(loc.AsRegister<Register>(), mem_address, cond);
4462 break;
4463 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4464 case Primitive::kPrimLong:
4465 case Primitive::kPrimFloat:
4466 case Primitive::kPrimDouble:
4467 default:
4468 LOG(FATAL) << "Unreachable type " << type;
4469 UNREACHABLE();
4470 }
4471}
4472
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004473void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004474 bool object_array_get_with_read_barrier =
4475 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004476 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004477 new (GetGraph()->GetArena()) LocationSummary(instruction,
4478 object_array_get_with_read_barrier ?
4479 LocationSummary::kCallOnSlowPath :
4480 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004481 locations->SetInAt(0, Location::RequiresRegister());
4482 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004483 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4484 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4485 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004486 // The output overlaps in the case of an object array get with
4487 // read barriers enabled: we do not want the move to overwrite the
4488 // array's location, as we need it to emit the read barrier.
4489 locations->SetOut(
4490 Location::RequiresRegister(),
4491 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004492 }
Roland Levillainc9285912015-12-18 10:38:42 +00004493 // We need a temporary register for the read barrier marking slow
4494 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
4495 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4496 locations->AddTemp(Location::RequiresRegister());
4497 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004498}
4499
4500void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4501 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004502 Location obj_loc = locations->InAt(0);
4503 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004504 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004505 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004506 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004507 Primitive::Type type = instruction->GetType();
Artem Serov328429f2016-07-06 16:23:04 +01004508 HInstruction* array_instr = instruction->GetArray();
4509 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Artem Serov6c916792016-07-11 14:02:34 +01004510
Roland Levillain4d027112015-07-01 15:41:14 +01004511 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004512 case Primitive::kPrimBoolean:
4513 case Primitive::kPrimByte:
4514 case Primitive::kPrimShort:
4515 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004516 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004517 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004518 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4519 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
4520
4521 LoadOperandType load_type = GetLoadOperandType(type);
4522 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004523 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004524 Register temp = IP;
4525
4526 if (has_intermediate_address) {
4527 // We do not need to compute the intermediate address from the array: the
4528 // input instruction has done it already. See the comment in
4529 // `TryExtractArrayAccessAddress()`.
4530 if (kIsDebugBuild) {
4531 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4532 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4533 }
4534 temp = obj;
4535 } else {
4536 __ add(temp, obj, ShifterOperand(data_offset));
4537 }
4538 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004539 }
4540 break;
4541 }
4542
Roland Levillainc9285912015-12-18 10:38:42 +00004543 case Primitive::kPrimNot: {
Roland Levillain12ecf082016-08-08 10:18:37 +01004544 // The read barrier instrumentation of object ArrayGet
4545 // instructions does not support the HIntermediateAddress
4546 // instruction.
4547 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
4548
Roland Levillainc9285912015-12-18 10:38:42 +00004549 static_assert(
4550 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4551 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004552 // /* HeapReference<Object> */ out =
4553 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4554 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4555 Location temp = locations->GetTemp(0);
4556 // Note that a potential implicit null check is handled in this
4557 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4558 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4559 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4560 } else {
4561 Register out = out_loc.AsRegister<Register>();
4562 if (index.IsConstant()) {
4563 size_t offset =
4564 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4565 __ LoadFromOffset(kLoadWord, out, obj, offset);
4566 codegen_->MaybeRecordImplicitNullCheck(instruction);
4567 // If read barriers are enabled, emit read barriers other than
4568 // Baker's using a slow path (and also unpoison the loaded
4569 // reference, if heap poisoning is enabled).
4570 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4571 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004572 Register temp = IP;
4573
4574 if (has_intermediate_address) {
4575 // We do not need to compute the intermediate address from the array: the
4576 // input instruction has done it already. See the comment in
4577 // `TryExtractArrayAccessAddress()`.
4578 if (kIsDebugBuild) {
4579 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4580 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4581 }
4582 temp = obj;
4583 } else {
4584 __ add(temp, obj, ShifterOperand(data_offset));
4585 }
4586 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004587
Roland Levillainc9285912015-12-18 10:38:42 +00004588 codegen_->MaybeRecordImplicitNullCheck(instruction);
4589 // If read barriers are enabled, emit read barriers other than
4590 // Baker's using a slow path (and also unpoison the loaded
4591 // reference, if heap poisoning is enabled).
4592 codegen_->MaybeGenerateReadBarrierSlow(
4593 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4594 }
4595 }
4596 break;
4597 }
4598
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004599 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004600 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004601 size_t offset =
4602 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004603 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004604 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004605 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004606 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004607 }
4608 break;
4609 }
4610
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004611 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004612 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004613 if (index.IsConstant()) {
4614 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004615 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004616 } else {
4617 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004618 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004619 }
4620 break;
4621 }
4622
4623 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004624 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004625 if (index.IsConstant()) {
4626 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004627 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004628 } else {
4629 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004630 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004631 }
4632 break;
4633 }
4634
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004635 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01004636 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004637 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004638 }
Roland Levillain4d027112015-07-01 15:41:14 +01004639
4640 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00004641 // Potential implicit null checks, in the case of reference
4642 // arrays, are handled in the previous switch statement.
4643 } else {
4644 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01004645 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004646}
4647
4648void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004649 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004650
4651 bool needs_write_barrier =
4652 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00004653 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
4654 bool object_array_set_with_read_barrier =
4655 kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004656
Nicolas Geoffray39468442014-09-02 15:17:15 +01004657 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004658 instruction,
Roland Levillain3b359c72015-11-17 19:35:12 +00004659 (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ?
4660 LocationSummary::kCallOnSlowPath :
4661 LocationSummary::kNoCall);
4662
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004663 locations->SetInAt(0, Location::RequiresRegister());
4664 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
4665 if (Primitive::IsFloatingPointType(value_type)) {
4666 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004667 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004668 locations->SetInAt(2, Location::RequiresRegister());
4669 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004670 if (needs_write_barrier) {
4671 // Temporary registers for the write barrier.
4672 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00004673 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004674 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004675}
4676
4677void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4678 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004679 Location array_loc = locations->InAt(0);
4680 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004681 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004682 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00004683 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004684 bool needs_write_barrier =
4685 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01004686 uint32_t data_offset =
4687 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
4688 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01004689 HInstruction* array_instr = instruction->GetArray();
4690 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004691
4692 switch (value_type) {
4693 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01004694 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004695 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01004696 case Primitive::kPrimChar:
4697 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004698 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004699 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4700 uint32_t full_offset =
4701 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
4702 StoreOperandType store_type = GetStoreOperandType(value_type);
4703 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004704 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004705 Register temp = IP;
4706
4707 if (has_intermediate_address) {
4708 // We do not need to compute the intermediate address from the array: the
4709 // input instruction has done it already. See the comment in
4710 // `TryExtractArrayAccessAddress()`.
4711 if (kIsDebugBuild) {
4712 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4713 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
4714 }
4715 temp = array;
4716 } else {
4717 __ add(temp, array, ShifterOperand(data_offset));
4718 }
Artem Serov6c916792016-07-11 14:02:34 +01004719 codegen_->StoreToShiftedRegOffset(value_type,
4720 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01004721 temp,
Artem Serov6c916792016-07-11 14:02:34 +01004722 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004723 }
4724 break;
4725 }
4726
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004727 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00004728 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01004729 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
4730 // See the comment in instruction_simplifier_shared.cc.
4731 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004732
4733 if (instruction->InputAt(2)->IsNullConstant()) {
4734 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004735 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004736 size_t offset =
4737 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01004738 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004739 } else {
4740 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004741 __ add(IP, array, ShifterOperand(data_offset));
4742 codegen_->StoreToShiftedRegOffset(value_type,
4743 value_loc,
4744 IP,
4745 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004746 }
Roland Levillain1407ee72016-01-08 15:56:19 +00004747 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00004748 DCHECK(!needs_write_barrier);
4749 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004750 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004751 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004752
4753 DCHECK(needs_write_barrier);
4754 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
4755 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
4756 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4757 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4758 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4759 Label done;
4760 SlowPathCode* slow_path = nullptr;
4761
Roland Levillain3b359c72015-11-17 19:35:12 +00004762 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004763 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4764 codegen_->AddSlowPath(slow_path);
4765 if (instruction->GetValueCanBeNull()) {
4766 Label non_zero;
4767 __ CompareAndBranchIfNonZero(value, &non_zero);
4768 if (index.IsConstant()) {
4769 size_t offset =
4770 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4771 __ StoreToOffset(kStoreWord, value, array, offset);
4772 } else {
4773 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004774 __ add(IP, array, ShifterOperand(data_offset));
4775 codegen_->StoreToShiftedRegOffset(value_type,
4776 value_loc,
4777 IP,
4778 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004779 }
4780 codegen_->MaybeRecordImplicitNullCheck(instruction);
4781 __ b(&done);
4782 __ Bind(&non_zero);
4783 }
4784
Roland Levillain3b359c72015-11-17 19:35:12 +00004785 if (kEmitCompilerReadBarrier) {
4786 // When read barriers are enabled, the type checking
4787 // instrumentation requires two read barriers:
4788 //
4789 // __ Mov(temp2, temp1);
4790 // // /* HeapReference<Class> */ temp1 = temp1->component_type_
4791 // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
Roland Levillainc9285912015-12-18 10:38:42 +00004792 // codegen_->GenerateReadBarrierSlow(
Roland Levillain3b359c72015-11-17 19:35:12 +00004793 // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset);
4794 //
4795 // // /* HeapReference<Class> */ temp2 = value->klass_
4796 // __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
Roland Levillainc9285912015-12-18 10:38:42 +00004797 // codegen_->GenerateReadBarrierSlow(
Roland Levillain3b359c72015-11-17 19:35:12 +00004798 // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc);
4799 //
4800 // __ cmp(temp1, ShifterOperand(temp2));
4801 //
4802 // However, the second read barrier may trash `temp`, as it
4803 // is a temporary register, and as such would not be saved
4804 // along with live registers before calling the runtime (nor
4805 // restored afterwards). So in this case, we bail out and
4806 // delegate the work to the array set slow path.
4807 //
4808 // TODO: Extend the register allocator to support a new
4809 // "(locally) live temp" location so as to avoid always
4810 // going into the slow path when read barriers are enabled.
4811 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004812 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004813 // /* HeapReference<Class> */ temp1 = array->klass_
4814 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4815 codegen_->MaybeRecordImplicitNullCheck(instruction);
4816 __ MaybeUnpoisonHeapReference(temp1);
4817
4818 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4819 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4820 // /* HeapReference<Class> */ temp2 = value->klass_
4821 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4822 // If heap poisoning is enabled, no need to unpoison `temp1`
4823 // nor `temp2`, as we are comparing two poisoned references.
4824 __ cmp(temp1, ShifterOperand(temp2));
4825
4826 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4827 Label do_put;
4828 __ b(&do_put, EQ);
4829 // If heap poisoning is enabled, the `temp1` reference has
4830 // not been unpoisoned yet; unpoison it now.
4831 __ MaybeUnpoisonHeapReference(temp1);
4832
4833 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4834 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4835 // If heap poisoning is enabled, no need to unpoison
4836 // `temp1`, as we are comparing against null below.
4837 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4838 __ Bind(&do_put);
4839 } else {
4840 __ b(slow_path->GetEntryLabel(), NE);
4841 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004842 }
4843 }
4844
Artem Serov6c916792016-07-11 14:02:34 +01004845 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004846 if (kPoisonHeapReferences) {
4847 // Note that in the case where `value` is a null reference,
4848 // we do not enter this block, as a null reference does not
4849 // need poisoning.
4850 DCHECK_EQ(value_type, Primitive::kPrimNot);
4851 __ Mov(temp1, value);
4852 __ PoisonHeapReference(temp1);
4853 source = temp1;
4854 }
4855
4856 if (index.IsConstant()) {
4857 size_t offset =
4858 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4859 __ StoreToOffset(kStoreWord, source, array, offset);
4860 } else {
4861 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004862
4863 __ add(IP, array, ShifterOperand(data_offset));
4864 codegen_->StoreToShiftedRegOffset(value_type,
4865 Location::RegisterLocation(source),
4866 IP,
4867 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004868 }
4869
Roland Levillain3b359c72015-11-17 19:35:12 +00004870 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004871 codegen_->MaybeRecordImplicitNullCheck(instruction);
4872 }
4873
4874 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4875
4876 if (done.IsLinked()) {
4877 __ Bind(&done);
4878 }
4879
4880 if (slow_path != nullptr) {
4881 __ Bind(slow_path->GetExitLabel());
4882 }
4883
4884 break;
4885 }
4886
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004887 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004888 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004889 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004890 size_t offset =
4891 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004892 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004893 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004894 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004895 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004896 }
4897 break;
4898 }
4899
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004900 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004901 Location value = locations->InAt(2);
4902 DCHECK(value.IsFpuRegister());
4903 if (index.IsConstant()) {
4904 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004905 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004906 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004907 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004908 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4909 }
4910 break;
4911 }
4912
4913 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004914 Location value = locations->InAt(2);
4915 DCHECK(value.IsFpuRegisterPair());
4916 if (index.IsConstant()) {
4917 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004918 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004919 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004920 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004921 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4922 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004923
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004924 break;
4925 }
4926
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004927 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004928 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004929 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004930 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004931
Roland Levillain80e67092016-01-08 16:04:55 +00004932 // Objects are handled in the switch.
4933 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004934 codegen_->MaybeRecordImplicitNullCheck(instruction);
4935 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004936}
4937
4938void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004939 LocationSummary* locations =
4940 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004941 locations->SetInAt(0, Location::RequiresRegister());
4942 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004943}
4944
4945void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4946 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01004947 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00004948 Register obj = locations->InAt(0).AsRegister<Register>();
4949 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004950 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004951 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004952}
4953
Artem Serov328429f2016-07-06 16:23:04 +01004954void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Artem Serov328429f2016-07-06 16:23:04 +01004955 LocationSummary* locations =
4956 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4957
4958 locations->SetInAt(0, Location::RequiresRegister());
4959 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
4960 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4961}
4962
4963void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
4964 LocationSummary* locations = instruction->GetLocations();
4965 Location out = locations->Out();
4966 Location first = locations->InAt(0);
4967 Location second = locations->InAt(1);
4968
Artem Serov328429f2016-07-06 16:23:04 +01004969 if (second.IsRegister()) {
4970 __ add(out.AsRegister<Register>(),
4971 first.AsRegister<Register>(),
4972 ShifterOperand(second.AsRegister<Register>()));
4973 } else {
4974 __ AddConstant(out.AsRegister<Register>(),
4975 first.AsRegister<Register>(),
4976 second.GetConstant()->AsIntConstant()->GetValue());
4977 }
4978}
4979
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004980void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004981 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4982 ? LocationSummary::kCallOnSlowPath
4983 : LocationSummary::kNoCall;
4984 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004985 locations->SetInAt(0, Location::RequiresRegister());
4986 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004987 if (instruction->HasUses()) {
4988 locations->SetOut(Location::SameAsFirstInput());
4989 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004990}
4991
4992void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
4993 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07004994 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004995 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004996 codegen_->AddSlowPath(slow_path);
4997
Roland Levillain271ab9c2014-11-27 15:23:57 +00004998 Register index = locations->InAt(0).AsRegister<Register>();
4999 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005000
5001 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01005002 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005003}
5004
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005005void CodeGeneratorARM::MarkGCCard(Register temp,
5006 Register card,
5007 Register object,
5008 Register value,
5009 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005010 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005011 if (can_be_null) {
5012 __ CompareAndBranchIfZero(value, &is_null);
5013 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005014 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005015 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5016 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005017 if (can_be_null) {
5018 __ Bind(&is_null);
5019 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005020}
5021
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005022void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005023 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005024}
5025
5026void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005027 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5028}
5029
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005030void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
5031 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5032}
5033
5034void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005035 HBasicBlock* block = instruction->GetBlock();
5036 if (block->GetLoopInformation() != nullptr) {
5037 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5038 // The back edge will generate the suspend check.
5039 return;
5040 }
5041 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5042 // The goto will generate the suspend check.
5043 return;
5044 }
5045 GenerateSuspendCheck(instruction, nullptr);
5046}
5047
5048void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5049 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005050 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005051 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5052 if (slow_path == nullptr) {
5053 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5054 instruction->SetSlowPath(slow_path);
5055 codegen_->AddSlowPath(slow_path);
5056 if (successor != nullptr) {
5057 DCHECK(successor->IsLoopHeader());
5058 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5059 }
5060 } else {
5061 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5062 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005063
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005064 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005065 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005066 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005067 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005068 __ Bind(slow_path->GetReturnLabel());
5069 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005070 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005071 __ b(slow_path->GetEntryLabel());
5072 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005073}
5074
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005075ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5076 return codegen_->GetAssembler();
5077}
5078
5079void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005080 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005081 Location source = move->GetSource();
5082 Location destination = move->GetDestination();
5083
5084 if (source.IsRegister()) {
5085 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005086 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005087 } else if (destination.IsFpuRegister()) {
5088 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005089 } else {
5090 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005091 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005092 SP, destination.GetStackIndex());
5093 }
5094 } else if (source.IsStackSlot()) {
5095 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005096 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005097 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005098 } else if (destination.IsFpuRegister()) {
5099 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005100 } else {
5101 DCHECK(destination.IsStackSlot());
5102 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5103 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5104 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005105 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005106 if (destination.IsRegister()) {
5107 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5108 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005109 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005110 } else {
5111 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005112 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5113 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005114 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005115 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005116 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5117 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005118 } else if (destination.IsRegisterPair()) {
5119 DCHECK(ExpectedPairLayout(destination));
5120 __ LoadFromOffset(
5121 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5122 } else {
5123 DCHECK(destination.IsFpuRegisterPair()) << destination;
5124 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5125 SP,
5126 source.GetStackIndex());
5127 }
5128 } else if (source.IsRegisterPair()) {
5129 if (destination.IsRegisterPair()) {
5130 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5131 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005132 } else if (destination.IsFpuRegisterPair()) {
5133 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5134 source.AsRegisterPairLow<Register>(),
5135 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005136 } else {
5137 DCHECK(destination.IsDoubleStackSlot()) << destination;
5138 DCHECK(ExpectedPairLayout(source));
5139 __ StoreToOffset(
5140 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5141 }
5142 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005143 if (destination.IsRegisterPair()) {
5144 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5145 destination.AsRegisterPairHigh<Register>(),
5146 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5147 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005148 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5149 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5150 } else {
5151 DCHECK(destination.IsDoubleStackSlot()) << destination;
5152 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5153 SP,
5154 destination.GetStackIndex());
5155 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005156 } else {
5157 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005158 HConstant* constant = source.GetConstant();
5159 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5160 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005161 if (destination.IsRegister()) {
5162 __ LoadImmediate(destination.AsRegister<Register>(), value);
5163 } else {
5164 DCHECK(destination.IsStackSlot());
5165 __ LoadImmediate(IP, value);
5166 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5167 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005168 } else if (constant->IsLongConstant()) {
5169 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005170 if (destination.IsRegisterPair()) {
5171 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5172 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005173 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005174 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005175 __ LoadImmediate(IP, Low32Bits(value));
5176 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5177 __ LoadImmediate(IP, High32Bits(value));
5178 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5179 }
5180 } else if (constant->IsDoubleConstant()) {
5181 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005182 if (destination.IsFpuRegisterPair()) {
5183 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005184 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005185 DCHECK(destination.IsDoubleStackSlot()) << destination;
5186 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005187 __ LoadImmediate(IP, Low32Bits(int_value));
5188 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5189 __ LoadImmediate(IP, High32Bits(int_value));
5190 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5191 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005192 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005193 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005194 float value = constant->AsFloatConstant()->GetValue();
5195 if (destination.IsFpuRegister()) {
5196 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5197 } else {
5198 DCHECK(destination.IsStackSlot());
5199 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5200 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5201 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005202 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005203 }
5204}
5205
5206void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5207 __ Mov(IP, reg);
5208 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5209 __ StoreToOffset(kStoreWord, IP, SP, mem);
5210}
5211
5212void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5213 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5214 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5215 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5216 SP, mem1 + stack_offset);
5217 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5218 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5219 SP, mem2 + stack_offset);
5220 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5221}
5222
5223void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005224 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005225 Location source = move->GetSource();
5226 Location destination = move->GetDestination();
5227
5228 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005229 DCHECK_NE(source.AsRegister<Register>(), IP);
5230 DCHECK_NE(destination.AsRegister<Register>(), IP);
5231 __ Mov(IP, source.AsRegister<Register>());
5232 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5233 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005234 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005235 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005236 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005237 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005238 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5239 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005240 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005241 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005242 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005243 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005244 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005245 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005246 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005247 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005248 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5249 destination.AsRegisterPairHigh<Register>(),
5250 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005251 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005252 Register low_reg = source.IsRegisterPair()
5253 ? source.AsRegisterPairLow<Register>()
5254 : destination.AsRegisterPairLow<Register>();
5255 int mem = source.IsRegisterPair()
5256 ? destination.GetStackIndex()
5257 : source.GetStackIndex();
5258 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005259 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005260 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005261 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005262 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005263 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5264 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005265 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005266 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005267 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005268 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5269 DRegister reg = source.IsFpuRegisterPair()
5270 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5271 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5272 int mem = source.IsFpuRegisterPair()
5273 ? destination.GetStackIndex()
5274 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005275 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005276 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005277 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005278 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5279 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5280 : destination.AsFpuRegister<SRegister>();
5281 int mem = source.IsFpuRegister()
5282 ? destination.GetStackIndex()
5283 : source.GetStackIndex();
5284
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005285 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005286 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005287 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005288 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005289 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5290 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005291 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005292 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005293 }
5294}
5295
5296void ParallelMoveResolverARM::SpillScratch(int reg) {
5297 __ Push(static_cast<Register>(reg));
5298}
5299
5300void ParallelMoveResolverARM::RestoreScratch(int reg) {
5301 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005302}
5303
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005304HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5305 HLoadClass::LoadKind desired_class_load_kind) {
5306 if (kEmitCompilerReadBarrier) {
5307 switch (desired_class_load_kind) {
5308 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5309 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5310 case HLoadClass::LoadKind::kBootImageAddress:
5311 // TODO: Implement for read barrier.
5312 return HLoadClass::LoadKind::kDexCacheViaMethod;
5313 default:
5314 break;
5315 }
5316 }
5317 switch (desired_class_load_kind) {
5318 case HLoadClass::LoadKind::kReferrersClass:
5319 break;
5320 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5321 DCHECK(!GetCompilerOptions().GetCompilePic());
5322 break;
5323 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5324 DCHECK(GetCompilerOptions().GetCompilePic());
5325 break;
5326 case HLoadClass::LoadKind::kBootImageAddress:
5327 break;
5328 case HLoadClass::LoadKind::kDexCacheAddress:
5329 DCHECK(Runtime::Current()->UseJitCompilation());
5330 break;
5331 case HLoadClass::LoadKind::kDexCachePcRelative:
5332 DCHECK(!Runtime::Current()->UseJitCompilation());
5333 // We disable pc-relative load when there is an irreducible loop, as the optimization
5334 // is incompatible with it.
5335 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5336 // with irreducible loops.
5337 if (GetGraph()->HasIrreducibleLoops()) {
5338 return HLoadClass::LoadKind::kDexCacheViaMethod;
5339 }
5340 break;
5341 case HLoadClass::LoadKind::kDexCacheViaMethod:
5342 break;
5343 }
5344 return desired_class_load_kind;
5345}
5346
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005347void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005348 if (cls->NeedsAccessCheck()) {
5349 InvokeRuntimeCallingConvention calling_convention;
5350 CodeGenerator::CreateLoadClassLocationSummary(
5351 cls,
5352 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5353 Location::RegisterLocation(R0),
5354 /* code_generator_supports_read_barrier */ true);
5355 return;
5356 }
5357
5358 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5359 ? LocationSummary::kCallOnSlowPath
5360 : LocationSummary::kNoCall;
5361 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
5362 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5363 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5364 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5365 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5366 locations->SetInAt(0, Location::RequiresRegister());
5367 }
5368 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005369}
5370
5371void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005372 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005373 if (cls->NeedsAccessCheck()) {
5374 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
5375 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
5376 cls,
5377 cls->GetDexPc(),
5378 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005379 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005380 return;
5381 }
5382
Roland Levillain3b359c72015-11-17 19:35:12 +00005383 Location out_loc = locations->Out();
5384 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005385
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005386 bool generate_null_check = false;
5387 switch (cls->GetLoadKind()) {
5388 case HLoadClass::LoadKind::kReferrersClass: {
5389 DCHECK(!cls->CanCallRuntime());
5390 DCHECK(!cls->MustGenerateClinitCheck());
5391 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5392 Register current_method = locations->InAt(0).AsRegister<Register>();
5393 GenerateGcRootFieldLoad(
5394 cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5395 break;
5396 }
5397 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
5398 DCHECK(!kEmitCompilerReadBarrier);
5399 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5400 cls->GetTypeIndex()));
5401 break;
5402 }
5403 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
5404 DCHECK(!kEmitCompilerReadBarrier);
5405 CodeGeneratorARM::PcRelativePatchInfo* labels =
5406 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5407 __ BindTrackedLabel(&labels->movw_label);
5408 __ movw(out, /* placeholder */ 0u);
5409 __ BindTrackedLabel(&labels->movt_label);
5410 __ movt(out, /* placeholder */ 0u);
5411 __ BindTrackedLabel(&labels->add_pc_label);
5412 __ add(out, out, ShifterOperand(PC));
5413 break;
5414 }
5415 case HLoadClass::LoadKind::kBootImageAddress: {
5416 DCHECK(!kEmitCompilerReadBarrier);
5417 DCHECK_NE(cls->GetAddress(), 0u);
5418 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5419 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5420 break;
5421 }
5422 case HLoadClass::LoadKind::kDexCacheAddress: {
5423 DCHECK_NE(cls->GetAddress(), 0u);
5424 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5425 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5426 // a 128B range. To try and reduce the number of literals if we load multiple types,
5427 // simply split the dex cache address to a 128B aligned base loaded from a literal
5428 // and the remaining offset embedded in the load.
5429 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5430 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5431 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5432 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5433 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5434 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5435 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
5436 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5437 generate_null_check = !cls->IsInDexCache();
5438 break;
5439 }
5440 case HLoadClass::LoadKind::kDexCachePcRelative: {
5441 Register base_reg = locations->InAt(0).AsRegister<Register>();
5442 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5443 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5444 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
5445 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset);
5446 generate_null_check = !cls->IsInDexCache();
5447 break;
5448 }
5449 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5450 // /* GcRoot<mirror::Class>[] */ out =
5451 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5452 Register current_method = locations->InAt(0).AsRegister<Register>();
5453 __ LoadFromOffset(kLoadWord,
5454 out,
5455 current_method,
5456 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5457 // /* GcRoot<mirror::Class> */ out = out[type_index]
5458 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
5459 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5460 generate_null_check = !cls->IsInDexCache();
5461 }
5462 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005463
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005464 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5465 DCHECK(cls->CanCallRuntime());
5466 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
5467 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5468 codegen_->AddSlowPath(slow_path);
5469 if (generate_null_check) {
5470 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5471 }
5472 if (cls->MustGenerateClinitCheck()) {
5473 GenerateClassInitializationCheck(slow_path, out);
5474 } else {
5475 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005476 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005477 }
5478}
5479
5480void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5481 LocationSummary* locations =
5482 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5483 locations->SetInAt(0, Location::RequiresRegister());
5484 if (check->HasUses()) {
5485 locations->SetOut(Location::SameAsFirstInput());
5486 }
5487}
5488
5489void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005490 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07005491 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005492 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005493 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005494 GenerateClassInitializationCheck(slow_path,
5495 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005496}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005497
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005498void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07005499 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005500 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5501 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5502 __ b(slow_path->GetEntryLabel(), LT);
5503 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5504 // properly. Therefore, we do a memory fence.
5505 __ dmb(ISH);
5506 __ Bind(slow_path->GetExitLabel());
5507}
5508
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005509HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5510 HLoadString::LoadKind desired_string_load_kind) {
5511 if (kEmitCompilerReadBarrier) {
5512 switch (desired_string_load_kind) {
5513 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5514 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5515 case HLoadString::LoadKind::kBootImageAddress:
5516 // TODO: Implement for read barrier.
5517 return HLoadString::LoadKind::kDexCacheViaMethod;
5518 default:
5519 break;
5520 }
5521 }
5522 switch (desired_string_load_kind) {
5523 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5524 DCHECK(!GetCompilerOptions().GetCompilePic());
5525 break;
5526 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5527 DCHECK(GetCompilerOptions().GetCompilePic());
5528 break;
5529 case HLoadString::LoadKind::kBootImageAddress:
5530 break;
5531 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005532 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005533 break;
5534 case HLoadString::LoadKind::kDexCachePcRelative:
Calin Juravleffc87072016-04-20 14:22:09 +01005535 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005536 // We disable pc-relative load when there is an irreducible loop, as the optimization
5537 // is incompatible with it.
5538 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5539 // with irreducible loops.
5540 if (GetGraph()->HasIrreducibleLoops()) {
5541 return HLoadString::LoadKind::kDexCacheViaMethod;
5542 }
5543 break;
5544 case HLoadString::LoadKind::kDexCacheViaMethod:
5545 break;
5546 }
5547 return desired_string_load_kind;
5548}
5549
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005550void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005551 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005552 ? LocationSummary::kCallOnSlowPath
5553 : LocationSummary::kNoCall;
5554 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005555 HLoadString::LoadKind load_kind = load->GetLoadKind();
5556 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod ||
5557 load_kind == HLoadString::LoadKind::kDexCachePcRelative) {
5558 locations->SetInAt(0, Location::RequiresRegister());
5559 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005560 locations->SetOut(Location::RequiresRegister());
5561}
5562
5563void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005564 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005565 Location out_loc = locations->Out();
5566 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005567
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005568 switch (load->GetLoadKind()) {
5569 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
5570 DCHECK(!kEmitCompilerReadBarrier);
5571 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5572 load->GetStringIndex()));
5573 return; // No dex cache slow path.
5574 }
5575 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
5576 DCHECK(!kEmitCompilerReadBarrier);
5577 CodeGeneratorARM::PcRelativePatchInfo* labels =
5578 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5579 __ BindTrackedLabel(&labels->movw_label);
5580 __ movw(out, /* placeholder */ 0u);
5581 __ BindTrackedLabel(&labels->movt_label);
5582 __ movt(out, /* placeholder */ 0u);
5583 __ BindTrackedLabel(&labels->add_pc_label);
5584 __ add(out, out, ShifterOperand(PC));
5585 return; // No dex cache slow path.
5586 }
5587 case HLoadString::LoadKind::kBootImageAddress: {
5588 DCHECK(!kEmitCompilerReadBarrier);
5589 DCHECK_NE(load->GetAddress(), 0u);
5590 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5591 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5592 return; // No dex cache slow path.
5593 }
5594 case HLoadString::LoadKind::kDexCacheAddress: {
5595 DCHECK_NE(load->GetAddress(), 0u);
5596 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5597 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5598 // a 128B range. To try and reduce the number of literals if we load multiple strings,
5599 // simply split the dex cache address to a 128B aligned base loaded from a literal
5600 // and the remaining offset embedded in the load.
5601 static_assert(sizeof(GcRoot<mirror::String>) == 4u, "Expected GC root to be 4 bytes.");
5602 DCHECK_ALIGNED(load->GetAddress(), 4u);
5603 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5604 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5605 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5606 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005607 // /* GcRoot<mirror::String> */ out = *(base_address + offset)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005608 GenerateGcRootFieldLoad(load, out_loc, out, offset);
5609 break;
5610 }
5611 case HLoadString::LoadKind::kDexCachePcRelative: {
5612 Register base_reg = locations->InAt(0).AsRegister<Register>();
5613 HArmDexCacheArraysBase* base = load->InputAt(0)->AsArmDexCacheArraysBase();
5614 int32_t offset = load->GetDexCacheElementOffset() - base->GetElementOffset();
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005615 // /* GcRoot<mirror::String> */ out = *(dex_cache_arrays_base + offset)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005616 GenerateGcRootFieldLoad(load, out_loc, base_reg, offset);
5617 break;
5618 }
5619 case HLoadString::LoadKind::kDexCacheViaMethod: {
5620 Register current_method = locations->InAt(0).AsRegister<Register>();
5621
5622 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5623 GenerateGcRootFieldLoad(
5624 load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5625 // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_
5626 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
5627 // /* GcRoot<mirror::String> */ out = out[string_index]
5628 GenerateGcRootFieldLoad(
5629 load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
5630 break;
5631 }
5632 default:
5633 LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind();
5634 UNREACHABLE();
5635 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005636
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005637 if (!load->IsInDexCache()) {
5638 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5639 codegen_->AddSlowPath(slow_path);
5640 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5641 __ Bind(slow_path->GetExitLabel());
5642 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005643}
5644
David Brazdilcb1c0552015-08-04 16:22:25 +01005645static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005646 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005647}
5648
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005649void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5650 LocationSummary* locations =
5651 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5652 locations->SetOut(Location::RequiresRegister());
5653}
5654
5655void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005656 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005657 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5658}
5659
5660void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5661 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5662}
5663
5664void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005665 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005666 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005667}
5668
5669void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5670 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005671 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005672 InvokeRuntimeCallingConvention calling_convention;
5673 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5674}
5675
5676void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
5677 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00005678 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005679 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005680}
5681
Roland Levillainc9285912015-12-18 10:38:42 +00005682static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
5683 return kEmitCompilerReadBarrier &&
5684 (kUseBakerReadBarrier ||
5685 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5686 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5687 type_check_kind == TypeCheckKind::kArrayObjectCheck);
5688}
5689
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005690void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005691 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00005692 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5693 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005694 case TypeCheckKind::kExactCheck:
5695 case TypeCheckKind::kAbstractClassCheck:
5696 case TypeCheckKind::kClassHierarchyCheck:
5697 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005698 call_kind =
5699 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005700 break;
5701 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005702 case TypeCheckKind::kUnresolvedCheck:
5703 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005704 call_kind = LocationSummary::kCallOnSlowPath;
5705 break;
5706 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005707
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005708 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Roland Levillain3b359c72015-11-17 19:35:12 +00005709 locations->SetInAt(0, Location::RequiresRegister());
5710 locations->SetInAt(1, Location::RequiresRegister());
5711 // The "out" register is used as a temporary, so it overlaps with the inputs.
5712 // Note that TypeCheckSlowPathARM uses this register too.
5713 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5714 // When read barriers are enabled, we need a temporary register for
5715 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005716 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00005717 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005718 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005719}
5720
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005721void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005722 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005723 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005724 Location obj_loc = locations->InAt(0);
5725 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005726 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005727 Location out_loc = locations->Out();
5728 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005729 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005730 locations->GetTemp(0) :
5731 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005732 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005733 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5734 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5735 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005736 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07005737 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005738
5739 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005740 // avoid null check if we know obj is not null.
5741 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00005742 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005743 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005744
Roland Levillain3b359c72015-11-17 19:35:12 +00005745 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005746 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005747
Roland Levillainc9285912015-12-18 10:38:42 +00005748 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005749 case TypeCheckKind::kExactCheck: {
5750 __ cmp(out, ShifterOperand(cls));
5751 // Classes must be equal for the instanceof to succeed.
5752 __ b(&zero, NE);
5753 __ LoadImmediate(out, 1);
5754 __ b(&done);
5755 break;
5756 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005757
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005758 case TypeCheckKind::kAbstractClassCheck: {
5759 // If the class is abstract, we eagerly fetch the super class of the
5760 // object to avoid doing a comparison we know will fail.
5761 Label loop;
5762 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005763 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005764 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005765 // If `out` is null, we use it for the result, and jump to `done`.
5766 __ CompareAndBranchIfZero(out, &done);
5767 __ cmp(out, ShifterOperand(cls));
5768 __ b(&loop, NE);
5769 __ LoadImmediate(out, 1);
5770 if (zero.IsLinked()) {
5771 __ b(&done);
5772 }
5773 break;
5774 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005775
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005776 case TypeCheckKind::kClassHierarchyCheck: {
5777 // Walk over the class hierarchy to find a match.
5778 Label loop, success;
5779 __ Bind(&loop);
5780 __ cmp(out, ShifterOperand(cls));
5781 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005782 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005783 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005784 __ CompareAndBranchIfNonZero(out, &loop);
5785 // If `out` is null, we use it for the result, and jump to `done`.
5786 __ b(&done);
5787 __ Bind(&success);
5788 __ LoadImmediate(out, 1);
5789 if (zero.IsLinked()) {
5790 __ b(&done);
5791 }
5792 break;
5793 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005794
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005795 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005796 // Do an exact check.
5797 Label exact_check;
5798 __ cmp(out, ShifterOperand(cls));
5799 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005800 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005801 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005802 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005803 // If `out` is null, we use it for the result, and jump to `done`.
5804 __ CompareAndBranchIfZero(out, &done);
5805 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5806 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5807 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005808 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005809 __ LoadImmediate(out, 1);
5810 __ b(&done);
5811 break;
5812 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005813
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005814 case TypeCheckKind::kArrayCheck: {
5815 __ cmp(out, ShifterOperand(cls));
5816 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00005817 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5818 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005819 codegen_->AddSlowPath(slow_path);
5820 __ b(slow_path->GetEntryLabel(), NE);
5821 __ LoadImmediate(out, 1);
5822 if (zero.IsLinked()) {
5823 __ b(&done);
5824 }
5825 break;
5826 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005827
Calin Juravle98893e12015-10-02 21:05:03 +01005828 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005829 case TypeCheckKind::kInterfaceCheck: {
5830 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00005831 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00005832 // cases.
5833 //
5834 // We cannot directly call the InstanceofNonTrivial runtime
5835 // entry point without resorting to a type checking slow path
5836 // here (i.e. by calling InvokeRuntime directly), as it would
5837 // require to assign fixed registers for the inputs of this
5838 // HInstanceOf instruction (following the runtime calling
5839 // convention), which might be cluttered by the potential first
5840 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00005841 //
5842 // TODO: Introduce a new runtime entry point taking the object
5843 // to test (instead of its class) as argument, and let it deal
5844 // with the read barrier issues. This will let us refactor this
5845 // case of the `switch` code as it was previously (with a direct
5846 // call to the runtime not using a type checking slow path).
5847 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00005848 DCHECK(locations->OnlyCallsOnSlowPath());
5849 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5850 /* is_fatal */ false);
5851 codegen_->AddSlowPath(slow_path);
5852 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005853 if (zero.IsLinked()) {
5854 __ b(&done);
5855 }
5856 break;
5857 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005858 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005859
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005860 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005861 __ Bind(&zero);
5862 __ LoadImmediate(out, 0);
5863 }
5864
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005865 if (done.IsLinked()) {
5866 __ Bind(&done);
5867 }
5868
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005869 if (slow_path != nullptr) {
5870 __ Bind(slow_path->GetExitLabel());
5871 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005872}
5873
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005874void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005875 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5876 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
5877
Roland Levillain3b359c72015-11-17 19:35:12 +00005878 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5879 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005880 case TypeCheckKind::kExactCheck:
5881 case TypeCheckKind::kAbstractClassCheck:
5882 case TypeCheckKind::kClassHierarchyCheck:
5883 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005884 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
5885 LocationSummary::kCallOnSlowPath :
5886 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005887 break;
5888 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005889 case TypeCheckKind::kUnresolvedCheck:
5890 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005891 call_kind = LocationSummary::kCallOnSlowPath;
5892 break;
5893 }
5894
Roland Levillain3b359c72015-11-17 19:35:12 +00005895 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
5896 locations->SetInAt(0, Location::RequiresRegister());
5897 locations->SetInAt(1, Location::RequiresRegister());
5898 // Note that TypeCheckSlowPathARM uses this "temp" register too.
5899 locations->AddTemp(Location::RequiresRegister());
5900 // When read barriers are enabled, we need an additional temporary
5901 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005902 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005903 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005904 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005905}
5906
5907void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005908 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005909 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005910 Location obj_loc = locations->InAt(0);
5911 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005912 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005913 Location temp_loc = locations->GetTemp(0);
5914 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005915 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005916 locations->GetTemp(1) :
5917 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005918 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005919 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5920 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5921 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005922
Roland Levillain3b359c72015-11-17 19:35:12 +00005923 bool is_type_check_slow_path_fatal =
5924 (type_check_kind == TypeCheckKind::kExactCheck ||
5925 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5926 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5927 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
5928 !instruction->CanThrowIntoCatchBlock();
5929 SlowPathCode* type_check_slow_path =
5930 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5931 is_type_check_slow_path_fatal);
5932 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005933
5934 Label done;
5935 // Avoid null check if we know obj is not null.
5936 if (instruction->MustDoNullCheck()) {
5937 __ CompareAndBranchIfZero(obj, &done);
5938 }
5939
Roland Levillain3b359c72015-11-17 19:35:12 +00005940 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005941 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005942
Roland Levillain3b359c72015-11-17 19:35:12 +00005943 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005944 case TypeCheckKind::kExactCheck:
5945 case TypeCheckKind::kArrayCheck: {
5946 __ cmp(temp, ShifterOperand(cls));
5947 // Jump to slow path for throwing the exception or doing a
5948 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005949 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005950 break;
5951 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005952
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005953 case TypeCheckKind::kAbstractClassCheck: {
5954 // If the class is abstract, we eagerly fetch the super class of the
5955 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00005956 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005957 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005958 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005959 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005960
5961 // If the class reference currently in `temp` is not null, jump
5962 // to the `compare_classes` label to compare it with the checked
5963 // class.
5964 __ CompareAndBranchIfNonZero(temp, &compare_classes);
5965 // Otherwise, jump to the slow path to throw the exception.
5966 //
5967 // But before, move back the object's class into `temp` before
5968 // going into the slow path, as it has been overwritten in the
5969 // meantime.
5970 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005971 GenerateReferenceLoadTwoRegisters(
5972 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005973 __ b(type_check_slow_path->GetEntryLabel());
5974
5975 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005976 __ cmp(temp, ShifterOperand(cls));
5977 __ b(&loop, NE);
5978 break;
5979 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005980
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005981 case TypeCheckKind::kClassHierarchyCheck: {
5982 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005983 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005984 __ Bind(&loop);
5985 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005986 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005987
Roland Levillain3b359c72015-11-17 19:35:12 +00005988 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005989 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005990
5991 // If the class reference currently in `temp` is not null, jump
5992 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005993 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005994 // Otherwise, jump to the slow path to throw the exception.
5995 //
5996 // But before, move back the object's class into `temp` before
5997 // going into the slow path, as it has been overwritten in the
5998 // meantime.
5999 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006000 GenerateReferenceLoadTwoRegisters(
6001 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006002 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006003 break;
6004 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006005
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006006 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006007 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00006008 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006009 __ cmp(temp, ShifterOperand(cls));
6010 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006011
6012 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00006013 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006014 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006015
6016 // If the component type is not null (i.e. the object is indeed
6017 // an array), jump to label `check_non_primitive_component_type`
6018 // to further check that this component type is not a primitive
6019 // type.
6020 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6021 // Otherwise, jump to the slow path to throw the exception.
6022 //
6023 // But before, move back the object's class into `temp` before
6024 // going into the slow path, as it has been overwritten in the
6025 // meantime.
6026 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006027 GenerateReferenceLoadTwoRegisters(
6028 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006029 __ b(type_check_slow_path->GetEntryLabel());
6030
6031 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006032 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006033 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6034 __ CompareAndBranchIfZero(temp, &done);
6035 // Same comment as above regarding `temp` and the slow path.
6036 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006037 GenerateReferenceLoadTwoRegisters(
6038 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006039 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006040 break;
6041 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006042
Calin Juravle98893e12015-10-02 21:05:03 +01006043 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006044 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006045 // We always go into the type check slow path for the unresolved
6046 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006047 //
6048 // We cannot directly call the CheckCast runtime entry point
6049 // without resorting to a type checking slow path here (i.e. by
6050 // calling InvokeRuntime directly), as it would require to
6051 // assign fixed registers for the inputs of this HInstanceOf
6052 // instruction (following the runtime calling convention), which
6053 // might be cluttered by the potential first read barrier
6054 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006055 //
6056 // TODO: Introduce a new runtime entry point taking the object
6057 // to test (instead of its class) as argument, and let it deal
6058 // with the read barrier issues. This will let us refactor this
6059 // case of the `switch` code as it was previously (with a direct
6060 // call to the runtime not using a type checking slow path).
6061 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006062 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006063 break;
6064 }
6065 __ Bind(&done);
6066
Roland Levillain3b359c72015-11-17 19:35:12 +00006067 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006068}
6069
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006070void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6071 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006072 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006073 InvokeRuntimeCallingConvention calling_convention;
6074 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6075}
6076
6077void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6078 codegen_->InvokeRuntime(instruction->IsEnter()
6079 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
6080 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00006081 instruction->GetDexPc(),
6082 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00006083 if (instruction->IsEnter()) {
6084 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6085 } else {
6086 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6087 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006088}
6089
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006090void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6091void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6092void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006093
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006094void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006095 LocationSummary* locations =
6096 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6097 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6098 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006099 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006100 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006101 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006102 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006103}
6104
6105void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6106 HandleBitwiseOperation(instruction);
6107}
6108
6109void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6110 HandleBitwiseOperation(instruction);
6111}
6112
6113void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6114 HandleBitwiseOperation(instruction);
6115}
6116
Artem Serov7fc63502016-02-09 17:15:29 +00006117
6118void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6119 LocationSummary* locations =
6120 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6121 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6122 || instruction->GetResultType() == Primitive::kPrimLong);
6123
6124 locations->SetInAt(0, Location::RequiresRegister());
6125 locations->SetInAt(1, Location::RequiresRegister());
6126 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6127}
6128
6129void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6130 LocationSummary* locations = instruction->GetLocations();
6131 Location first = locations->InAt(0);
6132 Location second = locations->InAt(1);
6133 Location out = locations->Out();
6134
6135 if (instruction->GetResultType() == Primitive::kPrimInt) {
6136 Register first_reg = first.AsRegister<Register>();
6137 ShifterOperand second_reg(second.AsRegister<Register>());
6138 Register out_reg = out.AsRegister<Register>();
6139
6140 switch (instruction->GetOpKind()) {
6141 case HInstruction::kAnd:
6142 __ bic(out_reg, first_reg, second_reg);
6143 break;
6144 case HInstruction::kOr:
6145 __ orn(out_reg, first_reg, second_reg);
6146 break;
6147 // There is no EON on arm.
6148 case HInstruction::kXor:
6149 default:
6150 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6151 UNREACHABLE();
6152 }
6153 return;
6154
6155 } else {
6156 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6157 Register first_low = first.AsRegisterPairLow<Register>();
6158 Register first_high = first.AsRegisterPairHigh<Register>();
6159 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6160 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6161 Register out_low = out.AsRegisterPairLow<Register>();
6162 Register out_high = out.AsRegisterPairHigh<Register>();
6163
6164 switch (instruction->GetOpKind()) {
6165 case HInstruction::kAnd:
6166 __ bic(out_low, first_low, second_low);
6167 __ bic(out_high, first_high, second_high);
6168 break;
6169 case HInstruction::kOr:
6170 __ orn(out_low, first_low, second_low);
6171 __ orn(out_high, first_high, second_high);
6172 break;
6173 // There is no EON on arm.
6174 case HInstruction::kXor:
6175 default:
6176 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6177 UNREACHABLE();
6178 }
6179 }
6180}
6181
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006182void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6183 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6184 if (value == 0xffffffffu) {
6185 if (out != first) {
6186 __ mov(out, ShifterOperand(first));
6187 }
6188 return;
6189 }
6190 if (value == 0u) {
6191 __ mov(out, ShifterOperand(0));
6192 return;
6193 }
6194 ShifterOperand so;
6195 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6196 __ and_(out, first, so);
6197 } else {
6198 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6199 __ bic(out, first, ShifterOperand(~value));
6200 }
6201}
6202
6203void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6204 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6205 if (value == 0u) {
6206 if (out != first) {
6207 __ mov(out, ShifterOperand(first));
6208 }
6209 return;
6210 }
6211 if (value == 0xffffffffu) {
6212 __ mvn(out, ShifterOperand(0));
6213 return;
6214 }
6215 ShifterOperand so;
6216 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6217 __ orr(out, first, so);
6218 } else {
6219 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6220 __ orn(out, first, ShifterOperand(~value));
6221 }
6222}
6223
6224void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6225 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6226 if (value == 0u) {
6227 if (out != first) {
6228 __ mov(out, ShifterOperand(first));
6229 }
6230 return;
6231 }
6232 __ eor(out, first, ShifterOperand(value));
6233}
6234
Vladimir Marko59751a72016-08-05 14:37:27 +01006235void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6236 Location first,
6237 uint64_t value) {
6238 Register out_low = out.AsRegisterPairLow<Register>();
6239 Register out_high = out.AsRegisterPairHigh<Register>();
6240 Register first_low = first.AsRegisterPairLow<Register>();
6241 Register first_high = first.AsRegisterPairHigh<Register>();
6242 uint32_t value_low = Low32Bits(value);
6243 uint32_t value_high = High32Bits(value);
6244 if (value_low == 0u) {
6245 if (out_low != first_low) {
6246 __ mov(out_low, ShifterOperand(first_low));
6247 }
6248 __ AddConstant(out_high, first_high, value_high);
6249 return;
6250 }
6251 __ AddConstantSetFlags(out_low, first_low, value_low);
6252 ShifterOperand so;
6253 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6254 __ adc(out_high, first_high, so);
6255 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6256 __ sbc(out_high, first_high, so);
6257 } else {
6258 LOG(FATAL) << "Unexpected constant " << value_high;
6259 UNREACHABLE();
6260 }
6261}
6262
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006263void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6264 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006265 Location first = locations->InAt(0);
6266 Location second = locations->InAt(1);
6267 Location out = locations->Out();
6268
6269 if (second.IsConstant()) {
6270 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6271 uint32_t value_low = Low32Bits(value);
6272 if (instruction->GetResultType() == Primitive::kPrimInt) {
6273 Register first_reg = first.AsRegister<Register>();
6274 Register out_reg = out.AsRegister<Register>();
6275 if (instruction->IsAnd()) {
6276 GenerateAndConst(out_reg, first_reg, value_low);
6277 } else if (instruction->IsOr()) {
6278 GenerateOrrConst(out_reg, first_reg, value_low);
6279 } else {
6280 DCHECK(instruction->IsXor());
6281 GenerateEorConst(out_reg, first_reg, value_low);
6282 }
6283 } else {
6284 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6285 uint32_t value_high = High32Bits(value);
6286 Register first_low = first.AsRegisterPairLow<Register>();
6287 Register first_high = first.AsRegisterPairHigh<Register>();
6288 Register out_low = out.AsRegisterPairLow<Register>();
6289 Register out_high = out.AsRegisterPairHigh<Register>();
6290 if (instruction->IsAnd()) {
6291 GenerateAndConst(out_low, first_low, value_low);
6292 GenerateAndConst(out_high, first_high, value_high);
6293 } else if (instruction->IsOr()) {
6294 GenerateOrrConst(out_low, first_low, value_low);
6295 GenerateOrrConst(out_high, first_high, value_high);
6296 } else {
6297 DCHECK(instruction->IsXor());
6298 GenerateEorConst(out_low, first_low, value_low);
6299 GenerateEorConst(out_high, first_high, value_high);
6300 }
6301 }
6302 return;
6303 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006304
6305 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006306 Register first_reg = first.AsRegister<Register>();
6307 ShifterOperand second_reg(second.AsRegister<Register>());
6308 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006309 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006310 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006311 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006312 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006313 } else {
6314 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006315 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006316 }
6317 } else {
6318 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006319 Register first_low = first.AsRegisterPairLow<Register>();
6320 Register first_high = first.AsRegisterPairHigh<Register>();
6321 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6322 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6323 Register out_low = out.AsRegisterPairLow<Register>();
6324 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006325 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006326 __ and_(out_low, first_low, second_low);
6327 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006328 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006329 __ orr(out_low, first_low, second_low);
6330 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006331 } else {
6332 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006333 __ eor(out_low, first_low, second_low);
6334 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006335 }
6336 }
6337}
6338
Roland Levillainc9285912015-12-18 10:38:42 +00006339void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6340 Location out,
6341 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006342 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006343 Register out_reg = out.AsRegister<Register>();
6344 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006345 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006346 if (kUseBakerReadBarrier) {
6347 // Load with fast path based Baker's read barrier.
6348 // /* HeapReference<Object> */ out = *(out + offset)
6349 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006350 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006351 } else {
6352 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006353 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006354 // in the following move operation, as we will need it for the
6355 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006356 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006357 // /* HeapReference<Object> */ out = *(out + offset)
6358 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006359 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006360 }
6361 } else {
6362 // Plain load with no read barrier.
6363 // /* HeapReference<Object> */ out = *(out + offset)
6364 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6365 __ MaybeUnpoisonHeapReference(out_reg);
6366 }
6367}
6368
6369void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6370 Location out,
6371 Location obj,
6372 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006373 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006374 Register out_reg = out.AsRegister<Register>();
6375 Register obj_reg = obj.AsRegister<Register>();
6376 if (kEmitCompilerReadBarrier) {
6377 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006378 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006379 // Load with fast path based Baker's read barrier.
6380 // /* HeapReference<Object> */ out = *(obj + offset)
6381 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006382 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006383 } else {
6384 // Load with slow path based read barrier.
6385 // /* HeapReference<Object> */ out = *(obj + offset)
6386 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6387 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6388 }
6389 } else {
6390 // Plain load with no read barrier.
6391 // /* HeapReference<Object> */ out = *(obj + offset)
6392 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6393 __ MaybeUnpoisonHeapReference(out_reg);
6394 }
6395}
6396
6397void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6398 Location root,
6399 Register obj,
6400 uint32_t offset) {
6401 Register root_reg = root.AsRegister<Register>();
6402 if (kEmitCompilerReadBarrier) {
6403 if (kUseBakerReadBarrier) {
6404 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6405 // Baker's read barrier are used:
6406 //
6407 // root = obj.field;
6408 // if (Thread::Current()->GetIsGcMarking()) {
6409 // root = ReadBarrier::Mark(root)
6410 // }
6411
6412 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6413 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6414 static_assert(
6415 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6416 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6417 "have different sizes.");
6418 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6419 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6420 "have different sizes.");
6421
6422 // Slow path used to mark the GC root `root`.
6423 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006424 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006425 codegen_->AddSlowPath(slow_path);
6426
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006427 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006428 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006429 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006430 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6431 __ Bind(slow_path->GetExitLabel());
6432 } else {
6433 // GC root loaded through a slow path for read barriers other
6434 // than Baker's.
6435 // /* GcRoot<mirror::Object>* */ root = obj + offset
6436 __ AddConstant(root_reg, obj, offset);
6437 // /* mirror::Object* */ root = root->Read()
6438 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6439 }
6440 } else {
6441 // Plain GC root load with no read barrier.
6442 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6443 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6444 // Note that GC roots are not affected by heap poisoning, thus we
6445 // do not have to unpoison `root_reg` here.
6446 }
6447}
6448
6449void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6450 Location ref,
6451 Register obj,
6452 uint32_t offset,
6453 Location temp,
6454 bool needs_null_check) {
6455 DCHECK(kEmitCompilerReadBarrier);
6456 DCHECK(kUseBakerReadBarrier);
6457
6458 // /* HeapReference<Object> */ ref = *(obj + offset)
6459 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006460 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006461 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006462 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006463}
6464
6465void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6466 Location ref,
6467 Register obj,
6468 uint32_t data_offset,
6469 Location index,
6470 Location temp,
6471 bool needs_null_check) {
6472 DCHECK(kEmitCompilerReadBarrier);
6473 DCHECK(kUseBakerReadBarrier);
6474
Roland Levillainbfea3352016-06-23 13:48:47 +01006475 static_assert(
6476 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6477 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006478 // /* HeapReference<Object> */ ref =
6479 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006480 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006481 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006482 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006483}
6484
6485void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6486 Location ref,
6487 Register obj,
6488 uint32_t offset,
6489 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006490 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006491 Location temp,
6492 bool needs_null_check) {
6493 DCHECK(kEmitCompilerReadBarrier);
6494 DCHECK(kUseBakerReadBarrier);
6495
6496 // In slow path based read barriers, the read barrier call is
6497 // inserted after the original load. However, in fast path based
6498 // Baker's read barriers, we need to perform the load of
6499 // mirror::Object::monitor_ *before* the original reference load.
6500 // This load-load ordering is required by the read barrier.
6501 // The fast path/slow path (for Baker's algorithm) should look like:
6502 //
6503 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6504 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6505 // HeapReference<Object> ref = *src; // Original reference load.
6506 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6507 // if (is_gray) {
6508 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6509 // }
6510 //
6511 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006512 // slightly more complex as it performs additional checks that we do
6513 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006514
6515 Register ref_reg = ref.AsRegister<Register>();
6516 Register temp_reg = temp.AsRegister<Register>();
6517 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6518
6519 // /* int32_t */ monitor = obj->monitor_
6520 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6521 if (needs_null_check) {
6522 MaybeRecordImplicitNullCheck(instruction);
6523 }
6524 // /* LockWord */ lock_word = LockWord(monitor)
6525 static_assert(sizeof(LockWord) == sizeof(int32_t),
6526 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006527
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006528 // Introduce a dependency on the lock_word including the rb_state,
6529 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006530 // a memory barrier (which would be more expensive).
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006531 // obj is unchanged by this operation, but its value now depends on temp_reg.
6532 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006533
6534 // The actual reference load.
6535 if (index.IsValid()) {
Roland Levillainbfea3352016-06-23 13:48:47 +01006536 // Load types involving an "index": ArrayGet and
6537 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
6538 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006539 if (index.IsConstant()) {
6540 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006541 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006542 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6543 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006544 // Handle the special case of the
6545 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use
6546 // a register pair as index ("long offset"), of which only the low
6547 // part contains data.
6548 Register index_reg = index.IsRegisterPair()
6549 ? index.AsRegisterPairLow<Register>()
6550 : index.AsRegister<Register>();
6551 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006552 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6553 }
6554 } else {
6555 // /* HeapReference<Object> */ ref = *(obj + offset)
6556 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6557 }
6558
6559 // Object* ref = ref_addr->AsMirrorPtr()
6560 __ MaybeUnpoisonHeapReference(ref_reg);
6561
6562 // Slow path used to mark the object `ref` when it is gray.
6563 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006564 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
Roland Levillainc9285912015-12-18 10:38:42 +00006565 AddSlowPath(slow_path);
6566
6567 // if (rb_state == ReadBarrier::gray_ptr_)
6568 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006569 // Given the numeric representation, it's enough to check the low bit of the
6570 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6571 // which can be a 16-bit instruction unlike the TST immediate.
6572 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6573 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6574 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6575 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6576 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006577 __ Bind(slow_path->GetExitLabel());
6578}
6579
6580void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6581 Location out,
6582 Location ref,
6583 Location obj,
6584 uint32_t offset,
6585 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006586 DCHECK(kEmitCompilerReadBarrier);
6587
Roland Levillainc9285912015-12-18 10:38:42 +00006588 // Insert a slow path based read barrier *after* the reference load.
6589 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006590 // If heap poisoning is enabled, the unpoisoning of the loaded
6591 // reference will be carried out by the runtime within the slow
6592 // path.
6593 //
6594 // Note that `ref` currently does not get unpoisoned (when heap
6595 // poisoning is enabled), which is alright as the `ref` argument is
6596 // not used by the artReadBarrierSlow entry point.
6597 //
6598 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
6599 SlowPathCode* slow_path = new (GetGraph()->GetArena())
6600 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6601 AddSlowPath(slow_path);
6602
Roland Levillain3b359c72015-11-17 19:35:12 +00006603 __ b(slow_path->GetEntryLabel());
6604 __ Bind(slow_path->GetExitLabel());
6605}
6606
Roland Levillainc9285912015-12-18 10:38:42 +00006607void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6608 Location out,
6609 Location ref,
6610 Location obj,
6611 uint32_t offset,
6612 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006613 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006614 // Baker's read barriers shall be handled by the fast path
6615 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6616 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006617 // If heap poisoning is enabled, unpoisoning will be taken care of
6618 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006619 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006620 } else if (kPoisonHeapReferences) {
6621 __ UnpoisonHeapReference(out.AsRegister<Register>());
6622 }
6623}
6624
Roland Levillainc9285912015-12-18 10:38:42 +00006625void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6626 Location out,
6627 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006628 DCHECK(kEmitCompilerReadBarrier);
6629
Roland Levillainc9285912015-12-18 10:38:42 +00006630 // Insert a slow path based read barrier *after* the GC root load.
6631 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006632 // Note that GC roots are not affected by heap poisoning, so we do
6633 // not need to do anything special for this here.
6634 SlowPathCode* slow_path =
6635 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6636 AddSlowPath(slow_path);
6637
Roland Levillain3b359c72015-11-17 19:35:12 +00006638 __ b(slow_path->GetEntryLabel());
6639 __ Bind(slow_path->GetExitLabel());
6640}
6641
Vladimir Markodc151b22015-10-15 18:02:30 +01006642HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6643 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
6644 MethodReference target_method) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006645 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6646 // We disable pc-relative load when there is an irreducible loop, as the optimization
6647 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006648 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6649 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006650 if (GetGraph()->HasIrreducibleLoops() &&
6651 (dispatch_info.method_load_kind ==
6652 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
6653 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
6654 }
6655
6656 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01006657 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
6658 if (&outer_dex_file != target_method.dex_file) {
6659 // Calls across dex files are more likely to exceed the available BL range,
6660 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
6661 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
6662 (desired_dispatch_info.method_load_kind ==
6663 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
6664 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
6665 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
6666 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006667 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01006668 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006669 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01006670 0u
6671 };
6672 }
6673 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006674 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006675}
6676
Vladimir Markob4536b72015-11-24 13:45:23 +00006677Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
6678 Register temp) {
6679 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
6680 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
6681 if (!invoke->GetLocations()->Intrinsified()) {
6682 return location.AsRegister<Register>();
6683 }
6684 // For intrinsics we allow any location, so it may be on the stack.
6685 if (!location.IsRegister()) {
6686 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
6687 return temp;
6688 }
6689 // For register locations, check if the register was saved. If so, get it from the stack.
6690 // Note: There is a chance that the register was saved but not overwritten, so we could
6691 // save one load. However, since this is just an intrinsic slow path we prefer this
6692 // simple and more robust approach rather that trying to determine if that's the case.
6693 SlowPathCode* slow_path = GetCurrentSlowPath();
6694 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
6695 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
6696 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
6697 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
6698 return temp;
6699 }
6700 return location.AsRegister<Register>();
6701}
6702
Nicolas Geoffray38207af2015-06-01 15:46:22 +01006703void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00006704 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00006705 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00006706 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6707 // LR = code address from literal pool with link-time patch.
6708 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00006709 break;
6710 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6711 // LR = invoke->GetDirectCodePtr();
6712 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00006713 break;
6714 default:
6715 break;
6716 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006717
Vladimir Marko58155012015-08-19 12:49:41 +00006718 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
6719 switch (invoke->GetMethodLoadKind()) {
6720 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
6721 // temp = thread->string_init_entrypoint
6722 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
6723 break;
6724 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006725 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006726 break;
6727 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
6728 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
6729 break;
6730 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
6731 __ LoadLiteral(temp.AsRegister<Register>(),
6732 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
6733 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00006734 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
6735 HArmDexCacheArraysBase* base =
6736 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
6737 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
6738 temp.AsRegister<Register>());
6739 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
6740 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
6741 break;
6742 }
Vladimir Marko58155012015-08-19 12:49:41 +00006743 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00006744 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006745 Register method_reg;
6746 Register reg = temp.AsRegister<Register>();
6747 if (current_method.IsRegister()) {
6748 method_reg = current_method.AsRegister<Register>();
6749 } else {
6750 DCHECK(invoke->GetLocations()->Intrinsified());
6751 DCHECK(!current_method.IsValid());
6752 method_reg = reg;
6753 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
6754 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006755 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
6756 __ LoadFromOffset(kLoadWord,
6757 reg,
6758 method_reg,
6759 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01006760 // temp = temp[index_in_cache];
6761 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
6762 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00006763 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
6764 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01006765 }
Vladimir Marko58155012015-08-19 12:49:41 +00006766 }
6767
6768 switch (invoke->GetCodePtrLocation()) {
6769 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
6770 __ bl(GetFrameEntryLabel());
6771 break;
6772 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01006773 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07006774 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01006775 // Arbitrarily branch to the BL itself, override at link time.
6776 __ bl(&relative_call_patches_.back().label);
6777 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006778 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6779 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6780 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00006781 // LR()
6782 __ blx(LR);
6783 break;
6784 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6785 // LR = callee_method->entry_point_from_quick_compiled_code_
6786 __ LoadFromOffset(
6787 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07006788 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006789 // LR()
6790 __ blx(LR);
6791 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006792 }
6793
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006794 DCHECK(!IsLeafMethod());
6795}
6796
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006797void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
6798 Register temp = temp_location.AsRegister<Register>();
6799 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6800 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006801
6802 // Use the calling convention instead of the location of the receiver, as
6803 // intrinsics may have put the receiver in a different register. In the intrinsics
6804 // slow path, the arguments have been moved to the right place, so here we are
6805 // guaranteed that the receiver is the first register of the calling convention.
6806 InvokeDexCallingConvention calling_convention;
6807 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006808 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00006809 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006810 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006811 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00006812 // Instead of simply (possibly) unpoisoning `temp` here, we should
6813 // emit a read barrier for the previous class reference load.
6814 // However this is not required in practice, as this is an
6815 // intermediate/temporary reference and because the current
6816 // concurrent copying collector keeps the from-space memory
6817 // intact/accessible until the end of the marking phase (the
6818 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006819 __ MaybeUnpoisonHeapReference(temp);
6820 // temp = temp->GetMethodAt(method_offset);
6821 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006822 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006823 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
6824 // LR = temp->GetEntryPoint();
6825 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
6826 // LR();
6827 __ blx(LR);
6828}
6829
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006830CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
6831 const DexFile& dex_file, uint32_t string_index) {
6832 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
6833}
6834
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006835CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
6836 const DexFile& dex_file, uint32_t type_index) {
6837 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
6838}
6839
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006840CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
6841 const DexFile& dex_file, uint32_t element_offset) {
6842 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
6843}
6844
6845CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
6846 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
6847 patches->emplace_back(dex_file, offset_or_index);
6848 return &patches->back();
6849}
6850
6851Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
6852 uint32_t string_index) {
6853 return boot_image_string_patches_.GetOrCreate(
6854 StringReference(&dex_file, string_index),
6855 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6856}
6857
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006858Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
6859 uint32_t type_index) {
6860 return boot_image_type_patches_.GetOrCreate(
6861 TypeReference(&dex_file, type_index),
6862 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6863}
6864
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006865Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
6866 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
6867 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
6868 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
6869}
6870
6871Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
6872 return DeduplicateUint32Literal(address, &uint32_literals_);
6873}
6874
Vladimir Marko58155012015-08-19 12:49:41 +00006875void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
6876 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00006877 size_t size =
6878 method_patches_.size() +
6879 call_patches_.size() +
6880 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006881 /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() +
6882 boot_image_string_patches_.size() +
6883 /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006884 boot_image_type_patches_.size() +
6885 /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006886 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00006887 linker_patches->reserve(size);
6888 for (const auto& entry : method_patches_) {
6889 const MethodReference& target_method = entry.first;
6890 Literal* literal = entry.second;
6891 DCHECK(literal->GetLabel()->IsBound());
6892 uint32_t literal_offset = literal->GetLabel()->Position();
6893 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
6894 target_method.dex_file,
6895 target_method.dex_method_index));
6896 }
6897 for (const auto& entry : call_patches_) {
6898 const MethodReference& target_method = entry.first;
6899 Literal* literal = entry.second;
6900 DCHECK(literal->GetLabel()->IsBound());
6901 uint32_t literal_offset = literal->GetLabel()->Position();
6902 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
6903 target_method.dex_file,
6904 target_method.dex_method_index));
6905 }
6906 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
6907 uint32_t literal_offset = info.label.Position();
6908 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
6909 info.target_method.dex_file,
6910 info.target_method.dex_method_index));
6911 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006912 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
6913 const DexFile& dex_file = info.target_dex_file;
6914 size_t base_element_offset = info.offset_or_index;
6915 DCHECK(info.add_pc_label.IsBound());
6916 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006917 // Add MOVW patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006918 DCHECK(info.movw_label.IsBound());
6919 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006920 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset,
6921 &dex_file,
6922 add_pc_offset,
6923 base_element_offset));
6924 // Add MOVT patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006925 DCHECK(info.movt_label.IsBound());
6926 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006927 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset,
6928 &dex_file,
6929 add_pc_offset,
6930 base_element_offset));
6931 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006932 for (const auto& entry : boot_image_string_patches_) {
6933 const StringReference& target_string = entry.first;
6934 Literal* literal = entry.second;
6935 DCHECK(literal->GetLabel()->IsBound());
6936 uint32_t literal_offset = literal->GetLabel()->Position();
6937 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
6938 target_string.dex_file,
6939 target_string.string_index));
6940 }
6941 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
6942 const DexFile& dex_file = info.target_dex_file;
6943 uint32_t string_index = info.offset_or_index;
6944 DCHECK(info.add_pc_label.IsBound());
6945 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6946 // Add MOVW patch.
6947 DCHECK(info.movw_label.IsBound());
6948 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6949 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset,
6950 &dex_file,
6951 add_pc_offset,
6952 string_index));
6953 // Add MOVT patch.
6954 DCHECK(info.movt_label.IsBound());
6955 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6956 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset,
6957 &dex_file,
6958 add_pc_offset,
6959 string_index));
6960 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006961 for (const auto& entry : boot_image_type_patches_) {
6962 const TypeReference& target_type = entry.first;
6963 Literal* literal = entry.second;
6964 DCHECK(literal->GetLabel()->IsBound());
6965 uint32_t literal_offset = literal->GetLabel()->Position();
6966 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
6967 target_type.dex_file,
6968 target_type.type_index));
6969 }
6970 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
6971 const DexFile& dex_file = info.target_dex_file;
6972 uint32_t type_index = info.offset_or_index;
6973 DCHECK(info.add_pc_label.IsBound());
6974 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6975 // Add MOVW patch.
6976 DCHECK(info.movw_label.IsBound());
6977 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6978 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset,
6979 &dex_file,
6980 add_pc_offset,
6981 type_index));
6982 // Add MOVT patch.
6983 DCHECK(info.movt_label.IsBound());
6984 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6985 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset,
6986 &dex_file,
6987 add_pc_offset,
6988 type_index));
6989 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006990 for (const auto& entry : boot_image_address_patches_) {
6991 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
6992 Literal* literal = entry.second;
6993 DCHECK(literal->GetLabel()->IsBound());
6994 uint32_t literal_offset = literal->GetLabel()->Position();
6995 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
6996 }
6997}
6998
6999Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
7000 return map->GetOrCreate(
7001 value,
7002 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00007003}
7004
7005Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
7006 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007007 return map->GetOrCreate(
7008 target_method,
7009 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00007010}
7011
7012Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
7013 return DeduplicateMethodLiteral(target_method, &method_patches_);
7014}
7015
7016Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
7017 return DeduplicateMethodLiteral(target_method, &call_patches_);
7018}
7019
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03007020void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7021 LocationSummary* locations =
7022 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7023 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7024 Location::RequiresRegister());
7025 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7026 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7027 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7028}
7029
7030void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7031 LocationSummary* locations = instr->GetLocations();
7032 Register res = locations->Out().AsRegister<Register>();
7033 Register accumulator =
7034 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7035 Register mul_left =
7036 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7037 Register mul_right =
7038 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7039
7040 if (instr->GetOpKind() == HInstruction::kAdd) {
7041 __ mla(res, mul_left, mul_right, accumulator);
7042 } else {
7043 __ mls(res, mul_left, mul_right, accumulator);
7044 }
7045}
7046
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007047void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007048 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007049 LOG(FATAL) << "Unreachable";
7050}
7051
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007052void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007053 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007054 LOG(FATAL) << "Unreachable";
7055}
7056
Mark Mendellfe57faa2015-09-18 09:26:15 -04007057// Simple implementation of packed switch - generate cascaded compare/jumps.
7058void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7059 LocationSummary* locations =
7060 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7061 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007062 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007063 codegen_->GetAssembler()->IsThumb()) {
7064 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7065 if (switch_instr->GetStartValue() != 0) {
7066 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7067 }
7068 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007069}
7070
7071void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7072 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007073 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007074 LocationSummary* locations = switch_instr->GetLocations();
7075 Register value_reg = locations->InAt(0).AsRegister<Register>();
7076 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7077
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007078 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007079 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007080 Register temp_reg = IP;
7081 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7082 // the immediate, because IP is used as the destination register. For the other
7083 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7084 // and they can be encoded in the instruction without making use of IP register.
7085 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7086
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007087 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007088 // Jump to successors[0] if value == lower_bound.
7089 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7090 int32_t last_index = 0;
7091 for (; num_entries - last_index > 2; last_index += 2) {
7092 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7093 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7094 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7095 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7096 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7097 }
7098 if (num_entries - last_index == 2) {
7099 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007100 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007101 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007102 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007103
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007104 // And the default for any other value.
7105 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7106 __ b(codegen_->GetLabelOf(default_block));
7107 }
7108 } else {
7109 // Create a table lookup.
7110 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7111
7112 // Materialize a pointer to the switch table
7113 std::vector<Label*> labels(num_entries);
7114 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7115 for (uint32_t i = 0; i < num_entries; i++) {
7116 labels[i] = codegen_->GetLabelOf(successors[i]);
7117 }
7118 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7119
7120 // Remove the bias.
7121 Register key_reg;
7122 if (lower_bound != 0) {
7123 key_reg = locations->GetTemp(1).AsRegister<Register>();
7124 __ AddConstant(key_reg, value_reg, -lower_bound);
7125 } else {
7126 key_reg = value_reg;
7127 }
7128
7129 // Check whether the value is in the table, jump to default block if not.
7130 __ CmpConstant(key_reg, num_entries - 1);
7131 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7132
7133 // Load the displacement from the table.
7134 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7135
7136 // Dispatch is a direct add to the PC (for Thumb2).
7137 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007138 }
7139}
7140
Vladimir Markob4536b72015-11-24 13:45:23 +00007141void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7142 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7143 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007144}
7145
7146void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7147 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007148 CodeGeneratorARM::PcRelativePatchInfo* labels =
7149 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007150 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007151 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007152 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007153 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007154 __ BindTrackedLabel(&labels->add_pc_label);
7155 __ add(base_reg, base_reg, ShifterOperand(PC));
7156}
7157
Andreas Gampe85b62f22015-09-09 13:15:38 -07007158void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7159 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007160 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007161 return;
7162 }
7163
7164 DCHECK_NE(type, Primitive::kPrimVoid);
7165
7166 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7167 if (return_loc.Equals(trg)) {
7168 return;
7169 }
7170
7171 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7172 // with the last branch.
7173 if (type == Primitive::kPrimLong) {
7174 HParallelMove parallel_move(GetGraph()->GetArena());
7175 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7176 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7177 GetMoveResolver()->EmitNativeCode(&parallel_move);
7178 } else if (type == Primitive::kPrimDouble) {
7179 HParallelMove parallel_move(GetGraph()->GetArena());
7180 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7181 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7182 GetMoveResolver()->EmitNativeCode(&parallel_move);
7183 } else {
7184 // Let the parallel move resolver take care of all of this.
7185 HParallelMove parallel_move(GetGraph()->GetArena());
7186 parallel_move.AddMove(return_loc, trg, type, nullptr);
7187 GetMoveResolver()->EmitNativeCode(&parallel_move);
7188 }
7189}
7190
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007191void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7192 LocationSummary* locations =
7193 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7194 locations->SetInAt(0, Location::RequiresRegister());
7195 locations->SetOut(Location::RequiresRegister());
7196}
7197
7198void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7199 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007200 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007201 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007202 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007203 __ LoadFromOffset(kLoadWord,
7204 locations->Out().AsRegister<Register>(),
7205 locations->InAt(0).AsRegister<Register>(),
7206 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007207 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007208 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007209 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007210 __ LoadFromOffset(kLoadWord,
7211 locations->Out().AsRegister<Register>(),
7212 locations->InAt(0).AsRegister<Register>(),
7213 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7214 __ LoadFromOffset(kLoadWord,
7215 locations->Out().AsRegister<Register>(),
7216 locations->Out().AsRegister<Register>(),
7217 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007218 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007219}
7220
Roland Levillain4d027112015-07-01 15:41:14 +01007221#undef __
7222#undef QUICK_ENTRY_POINT
7223
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007224} // namespace arm
7225} // namespace art