blob: 4c4128c5f82428f5de3ae5f1eb471fc592113038 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Vladimir Marko58155012015-08-19 12:49:41 +000022#include "compiled_method.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070023#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010024#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080025#include "intrinsics.h"
26#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070027#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070029#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010030#include "utils/arm/assembler_arm.h"
31#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000032#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010033#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010036
Roland Levillain3b359c72015-11-17 19:35:12 +000037template<class MirrorType>
38class GcRoot;
39
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000040namespace arm {
41
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000042static bool ExpectedPairLayout(Location location) {
43 // We expected this for both core and fpu register pairs.
44 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
45}
46
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010047static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010048static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010049
David Brazdil58282f42016-01-14 12:45:10 +000050static constexpr Register kCoreAlwaysSpillRegister = R5;
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000051static constexpr Register kCoreCalleeSaves[] =
Andreas Gampe501fd632015-09-10 16:11:06 -070052 { R5, R6, R7, R8, R10, R11, LR };
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000053static constexpr SRegister kFpuCalleeSaves[] =
54 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010055
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000056// D31 cannot be split into two S registers, and the register allocator only works on
57// S registers. Therefore there is no need to block it.
58static constexpr DRegister DTMP = D31;
59
Vladimir Markof3e0ee22015-12-17 15:23:13 +000060static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7;
Andreas Gampe7cffc3b2015-10-19 21:31:53 -070061
Roland Levillain7cbd27f2016-08-11 23:53:33 +010062// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
63#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -070064#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065
Andreas Gampe85b62f22015-09-09 13:15:38 -070066class NullCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 public:
David Srbecky9cd6d372016-02-09 15:24:47 +000068 explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010069
Alexandre Rames67555f72014-11-18 10:55:16 +000070 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010071 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010072 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000073 if (instruction_->CanThrowIntoCatchBlock()) {
74 // Live registers will be restored in the catch block if caught.
75 SaveLiveRegisters(codegen, instruction_->GetLocations());
76 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010077 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000078 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +000079 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080 }
81
Alexandre Rames8158f282015-08-07 10:26:17 +010082 bool IsFatal() const OVERRIDE { return true; }
83
Alexandre Rames9931f312015-06-19 14:47:01 +010084 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
85
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086 private:
Nicolas Geoffraye5038322014-07-04 09:41:32 +010087 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
88};
89
Andreas Gampe85b62f22015-09-09 13:15:38 -070090class DivZeroCheckSlowPathARM : public SlowPathCode {
Calin Juravled0d48522014-11-04 16:40:20 +000091 public:
David Srbecky9cd6d372016-02-09 15:24:47 +000092 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCode(instruction) {}
Calin Juravled0d48522014-11-04 16:40:20 +000093
Alexandre Rames67555f72014-11-18 10:55:16 +000094 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000095 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
96 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000097 if (instruction_->CanThrowIntoCatchBlock()) {
98 // Live registers will be restored in the catch block if caught.
99 SaveLiveRegisters(codegen, instruction_->GetLocations());
100 }
Calin Juravled0d48522014-11-04 16:40:20 +0000101 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000102 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000103 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Calin Juravled0d48522014-11-04 16:40:20 +0000104 }
105
Alexandre Rames8158f282015-08-07 10:26:17 +0100106 bool IsFatal() const OVERRIDE { return true; }
107
Alexandre Rames9931f312015-06-19 14:47:01 +0100108 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
109
Calin Juravled0d48522014-11-04 16:40:20 +0000110 private:
Calin Juravled0d48522014-11-04 16:40:20 +0000111 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
112};
113
Andreas Gampe85b62f22015-09-09 13:15:38 -0700114class SuspendCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000115 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000116 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000117 : SlowPathCode(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000118
Alexandre Rames67555f72014-11-18 10:55:16 +0000119 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100120 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000121 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100122 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000123 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000124 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 if (successor_ == nullptr) {
126 __ b(GetReturnLabel());
127 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100128 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000130 }
131
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100132 Label* GetReturnLabel() {
133 DCHECK(successor_ == nullptr);
134 return &return_label_;
135 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000136
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100137 HBasicBlock* GetSuccessor() const {
138 return successor_;
139 }
140
Alexandre Rames9931f312015-06-19 14:47:01 +0100141 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
142
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000143 private:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100144 // If not null, the block to branch to after the suspend check.
145 HBasicBlock* const successor_;
146
147 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000148 Label return_label_;
149
150 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
151};
152
Andreas Gampe85b62f22015-09-09 13:15:38 -0700153class BoundsCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100154 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100155 explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000156 : SlowPathCode(instruction) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100157
Alexandre Rames67555f72014-11-18 10:55:16 +0000158 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100159 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100160 LocationSummary* locations = instruction_->GetLocations();
161
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000163 if (instruction_->CanThrowIntoCatchBlock()) {
164 // Live registers will be restored in the catch block if caught.
165 SaveLiveRegisters(codegen, instruction_->GetLocations());
166 }
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000167 // We're moving two locations to locations that could overlap, so we need a parallel
168 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100169 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000170 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100171 locations->InAt(0),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000172 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100173 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100174 locations->InAt(1),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100175 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
176 Primitive::kPrimInt);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100177 uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt()
178 ? QUICK_ENTRY_POINT(pThrowStringBounds)
179 : QUICK_ENTRY_POINT(pThrowArrayBounds);
180 arm_codegen->InvokeRuntime(entry_point_offset, instruction_, instruction_->GetDexPc(), this);
181 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Roland Levillain888d0672015-11-23 18:53:50 +0000182 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 }
184
Alexandre Rames8158f282015-08-07 10:26:17 +0100185 bool IsFatal() const OVERRIDE { return true; }
186
Alexandre Rames9931f312015-06-19 14:47:01 +0100187 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
188
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100189 private:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100190 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
191};
192
Andreas Gampe85b62f22015-09-09 13:15:38 -0700193class LoadClassSlowPathARM : public SlowPathCode {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100194 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000195 LoadClassSlowPathARM(HLoadClass* cls,
196 HInstruction* at,
197 uint32_t dex_pc,
198 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000199 : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
201 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202
Alexandre Rames67555f72014-11-18 10:55:16 +0000203 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 LocationSummary* locations = at_->GetLocations();
205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
207 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000208 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 int32_t entry_point_offset = do_clinit_
213 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
214 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000215 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Roland Levillain888d0672015-11-23 18:53:50 +0000216 if (do_clinit_) {
217 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
218 } else {
219 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
220 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000221
222 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000223 Location out = locations->Out();
224 if (out.IsValid()) {
225 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000226 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
227 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000228 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100229 __ b(GetExitLabel());
230 }
231
Alexandre Rames9931f312015-06-19 14:47:01 +0100232 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
233
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100234 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000235 // The class this slow path will load.
236 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100237
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000238 // The instruction where this slow path is happening.
239 // (Might be the load class or an initialization check).
240 HInstruction* const at_;
241
242 // The dex PC of `at_`.
243 const uint32_t dex_pc_;
244
245 // Whether to initialize the class.
246 const bool do_clinit_;
247
248 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100249};
250
Andreas Gampe85b62f22015-09-09 13:15:38 -0700251class LoadStringSlowPathARM : public SlowPathCode {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000252 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000253 explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000254
Alexandre Rames67555f72014-11-18 10:55:16 +0000255 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000256 LocationSummary* locations = instruction_->GetLocations();
257 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
258
259 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
260 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000261 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000262
263 InvokeRuntimeCallingConvention calling_convention;
David Srbecky9cd6d372016-02-09 15:24:47 +0000264 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
265 __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000266 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000267 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000268 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000269 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
270
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000271 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000272 __ b(GetExitLabel());
273 }
274
Alexandre Rames9931f312015-06-19 14:47:01 +0100275 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
276
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000277 private:
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000278 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
279};
280
Andreas Gampe85b62f22015-09-09 13:15:38 -0700281class TypeCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000282 public:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000283 TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal)
David Srbecky9cd6d372016-02-09 15:24:47 +0000284 : SlowPathCode(instruction), is_fatal_(is_fatal) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
Alexandre Rames67555f72014-11-18 10:55:16 +0000286 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000287 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100288 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
289 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000290 DCHECK(instruction_->IsCheckCast()
291 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000292
293 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
294 __ Bind(GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000295
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000296 if (!is_fatal_) {
297 SaveLiveRegisters(codegen, locations);
298 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000299
300 // We're moving two locations to locations that could overlap, so we need a parallel
301 // move resolver.
302 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000303 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100304 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000305 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100306 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100307 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100308 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
309 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000310
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000311 if (instruction_->IsInstanceOf()) {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100312 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
313 instruction_,
314 instruction_->GetDexPc(),
315 this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000316 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700317 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000318 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
319 } else {
320 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100321 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
322 instruction_,
323 instruction_->GetDexPc(),
324 this);
Roland Levillain3b359c72015-11-17 19:35:12 +0000325 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000326 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000327
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000328 if (!is_fatal_) {
329 RestoreLiveRegisters(codegen, locations);
330 __ b(GetExitLabel());
331 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000332 }
333
Alexandre Rames9931f312015-06-19 14:47:01 +0100334 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
335
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000336 bool IsFatal() const OVERRIDE { return is_fatal_; }
337
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000338 private:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000339 const bool is_fatal_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000340
341 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
342};
343
Andreas Gampe85b62f22015-09-09 13:15:38 -0700344class DeoptimizationSlowPathARM : public SlowPathCode {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700345 public:
Aart Bik42249c32016-01-07 15:33:50 -0800346 explicit DeoptimizationSlowPathARM(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000347 : SlowPathCode(instruction) {}
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700348
349 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800350 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700351 __ Bind(GetEntryLabel());
352 SaveLiveRegisters(codegen, instruction_->GetLocations());
Aart Bik42249c32016-01-07 15:33:50 -0800353 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize),
354 instruction_,
355 instruction_->GetDexPc(),
356 this);
Roland Levillain888d0672015-11-23 18:53:50 +0000357 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700358 }
359
Alexandre Rames9931f312015-06-19 14:47:01 +0100360 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
361
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700362 private:
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700363 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
364};
365
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100366class ArraySetSlowPathARM : public SlowPathCode {
367 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000368 explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCode(instruction) {}
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100369
370 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
371 LocationSummary* locations = instruction_->GetLocations();
372 __ Bind(GetEntryLabel());
373 SaveLiveRegisters(codegen, locations);
374
375 InvokeRuntimeCallingConvention calling_convention;
376 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
377 parallel_move.AddMove(
378 locations->InAt(0),
379 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
380 Primitive::kPrimNot,
381 nullptr);
382 parallel_move.AddMove(
383 locations->InAt(1),
384 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
385 Primitive::kPrimInt,
386 nullptr);
387 parallel_move.AddMove(
388 locations->InAt(2),
389 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
390 Primitive::kPrimNot,
391 nullptr);
392 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
393
394 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
395 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
396 instruction_,
397 instruction_->GetDexPc(),
398 this);
Roland Levillain888d0672015-11-23 18:53:50 +0000399 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100400 RestoreLiveRegisters(codegen, locations);
401 __ b(GetExitLabel());
402 }
403
404 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; }
405
406 private:
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100407 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM);
408};
409
Roland Levillainc9285912015-12-18 10:38:42 +0000410// Slow path marking an object during a read barrier.
411class ReadBarrierMarkSlowPathARM : public SlowPathCode {
412 public:
Roland Levillain02b75802016-07-13 11:54:35 +0100413 ReadBarrierMarkSlowPathARM(HInstruction* instruction, Location obj)
414 : SlowPathCode(instruction), obj_(obj) {
Roland Levillainc9285912015-12-18 10:38:42 +0000415 DCHECK(kEmitCompilerReadBarrier);
416 }
417
418 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; }
419
420 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
421 LocationSummary* locations = instruction_->GetLocations();
Roland Levillain02b75802016-07-13 11:54:35 +0100422 Register reg = obj_.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +0000423 DCHECK(locations->CanCall());
Roland Levillain02b75802016-07-13 11:54:35 +0100424 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg));
Roland Levillainc9285912015-12-18 10:38:42 +0000425 DCHECK(instruction_->IsInstanceFieldGet() ||
426 instruction_->IsStaticFieldGet() ||
427 instruction_->IsArrayGet() ||
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();
435
436 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100437 // No need to save live registers; it's taken care of by the
438 // entrypoint. Also, there is no need to update the stack mask,
439 // as this runtime call will not trigger a garbage collection.
Roland Levillainc9285912015-12-18 10:38:42 +0000440 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Roland Levillain02b75802016-07-13 11:54:35 +0100441 DCHECK_NE(reg, SP);
442 DCHECK_NE(reg, LR);
443 DCHECK_NE(reg, PC);
444 DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg;
445 // "Compact" slow path, saving two moves.
446 //
447 // Instead of using the standard runtime calling convention (input
448 // and output in R0):
449 //
450 // R0 <- obj
451 // R0 <- ReadBarrierMark(R0)
452 // obj <- R0
453 //
454 // we just use rX (the register holding `obj`) as input and output
455 // of a dedicated entrypoint:
456 //
457 // rX <- ReadBarrierMarkRegX(rX)
458 //
459 int32_t entry_point_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -0700460 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg);
Roland Levillaindec8f632016-07-22 17:10:06 +0100461 // This runtime call does not require a stack map.
462 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
Roland Levillainc9285912015-12-18 10:38:42 +0000463 __ b(GetExitLabel());
464 }
465
466 private:
Roland Levillainc9285912015-12-18 10:38:42 +0000467 const Location obj_;
468
469 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM);
470};
471
Roland Levillain3b359c72015-11-17 19:35:12 +0000472// Slow path generating a read barrier for a heap reference.
473class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode {
474 public:
475 ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction,
476 Location out,
477 Location ref,
478 Location obj,
479 uint32_t offset,
480 Location index)
David Srbecky9cd6d372016-02-09 15:24:47 +0000481 : SlowPathCode(instruction),
Roland Levillain3b359c72015-11-17 19:35:12 +0000482 out_(out),
483 ref_(ref),
484 obj_(obj),
485 offset_(offset),
486 index_(index) {
487 DCHECK(kEmitCompilerReadBarrier);
488 // If `obj` is equal to `out` or `ref`, it means the initial object
489 // has been overwritten by (or after) the heap object reference load
490 // to be instrumented, e.g.:
491 //
492 // __ LoadFromOffset(kLoadWord, out, out, offset);
Roland Levillainc9285912015-12-18 10:38:42 +0000493 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
Roland Levillain3b359c72015-11-17 19:35:12 +0000494 //
495 // In that case, we have lost the information about the original
496 // object, and the emitted read barrier cannot work properly.
497 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
498 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
499 }
500
501 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
502 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
503 LocationSummary* locations = instruction_->GetLocations();
504 Register reg_out = out_.AsRegister<Register>();
505 DCHECK(locations->CanCall());
506 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillain3d312422016-06-23 13:53:42 +0100507 DCHECK(instruction_->IsInstanceFieldGet() ||
508 instruction_->IsStaticFieldGet() ||
509 instruction_->IsArrayGet() ||
510 instruction_->IsInstanceOf() ||
511 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100512 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillainc9285912015-12-18 10:38:42 +0000513 << "Unexpected instruction in read barrier for heap reference slow path: "
514 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000515
516 __ Bind(GetEntryLabel());
517 SaveLiveRegisters(codegen, locations);
518
519 // We may have to change the index's value, but as `index_` is a
520 // constant member (like other "inputs" of this slow path),
521 // introduce a copy of it, `index`.
522 Location index = index_;
523 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100524 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain3b359c72015-11-17 19:35:12 +0000525 if (instruction_->IsArrayGet()) {
526 // Compute the actual memory offset and store it in `index`.
527 Register index_reg = index_.AsRegister<Register>();
528 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
529 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
530 // We are about to change the value of `index_reg` (see the
531 // calls to art::arm::Thumb2Assembler::Lsl and
532 // art::arm::Thumb2Assembler::AddConstant below), but it has
533 // not been saved by the previous call to
534 // art::SlowPathCode::SaveLiveRegisters, as it is a
535 // callee-save register --
536 // art::SlowPathCode::SaveLiveRegisters does not consider
537 // callee-save registers, as it has been designed with the
538 // assumption that callee-save registers are supposed to be
539 // handled by the called function. So, as a callee-save
540 // register, `index_reg` _would_ eventually be saved onto
541 // the stack, but it would be too late: we would have
542 // changed its value earlier. Therefore, we manually save
543 // it here into another freely available register,
544 // `free_reg`, chosen of course among the caller-save
545 // registers (as a callee-save `free_reg` register would
546 // exhibit the same problem).
547 //
548 // Note we could have requested a temporary register from
549 // the register allocator instead; but we prefer not to, as
550 // this is a slow path, and we know we can find a
551 // caller-save register that is available.
552 Register free_reg = FindAvailableCallerSaveRegister(codegen);
553 __ Mov(free_reg, index_reg);
554 index_reg = free_reg;
555 index = Location::RegisterLocation(index_reg);
556 } else {
557 // The initial register stored in `index_` has already been
558 // saved in the call to art::SlowPathCode::SaveLiveRegisters
559 // (as it is not a callee-save register), so we can freely
560 // use it.
561 }
562 // Shifting the index value contained in `index_reg` by the scale
563 // factor (2) cannot overflow in practice, as the runtime is
564 // unable to allocate object arrays with a size larger than
565 // 2^26 - 1 (that is, 2^28 - 4 bytes).
566 __ Lsl(index_reg, index_reg, TIMES_4);
567 static_assert(
568 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
569 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
570 __ AddConstant(index_reg, index_reg, offset_);
571 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100572 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
573 // intrinsics, `index_` is not shifted by a scale factor of 2
574 // (as in the case of ArrayGet), as it is actually an offset
575 // to an object field within an object.
576 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000577 DCHECK(instruction_->GetLocations()->Intrinsified());
578 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
579 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
580 << instruction_->AsInvoke()->GetIntrinsic();
581 DCHECK_EQ(offset_, 0U);
582 DCHECK(index_.IsRegisterPair());
583 // UnsafeGet's offset location is a register pair, the low
584 // part contains the correct offset.
585 index = index_.ToLow();
586 }
587 }
588
589 // We're moving two or three locations to locations that could
590 // overlap, so we need a parallel move resolver.
591 InvokeRuntimeCallingConvention calling_convention;
592 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
593 parallel_move.AddMove(ref_,
594 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
595 Primitive::kPrimNot,
596 nullptr);
597 parallel_move.AddMove(obj_,
598 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
599 Primitive::kPrimNot,
600 nullptr);
601 if (index.IsValid()) {
602 parallel_move.AddMove(index,
603 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
604 Primitive::kPrimInt,
605 nullptr);
606 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
607 } else {
608 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
609 __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_);
610 }
611 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow),
612 instruction_,
613 instruction_->GetDexPc(),
614 this);
615 CheckEntrypointTypes<
616 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
617 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
618
619 RestoreLiveRegisters(codegen, locations);
620 __ b(GetExitLabel());
621 }
622
623 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; }
624
625 private:
626 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
627 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
628 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
629 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
630 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
631 return static_cast<Register>(i);
632 }
633 }
634 // We shall never fail to find a free caller-save register, as
635 // there are more than two core caller-save registers on ARM
636 // (meaning it is possible to find one which is different from
637 // `ref` and `obj`).
638 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
639 LOG(FATAL) << "Could not find a free caller-save register";
640 UNREACHABLE();
641 }
642
Roland Levillain3b359c72015-11-17 19:35:12 +0000643 const Location out_;
644 const Location ref_;
645 const Location obj_;
646 const uint32_t offset_;
647 // An additional location containing an index to an array.
648 // Only used for HArrayGet and the UnsafeGetObject &
649 // UnsafeGetObjectVolatile intrinsics.
650 const Location index_;
651
652 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM);
653};
654
655// Slow path generating a read barrier for a GC root.
656class ReadBarrierForRootSlowPathARM : public SlowPathCode {
657 public:
658 ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root)
David Srbecky9cd6d372016-02-09 15:24:47 +0000659 : SlowPathCode(instruction), out_(out), root_(root) {
Roland Levillainc9285912015-12-18 10:38:42 +0000660 DCHECK(kEmitCompilerReadBarrier);
661 }
Roland Levillain3b359c72015-11-17 19:35:12 +0000662
663 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
664 LocationSummary* locations = instruction_->GetLocations();
665 Register reg_out = out_.AsRegister<Register>();
666 DCHECK(locations->CanCall());
667 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillainc9285912015-12-18 10:38:42 +0000668 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
669 << "Unexpected instruction in read barrier for GC root slow path: "
670 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000671
672 __ Bind(GetEntryLabel());
673 SaveLiveRegisters(codegen, locations);
674
675 InvokeRuntimeCallingConvention calling_convention;
676 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
677 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_);
678 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow),
679 instruction_,
680 instruction_->GetDexPc(),
681 this);
682 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
683 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
684
685 RestoreLiveRegisters(codegen, locations);
686 __ b(GetExitLabel());
687 }
688
689 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; }
690
691 private:
Roland Levillain3b359c72015-11-17 19:35:12 +0000692 const Location out_;
693 const Location root_;
694
695 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM);
696};
697
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000698#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100699// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
700#define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT
Dave Allison20dfc792014-06-16 20:44:29 -0700701
Aart Bike9f37602015-10-09 11:15:55 -0700702inline Condition ARMCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700703 switch (cond) {
704 case kCondEQ: return EQ;
705 case kCondNE: return NE;
706 case kCondLT: return LT;
707 case kCondLE: return LE;
708 case kCondGT: return GT;
709 case kCondGE: return GE;
Aart Bike9f37602015-10-09 11:15:55 -0700710 case kCondB: return LO;
711 case kCondBE: return LS;
712 case kCondA: return HI;
713 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700714 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100715 LOG(FATAL) << "Unreachable";
716 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700717}
718
Aart Bike9f37602015-10-09 11:15:55 -0700719// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100720inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700721 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100722 case kCondEQ: return EQ;
723 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -0700724 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100725 case kCondLT: return LO;
726 case kCondLE: return LS;
727 case kCondGT: return HI;
728 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -0700729 // Unsigned remain unchanged.
730 case kCondB: return LO;
731 case kCondBE: return LS;
732 case kCondA: return HI;
733 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700734 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100735 LOG(FATAL) << "Unreachable";
736 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700737}
738
Vladimir Markod6e069b2016-01-18 11:11:01 +0000739inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) {
740 // The ARM condition codes can express all the necessary branches, see the
741 // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual.
742 // There is no dex instruction or HIR that would need the missing conditions
743 // "equal or unordered" or "not equal".
744 switch (cond) {
745 case kCondEQ: return EQ;
746 case kCondNE: return NE /* unordered */;
747 case kCondLT: return gt_bias ? CC : LT /* unordered */;
748 case kCondLE: return gt_bias ? LS : LE /* unordered */;
749 case kCondGT: return gt_bias ? HI /* unordered */ : GT;
750 case kCondGE: return gt_bias ? CS /* unordered */ : GE;
751 default:
752 LOG(FATAL) << "UNREACHABLE";
753 UNREACHABLE();
754 }
755}
756
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100757void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100758 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100759}
760
761void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100762 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100763}
764
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100765size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
766 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
767 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100768}
769
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100770size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
771 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
772 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100773}
774
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000775size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
776 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
777 return kArmWordSize;
778}
779
780size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
781 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
782 return kArmWordSize;
783}
784
Calin Juravle34166012014-12-19 17:22:29 +0000785CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000786 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100787 const CompilerOptions& compiler_options,
788 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000789 : CodeGenerator(graph,
790 kNumberOfCoreRegisters,
791 kNumberOfSRegisters,
792 kNumberOfRegisterPairs,
793 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
794 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +0000795 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
796 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100797 compiler_options,
798 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100799 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100800 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100801 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100802 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100803 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +0000804 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000805 uint32_literals_(std::less<uint32_t>(),
806 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +0100807 method_patches_(MethodReferenceComparator(),
808 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
809 call_patches_(MethodReferenceComparator(),
810 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markob4536b72015-11-24 13:45:23 +0000811 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000812 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
813 boot_image_string_patches_(StringReferenceValueComparator(),
814 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
815 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100816 boot_image_type_patches_(TypeReferenceValueComparator(),
817 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
818 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000819 boot_image_address_patches_(std::less<uint32_t>(),
820 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700821 // Always save the LR register to mimic Quick.
822 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100823}
824
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000825void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
826 // Ensure that we fix up branches and literal loads and emit the literal pool.
827 __ FinalizeCode();
828
829 // Adjust native pc offsets in stack maps.
830 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
831 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
832 uint32_t new_position = __ GetAdjustedPosition(old_position);
833 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
834 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100835 // Adjust pc offsets for the disassembly information.
836 if (disasm_info_ != nullptr) {
837 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
838 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
839 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
840 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
841 it.second.start = __ GetAdjustedPosition(it.second.start);
842 it.second.end = __ GetAdjustedPosition(it.second.end);
843 }
844 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
845 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
846 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
847 }
848 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000849
850 CodeGenerator::Finalize(allocator);
851}
852
David Brazdil58282f42016-01-14 12:45:10 +0000853void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100854 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100855 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100856
857 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100858 blocked_core_registers_[SP] = true;
859 blocked_core_registers_[LR] = true;
860 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100861
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100862 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100863 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100864
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100865 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100866 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100867
David Brazdil58282f42016-01-14 12:45:10 +0000868 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100869 // Stubs do not save callee-save floating point registers. If the graph
870 // is debuggable, we need to deal with these registers differently. For
871 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000872 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
873 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
874 }
875 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100876
877 UpdateBlockedPairRegisters();
878}
879
880void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
881 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
882 ArmManagedRegister current =
883 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
884 if (blocked_core_registers_[current.AsRegisterPairLow()]
885 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
886 blocked_register_pairs_[i] = true;
887 }
888 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100889}
890
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100891InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
Aart Bik42249c32016-01-07 15:33:50 -0800892 : InstructionCodeGenerator(graph, codegen),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100893 assembler_(codegen->GetAssembler()),
894 codegen_(codegen) {}
895
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000896void CodeGeneratorARM::ComputeSpillMask() {
897 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
898 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
David Brazdil58282f42016-01-14 12:45:10 +0000899 // There is no easy instruction to restore just the PC on thumb2. We spill and
900 // restore another arbitrary register.
901 core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000902 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
903 // We use vpush and vpop for saving and restoring floating point registers, which take
904 // a SRegister and the number of registers to save/restore after that SRegister. We
905 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
906 // but in the range.
907 if (fpu_spill_mask_ != 0) {
908 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
909 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
910 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
911 fpu_spill_mask_ |= (1 << i);
912 }
913 }
914}
915
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100916static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100917 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100918}
919
920static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100921 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100922}
923
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000924void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000925 bool skip_overflow_check =
926 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000927 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000928 __ Bind(&frame_entry_label_);
929
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000930 if (HasEmptyFrame()) {
931 return;
932 }
933
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100934 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000935 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
936 __ LoadFromOffset(kLoadWord, IP, IP, 0);
937 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100938 }
939
Andreas Gampe501fd632015-09-10 16:11:06 -0700940 __ PushList(core_spill_mask_);
941 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
942 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000943 if (fpu_spill_mask_ != 0) {
944 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
945 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100946 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100947 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000948 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100949 int adjust = GetFrameSize() - FrameEntrySpillSize();
950 __ AddConstant(SP, -adjust);
951 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100952 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000953}
954
955void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000956 if (HasEmptyFrame()) {
957 __ bx(LR);
958 return;
959 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100960 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100961 int adjust = GetFrameSize() - FrameEntrySpillSize();
962 __ AddConstant(SP, adjust);
963 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000964 if (fpu_spill_mask_ != 0) {
965 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
966 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
Andreas Gampe542451c2016-07-26 09:02:02 -0700967 __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100968 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000969 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700970 // Pop LR into PC to return.
971 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
972 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
973 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100974 __ cfi().RestoreState();
975 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000976}
977
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100978void CodeGeneratorARM::Bind(HBasicBlock* block) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700979 Label* label = GetLabelOf(block);
980 __ BindTrackedLabel(label);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000981}
982
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100983Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100984 switch (type) {
985 case Primitive::kPrimBoolean:
986 case Primitive::kPrimByte:
987 case Primitive::kPrimChar:
988 case Primitive::kPrimShort:
989 case Primitive::kPrimInt:
990 case Primitive::kPrimNot: {
991 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000992 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100993 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100994 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100995 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000996 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100997 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100998 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100999
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001000 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001001 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 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001004 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001005 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001006 if (calling_convention.GetRegisterAt(index) == R1) {
1007 // Skip R1, and use R2_R3 instead.
1008 gp_index_++;
1009 index++;
1010 }
1011 }
1012 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
1013 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001014 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +01001015
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001016 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001017 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001018 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001019 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
1020 }
1021 }
1022
1023 case Primitive::kPrimFloat: {
1024 uint32_t stack_index = stack_index_++;
1025 if (float_index_ % 2 == 0) {
1026 float_index_ = std::max(double_index_, float_index_);
1027 }
1028 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
1029 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
1030 } else {
1031 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
1032 }
1033 }
1034
1035 case Primitive::kPrimDouble: {
1036 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
1037 uint32_t stack_index = stack_index_;
1038 stack_index_ += 2;
1039 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
1040 uint32_t index = double_index_;
1041 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001042 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001043 calling_convention.GetFpuRegisterAt(index),
1044 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001045 DCHECK(ExpectedPairLayout(result));
1046 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001047 } else {
1048 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001049 }
1050 }
1051
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001052 case Primitive::kPrimVoid:
1053 LOG(FATAL) << "Unexpected parameter type " << type;
1054 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001055 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001056 return Location::NoLocation();
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001057}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001058
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001059Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001060 switch (type) {
1061 case Primitive::kPrimBoolean:
1062 case Primitive::kPrimByte:
1063 case Primitive::kPrimChar:
1064 case Primitive::kPrimShort:
1065 case Primitive::kPrimInt:
1066 case Primitive::kPrimNot: {
1067 return Location::RegisterLocation(R0);
1068 }
1069
1070 case Primitive::kPrimFloat: {
1071 return Location::FpuRegisterLocation(S0);
1072 }
1073
1074 case Primitive::kPrimLong: {
1075 return Location::RegisterPairLocation(R0, R1);
1076 }
1077
1078 case Primitive::kPrimDouble: {
1079 return Location::FpuRegisterPairLocation(S0, S1);
1080 }
1081
1082 case Primitive::kPrimVoid:
Roland Levillain3b359c72015-11-17 19:35:12 +00001083 return Location::NoLocation();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001084 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +01001085
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001086 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001087}
1088
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001089Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
1090 return Location::RegisterLocation(kMethodRegisterArgument);
1091}
1092
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001093void CodeGeneratorARM::Move32(Location destination, Location source) {
1094 if (source.Equals(destination)) {
1095 return;
1096 }
1097 if (destination.IsRegister()) {
1098 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001099 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001100 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001101 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001102 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001103 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001104 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001105 } else if (destination.IsFpuRegister()) {
1106 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001107 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001108 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001109 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001110 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001111 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001112 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001113 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001114 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001115 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001116 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001117 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001118 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001119 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001120 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001121 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1122 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001123 }
1124 }
1125}
1126
1127void CodeGeneratorARM::Move64(Location destination, Location source) {
1128 if (source.Equals(destination)) {
1129 return;
1130 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001131 if (destination.IsRegisterPair()) {
1132 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001133 EmitParallelMoves(
1134 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
1135 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001136 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001137 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001138 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
1139 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001140 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001141 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001142 } else if (source.IsFpuRegisterPair()) {
1143 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
1144 destination.AsRegisterPairHigh<Register>(),
1145 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001146 } else {
1147 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001148 DCHECK(ExpectedPairLayout(destination));
1149 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
1150 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001151 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001152 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001153 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001154 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1155 SP,
1156 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001157 } else if (source.IsRegisterPair()) {
1158 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1159 source.AsRegisterPairLow<Register>(),
1160 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001161 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001162 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001163 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001164 } else {
1165 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001166 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001167 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001168 if (source.AsRegisterPairLow<Register>() == R1) {
1169 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001170 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
1171 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001172 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001173 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001174 SP, destination.GetStackIndex());
1175 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001176 } else if (source.IsFpuRegisterPair()) {
1177 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
1178 SP,
1179 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001180 } else {
1181 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001182 EmitParallelMoves(
1183 Location::StackSlot(source.GetStackIndex()),
1184 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001185 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001186 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001187 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
1188 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001189 }
1190 }
1191}
1192
Calin Juravle175dc732015-08-25 15:42:32 +01001193void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1194 DCHECK(location.IsRegister());
1195 __ LoadImmediate(location.AsRegister<Register>(), value);
1196}
1197
Calin Juravlee460d1d2015-09-29 04:52:17 +01001198void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001199 HParallelMove move(GetGraph()->GetArena());
1200 move.AddMove(src, dst, dst_type, nullptr);
1201 GetMoveResolver()->EmitNativeCode(&move);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001202}
1203
1204void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1205 if (location.IsRegister()) {
1206 locations->AddTemp(location);
1207 } else if (location.IsRegisterPair()) {
1208 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1209 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1210 } else {
1211 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1212 }
1213}
1214
Calin Juravle175dc732015-08-25 15:42:32 +01001215void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1216 HInstruction* instruction,
1217 uint32_t dex_pc,
1218 SlowPathCode* slow_path) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001219 InvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value(),
Calin Juravle175dc732015-08-25 15:42:32 +01001220 instruction,
1221 dex_pc,
1222 slow_path);
1223}
1224
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001225void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
1226 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001227 uint32_t dex_pc,
1228 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001229 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001230 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1231 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001232 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001233}
1234
Roland Levillaindec8f632016-07-22 17:10:06 +01001235void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1236 HInstruction* instruction,
1237 SlowPathCode* slow_path) {
1238 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1239 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1240 __ blx(LR);
1241}
1242
David Brazdilfc6a86a2015-06-26 10:33:45 +00001243void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001244 DCHECK(!successor->IsExitBlock());
1245
1246 HBasicBlock* block = got->GetBlock();
1247 HInstruction* previous = got->GetPrevious();
1248
1249 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001250 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001251 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1252 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1253 return;
1254 }
1255
1256 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1257 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1258 }
1259 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001260 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001261 }
1262}
1263
David Brazdilfc6a86a2015-06-26 10:33:45 +00001264void LocationsBuilderARM::VisitGoto(HGoto* got) {
1265 got->SetLocations(nullptr);
1266}
1267
1268void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1269 HandleGoto(got, got->GetSuccessor());
1270}
1271
1272void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1273 try_boundary->SetLocations(nullptr);
1274}
1275
1276void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1277 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1278 if (!successor->IsExitBlock()) {
1279 HandleGoto(try_boundary, successor);
1280 }
1281}
1282
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001283void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001284 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001285}
1286
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001287void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001288}
1289
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001290void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1291 Primitive::Type type = instruction->InputAt(0)->GetType();
1292 Location lhs_loc = instruction->GetLocations()->InAt(0);
1293 Location rhs_loc = instruction->GetLocations()->InAt(1);
1294 if (rhs_loc.IsConstant()) {
1295 // 0.0 is the only immediate that can be encoded directly in
1296 // a VCMP instruction.
1297 //
1298 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1299 // specify that in a floating-point comparison, positive zero
1300 // and negative zero are considered equal, so we can use the
1301 // literal 0.0 for both cases here.
1302 //
1303 // Note however that some methods (Float.equal, Float.compare,
1304 // Float.compareTo, Double.equal, Double.compare,
1305 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1306 // StrictMath.min) consider 0.0 to be (strictly) greater than
1307 // -0.0. So if we ever translate calls to these methods into a
1308 // HCompare instruction, we must handle the -0.0 case with
1309 // care here.
1310 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1311 if (type == Primitive::kPrimFloat) {
1312 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1313 } else {
1314 DCHECK_EQ(type, Primitive::kPrimDouble);
1315 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1316 }
1317 } else {
1318 if (type == Primitive::kPrimFloat) {
1319 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1320 } else {
1321 DCHECK_EQ(type, Primitive::kPrimDouble);
1322 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1323 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1324 }
1325 }
1326}
1327
Roland Levillain4fa13f62015-07-06 18:11:54 +01001328void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1329 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001330 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001331 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001332 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001333}
1334
1335void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1336 Label* true_label,
1337 Label* false_label) {
1338 LocationSummary* locations = cond->GetLocations();
1339 Location left = locations->InAt(0);
1340 Location right = locations->InAt(1);
1341 IfCondition if_cond = cond->GetCondition();
1342
1343 Register left_high = left.AsRegisterPairHigh<Register>();
1344 Register left_low = left.AsRegisterPairLow<Register>();
1345 IfCondition true_high_cond = if_cond;
1346 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001347 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001348
1349 // Set the conditions for the test, remembering that == needs to be
1350 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001351 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001352 switch (if_cond) {
1353 case kCondEQ:
1354 case kCondNE:
1355 // Nothing to do.
1356 break;
1357 case kCondLT:
1358 false_high_cond = kCondGT;
1359 break;
1360 case kCondLE:
1361 true_high_cond = kCondLT;
1362 break;
1363 case kCondGT:
1364 false_high_cond = kCondLT;
1365 break;
1366 case kCondGE:
1367 true_high_cond = kCondGT;
1368 break;
Aart Bike9f37602015-10-09 11:15:55 -07001369 case kCondB:
1370 false_high_cond = kCondA;
1371 break;
1372 case kCondBE:
1373 true_high_cond = kCondB;
1374 break;
1375 case kCondA:
1376 false_high_cond = kCondB;
1377 break;
1378 case kCondAE:
1379 true_high_cond = kCondA;
1380 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001381 }
1382 if (right.IsConstant()) {
1383 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1384 int32_t val_low = Low32Bits(value);
1385 int32_t val_high = High32Bits(value);
1386
Vladimir Markoac6ac102015-12-17 12:14:00 +00001387 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001388 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001389 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001390 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001391 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001392 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001393 __ b(true_label, ARMCondition(true_high_cond));
1394 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001395 }
1396 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001397 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001398 } else {
1399 Register right_high = right.AsRegisterPairHigh<Register>();
1400 Register right_low = right.AsRegisterPairLow<Register>();
1401
1402 __ cmp(left_high, ShifterOperand(right_high));
1403 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001404 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001405 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001406 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001407 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001408 __ b(true_label, ARMCondition(true_high_cond));
1409 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001410 }
1411 // Must be equal high, so compare the lows.
1412 __ cmp(left_low, ShifterOperand(right_low));
1413 }
1414 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001415 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001416 __ b(true_label, final_condition);
1417}
1418
David Brazdil0debae72015-11-12 18:37:00 +00001419void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1420 Label* true_target_in,
1421 Label* false_target_in) {
1422 // Generated branching requires both targets to be explicit. If either of the
1423 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1424 Label fallthrough_target;
1425 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1426 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1427
Roland Levillain4fa13f62015-07-06 18:11:54 +01001428 Primitive::Type type = condition->InputAt(0)->GetType();
1429 switch (type) {
1430 case Primitive::kPrimLong:
1431 GenerateLongComparesAndJumps(condition, true_target, false_target);
1432 break;
1433 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001434 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001435 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001436 GenerateFPJumps(condition, true_target, false_target);
1437 break;
1438 default:
1439 LOG(FATAL) << "Unexpected compare type " << type;
1440 }
1441
David Brazdil0debae72015-11-12 18:37:00 +00001442 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001443 __ b(false_target);
1444 }
David Brazdil0debae72015-11-12 18:37:00 +00001445
1446 if (fallthrough_target.IsLinked()) {
1447 __ Bind(&fallthrough_target);
1448 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001449}
1450
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001451void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001452 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001453 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001454 Label* false_target) {
1455 HInstruction* cond = instruction->InputAt(condition_input_index);
1456
1457 if (true_target == nullptr && false_target == nullptr) {
1458 // Nothing to do. The code always falls through.
1459 return;
1460 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001461 // Constant condition, statically compared against "true" (integer value 1).
1462 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001463 if (true_target != nullptr) {
1464 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001465 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001466 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001467 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001468 if (false_target != nullptr) {
1469 __ b(false_target);
1470 }
1471 }
1472 return;
1473 }
1474
1475 // The following code generates these patterns:
1476 // (1) true_target == nullptr && false_target != nullptr
1477 // - opposite condition true => branch to false_target
1478 // (2) true_target != nullptr && false_target == nullptr
1479 // - condition true => branch to true_target
1480 // (3) true_target != nullptr && false_target != nullptr
1481 // - condition true => branch to true_target
1482 // - branch to false_target
1483 if (IsBooleanValueOrMaterializedCondition(cond)) {
1484 // Condition has been materialized, compare the output to 0.
1485 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1486 DCHECK(cond_val.IsRegister());
1487 if (true_target == nullptr) {
1488 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1489 } else {
1490 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001491 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001492 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001493 // Condition has not been materialized. Use its inputs as the comparison and
1494 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001495 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001496
1497 // If this is a long or FP comparison that has been folded into
1498 // the HCondition, generate the comparison directly.
1499 Primitive::Type type = condition->InputAt(0)->GetType();
1500 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1501 GenerateCompareTestAndBranch(condition, true_target, false_target);
1502 return;
1503 }
1504
1505 LocationSummary* locations = cond->GetLocations();
1506 DCHECK(locations->InAt(0).IsRegister());
1507 Register left = locations->InAt(0).AsRegister<Register>();
1508 Location right = locations->InAt(1);
1509 if (right.IsRegister()) {
1510 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001511 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001512 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001513 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001514 }
1515 if (true_target == nullptr) {
1516 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1517 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001518 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001519 }
Dave Allison20dfc792014-06-16 20:44:29 -07001520 }
David Brazdil0debae72015-11-12 18:37:00 +00001521
1522 // If neither branch falls through (case 3), the conditional branch to `true_target`
1523 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1524 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001525 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001526 }
1527}
1528
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001529void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001530 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1531 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001532 locations->SetInAt(0, Location::RequiresRegister());
1533 }
1534}
1535
1536void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001537 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1538 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1539 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1540 nullptr : codegen_->GetLabelOf(true_successor);
1541 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1542 nullptr : codegen_->GetLabelOf(false_successor);
1543 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001544}
1545
1546void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1547 LocationSummary* locations = new (GetGraph()->GetArena())
1548 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00001549 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001550 locations->SetInAt(0, Location::RequiresRegister());
1551 }
1552}
1553
1554void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08001555 SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001556 GenerateTestAndBranch(deoptimize,
1557 /* condition_input_index */ 0,
1558 slow_path->GetEntryLabel(),
1559 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001560}
Dave Allison20dfc792014-06-16 20:44:29 -07001561
David Brazdil74eb1b22015-12-14 11:44:01 +00001562void LocationsBuilderARM::VisitSelect(HSelect* select) {
1563 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1564 if (Primitive::IsFloatingPointType(select->GetType())) {
1565 locations->SetInAt(0, Location::RequiresFpuRegister());
1566 locations->SetInAt(1, Location::RequiresFpuRegister());
1567 } else {
1568 locations->SetInAt(0, Location::RequiresRegister());
1569 locations->SetInAt(1, Location::RequiresRegister());
1570 }
1571 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1572 locations->SetInAt(2, Location::RequiresRegister());
1573 }
1574 locations->SetOut(Location::SameAsFirstInput());
1575}
1576
1577void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1578 LocationSummary* locations = select->GetLocations();
1579 Label false_target;
1580 GenerateTestAndBranch(select,
1581 /* condition_input_index */ 2,
1582 /* true_target */ nullptr,
1583 &false_target);
1584 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1585 __ Bind(&false_target);
1586}
1587
David Srbecky0cf44932015-12-09 14:09:59 +00001588void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1589 new (GetGraph()->GetArena()) LocationSummary(info);
1590}
1591
David Srbeckyd28f4a02016-03-14 17:14:24 +00001592void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1593 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001594}
1595
1596void CodeGeneratorARM::GenerateNop() {
1597 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001598}
1599
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001600void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001601 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001602 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001603 // Handle the long/FP comparisons made in instruction simplification.
1604 switch (cond->InputAt(0)->GetType()) {
1605 case Primitive::kPrimLong:
1606 locations->SetInAt(0, Location::RequiresRegister());
1607 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001608 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001609 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1610 }
1611 break;
1612
1613 case Primitive::kPrimFloat:
1614 case Primitive::kPrimDouble:
1615 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001616 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001617 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001618 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1619 }
1620 break;
1621
1622 default:
1623 locations->SetInAt(0, Location::RequiresRegister());
1624 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001625 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001626 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1627 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001628 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001629}
1630
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001631void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001632 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001633 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001634 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001635
1636 LocationSummary* locations = cond->GetLocations();
1637 Location left = locations->InAt(0);
1638 Location right = locations->InAt(1);
1639 Register out = locations->Out().AsRegister<Register>();
1640 Label true_label, false_label;
1641
1642 switch (cond->InputAt(0)->GetType()) {
1643 default: {
1644 // Integer case.
1645 if (right.IsRegister()) {
1646 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1647 } else {
1648 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001649 __ CmpConstant(left.AsRegister<Register>(),
1650 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001651 }
Aart Bike9f37602015-10-09 11:15:55 -07001652 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001653 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001654 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001655 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001656 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001657 return;
1658 }
1659 case Primitive::kPrimLong:
1660 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1661 break;
1662 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001663 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001664 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001665 GenerateFPJumps(cond, &true_label, &false_label);
1666 break;
1667 }
1668
1669 // Convert the jumps into the result.
1670 Label done_label;
1671
1672 // False case: result = 0.
1673 __ Bind(&false_label);
1674 __ LoadImmediate(out, 0);
1675 __ b(&done_label);
1676
1677 // True case: result = 1.
1678 __ Bind(&true_label);
1679 __ LoadImmediate(out, 1);
1680 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001681}
1682
1683void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001684 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001685}
1686
1687void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001688 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001689}
1690
1691void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001692 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001693}
1694
1695void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001696 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001697}
1698
1699void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001700 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001701}
1702
1703void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001704 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001705}
1706
1707void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001708 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001709}
1710
1711void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001712 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001713}
1714
1715void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001716 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001717}
1718
1719void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001720 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001721}
1722
1723void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001724 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001725}
1726
1727void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001728 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001729}
1730
Aart Bike9f37602015-10-09 11:15:55 -07001731void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001732 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001733}
1734
1735void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001736 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001737}
1738
1739void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001740 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001741}
1742
1743void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001744 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001745}
1746
1747void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001748 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001749}
1750
1751void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001752 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001753}
1754
1755void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001756 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001757}
1758
1759void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001760 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001761}
1762
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001763void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001764 LocationSummary* locations =
1765 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001766 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001767}
1768
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001769void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001770 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001771}
1772
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001773void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1774 LocationSummary* locations =
1775 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1776 locations->SetOut(Location::ConstantLocation(constant));
1777}
1778
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001779void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001780 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001781}
1782
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001783void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001784 LocationSummary* locations =
1785 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001786 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001787}
1788
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001789void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001790 // Will be generated at use site.
1791}
1792
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001793void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1794 LocationSummary* locations =
1795 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1796 locations->SetOut(Location::ConstantLocation(constant));
1797}
1798
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001799void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001800 // Will be generated at use site.
1801}
1802
1803void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* 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::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001810 // Will be generated at use site.
1811}
1812
Calin Juravle27df7582015-04-17 19:12:31 +01001813void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1814 memory_barrier->SetLocations(nullptr);
1815}
1816
1817void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00001818 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01001819}
1820
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001821void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001822 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001823}
1824
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001825void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001826 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001827}
1828
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001829void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001830 LocationSummary* locations =
1831 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001832 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001833}
1834
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001835void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001836 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001837}
1838
Calin Juravle175dc732015-08-25 15:42:32 +01001839void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1840 // The trampoline uses the same calling convention as dex calling conventions,
1841 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1842 // the method_idx.
1843 HandleInvoke(invoke);
1844}
1845
1846void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1847 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1848}
1849
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001850void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001851 // Explicit clinit checks triggered by static invokes must have been pruned by
1852 // art::PrepareForRegisterAllocation.
1853 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001854
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001855 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001856 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001857 codegen_->GetInstructionSetFeatures());
1858 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00001859 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
1860 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
1861 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001862 return;
1863 }
1864
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001865 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00001866
1867 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
1868 if (invoke->HasPcRelativeDexCache()) {
1869 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
1870 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001871}
1872
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001873static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1874 if (invoke->GetLocations()->Intrinsified()) {
1875 IntrinsicCodeGeneratorARM intrinsic(codegen);
1876 intrinsic.Dispatch(invoke);
1877 return true;
1878 }
1879 return false;
1880}
1881
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001882void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001883 // Explicit clinit checks triggered by static invokes must have been pruned by
1884 // art::PrepareForRegisterAllocation.
1885 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001886
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001887 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1888 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001889 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001890
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001891 LocationSummary* locations = invoke->GetLocations();
1892 codegen_->GenerateStaticOrDirectCall(
1893 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001894 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001895}
1896
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001897void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001898 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001899 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001900}
1901
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001902void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001903 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001904 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001905 codegen_->GetInstructionSetFeatures());
1906 if (intrinsic.TryDispatch(invoke)) {
1907 return;
1908 }
1909
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001910 HandleInvoke(invoke);
1911}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001912
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001913void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001914 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1915 return;
1916 }
1917
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001918 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001919 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001920 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001921}
1922
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001923void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1924 HandleInvoke(invoke);
1925 // Add the hidden argument.
1926 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1927}
1928
1929void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1930 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00001931 LocationSummary* locations = invoke->GetLocations();
1932 Register temp = locations->GetTemp(0).AsRegister<Register>();
1933 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001934 Location receiver = locations->InAt(0);
1935 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1936
Roland Levillain3b359c72015-11-17 19:35:12 +00001937 // Set the hidden argument. This is safe to do this here, as R12
1938 // won't be modified thereafter, before the `blx` (call) instruction.
1939 DCHECK_EQ(R12, hidden_reg);
1940 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001941
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001942 if (receiver.IsStackSlot()) {
1943 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00001944 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001945 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1946 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00001947 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00001948 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001949 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001950 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00001951 // Instead of simply (possibly) unpoisoning `temp` here, we should
1952 // emit a read barrier for the previous class reference load.
1953 // However this is not required in practice, as this is an
1954 // intermediate/temporary reference and because the current
1955 // concurrent copying collector keeps the from-space memory
1956 // intact/accessible until the end of the marking phase (the
1957 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01001958 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001959 __ LoadFromOffset(kLoadWord, temp, temp,
1960 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
1961 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00001962 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001963 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001964 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00001965 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07001966 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001967 // LR = temp->GetEntryPoint();
1968 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1969 // LR();
1970 __ blx(LR);
1971 DCHECK(!codegen_->IsLeafMethod());
1972 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1973}
1974
Roland Levillain88cb1752014-10-20 16:36:47 +01001975void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1976 LocationSummary* locations =
1977 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1978 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001979 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001980 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001981 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1982 break;
1983 }
1984 case Primitive::kPrimLong: {
1985 locations->SetInAt(0, Location::RequiresRegister());
1986 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001987 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001988 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001989
Roland Levillain88cb1752014-10-20 16:36:47 +01001990 case Primitive::kPrimFloat:
1991 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001992 locations->SetInAt(0, Location::RequiresFpuRegister());
1993 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001994 break;
1995
1996 default:
1997 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1998 }
1999}
2000
2001void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
2002 LocationSummary* locations = neg->GetLocations();
2003 Location out = locations->Out();
2004 Location in = locations->InAt(0);
2005 switch (neg->GetResultType()) {
2006 case Primitive::kPrimInt:
2007 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002008 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01002009 break;
2010
2011 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002012 DCHECK(in.IsRegisterPair());
2013 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
2014 __ rsbs(out.AsRegisterPairLow<Register>(),
2015 in.AsRegisterPairLow<Register>(),
2016 ShifterOperand(0));
2017 // We cannot emit an RSC (Reverse Subtract with Carry)
2018 // instruction here, as it does not exist in the Thumb-2
2019 // instruction set. We use the following approach
2020 // using SBC and SUB instead.
2021 //
2022 // out.hi = -C
2023 __ sbc(out.AsRegisterPairHigh<Register>(),
2024 out.AsRegisterPairHigh<Register>(),
2025 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2026 // out.hi = out.hi - in.hi
2027 __ sub(out.AsRegisterPairHigh<Register>(),
2028 out.AsRegisterPairHigh<Register>(),
2029 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2030 break;
2031
Roland Levillain88cb1752014-10-20 16:36:47 +01002032 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002033 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002034 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002035 break;
2036
Roland Levillain88cb1752014-10-20 16:36:47 +01002037 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002038 DCHECK(in.IsFpuRegisterPair());
2039 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2040 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002041 break;
2042
2043 default:
2044 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2045 }
2046}
2047
Roland Levillaindff1f282014-11-05 14:15:05 +00002048void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002049 Primitive::Type result_type = conversion->GetResultType();
2050 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002051 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002052
Roland Levillain5b3ee562015-04-14 16:02:41 +01002053 // The float-to-long, double-to-long and long-to-float type conversions
2054 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002055 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002056 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2057 && result_type == Primitive::kPrimLong)
2058 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002059 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002060 : LocationSummary::kNoCall;
2061 LocationSummary* locations =
2062 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2063
David Brazdilb2bd1c52015-03-25 11:17:37 +00002064 // The Java language does not allow treating boolean as an integral type but
2065 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002066
Roland Levillaindff1f282014-11-05 14:15:05 +00002067 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002068 case Primitive::kPrimByte:
2069 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002070 case Primitive::kPrimLong:
2071 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002072 case Primitive::kPrimBoolean:
2073 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002074 case Primitive::kPrimShort:
2075 case Primitive::kPrimInt:
2076 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002077 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002078 locations->SetInAt(0, Location::RequiresRegister());
2079 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2080 break;
2081
2082 default:
2083 LOG(FATAL) << "Unexpected type conversion from " << input_type
2084 << " to " << result_type;
2085 }
2086 break;
2087
Roland Levillain01a8d712014-11-14 16:27:39 +00002088 case Primitive::kPrimShort:
2089 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002090 case Primitive::kPrimLong:
2091 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002092 case Primitive::kPrimBoolean:
2093 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002094 case Primitive::kPrimByte:
2095 case Primitive::kPrimInt:
2096 case Primitive::kPrimChar:
2097 // Processing a Dex `int-to-short' instruction.
2098 locations->SetInAt(0, Location::RequiresRegister());
2099 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2100 break;
2101
2102 default:
2103 LOG(FATAL) << "Unexpected type conversion from " << input_type
2104 << " to " << result_type;
2105 }
2106 break;
2107
Roland Levillain946e1432014-11-11 17:35:19 +00002108 case Primitive::kPrimInt:
2109 switch (input_type) {
2110 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002111 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002112 locations->SetInAt(0, Location::Any());
2113 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2114 break;
2115
2116 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002117 // Processing a Dex `float-to-int' instruction.
2118 locations->SetInAt(0, Location::RequiresFpuRegister());
2119 locations->SetOut(Location::RequiresRegister());
2120 locations->AddTemp(Location::RequiresFpuRegister());
2121 break;
2122
Roland Levillain946e1432014-11-11 17:35:19 +00002123 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002124 // Processing a Dex `double-to-int' instruction.
2125 locations->SetInAt(0, Location::RequiresFpuRegister());
2126 locations->SetOut(Location::RequiresRegister());
2127 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002128 break;
2129
2130 default:
2131 LOG(FATAL) << "Unexpected type conversion from " << input_type
2132 << " to " << result_type;
2133 }
2134 break;
2135
Roland Levillaindff1f282014-11-05 14:15:05 +00002136 case Primitive::kPrimLong:
2137 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002138 case Primitive::kPrimBoolean:
2139 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002140 case Primitive::kPrimByte:
2141 case Primitive::kPrimShort:
2142 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002143 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002144 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002145 locations->SetInAt(0, Location::RequiresRegister());
2146 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2147 break;
2148
Roland Levillain624279f2014-12-04 11:54:28 +00002149 case Primitive::kPrimFloat: {
2150 // Processing a Dex `float-to-long' instruction.
2151 InvokeRuntimeCallingConvention calling_convention;
2152 locations->SetInAt(0, Location::FpuRegisterLocation(
2153 calling_convention.GetFpuRegisterAt(0)));
2154 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2155 break;
2156 }
2157
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002158 case Primitive::kPrimDouble: {
2159 // Processing a Dex `double-to-long' instruction.
2160 InvokeRuntimeCallingConvention calling_convention;
2161 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2162 calling_convention.GetFpuRegisterAt(0),
2163 calling_convention.GetFpuRegisterAt(1)));
2164 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002165 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002166 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002167
2168 default:
2169 LOG(FATAL) << "Unexpected type conversion from " << input_type
2170 << " to " << result_type;
2171 }
2172 break;
2173
Roland Levillain981e4542014-11-14 11:47:14 +00002174 case Primitive::kPrimChar:
2175 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002176 case Primitive::kPrimLong:
2177 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002178 case Primitive::kPrimBoolean:
2179 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002180 case Primitive::kPrimByte:
2181 case Primitive::kPrimShort:
2182 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002183 // Processing a Dex `int-to-char' instruction.
2184 locations->SetInAt(0, Location::RequiresRegister());
2185 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2186 break;
2187
2188 default:
2189 LOG(FATAL) << "Unexpected type conversion from " << input_type
2190 << " to " << result_type;
2191 }
2192 break;
2193
Roland Levillaindff1f282014-11-05 14:15:05 +00002194 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002195 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002196 case Primitive::kPrimBoolean:
2197 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002198 case Primitive::kPrimByte:
2199 case Primitive::kPrimShort:
2200 case Primitive::kPrimInt:
2201 case Primitive::kPrimChar:
2202 // Processing a Dex `int-to-float' instruction.
2203 locations->SetInAt(0, Location::RequiresRegister());
2204 locations->SetOut(Location::RequiresFpuRegister());
2205 break;
2206
Roland Levillain5b3ee562015-04-14 16:02:41 +01002207 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002208 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002209 InvokeRuntimeCallingConvention calling_convention;
2210 locations->SetInAt(0, Location::RegisterPairLocation(
2211 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2212 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002213 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002214 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002215
Roland Levillaincff13742014-11-17 14:32:17 +00002216 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002217 // Processing a Dex `double-to-float' instruction.
2218 locations->SetInAt(0, Location::RequiresFpuRegister());
2219 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002220 break;
2221
2222 default:
2223 LOG(FATAL) << "Unexpected type conversion from " << input_type
2224 << " to " << result_type;
2225 };
2226 break;
2227
Roland Levillaindff1f282014-11-05 14:15:05 +00002228 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002229 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002230 case Primitive::kPrimBoolean:
2231 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002232 case Primitive::kPrimByte:
2233 case Primitive::kPrimShort:
2234 case Primitive::kPrimInt:
2235 case Primitive::kPrimChar:
2236 // Processing a Dex `int-to-double' instruction.
2237 locations->SetInAt(0, Location::RequiresRegister());
2238 locations->SetOut(Location::RequiresFpuRegister());
2239 break;
2240
2241 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002242 // Processing a Dex `long-to-double' instruction.
2243 locations->SetInAt(0, Location::RequiresRegister());
2244 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002245 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002246 locations->AddTemp(Location::RequiresFpuRegister());
2247 break;
2248
Roland Levillaincff13742014-11-17 14:32:17 +00002249 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002250 // Processing a Dex `float-to-double' instruction.
2251 locations->SetInAt(0, Location::RequiresFpuRegister());
2252 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002253 break;
2254
2255 default:
2256 LOG(FATAL) << "Unexpected type conversion from " << input_type
2257 << " to " << result_type;
2258 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002259 break;
2260
2261 default:
2262 LOG(FATAL) << "Unexpected type conversion from " << input_type
2263 << " to " << result_type;
2264 }
2265}
2266
2267void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2268 LocationSummary* locations = conversion->GetLocations();
2269 Location out = locations->Out();
2270 Location in = locations->InAt(0);
2271 Primitive::Type result_type = conversion->GetResultType();
2272 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002273 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002274 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002275 case Primitive::kPrimByte:
2276 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002277 case Primitive::kPrimLong:
2278 // Type conversion from long to byte is a result of code transformations.
2279 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2280 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002281 case Primitive::kPrimBoolean:
2282 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002283 case Primitive::kPrimShort:
2284 case Primitive::kPrimInt:
2285 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002286 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002287 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002288 break;
2289
2290 default:
2291 LOG(FATAL) << "Unexpected type conversion from " << input_type
2292 << " to " << result_type;
2293 }
2294 break;
2295
Roland Levillain01a8d712014-11-14 16:27:39 +00002296 case Primitive::kPrimShort:
2297 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002298 case Primitive::kPrimLong:
2299 // Type conversion from long to short is a result of code transformations.
2300 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2301 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002302 case Primitive::kPrimBoolean:
2303 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002304 case Primitive::kPrimByte:
2305 case Primitive::kPrimInt:
2306 case Primitive::kPrimChar:
2307 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002308 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002309 break;
2310
2311 default:
2312 LOG(FATAL) << "Unexpected type conversion from " << input_type
2313 << " to " << result_type;
2314 }
2315 break;
2316
Roland Levillain946e1432014-11-11 17:35:19 +00002317 case Primitive::kPrimInt:
2318 switch (input_type) {
2319 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002320 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002321 DCHECK(out.IsRegister());
2322 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002323 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002324 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002325 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002326 } else {
2327 DCHECK(in.IsConstant());
2328 DCHECK(in.GetConstant()->IsLongConstant());
2329 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002330 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002331 }
2332 break;
2333
Roland Levillain3f8f9362014-12-02 17:45:01 +00002334 case Primitive::kPrimFloat: {
2335 // Processing a Dex `float-to-int' instruction.
2336 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002337 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002338 __ vmovrs(out.AsRegister<Register>(), temp);
2339 break;
2340 }
2341
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002342 case Primitive::kPrimDouble: {
2343 // Processing a Dex `double-to-int' instruction.
2344 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002345 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002346 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002347 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002348 }
Roland Levillain946e1432014-11-11 17:35:19 +00002349
2350 default:
2351 LOG(FATAL) << "Unexpected type conversion from " << input_type
2352 << " to " << result_type;
2353 }
2354 break;
2355
Roland Levillaindff1f282014-11-05 14:15:05 +00002356 case Primitive::kPrimLong:
2357 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002358 case Primitive::kPrimBoolean:
2359 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002360 case Primitive::kPrimByte:
2361 case Primitive::kPrimShort:
2362 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002363 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002364 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002365 DCHECK(out.IsRegisterPair());
2366 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002367 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002368 // Sign extension.
2369 __ Asr(out.AsRegisterPairHigh<Register>(),
2370 out.AsRegisterPairLow<Register>(),
2371 31);
2372 break;
2373
2374 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002375 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002376 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2377 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002378 conversion->GetDexPc(),
2379 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002380 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002381 break;
2382
Roland Levillaindff1f282014-11-05 14:15:05 +00002383 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002384 // Processing a Dex `double-to-long' instruction.
2385 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2386 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002387 conversion->GetDexPc(),
2388 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002389 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002390 break;
2391
2392 default:
2393 LOG(FATAL) << "Unexpected type conversion from " << input_type
2394 << " to " << result_type;
2395 }
2396 break;
2397
Roland Levillain981e4542014-11-14 11:47:14 +00002398 case Primitive::kPrimChar:
2399 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002400 case Primitive::kPrimLong:
2401 // Type conversion from long to char is a result of code transformations.
2402 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2403 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002404 case Primitive::kPrimBoolean:
2405 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002406 case Primitive::kPrimByte:
2407 case Primitive::kPrimShort:
2408 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002409 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002410 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002411 break;
2412
2413 default:
2414 LOG(FATAL) << "Unexpected type conversion from " << input_type
2415 << " to " << result_type;
2416 }
2417 break;
2418
Roland Levillaindff1f282014-11-05 14:15:05 +00002419 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002420 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002421 case Primitive::kPrimBoolean:
2422 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002423 case Primitive::kPrimByte:
2424 case Primitive::kPrimShort:
2425 case Primitive::kPrimInt:
2426 case Primitive::kPrimChar: {
2427 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002428 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2429 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002430 break;
2431 }
2432
Roland Levillain5b3ee562015-04-14 16:02:41 +01002433 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002434 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002435 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2436 conversion,
2437 conversion->GetDexPc(),
2438 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002439 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002440 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002441
Roland Levillaincff13742014-11-17 14:32:17 +00002442 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002443 // Processing a Dex `double-to-float' instruction.
2444 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2445 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002446 break;
2447
2448 default:
2449 LOG(FATAL) << "Unexpected type conversion from " << input_type
2450 << " to " << result_type;
2451 };
2452 break;
2453
Roland Levillaindff1f282014-11-05 14:15:05 +00002454 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002455 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002456 case Primitive::kPrimBoolean:
2457 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002458 case Primitive::kPrimByte:
2459 case Primitive::kPrimShort:
2460 case Primitive::kPrimInt:
2461 case Primitive::kPrimChar: {
2462 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002463 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002464 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2465 out.AsFpuRegisterPairLow<SRegister>());
2466 break;
2467 }
2468
Roland Levillain647b9ed2014-11-27 12:06:00 +00002469 case Primitive::kPrimLong: {
2470 // Processing a Dex `long-to-double' instruction.
2471 Register low = in.AsRegisterPairLow<Register>();
2472 Register high = in.AsRegisterPairHigh<Register>();
2473 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2474 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002475 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002476 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002477 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2478 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002479
Roland Levillain682393c2015-04-14 15:57:52 +01002480 // temp_d = int-to-double(high)
2481 __ vmovsr(temp_s, high);
2482 __ vcvtdi(temp_d, temp_s);
2483 // constant_d = k2Pow32EncodingForDouble
2484 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2485 // out_d = unsigned-to-double(low)
2486 __ vmovsr(out_s, low);
2487 __ vcvtdu(out_d, out_s);
2488 // out_d += temp_d * constant_d
2489 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002490 break;
2491 }
2492
Roland Levillaincff13742014-11-17 14:32:17 +00002493 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002494 // Processing a Dex `float-to-double' instruction.
2495 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2496 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002497 break;
2498
2499 default:
2500 LOG(FATAL) << "Unexpected type conversion from " << input_type
2501 << " to " << result_type;
2502 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002503 break;
2504
2505 default:
2506 LOG(FATAL) << "Unexpected type conversion from " << input_type
2507 << " to " << result_type;
2508 }
2509}
2510
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002511void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002512 LocationSummary* locations =
2513 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002514 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002515 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002516 locations->SetInAt(0, Location::RequiresRegister());
2517 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002518 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2519 break;
2520 }
2521
2522 case Primitive::kPrimLong: {
2523 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002524 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002525 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002526 break;
2527 }
2528
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002529 case Primitive::kPrimFloat:
2530 case Primitive::kPrimDouble: {
2531 locations->SetInAt(0, Location::RequiresFpuRegister());
2532 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002533 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002534 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002535 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002536
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002537 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002538 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002539 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002540}
2541
2542void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2543 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002544 Location out = locations->Out();
2545 Location first = locations->InAt(0);
2546 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002547 switch (add->GetResultType()) {
2548 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002549 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002550 __ add(out.AsRegister<Register>(),
2551 first.AsRegister<Register>(),
2552 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002553 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002554 __ AddConstant(out.AsRegister<Register>(),
2555 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002556 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002557 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002558 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002559
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002560 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002561 if (second.IsConstant()) {
2562 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2563 GenerateAddLongConst(out, first, value);
2564 } else {
2565 DCHECK(second.IsRegisterPair());
2566 __ adds(out.AsRegisterPairLow<Register>(),
2567 first.AsRegisterPairLow<Register>(),
2568 ShifterOperand(second.AsRegisterPairLow<Register>()));
2569 __ adc(out.AsRegisterPairHigh<Register>(),
2570 first.AsRegisterPairHigh<Register>(),
2571 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2572 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002573 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002574 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002575
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002576 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002577 __ vadds(out.AsFpuRegister<SRegister>(),
2578 first.AsFpuRegister<SRegister>(),
2579 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002580 break;
2581
2582 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002583 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2584 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2585 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002586 break;
2587
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002588 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002589 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002590 }
2591}
2592
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002593void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002594 LocationSummary* locations =
2595 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002596 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002597 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002598 locations->SetInAt(0, Location::RequiresRegister());
2599 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002600 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2601 break;
2602 }
2603
2604 case Primitive::kPrimLong: {
2605 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002606 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002607 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002608 break;
2609 }
Calin Juravle11351682014-10-23 15:38:15 +01002610 case Primitive::kPrimFloat:
2611 case Primitive::kPrimDouble: {
2612 locations->SetInAt(0, Location::RequiresFpuRegister());
2613 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002614 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002615 break;
Calin Juravle11351682014-10-23 15:38:15 +01002616 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002617 default:
Calin Juravle11351682014-10-23 15:38:15 +01002618 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002619 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002620}
2621
2622void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2623 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002624 Location out = locations->Out();
2625 Location first = locations->InAt(0);
2626 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002627 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002628 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002629 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002630 __ sub(out.AsRegister<Register>(),
2631 first.AsRegister<Register>(),
2632 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002633 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002634 __ AddConstant(out.AsRegister<Register>(),
2635 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002636 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002637 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002638 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002639 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002640
Calin Juravle11351682014-10-23 15:38:15 +01002641 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002642 if (second.IsConstant()) {
2643 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2644 GenerateAddLongConst(out, first, -value);
2645 } else {
2646 DCHECK(second.IsRegisterPair());
2647 __ subs(out.AsRegisterPairLow<Register>(),
2648 first.AsRegisterPairLow<Register>(),
2649 ShifterOperand(second.AsRegisterPairLow<Register>()));
2650 __ sbc(out.AsRegisterPairHigh<Register>(),
2651 first.AsRegisterPairHigh<Register>(),
2652 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2653 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002654 break;
Calin Juravle11351682014-10-23 15:38:15 +01002655 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002656
Calin Juravle11351682014-10-23 15:38:15 +01002657 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002658 __ vsubs(out.AsFpuRegister<SRegister>(),
2659 first.AsFpuRegister<SRegister>(),
2660 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002661 break;
Calin Juravle11351682014-10-23 15:38:15 +01002662 }
2663
2664 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002665 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2666 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2667 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002668 break;
2669 }
2670
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002671
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002672 default:
Calin Juravle11351682014-10-23 15:38:15 +01002673 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002674 }
2675}
2676
Calin Juravle34bacdf2014-10-07 20:23:36 +01002677void LocationsBuilderARM::VisitMul(HMul* mul) {
2678 LocationSummary* locations =
2679 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2680 switch (mul->GetResultType()) {
2681 case Primitive::kPrimInt:
2682 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002683 locations->SetInAt(0, Location::RequiresRegister());
2684 locations->SetInAt(1, Location::RequiresRegister());
2685 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002686 break;
2687 }
2688
Calin Juravleb5bfa962014-10-21 18:02:24 +01002689 case Primitive::kPrimFloat:
2690 case Primitive::kPrimDouble: {
2691 locations->SetInAt(0, Location::RequiresFpuRegister());
2692 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002693 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002694 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002695 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002696
2697 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002698 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002699 }
2700}
2701
2702void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2703 LocationSummary* locations = mul->GetLocations();
2704 Location out = locations->Out();
2705 Location first = locations->InAt(0);
2706 Location second = locations->InAt(1);
2707 switch (mul->GetResultType()) {
2708 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002709 __ mul(out.AsRegister<Register>(),
2710 first.AsRegister<Register>(),
2711 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002712 break;
2713 }
2714 case Primitive::kPrimLong: {
2715 Register out_hi = out.AsRegisterPairHigh<Register>();
2716 Register out_lo = out.AsRegisterPairLow<Register>();
2717 Register in1_hi = first.AsRegisterPairHigh<Register>();
2718 Register in1_lo = first.AsRegisterPairLow<Register>();
2719 Register in2_hi = second.AsRegisterPairHigh<Register>();
2720 Register in2_lo = second.AsRegisterPairLow<Register>();
2721
2722 // Extra checks to protect caused by the existence of R1_R2.
2723 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2724 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2725 DCHECK_NE(out_hi, in1_lo);
2726 DCHECK_NE(out_hi, in2_lo);
2727
2728 // input: in1 - 64 bits, in2 - 64 bits
2729 // output: out
2730 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2731 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2732 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2733
2734 // IP <- in1.lo * in2.hi
2735 __ mul(IP, in1_lo, in2_hi);
2736 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2737 __ mla(out_hi, in1_hi, in2_lo, IP);
2738 // out.lo <- (in1.lo * in2.lo)[31:0];
2739 __ umull(out_lo, IP, in1_lo, in2_lo);
2740 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2741 __ add(out_hi, out_hi, ShifterOperand(IP));
2742 break;
2743 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002744
2745 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002746 __ vmuls(out.AsFpuRegister<SRegister>(),
2747 first.AsFpuRegister<SRegister>(),
2748 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002749 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002750 }
2751
2752 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002753 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2754 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2755 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002756 break;
2757 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002758
2759 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002760 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002761 }
2762}
2763
Zheng Xuc6667102015-05-15 16:08:45 +08002764void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2765 DCHECK(instruction->IsDiv() || instruction->IsRem());
2766 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2767
2768 LocationSummary* locations = instruction->GetLocations();
2769 Location second = locations->InAt(1);
2770 DCHECK(second.IsConstant());
2771
2772 Register out = locations->Out().AsRegister<Register>();
2773 Register dividend = locations->InAt(0).AsRegister<Register>();
2774 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2775 DCHECK(imm == 1 || imm == -1);
2776
2777 if (instruction->IsRem()) {
2778 __ LoadImmediate(out, 0);
2779 } else {
2780 if (imm == 1) {
2781 __ Mov(out, dividend);
2782 } else {
2783 __ rsb(out, dividend, ShifterOperand(0));
2784 }
2785 }
2786}
2787
2788void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2789 DCHECK(instruction->IsDiv() || instruction->IsRem());
2790 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2791
2792 LocationSummary* locations = instruction->GetLocations();
2793 Location second = locations->InAt(1);
2794 DCHECK(second.IsConstant());
2795
2796 Register out = locations->Out().AsRegister<Register>();
2797 Register dividend = locations->InAt(0).AsRegister<Register>();
2798 Register temp = locations->GetTemp(0).AsRegister<Register>();
2799 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002800 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002801 int ctz_imm = CTZ(abs_imm);
2802
2803 if (ctz_imm == 1) {
2804 __ Lsr(temp, dividend, 32 - ctz_imm);
2805 } else {
2806 __ Asr(temp, dividend, 31);
2807 __ Lsr(temp, temp, 32 - ctz_imm);
2808 }
2809 __ add(out, temp, ShifterOperand(dividend));
2810
2811 if (instruction->IsDiv()) {
2812 __ Asr(out, out, ctz_imm);
2813 if (imm < 0) {
2814 __ rsb(out, out, ShifterOperand(0));
2815 }
2816 } else {
2817 __ ubfx(out, out, 0, ctz_imm);
2818 __ sub(out, out, ShifterOperand(temp));
2819 }
2820}
2821
2822void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2823 DCHECK(instruction->IsDiv() || instruction->IsRem());
2824 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2825
2826 LocationSummary* locations = instruction->GetLocations();
2827 Location second = locations->InAt(1);
2828 DCHECK(second.IsConstant());
2829
2830 Register out = locations->Out().AsRegister<Register>();
2831 Register dividend = locations->InAt(0).AsRegister<Register>();
2832 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2833 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2834 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2835
2836 int64_t magic;
2837 int shift;
2838 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2839
2840 __ LoadImmediate(temp1, magic);
2841 __ smull(temp2, temp1, dividend, temp1);
2842
2843 if (imm > 0 && magic < 0) {
2844 __ add(temp1, temp1, ShifterOperand(dividend));
2845 } else if (imm < 0 && magic > 0) {
2846 __ sub(temp1, temp1, ShifterOperand(dividend));
2847 }
2848
2849 if (shift != 0) {
2850 __ Asr(temp1, temp1, shift);
2851 }
2852
2853 if (instruction->IsDiv()) {
2854 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2855 } else {
2856 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2857 // TODO: Strength reduction for mls.
2858 __ LoadImmediate(temp2, imm);
2859 __ mls(out, temp1, temp2, dividend);
2860 }
2861}
2862
2863void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2864 DCHECK(instruction->IsDiv() || instruction->IsRem());
2865 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2866
2867 LocationSummary* locations = instruction->GetLocations();
2868 Location second = locations->InAt(1);
2869 DCHECK(second.IsConstant());
2870
2871 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2872 if (imm == 0) {
2873 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2874 } else if (imm == 1 || imm == -1) {
2875 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002876 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002877 DivRemByPowerOfTwo(instruction);
2878 } else {
2879 DCHECK(imm <= -2 || imm >= 2);
2880 GenerateDivRemWithAnyConstant(instruction);
2881 }
2882}
2883
Calin Juravle7c4954d2014-10-28 16:57:40 +00002884void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002885 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2886 if (div->GetResultType() == Primitive::kPrimLong) {
2887 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002888 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002889 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2890 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002891 } else if (div->GetResultType() == Primitive::kPrimInt &&
2892 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2893 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002894 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002895 }
2896
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002897 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2898
Calin Juravle7c4954d2014-10-28 16:57:40 +00002899 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002900 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002901 if (div->InputAt(1)->IsConstant()) {
2902 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00002903 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08002904 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002905 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
2906 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08002907 // No temp register required.
2908 } else {
2909 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002910 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002911 locations->AddTemp(Location::RequiresRegister());
2912 }
2913 }
2914 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002915 locations->SetInAt(0, Location::RequiresRegister());
2916 locations->SetInAt(1, Location::RequiresRegister());
2917 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2918 } else {
2919 InvokeRuntimeCallingConvention calling_convention;
2920 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2921 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2922 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2923 // we only need the former.
2924 locations->SetOut(Location::RegisterLocation(R0));
2925 }
Calin Juravled0d48522014-11-04 16:40:20 +00002926 break;
2927 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002928 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002929 InvokeRuntimeCallingConvention calling_convention;
2930 locations->SetInAt(0, Location::RegisterPairLocation(
2931 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2932 locations->SetInAt(1, Location::RegisterPairLocation(
2933 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002934 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002935 break;
2936 }
2937 case Primitive::kPrimFloat:
2938 case Primitive::kPrimDouble: {
2939 locations->SetInAt(0, Location::RequiresFpuRegister());
2940 locations->SetInAt(1, Location::RequiresFpuRegister());
2941 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2942 break;
2943 }
2944
2945 default:
2946 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2947 }
2948}
2949
2950void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2951 LocationSummary* locations = div->GetLocations();
2952 Location out = locations->Out();
2953 Location first = locations->InAt(0);
2954 Location second = locations->InAt(1);
2955
2956 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002957 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002958 if (second.IsConstant()) {
2959 GenerateDivRemConstantIntegral(div);
2960 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002961 __ sdiv(out.AsRegister<Register>(),
2962 first.AsRegister<Register>(),
2963 second.AsRegister<Register>());
2964 } else {
2965 InvokeRuntimeCallingConvention calling_convention;
2966 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2967 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2968 DCHECK_EQ(R0, out.AsRegister<Register>());
2969
2970 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002971 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002972 }
Calin Juravled0d48522014-11-04 16:40:20 +00002973 break;
2974 }
2975
Calin Juravle7c4954d2014-10-28 16:57:40 +00002976 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002977 InvokeRuntimeCallingConvention calling_convention;
2978 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2979 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2980 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2981 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2982 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002983 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002984
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002985 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002986 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002987 break;
2988 }
2989
2990 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002991 __ vdivs(out.AsFpuRegister<SRegister>(),
2992 first.AsFpuRegister<SRegister>(),
2993 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002994 break;
2995 }
2996
2997 case Primitive::kPrimDouble: {
2998 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2999 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
3000 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
3001 break;
3002 }
3003
3004 default:
3005 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3006 }
3007}
3008
Calin Juravlebacfec32014-11-14 15:54:36 +00003009void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003010 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003011
3012 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003013 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08003014 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
3015 // sdiv will be replaced by other instruction sequence.
3016 call_kind = LocationSummary::kNoCall;
3017 } else if ((rem->GetResultType() == Primitive::kPrimInt)
3018 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003019 // Have hardware divide instruction for int, do it with three instructions.
3020 call_kind = LocationSummary::kNoCall;
3021 }
3022
Calin Juravlebacfec32014-11-14 15:54:36 +00003023 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3024
Calin Juravled2ec87d2014-12-08 14:24:46 +00003025 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003026 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003027 if (rem->InputAt(1)->IsConstant()) {
3028 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003029 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003030 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003031 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3032 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003033 // No temp register required.
3034 } else {
3035 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003036 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003037 locations->AddTemp(Location::RequiresRegister());
3038 }
3039 }
3040 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003041 locations->SetInAt(0, Location::RequiresRegister());
3042 locations->SetInAt(1, Location::RequiresRegister());
3043 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3044 locations->AddTemp(Location::RequiresRegister());
3045 } else {
3046 InvokeRuntimeCallingConvention calling_convention;
3047 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3048 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3049 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3050 // we only need the latter.
3051 locations->SetOut(Location::RegisterLocation(R1));
3052 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003053 break;
3054 }
3055 case Primitive::kPrimLong: {
3056 InvokeRuntimeCallingConvention calling_convention;
3057 locations->SetInAt(0, Location::RegisterPairLocation(
3058 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3059 locations->SetInAt(1, Location::RegisterPairLocation(
3060 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3061 // The runtime helper puts the output in R2,R3.
3062 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3063 break;
3064 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003065 case Primitive::kPrimFloat: {
3066 InvokeRuntimeCallingConvention calling_convention;
3067 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3068 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3069 locations->SetOut(Location::FpuRegisterLocation(S0));
3070 break;
3071 }
3072
Calin Juravlebacfec32014-11-14 15:54:36 +00003073 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003074 InvokeRuntimeCallingConvention calling_convention;
3075 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3076 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3077 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3078 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3079 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003080 break;
3081 }
3082
3083 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003084 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003085 }
3086}
3087
3088void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3089 LocationSummary* locations = rem->GetLocations();
3090 Location out = locations->Out();
3091 Location first = locations->InAt(0);
3092 Location second = locations->InAt(1);
3093
Calin Juravled2ec87d2014-12-08 14:24:46 +00003094 Primitive::Type type = rem->GetResultType();
3095 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003096 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003097 if (second.IsConstant()) {
3098 GenerateDivRemConstantIntegral(rem);
3099 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003100 Register reg1 = first.AsRegister<Register>();
3101 Register reg2 = second.AsRegister<Register>();
3102 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003103
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003104 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003105 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003106 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003107 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003108 } else {
3109 InvokeRuntimeCallingConvention calling_convention;
3110 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3111 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3112 DCHECK_EQ(R1, out.AsRegister<Register>());
3113
3114 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003115 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003116 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003117 break;
3118 }
3119
3120 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003121 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003122 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003123 break;
3124 }
3125
Calin Juravled2ec87d2014-12-08 14:24:46 +00003126 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003127 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003128 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003129 break;
3130 }
3131
Calin Juravlebacfec32014-11-14 15:54:36 +00003132 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003133 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003134 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003135 break;
3136 }
3137
3138 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003139 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003140 }
3141}
3142
Calin Juravled0d48522014-11-04 16:40:20 +00003143void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003144 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3145 ? LocationSummary::kCallOnSlowPath
3146 : LocationSummary::kNoCall;
3147 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003148 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003149 if (instruction->HasUses()) {
3150 locations->SetOut(Location::SameAsFirstInput());
3151 }
3152}
3153
3154void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003155 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003156 codegen_->AddSlowPath(slow_path);
3157
3158 LocationSummary* locations = instruction->GetLocations();
3159 Location value = locations->InAt(0);
3160
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003161 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003162 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003163 case Primitive::kPrimByte:
3164 case Primitive::kPrimChar:
3165 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003166 case Primitive::kPrimInt: {
3167 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003168 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003169 } else {
3170 DCHECK(value.IsConstant()) << value;
3171 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3172 __ b(slow_path->GetEntryLabel());
3173 }
3174 }
3175 break;
3176 }
3177 case Primitive::kPrimLong: {
3178 if (value.IsRegisterPair()) {
3179 __ orrs(IP,
3180 value.AsRegisterPairLow<Register>(),
3181 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3182 __ b(slow_path->GetEntryLabel(), EQ);
3183 } else {
3184 DCHECK(value.IsConstant()) << value;
3185 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3186 __ b(slow_path->GetEntryLabel());
3187 }
3188 }
3189 break;
3190 default:
3191 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3192 }
3193 }
Calin Juravled0d48522014-11-04 16:40:20 +00003194}
3195
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003196void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3197 Register in = locations->InAt(0).AsRegister<Register>();
3198 Location rhs = locations->InAt(1);
3199 Register out = locations->Out().AsRegister<Register>();
3200
3201 if (rhs.IsConstant()) {
3202 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3203 // so map all rotations to a +ve. equivalent in that range.
3204 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3205 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3206 if (rot) {
3207 // Rotate, mapping left rotations to right equivalents if necessary.
3208 // (e.g. left by 2 bits == right by 30.)
3209 __ Ror(out, in, rot);
3210 } else if (out != in) {
3211 __ Mov(out, in);
3212 }
3213 } else {
3214 __ Ror(out, in, rhs.AsRegister<Register>());
3215 }
3216}
3217
3218// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3219// rotates by swapping input regs (effectively rotating by the first 32-bits of
3220// a larger rotation) or flipping direction (thus treating larger right/left
3221// rotations as sub-word sized rotations in the other direction) as appropriate.
3222void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3223 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3224 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3225 Location rhs = locations->InAt(1);
3226 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3227 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3228
3229 if (rhs.IsConstant()) {
3230 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3231 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003232 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003233 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3234 // logic below to a simple pair of binary orr.
3235 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3236 if (rot >= kArmBitsPerWord) {
3237 rot -= kArmBitsPerWord;
3238 std::swap(in_reg_hi, in_reg_lo);
3239 }
3240 // Rotate, or mov to out for zero or word size rotations.
3241 if (rot != 0u) {
3242 __ Lsr(out_reg_hi, in_reg_hi, rot);
3243 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3244 __ Lsr(out_reg_lo, in_reg_lo, rot);
3245 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3246 } else {
3247 __ Mov(out_reg_lo, in_reg_lo);
3248 __ Mov(out_reg_hi, in_reg_hi);
3249 }
3250 } else {
3251 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3252 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3253 Label end;
3254 Label shift_by_32_plus_shift_right;
3255
3256 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3257 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3258 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3259 __ b(&shift_by_32_plus_shift_right, CC);
3260
3261 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3262 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3263 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3264 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3265 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3266 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3267 __ Lsr(shift_left, in_reg_hi, shift_right);
3268 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3269 __ b(&end);
3270
3271 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3272 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3273 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3274 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3275 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3276 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3277 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3278 __ Lsl(shift_right, in_reg_hi, shift_left);
3279 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3280
3281 __ Bind(&end);
3282 }
3283}
Roland Levillain22c49222016-03-18 14:04:28 +00003284
3285void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003286 LocationSummary* locations =
3287 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3288 switch (ror->GetResultType()) {
3289 case Primitive::kPrimInt: {
3290 locations->SetInAt(0, Location::RequiresRegister());
3291 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3292 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3293 break;
3294 }
3295 case Primitive::kPrimLong: {
3296 locations->SetInAt(0, Location::RequiresRegister());
3297 if (ror->InputAt(1)->IsConstant()) {
3298 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3299 } else {
3300 locations->SetInAt(1, Location::RequiresRegister());
3301 locations->AddTemp(Location::RequiresRegister());
3302 locations->AddTemp(Location::RequiresRegister());
3303 }
3304 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3305 break;
3306 }
3307 default:
3308 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3309 }
3310}
3311
Roland Levillain22c49222016-03-18 14:04:28 +00003312void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003313 LocationSummary* locations = ror->GetLocations();
3314 Primitive::Type type = ror->GetResultType();
3315 switch (type) {
3316 case Primitive::kPrimInt: {
3317 HandleIntegerRotate(locations);
3318 break;
3319 }
3320 case Primitive::kPrimLong: {
3321 HandleLongRotate(locations);
3322 break;
3323 }
3324 default:
3325 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003326 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003327 }
3328}
3329
Calin Juravle9aec02f2014-11-18 23:06:35 +00003330void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3331 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3332
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003333 LocationSummary* locations =
3334 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003335
3336 switch (op->GetResultType()) {
3337 case Primitive::kPrimInt: {
3338 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003339 if (op->InputAt(1)->IsConstant()) {
3340 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3341 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3342 } else {
3343 locations->SetInAt(1, Location::RequiresRegister());
3344 // Make the output overlap, as it will be used to hold the masked
3345 // second input.
3346 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3347 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003348 break;
3349 }
3350 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003351 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003352 if (op->InputAt(1)->IsConstant()) {
3353 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3354 // For simplicity, use kOutputOverlap even though we only require that low registers
3355 // don't clash with high registers which the register allocator currently guarantees.
3356 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3357 } else {
3358 locations->SetInAt(1, Location::RequiresRegister());
3359 locations->AddTemp(Location::RequiresRegister());
3360 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3361 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003362 break;
3363 }
3364 default:
3365 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3366 }
3367}
3368
3369void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3370 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3371
3372 LocationSummary* locations = op->GetLocations();
3373 Location out = locations->Out();
3374 Location first = locations->InAt(0);
3375 Location second = locations->InAt(1);
3376
3377 Primitive::Type type = op->GetResultType();
3378 switch (type) {
3379 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003380 Register out_reg = out.AsRegister<Register>();
3381 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003382 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003383 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003384 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003385 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003386 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003387 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003388 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003389 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003390 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003391 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003392 }
3393 } else {
3394 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003395 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003396 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003397 __ Mov(out_reg, first_reg);
3398 } else if (op->IsShl()) {
3399 __ Lsl(out_reg, first_reg, shift_value);
3400 } else if (op->IsShr()) {
3401 __ Asr(out_reg, first_reg, shift_value);
3402 } else {
3403 __ Lsr(out_reg, first_reg, shift_value);
3404 }
3405 }
3406 break;
3407 }
3408 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003409 Register o_h = out.AsRegisterPairHigh<Register>();
3410 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003411
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003412 Register high = first.AsRegisterPairHigh<Register>();
3413 Register low = first.AsRegisterPairLow<Register>();
3414
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003415 if (second.IsRegister()) {
3416 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003417
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003418 Register second_reg = second.AsRegister<Register>();
3419
3420 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003421 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003422 // Shift the high part
3423 __ Lsl(o_h, high, o_l);
3424 // Shift the low part and `or` what overflew on the high part
3425 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3426 __ Lsr(temp, low, temp);
3427 __ orr(o_h, o_h, ShifterOperand(temp));
3428 // If the shift is > 32 bits, override the high part
3429 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3430 __ it(PL);
3431 __ Lsl(o_h, low, temp, PL);
3432 // Shift the low part
3433 __ Lsl(o_l, low, o_l);
3434 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003435 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003436 // Shift the low part
3437 __ Lsr(o_l, low, o_h);
3438 // Shift the high part and `or` what underflew on the low part
3439 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3440 __ Lsl(temp, high, temp);
3441 __ orr(o_l, o_l, ShifterOperand(temp));
3442 // If the shift is > 32 bits, override the low part
3443 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3444 __ it(PL);
3445 __ Asr(o_l, high, temp, PL);
3446 // Shift the high part
3447 __ Asr(o_h, high, o_h);
3448 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003449 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003450 // same as Shr except we use `Lsr`s and not `Asr`s
3451 __ Lsr(o_l, low, o_h);
3452 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3453 __ Lsl(temp, high, temp);
3454 __ orr(o_l, o_l, ShifterOperand(temp));
3455 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3456 __ it(PL);
3457 __ Lsr(o_l, high, temp, PL);
3458 __ Lsr(o_h, high, o_h);
3459 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003460 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003461 // Register allocator doesn't create partial overlap.
3462 DCHECK_NE(o_l, high);
3463 DCHECK_NE(o_h, low);
3464 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003465 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003466 if (shift_value > 32) {
3467 if (op->IsShl()) {
3468 __ Lsl(o_h, low, shift_value - 32);
3469 __ LoadImmediate(o_l, 0);
3470 } else if (op->IsShr()) {
3471 __ Asr(o_l, high, shift_value - 32);
3472 __ Asr(o_h, high, 31);
3473 } else {
3474 __ Lsr(o_l, high, shift_value - 32);
3475 __ LoadImmediate(o_h, 0);
3476 }
3477 } else if (shift_value == 32) {
3478 if (op->IsShl()) {
3479 __ mov(o_h, ShifterOperand(low));
3480 __ LoadImmediate(o_l, 0);
3481 } else if (op->IsShr()) {
3482 __ mov(o_l, ShifterOperand(high));
3483 __ Asr(o_h, high, 31);
3484 } else {
3485 __ mov(o_l, ShifterOperand(high));
3486 __ LoadImmediate(o_h, 0);
3487 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003488 } else if (shift_value == 1) {
3489 if (op->IsShl()) {
3490 __ Lsls(o_l, low, 1);
3491 __ adc(o_h, high, ShifterOperand(high));
3492 } else if (op->IsShr()) {
3493 __ Asrs(o_h, high, 1);
3494 __ Rrx(o_l, low);
3495 } else {
3496 __ Lsrs(o_h, high, 1);
3497 __ Rrx(o_l, low);
3498 }
3499 } else {
3500 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003501 if (op->IsShl()) {
3502 __ Lsl(o_h, high, shift_value);
3503 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3504 __ Lsl(o_l, low, shift_value);
3505 } else if (op->IsShr()) {
3506 __ Lsr(o_l, low, shift_value);
3507 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3508 __ Asr(o_h, high, shift_value);
3509 } else {
3510 __ Lsr(o_l, low, shift_value);
3511 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3512 __ Lsr(o_h, high, shift_value);
3513 }
3514 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003515 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003516 break;
3517 }
3518 default:
3519 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003520 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003521 }
3522}
3523
3524void LocationsBuilderARM::VisitShl(HShl* shl) {
3525 HandleShift(shl);
3526}
3527
3528void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3529 HandleShift(shl);
3530}
3531
3532void LocationsBuilderARM::VisitShr(HShr* shr) {
3533 HandleShift(shr);
3534}
3535
3536void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3537 HandleShift(shr);
3538}
3539
3540void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3541 HandleShift(ushr);
3542}
3543
3544void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3545 HandleShift(ushr);
3546}
3547
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003548void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003549 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003550 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003551 if (instruction->IsStringAlloc()) {
3552 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3553 } else {
3554 InvokeRuntimeCallingConvention calling_convention;
3555 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3556 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3557 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003558 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003559}
3560
3561void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003562 // Note: if heap poisoning is enabled, the entry point takes cares
3563 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003564 if (instruction->IsStringAlloc()) {
3565 // String is allocated through StringFactory. Call NewEmptyString entry point.
3566 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003567 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003568 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3569 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3570 __ blx(LR);
3571 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3572 } else {
3573 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
3574 instruction,
3575 instruction->GetDexPc(),
3576 nullptr);
3577 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3578 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003579}
3580
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003581void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3582 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003583 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003584 InvokeRuntimeCallingConvention calling_convention;
3585 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003586 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003587 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003588 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003589}
3590
3591void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3592 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003593 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003594 // Note: if heap poisoning is enabled, the entry point takes cares
3595 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003596 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003597 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003598 instruction->GetDexPc(),
3599 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003600 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003601}
3602
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003603void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003604 LocationSummary* locations =
3605 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003606 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3607 if (location.IsStackSlot()) {
3608 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3609 } else if (location.IsDoubleStackSlot()) {
3610 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003611 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003612 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003613}
3614
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003615void InstructionCodeGeneratorARM::VisitParameterValue(
3616 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003617 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003618}
3619
3620void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3621 LocationSummary* locations =
3622 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3623 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3624}
3625
3626void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3627 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003628}
3629
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003630void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003631 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003632 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003633 locations->SetInAt(0, Location::RequiresRegister());
3634 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003635}
3636
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003637void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3638 LocationSummary* locations = not_->GetLocations();
3639 Location out = locations->Out();
3640 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003641 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003642 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003643 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003644 break;
3645
3646 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003647 __ mvn(out.AsRegisterPairLow<Register>(),
3648 ShifterOperand(in.AsRegisterPairLow<Register>()));
3649 __ mvn(out.AsRegisterPairHigh<Register>(),
3650 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003651 break;
3652
3653 default:
3654 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3655 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003656}
3657
David Brazdil66d126e2015-04-03 16:02:44 +01003658void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3659 LocationSummary* locations =
3660 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3661 locations->SetInAt(0, Location::RequiresRegister());
3662 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3663}
3664
3665void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003666 LocationSummary* locations = bool_not->GetLocations();
3667 Location out = locations->Out();
3668 Location in = locations->InAt(0);
3669 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3670}
3671
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003672void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003673 LocationSummary* locations =
3674 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003675 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003676 case Primitive::kPrimBoolean:
3677 case Primitive::kPrimByte:
3678 case Primitive::kPrimShort:
3679 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003680 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00003681 case Primitive::kPrimLong: {
3682 locations->SetInAt(0, Location::RequiresRegister());
3683 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003684 // Output overlaps because it is written before doing the low comparison.
3685 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003686 break;
3687 }
3688 case Primitive::kPrimFloat:
3689 case Primitive::kPrimDouble: {
3690 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003691 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00003692 locations->SetOut(Location::RequiresRegister());
3693 break;
3694 }
3695 default:
3696 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3697 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003698}
3699
3700void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003701 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003702 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003703 Location left = locations->InAt(0);
3704 Location right = locations->InAt(1);
3705
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003706 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003707 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00003708 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00003709 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003710 case Primitive::kPrimBoolean:
3711 case Primitive::kPrimByte:
3712 case Primitive::kPrimShort:
3713 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003714 case Primitive::kPrimInt: {
3715 __ LoadImmediate(out, 0);
3716 __ cmp(left.AsRegister<Register>(),
3717 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
3718 less_cond = LT;
3719 break;
3720 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003721 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003722 __ cmp(left.AsRegisterPairHigh<Register>(),
3723 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003724 __ b(&less, LT);
3725 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003726 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003727 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003728 __ cmp(left.AsRegisterPairLow<Register>(),
3729 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003730 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00003731 break;
3732 }
3733 case Primitive::kPrimFloat:
3734 case Primitive::kPrimDouble: {
3735 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003736 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00003737 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003738 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003739 break;
3740 }
3741 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003742 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00003743 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003744 }
Aart Bika19616e2016-02-01 18:57:58 -08003745
Calin Juravleddb7df22014-11-25 20:56:51 +00003746 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00003747 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00003748
3749 __ Bind(&greater);
3750 __ LoadImmediate(out, 1);
3751 __ b(&done);
3752
3753 __ Bind(&less);
3754 __ LoadImmediate(out, -1);
3755
3756 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003757}
3758
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003759void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003760 LocationSummary* locations =
3761 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003762 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003763 locations->SetInAt(i, Location::Any());
3764 }
3765 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003766}
3767
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003768void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003769 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003770}
3771
Roland Levillainc9285912015-12-18 10:38:42 +00003772void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3773 // TODO (ported from quick): revisit ARM barrier kinds.
3774 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00003775 switch (kind) {
3776 case MemBarrierKind::kAnyStore:
3777 case MemBarrierKind::kLoadAny:
3778 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003779 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003780 break;
3781 }
3782 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003783 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003784 break;
3785 }
3786 default:
3787 LOG(FATAL) << "Unexpected memory barrier " << kind;
3788 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003789 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003790}
3791
3792void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3793 uint32_t offset,
3794 Register out_lo,
3795 Register out_hi) {
3796 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00003797 // Ensure `out_lo` is different from `addr`, so that loading
3798 // `offset` into `out_lo` does not clutter `addr`.
3799 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00003800 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003801 __ add(IP, addr, ShifterOperand(out_lo));
3802 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003803 }
3804 __ ldrexd(out_lo, out_hi, addr);
3805}
3806
3807void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3808 uint32_t offset,
3809 Register value_lo,
3810 Register value_hi,
3811 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003812 Register temp2,
3813 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003814 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003815 if (offset != 0) {
3816 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003817 __ add(IP, addr, ShifterOperand(temp1));
3818 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003819 }
3820 __ Bind(&fail);
3821 // We need a load followed by store. (The address used in a STREX instruction must
3822 // be the same as the address in the most recently executed LDREX instruction.)
3823 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003824 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003825 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003826 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003827}
3828
3829void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3830 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3831
Nicolas Geoffray39468442014-09-02 15:17:15 +01003832 LocationSummary* locations =
3833 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003834 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003835
Calin Juravle52c48962014-12-16 17:02:57 +00003836 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003837 if (Primitive::IsFloatingPointType(field_type)) {
3838 locations->SetInAt(1, Location::RequiresFpuRegister());
3839 } else {
3840 locations->SetInAt(1, Location::RequiresRegister());
3841 }
3842
Calin Juravle52c48962014-12-16 17:02:57 +00003843 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003844 bool generate_volatile = field_info.IsVolatile()
3845 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003846 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003847 bool needs_write_barrier =
3848 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003849 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003850 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003851 if (needs_write_barrier) {
3852 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003853 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003854 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003855 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003856 // - registers need to be consecutive
3857 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003858 // We don't test for ARM yet, and the assertion makes sure that we
3859 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003860 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3861
3862 locations->AddTemp(Location::RequiresRegister());
3863 locations->AddTemp(Location::RequiresRegister());
3864 if (field_type == Primitive::kPrimDouble) {
3865 // For doubles we need two more registers to copy the value.
3866 locations->AddTemp(Location::RegisterLocation(R2));
3867 locations->AddTemp(Location::RegisterLocation(R3));
3868 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003869 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003870}
3871
Calin Juravle52c48962014-12-16 17:02:57 +00003872void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003873 const FieldInfo& field_info,
3874 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003875 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3876
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003877 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003878 Register base = locations->InAt(0).AsRegister<Register>();
3879 Location value = locations->InAt(1);
3880
3881 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003882 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003883 Primitive::Type field_type = field_info.GetFieldType();
3884 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003885 bool needs_write_barrier =
3886 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003887
3888 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003889 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00003890 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003891
3892 switch (field_type) {
3893 case Primitive::kPrimBoolean:
3894 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003895 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003896 break;
3897 }
3898
3899 case Primitive::kPrimShort:
3900 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003901 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003902 break;
3903 }
3904
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003905 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003906 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003907 if (kPoisonHeapReferences && needs_write_barrier) {
3908 // Note that in the case where `value` is a null reference,
3909 // we do not enter this block, as a null reference does not
3910 // need poisoning.
3911 DCHECK_EQ(field_type, Primitive::kPrimNot);
3912 Register temp = locations->GetTemp(0).AsRegister<Register>();
3913 __ Mov(temp, value.AsRegister<Register>());
3914 __ PoisonHeapReference(temp);
3915 __ StoreToOffset(kStoreWord, temp, base, offset);
3916 } else {
3917 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3918 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003919 break;
3920 }
3921
3922 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003923 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003924 GenerateWideAtomicStore(base, offset,
3925 value.AsRegisterPairLow<Register>(),
3926 value.AsRegisterPairHigh<Register>(),
3927 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003928 locations->GetTemp(1).AsRegister<Register>(),
3929 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003930 } else {
3931 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003932 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003933 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003934 break;
3935 }
3936
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003937 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003938 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003939 break;
3940 }
3941
3942 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003943 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003944 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003945 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3946 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3947
3948 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3949
3950 GenerateWideAtomicStore(base, offset,
3951 value_reg_lo,
3952 value_reg_hi,
3953 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003954 locations->GetTemp(3).AsRegister<Register>(),
3955 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003956 } else {
3957 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003958 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003959 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003960 break;
3961 }
3962
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003963 case Primitive::kPrimVoid:
3964 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003965 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003966 }
Calin Juravle52c48962014-12-16 17:02:57 +00003967
Calin Juravle77520bc2015-01-12 18:45:46 +00003968 // Longs and doubles are handled in the switch.
3969 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3970 codegen_->MaybeRecordImplicitNullCheck(instruction);
3971 }
3972
3973 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3974 Register temp = locations->GetTemp(0).AsRegister<Register>();
3975 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003976 codegen_->MarkGCCard(
3977 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003978 }
3979
Calin Juravle52c48962014-12-16 17:02:57 +00003980 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003981 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00003982 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003983}
3984
Calin Juravle52c48962014-12-16 17:02:57 +00003985void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3986 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00003987
3988 bool object_field_get_with_read_barrier =
3989 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003990 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00003991 new (GetGraph()->GetArena()) LocationSummary(instruction,
3992 object_field_get_with_read_barrier ?
3993 LocationSummary::kCallOnSlowPath :
3994 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003995 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003996
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003997 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003998 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003999 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00004000 // The output overlaps in case of volatile long: we don't want the
4001 // code generated by GenerateWideAtomicLoad to overwrite the
4002 // object's location. Likewise, in the case of an object field get
4003 // with read barriers enabled, we do not want the load to overwrite
4004 // the object's location, as we need it to emit the read barrier.
4005 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
4006 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01004007
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004008 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4009 locations->SetOut(Location::RequiresFpuRegister());
4010 } else {
4011 locations->SetOut(Location::RequiresRegister(),
4012 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
4013 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004014 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00004015 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00004016 // - registers need to be consecutive
4017 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00004018 // We don't test for ARM yet, and the assertion makes sure that we
4019 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00004020 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
4021 locations->AddTemp(Location::RequiresRegister());
4022 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00004023 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4024 // We need a temporary register for the read barrier marking slow
4025 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4026 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004027 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004028}
4029
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004030Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
4031 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
4032 << input->GetType();
4033 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
4034 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4035 return Location::ConstantLocation(input->AsConstant());
4036 } else {
4037 return Location::RequiresFpuRegister();
4038 }
4039}
4040
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004041Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4042 Opcode opcode) {
4043 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4044 if (constant->IsConstant() &&
4045 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4046 return Location::ConstantLocation(constant->AsConstant());
4047 }
4048 return Location::RequiresRegister();
4049}
4050
4051bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4052 Opcode opcode) {
4053 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4054 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004055 Opcode high_opcode = opcode;
4056 SetCc low_set_cc = kCcDontCare;
4057 switch (opcode) {
4058 case SUB:
4059 // Flip the operation to an ADD.
4060 value = -value;
4061 opcode = ADD;
4062 FALLTHROUGH_INTENDED;
4063 case ADD:
4064 if (Low32Bits(value) == 0u) {
4065 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4066 }
4067 high_opcode = ADC;
4068 low_set_cc = kCcSet;
4069 break;
4070 default:
4071 break;
4072 }
4073 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4074 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004075 } else {
4076 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4077 }
4078}
4079
Vladimir Marko59751a72016-08-05 14:37:27 +01004080bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4081 Opcode opcode,
4082 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004083 ShifterOperand so;
4084 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004085 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004086 return true;
4087 }
4088 Opcode neg_opcode = kNoOperand;
4089 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004090 case AND: neg_opcode = BIC; value = ~value; break;
4091 case ORR: neg_opcode = ORN; value = ~value; break;
4092 case ADD: neg_opcode = SUB; value = -value; break;
4093 case ADC: neg_opcode = SBC; value = ~value; break;
4094 case SUB: neg_opcode = ADD; value = -value; break;
4095 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004096 default:
4097 return false;
4098 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004099 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004100}
4101
Calin Juravle52c48962014-12-16 17:02:57 +00004102void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4103 const FieldInfo& field_info) {
4104 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004105
Calin Juravle52c48962014-12-16 17:02:57 +00004106 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004107 Location base_loc = locations->InAt(0);
4108 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004109 Location out = locations->Out();
4110 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004111 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004112 Primitive::Type field_type = field_info.GetFieldType();
4113 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4114
4115 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004116 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004117 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004118 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004119
Roland Levillainc9285912015-12-18 10:38:42 +00004120 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004121 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004122 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004123
Roland Levillainc9285912015-12-18 10:38:42 +00004124 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004125 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004126 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004127
Roland Levillainc9285912015-12-18 10:38:42 +00004128 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004129 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004130 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004131
4132 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004133 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004134 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004135
4136 case Primitive::kPrimNot: {
4137 // /* HeapReference<Object> */ out = *(base + offset)
4138 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4139 Location temp_loc = locations->GetTemp(0);
4140 // Note that a potential implicit null check is handled in this
4141 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4142 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4143 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4144 if (is_volatile) {
4145 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4146 }
4147 } else {
4148 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4149 codegen_->MaybeRecordImplicitNullCheck(instruction);
4150 if (is_volatile) {
4151 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4152 }
4153 // If read barriers are enabled, emit read barriers other than
4154 // Baker's using a slow path (and also unpoison the loaded
4155 // reference, if heap poisoning is enabled).
4156 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4157 }
4158 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004159 }
4160
Roland Levillainc9285912015-12-18 10:38:42 +00004161 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004162 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004163 GenerateWideAtomicLoad(base, offset,
4164 out.AsRegisterPairLow<Register>(),
4165 out.AsRegisterPairHigh<Register>());
4166 } else {
4167 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4168 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004169 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004170
Roland Levillainc9285912015-12-18 10:38:42 +00004171 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004172 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004173 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004174
4175 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004176 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004177 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004178 Register lo = locations->GetTemp(0).AsRegister<Register>();
4179 Register hi = locations->GetTemp(1).AsRegister<Register>();
4180 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004181 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004182 __ vmovdrr(out_reg, lo, hi);
4183 } else {
4184 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004185 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004186 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004187 break;
4188 }
4189
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004190 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004191 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004192 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004193 }
Calin Juravle52c48962014-12-16 17:02:57 +00004194
Roland Levillainc9285912015-12-18 10:38:42 +00004195 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4196 // Potential implicit null checks, in the case of reference or
4197 // double fields, are handled in the previous switch statement.
4198 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004199 codegen_->MaybeRecordImplicitNullCheck(instruction);
4200 }
4201
Calin Juravle52c48962014-12-16 17:02:57 +00004202 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004203 if (field_type == Primitive::kPrimNot) {
4204 // Memory barriers, in the case of references, are also handled
4205 // in the previous switch statement.
4206 } else {
4207 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4208 }
Roland Levillain4d027112015-07-01 15:41:14 +01004209 }
Calin Juravle52c48962014-12-16 17:02:57 +00004210}
4211
4212void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4213 HandleFieldSet(instruction, instruction->GetFieldInfo());
4214}
4215
4216void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004217 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004218}
4219
4220void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4221 HandleFieldGet(instruction, instruction->GetFieldInfo());
4222}
4223
4224void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4225 HandleFieldGet(instruction, instruction->GetFieldInfo());
4226}
4227
4228void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4229 HandleFieldGet(instruction, instruction->GetFieldInfo());
4230}
4231
4232void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4233 HandleFieldGet(instruction, instruction->GetFieldInfo());
4234}
4235
4236void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4237 HandleFieldSet(instruction, instruction->GetFieldInfo());
4238}
4239
4240void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004241 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004242}
4243
Calin Juravlee460d1d2015-09-29 04:52:17 +01004244void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4245 HUnresolvedInstanceFieldGet* instruction) {
4246 FieldAccessCallingConventionARM calling_convention;
4247 codegen_->CreateUnresolvedFieldLocationSummary(
4248 instruction, instruction->GetFieldType(), calling_convention);
4249}
4250
4251void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4252 HUnresolvedInstanceFieldGet* instruction) {
4253 FieldAccessCallingConventionARM calling_convention;
4254 codegen_->GenerateUnresolvedFieldAccess(instruction,
4255 instruction->GetFieldType(),
4256 instruction->GetFieldIndex(),
4257 instruction->GetDexPc(),
4258 calling_convention);
4259}
4260
4261void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4262 HUnresolvedInstanceFieldSet* instruction) {
4263 FieldAccessCallingConventionARM calling_convention;
4264 codegen_->CreateUnresolvedFieldLocationSummary(
4265 instruction, instruction->GetFieldType(), calling_convention);
4266}
4267
4268void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4269 HUnresolvedInstanceFieldSet* instruction) {
4270 FieldAccessCallingConventionARM calling_convention;
4271 codegen_->GenerateUnresolvedFieldAccess(instruction,
4272 instruction->GetFieldType(),
4273 instruction->GetFieldIndex(),
4274 instruction->GetDexPc(),
4275 calling_convention);
4276}
4277
4278void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4279 HUnresolvedStaticFieldGet* instruction) {
4280 FieldAccessCallingConventionARM calling_convention;
4281 codegen_->CreateUnresolvedFieldLocationSummary(
4282 instruction, instruction->GetFieldType(), calling_convention);
4283}
4284
4285void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4286 HUnresolvedStaticFieldGet* instruction) {
4287 FieldAccessCallingConventionARM calling_convention;
4288 codegen_->GenerateUnresolvedFieldAccess(instruction,
4289 instruction->GetFieldType(),
4290 instruction->GetFieldIndex(),
4291 instruction->GetDexPc(),
4292 calling_convention);
4293}
4294
4295void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4296 HUnresolvedStaticFieldSet* instruction) {
4297 FieldAccessCallingConventionARM calling_convention;
4298 codegen_->CreateUnresolvedFieldLocationSummary(
4299 instruction, instruction->GetFieldType(), calling_convention);
4300}
4301
4302void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4303 HUnresolvedStaticFieldSet* instruction) {
4304 FieldAccessCallingConventionARM calling_convention;
4305 codegen_->GenerateUnresolvedFieldAccess(instruction,
4306 instruction->GetFieldType(),
4307 instruction->GetFieldIndex(),
4308 instruction->GetDexPc(),
4309 calling_convention);
4310}
4311
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004312void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004313 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4314 ? LocationSummary::kCallOnSlowPath
4315 : LocationSummary::kNoCall;
4316 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00004317 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004318 if (instruction->HasUses()) {
4319 locations->SetOut(Location::SameAsFirstInput());
4320 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004321}
4322
Calin Juravle2ae48182016-03-16 14:05:09 +00004323void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4324 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004325 return;
4326 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004327 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004328
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004329 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004330 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004331}
4332
Calin Juravle2ae48182016-03-16 14:05:09 +00004333void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004334 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004335 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004336
4337 LocationSummary* locations = instruction->GetLocations();
4338 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004339
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004340 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004341}
4342
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004343void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004344 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004345}
4346
Artem Serov6c916792016-07-11 14:02:34 +01004347static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4348 switch (type) {
4349 case Primitive::kPrimNot:
4350 return kLoadWord;
4351 case Primitive::kPrimBoolean:
4352 return kLoadUnsignedByte;
4353 case Primitive::kPrimByte:
4354 return kLoadSignedByte;
4355 case Primitive::kPrimChar:
4356 return kLoadUnsignedHalfword;
4357 case Primitive::kPrimShort:
4358 return kLoadSignedHalfword;
4359 case Primitive::kPrimInt:
4360 return kLoadWord;
4361 case Primitive::kPrimLong:
4362 return kLoadWordPair;
4363 case Primitive::kPrimFloat:
4364 return kLoadSWord;
4365 case Primitive::kPrimDouble:
4366 return kLoadDWord;
4367 default:
4368 LOG(FATAL) << "Unreachable type " << type;
4369 UNREACHABLE();
4370 }
4371}
4372
4373static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4374 switch (type) {
4375 case Primitive::kPrimNot:
4376 return kStoreWord;
4377 case Primitive::kPrimBoolean:
4378 case Primitive::kPrimByte:
4379 return kStoreByte;
4380 case Primitive::kPrimChar:
4381 case Primitive::kPrimShort:
4382 return kStoreHalfword;
4383 case Primitive::kPrimInt:
4384 return kStoreWord;
4385 case Primitive::kPrimLong:
4386 return kStoreWordPair;
4387 case Primitive::kPrimFloat:
4388 return kStoreSWord;
4389 case Primitive::kPrimDouble:
4390 return kStoreDWord;
4391 default:
4392 LOG(FATAL) << "Unreachable type " << type;
4393 UNREACHABLE();
4394 }
4395}
4396
4397void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4398 Location out_loc,
4399 Register base,
4400 Register reg_offset,
4401 Condition cond) {
4402 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4403 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4404
4405 switch (type) {
4406 case Primitive::kPrimByte:
4407 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4408 break;
4409 case Primitive::kPrimBoolean:
4410 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4411 break;
4412 case Primitive::kPrimShort:
4413 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4414 break;
4415 case Primitive::kPrimChar:
4416 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4417 break;
4418 case Primitive::kPrimNot:
4419 case Primitive::kPrimInt:
4420 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4421 break;
4422 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4423 case Primitive::kPrimLong:
4424 case Primitive::kPrimFloat:
4425 case Primitive::kPrimDouble:
4426 default:
4427 LOG(FATAL) << "Unreachable type " << type;
4428 UNREACHABLE();
4429 }
4430}
4431
4432void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4433 Location loc,
4434 Register base,
4435 Register reg_offset,
4436 Condition cond) {
4437 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4438 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4439
4440 switch (type) {
4441 case Primitive::kPrimByte:
4442 case Primitive::kPrimBoolean:
4443 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4444 break;
4445 case Primitive::kPrimShort:
4446 case Primitive::kPrimChar:
4447 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4448 break;
4449 case Primitive::kPrimNot:
4450 case Primitive::kPrimInt:
4451 __ str(loc.AsRegister<Register>(), mem_address, cond);
4452 break;
4453 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4454 case Primitive::kPrimLong:
4455 case Primitive::kPrimFloat:
4456 case Primitive::kPrimDouble:
4457 default:
4458 LOG(FATAL) << "Unreachable type " << type;
4459 UNREACHABLE();
4460 }
4461}
4462
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004463void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004464 bool object_array_get_with_read_barrier =
4465 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004466 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004467 new (GetGraph()->GetArena()) LocationSummary(instruction,
4468 object_array_get_with_read_barrier ?
4469 LocationSummary::kCallOnSlowPath :
4470 LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004471 locations->SetInAt(0, Location::RequiresRegister());
4472 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004473 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4474 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4475 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004476 // The output overlaps in the case of an object array get with
4477 // read barriers enabled: we do not want the move to overwrite the
4478 // array's location, as we need it to emit the read barrier.
4479 locations->SetOut(
4480 Location::RequiresRegister(),
4481 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004482 }
Roland Levillainc9285912015-12-18 10:38:42 +00004483 // We need a temporary register for the read barrier marking slow
4484 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
4485 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4486 locations->AddTemp(Location::RequiresRegister());
4487 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004488}
4489
4490void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4491 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004492 Location obj_loc = locations->InAt(0);
4493 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004494 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004495 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004496 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004497 Primitive::Type type = instruction->GetType();
Artem Serov328429f2016-07-06 16:23:04 +01004498 HInstruction* array_instr = instruction->GetArray();
4499 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004500 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4501 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Artem Serov6c916792016-07-11 14:02:34 +01004502
Roland Levillain4d027112015-07-01 15:41:14 +01004503 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004504 case Primitive::kPrimBoolean:
4505 case Primitive::kPrimByte:
4506 case Primitive::kPrimShort:
4507 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004508 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004509 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004510 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4511 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
4512
4513 LoadOperandType load_type = GetLoadOperandType(type);
4514 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004515 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004516 Register temp = IP;
4517
4518 if (has_intermediate_address) {
4519 // We do not need to compute the intermediate address from the array: the
4520 // input instruction has done it already. See the comment in
4521 // `TryExtractArrayAccessAddress()`.
4522 if (kIsDebugBuild) {
4523 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4524 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4525 }
4526 temp = obj;
4527 } else {
4528 __ add(temp, obj, ShifterOperand(data_offset));
4529 }
4530 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004531 }
4532 break;
4533 }
4534
Roland Levillainc9285912015-12-18 10:38:42 +00004535 case Primitive::kPrimNot: {
4536 static_assert(
4537 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4538 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004539 // /* HeapReference<Object> */ out =
4540 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4541 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4542 Location temp = locations->GetTemp(0);
4543 // Note that a potential implicit null check is handled in this
4544 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4545 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4546 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4547 } else {
4548 Register out = out_loc.AsRegister<Register>();
4549 if (index.IsConstant()) {
4550 size_t offset =
4551 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4552 __ LoadFromOffset(kLoadWord, out, obj, offset);
4553 codegen_->MaybeRecordImplicitNullCheck(instruction);
4554 // If read barriers are enabled, emit read barriers other than
4555 // Baker's using a slow path (and also unpoison the loaded
4556 // reference, if heap poisoning is enabled).
4557 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4558 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004559 Register temp = IP;
4560
4561 if (has_intermediate_address) {
4562 // We do not need to compute the intermediate address from the array: the
4563 // input instruction has done it already. See the comment in
4564 // `TryExtractArrayAccessAddress()`.
4565 if (kIsDebugBuild) {
4566 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4567 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4568 }
4569 temp = obj;
4570 } else {
4571 __ add(temp, obj, ShifterOperand(data_offset));
4572 }
4573 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004574
Roland Levillainc9285912015-12-18 10:38:42 +00004575 codegen_->MaybeRecordImplicitNullCheck(instruction);
4576 // If read barriers are enabled, emit read barriers other than
4577 // Baker's using a slow path (and also unpoison the loaded
4578 // reference, if heap poisoning is enabled).
4579 codegen_->MaybeGenerateReadBarrierSlow(
4580 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4581 }
4582 }
4583 break;
4584 }
4585
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004586 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004587 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004588 size_t offset =
4589 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004590 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004591 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004592 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004593 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004594 }
4595 break;
4596 }
4597
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004598 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004599 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004600 if (index.IsConstant()) {
4601 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004602 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004603 } else {
4604 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004605 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004606 }
4607 break;
4608 }
4609
4610 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004611 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004612 if (index.IsConstant()) {
4613 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004614 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004615 } else {
4616 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004617 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004618 }
4619 break;
4620 }
4621
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004622 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01004623 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004624 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004625 }
Roland Levillain4d027112015-07-01 15:41:14 +01004626
4627 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00004628 // Potential implicit null checks, in the case of reference
4629 // arrays, are handled in the previous switch statement.
4630 } else {
4631 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01004632 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004633}
4634
4635void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004636 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004637
4638 bool needs_write_barrier =
4639 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00004640 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
4641 bool object_array_set_with_read_barrier =
4642 kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004643
Nicolas Geoffray39468442014-09-02 15:17:15 +01004644 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004645 instruction,
Roland Levillain3b359c72015-11-17 19:35:12 +00004646 (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ?
4647 LocationSummary::kCallOnSlowPath :
4648 LocationSummary::kNoCall);
4649
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004650 locations->SetInAt(0, Location::RequiresRegister());
4651 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
4652 if (Primitive::IsFloatingPointType(value_type)) {
4653 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004654 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004655 locations->SetInAt(2, Location::RequiresRegister());
4656 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004657 if (needs_write_barrier) {
4658 // Temporary registers for the write barrier.
4659 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00004660 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004661 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004662}
4663
4664void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4665 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004666 Location array_loc = locations->InAt(0);
4667 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004668 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004669 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00004670 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004671 bool needs_write_barrier =
4672 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01004673 uint32_t data_offset =
4674 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
4675 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01004676 HInstruction* array_instr = instruction->GetArray();
4677 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004678 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4679 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004680
4681 switch (value_type) {
4682 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01004683 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004684 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01004685 case Primitive::kPrimChar:
4686 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004687 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004688 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4689 uint32_t full_offset =
4690 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
4691 StoreOperandType store_type = GetStoreOperandType(value_type);
4692 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004693 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004694 Register temp = IP;
4695
4696 if (has_intermediate_address) {
4697 // We do not need to compute the intermediate address from the array: the
4698 // input instruction has done it already. See the comment in
4699 // `TryExtractArrayAccessAddress()`.
4700 if (kIsDebugBuild) {
4701 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4702 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
4703 }
4704 temp = array;
4705 } else {
4706 __ add(temp, array, ShifterOperand(data_offset));
4707 }
Artem Serov6c916792016-07-11 14:02:34 +01004708 codegen_->StoreToShiftedRegOffset(value_type,
4709 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01004710 temp,
Artem Serov6c916792016-07-11 14:02:34 +01004711 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004712 }
4713 break;
4714 }
4715
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004716 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00004717 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01004718 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
4719 // See the comment in instruction_simplifier_shared.cc.
4720 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004721
4722 if (instruction->InputAt(2)->IsNullConstant()) {
4723 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004724 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004725 size_t offset =
4726 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01004727 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004728 } else {
4729 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004730 __ add(IP, array, ShifterOperand(data_offset));
4731 codegen_->StoreToShiftedRegOffset(value_type,
4732 value_loc,
4733 IP,
4734 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004735 }
Roland Levillain1407ee72016-01-08 15:56:19 +00004736 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00004737 DCHECK(!needs_write_barrier);
4738 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004739 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004740 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004741
4742 DCHECK(needs_write_barrier);
4743 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
4744 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
4745 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4746 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4747 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4748 Label done;
4749 SlowPathCode* slow_path = nullptr;
4750
Roland Levillain3b359c72015-11-17 19:35:12 +00004751 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004752 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4753 codegen_->AddSlowPath(slow_path);
4754 if (instruction->GetValueCanBeNull()) {
4755 Label non_zero;
4756 __ CompareAndBranchIfNonZero(value, &non_zero);
4757 if (index.IsConstant()) {
4758 size_t offset =
4759 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4760 __ StoreToOffset(kStoreWord, value, array, offset);
4761 } else {
4762 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004763 __ add(IP, array, ShifterOperand(data_offset));
4764 codegen_->StoreToShiftedRegOffset(value_type,
4765 value_loc,
4766 IP,
4767 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004768 }
4769 codegen_->MaybeRecordImplicitNullCheck(instruction);
4770 __ b(&done);
4771 __ Bind(&non_zero);
4772 }
4773
Roland Levillain3b359c72015-11-17 19:35:12 +00004774 if (kEmitCompilerReadBarrier) {
4775 // When read barriers are enabled, the type checking
4776 // instrumentation requires two read barriers:
4777 //
4778 // __ Mov(temp2, temp1);
4779 // // /* HeapReference<Class> */ temp1 = temp1->component_type_
4780 // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
Roland Levillainc9285912015-12-18 10:38:42 +00004781 // codegen_->GenerateReadBarrierSlow(
Roland Levillain3b359c72015-11-17 19:35:12 +00004782 // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset);
4783 //
4784 // // /* HeapReference<Class> */ temp2 = value->klass_
4785 // __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
Roland Levillainc9285912015-12-18 10:38:42 +00004786 // codegen_->GenerateReadBarrierSlow(
Roland Levillain3b359c72015-11-17 19:35:12 +00004787 // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc);
4788 //
4789 // __ cmp(temp1, ShifterOperand(temp2));
4790 //
4791 // However, the second read barrier may trash `temp`, as it
4792 // is a temporary register, and as such would not be saved
4793 // along with live registers before calling the runtime (nor
4794 // restored afterwards). So in this case, we bail out and
4795 // delegate the work to the array set slow path.
4796 //
4797 // TODO: Extend the register allocator to support a new
4798 // "(locally) live temp" location so as to avoid always
4799 // going into the slow path when read barriers are enabled.
4800 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004801 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004802 // /* HeapReference<Class> */ temp1 = array->klass_
4803 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4804 codegen_->MaybeRecordImplicitNullCheck(instruction);
4805 __ MaybeUnpoisonHeapReference(temp1);
4806
4807 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4808 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4809 // /* HeapReference<Class> */ temp2 = value->klass_
4810 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4811 // If heap poisoning is enabled, no need to unpoison `temp1`
4812 // nor `temp2`, as we are comparing two poisoned references.
4813 __ cmp(temp1, ShifterOperand(temp2));
4814
4815 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4816 Label do_put;
4817 __ b(&do_put, EQ);
4818 // If heap poisoning is enabled, the `temp1` reference has
4819 // not been unpoisoned yet; unpoison it now.
4820 __ MaybeUnpoisonHeapReference(temp1);
4821
4822 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4823 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4824 // If heap poisoning is enabled, no need to unpoison
4825 // `temp1`, as we are comparing against null below.
4826 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4827 __ Bind(&do_put);
4828 } else {
4829 __ b(slow_path->GetEntryLabel(), NE);
4830 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004831 }
4832 }
4833
Artem Serov6c916792016-07-11 14:02:34 +01004834 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004835 if (kPoisonHeapReferences) {
4836 // Note that in the case where `value` is a null reference,
4837 // we do not enter this block, as a null reference does not
4838 // need poisoning.
4839 DCHECK_EQ(value_type, Primitive::kPrimNot);
4840 __ Mov(temp1, value);
4841 __ PoisonHeapReference(temp1);
4842 source = temp1;
4843 }
4844
4845 if (index.IsConstant()) {
4846 size_t offset =
4847 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4848 __ StoreToOffset(kStoreWord, source, array, offset);
4849 } else {
4850 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004851
4852 __ add(IP, array, ShifterOperand(data_offset));
4853 codegen_->StoreToShiftedRegOffset(value_type,
4854 Location::RegisterLocation(source),
4855 IP,
4856 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004857 }
4858
Roland Levillain3b359c72015-11-17 19:35:12 +00004859 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004860 codegen_->MaybeRecordImplicitNullCheck(instruction);
4861 }
4862
4863 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4864
4865 if (done.IsLinked()) {
4866 __ Bind(&done);
4867 }
4868
4869 if (slow_path != nullptr) {
4870 __ Bind(slow_path->GetExitLabel());
4871 }
4872
4873 break;
4874 }
4875
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004876 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004877 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004878 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004879 size_t offset =
4880 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004881 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004882 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004883 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004884 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004885 }
4886 break;
4887 }
4888
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004889 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004890 Location value = locations->InAt(2);
4891 DCHECK(value.IsFpuRegister());
4892 if (index.IsConstant()) {
4893 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004894 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004895 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004896 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004897 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4898 }
4899 break;
4900 }
4901
4902 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004903 Location value = locations->InAt(2);
4904 DCHECK(value.IsFpuRegisterPair());
4905 if (index.IsConstant()) {
4906 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004907 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004908 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004909 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004910 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4911 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004912
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004913 break;
4914 }
4915
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004916 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004917 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004918 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004919 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004920
Roland Levillain80e67092016-01-08 16:04:55 +00004921 // Objects are handled in the switch.
4922 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004923 codegen_->MaybeRecordImplicitNullCheck(instruction);
4924 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004925}
4926
4927void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004928 LocationSummary* locations =
4929 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004930 locations->SetInAt(0, Location::RequiresRegister());
4931 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004932}
4933
4934void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4935 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01004936 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00004937 Register obj = locations->InAt(0).AsRegister<Register>();
4938 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004939 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004940 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004941}
4942
Artem Serov328429f2016-07-06 16:23:04 +01004943void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Roland Levillain4a3aa572016-08-15 13:17:06 +00004944 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4945 DCHECK(!kEmitCompilerReadBarrier);
Artem Serov328429f2016-07-06 16:23:04 +01004946 LocationSummary* locations =
4947 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4948
4949 locations->SetInAt(0, Location::RequiresRegister());
4950 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
4951 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4952}
4953
4954void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
4955 LocationSummary* locations = instruction->GetLocations();
4956 Location out = locations->Out();
4957 Location first = locations->InAt(0);
4958 Location second = locations->InAt(1);
4959
Roland Levillain4a3aa572016-08-15 13:17:06 +00004960 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4961 DCHECK(!kEmitCompilerReadBarrier);
4962
Artem Serov328429f2016-07-06 16:23:04 +01004963 if (second.IsRegister()) {
4964 __ add(out.AsRegister<Register>(),
4965 first.AsRegister<Register>(),
4966 ShifterOperand(second.AsRegister<Register>()));
4967 } else {
4968 __ AddConstant(out.AsRegister<Register>(),
4969 first.AsRegister<Register>(),
4970 second.GetConstant()->AsIntConstant()->GetValue());
4971 }
4972}
4973
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004974void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004975 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4976 ? LocationSummary::kCallOnSlowPath
4977 : LocationSummary::kNoCall;
4978 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004979 locations->SetInAt(0, Location::RequiresRegister());
4980 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004981 if (instruction->HasUses()) {
4982 locations->SetOut(Location::SameAsFirstInput());
4983 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004984}
4985
4986void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
4987 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07004988 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004989 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004990 codegen_->AddSlowPath(slow_path);
4991
Roland Levillain271ab9c2014-11-27 15:23:57 +00004992 Register index = locations->InAt(0).AsRegister<Register>();
4993 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004994
4995 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01004996 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004997}
4998
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004999void CodeGeneratorARM::MarkGCCard(Register temp,
5000 Register card,
5001 Register object,
5002 Register value,
5003 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005004 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005005 if (can_be_null) {
5006 __ CompareAndBranchIfZero(value, &is_null);
5007 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005008 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005009 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5010 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005011 if (can_be_null) {
5012 __ Bind(&is_null);
5013 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005014}
5015
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005016void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005017 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005018}
5019
5020void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005021 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5022}
5023
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005024void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
5025 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5026}
5027
5028void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005029 HBasicBlock* block = instruction->GetBlock();
5030 if (block->GetLoopInformation() != nullptr) {
5031 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5032 // The back edge will generate the suspend check.
5033 return;
5034 }
5035 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5036 // The goto will generate the suspend check.
5037 return;
5038 }
5039 GenerateSuspendCheck(instruction, nullptr);
5040}
5041
5042void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5043 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005044 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005045 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5046 if (slow_path == nullptr) {
5047 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5048 instruction->SetSlowPath(slow_path);
5049 codegen_->AddSlowPath(slow_path);
5050 if (successor != nullptr) {
5051 DCHECK(successor->IsLoopHeader());
5052 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5053 }
5054 } else {
5055 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5056 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005057
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005058 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005059 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005060 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005061 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005062 __ Bind(slow_path->GetReturnLabel());
5063 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005064 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005065 __ b(slow_path->GetEntryLabel());
5066 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005067}
5068
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005069ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5070 return codegen_->GetAssembler();
5071}
5072
5073void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005074 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005075 Location source = move->GetSource();
5076 Location destination = move->GetDestination();
5077
5078 if (source.IsRegister()) {
5079 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005080 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005081 } else if (destination.IsFpuRegister()) {
5082 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005083 } else {
5084 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005085 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005086 SP, destination.GetStackIndex());
5087 }
5088 } else if (source.IsStackSlot()) {
5089 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005090 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005091 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005092 } else if (destination.IsFpuRegister()) {
5093 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005094 } else {
5095 DCHECK(destination.IsStackSlot());
5096 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5097 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5098 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005099 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005100 if (destination.IsRegister()) {
5101 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5102 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005103 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005104 } else {
5105 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005106 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5107 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005108 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005109 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005110 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5111 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005112 } else if (destination.IsRegisterPair()) {
5113 DCHECK(ExpectedPairLayout(destination));
5114 __ LoadFromOffset(
5115 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5116 } else {
5117 DCHECK(destination.IsFpuRegisterPair()) << destination;
5118 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5119 SP,
5120 source.GetStackIndex());
5121 }
5122 } else if (source.IsRegisterPair()) {
5123 if (destination.IsRegisterPair()) {
5124 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5125 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005126 } else if (destination.IsFpuRegisterPair()) {
5127 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5128 source.AsRegisterPairLow<Register>(),
5129 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005130 } else {
5131 DCHECK(destination.IsDoubleStackSlot()) << destination;
5132 DCHECK(ExpectedPairLayout(source));
5133 __ StoreToOffset(
5134 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5135 }
5136 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005137 if (destination.IsRegisterPair()) {
5138 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5139 destination.AsRegisterPairHigh<Register>(),
5140 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5141 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005142 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5143 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5144 } else {
5145 DCHECK(destination.IsDoubleStackSlot()) << destination;
5146 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5147 SP,
5148 destination.GetStackIndex());
5149 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005150 } else {
5151 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005152 HConstant* constant = source.GetConstant();
5153 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5154 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005155 if (destination.IsRegister()) {
5156 __ LoadImmediate(destination.AsRegister<Register>(), value);
5157 } else {
5158 DCHECK(destination.IsStackSlot());
5159 __ LoadImmediate(IP, value);
5160 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5161 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005162 } else if (constant->IsLongConstant()) {
5163 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005164 if (destination.IsRegisterPair()) {
5165 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5166 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005167 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005168 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005169 __ LoadImmediate(IP, Low32Bits(value));
5170 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5171 __ LoadImmediate(IP, High32Bits(value));
5172 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5173 }
5174 } else if (constant->IsDoubleConstant()) {
5175 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005176 if (destination.IsFpuRegisterPair()) {
5177 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005178 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005179 DCHECK(destination.IsDoubleStackSlot()) << destination;
5180 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005181 __ LoadImmediate(IP, Low32Bits(int_value));
5182 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5183 __ LoadImmediate(IP, High32Bits(int_value));
5184 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5185 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005186 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005187 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005188 float value = constant->AsFloatConstant()->GetValue();
5189 if (destination.IsFpuRegister()) {
5190 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5191 } else {
5192 DCHECK(destination.IsStackSlot());
5193 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5194 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5195 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005196 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005197 }
5198}
5199
5200void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5201 __ Mov(IP, reg);
5202 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5203 __ StoreToOffset(kStoreWord, IP, SP, mem);
5204}
5205
5206void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5207 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5208 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5209 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5210 SP, mem1 + stack_offset);
5211 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5212 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5213 SP, mem2 + stack_offset);
5214 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5215}
5216
5217void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005218 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005219 Location source = move->GetSource();
5220 Location destination = move->GetDestination();
5221
5222 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005223 DCHECK_NE(source.AsRegister<Register>(), IP);
5224 DCHECK_NE(destination.AsRegister<Register>(), IP);
5225 __ Mov(IP, source.AsRegister<Register>());
5226 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5227 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005228 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005229 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005230 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005231 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005232 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5233 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005234 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005235 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005236 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005237 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005238 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005239 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005240 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005241 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005242 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5243 destination.AsRegisterPairHigh<Register>(),
5244 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005245 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005246 Register low_reg = source.IsRegisterPair()
5247 ? source.AsRegisterPairLow<Register>()
5248 : destination.AsRegisterPairLow<Register>();
5249 int mem = source.IsRegisterPair()
5250 ? destination.GetStackIndex()
5251 : source.GetStackIndex();
5252 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005253 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005254 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005255 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005256 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005257 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5258 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005259 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005260 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005261 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005262 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5263 DRegister reg = source.IsFpuRegisterPair()
5264 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5265 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5266 int mem = source.IsFpuRegisterPair()
5267 ? destination.GetStackIndex()
5268 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005269 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005270 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005271 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005272 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5273 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5274 : destination.AsFpuRegister<SRegister>();
5275 int mem = source.IsFpuRegister()
5276 ? destination.GetStackIndex()
5277 : source.GetStackIndex();
5278
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005279 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005280 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005281 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005282 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005283 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5284 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005285 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005286 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005287 }
5288}
5289
5290void ParallelMoveResolverARM::SpillScratch(int reg) {
5291 __ Push(static_cast<Register>(reg));
5292}
5293
5294void ParallelMoveResolverARM::RestoreScratch(int reg) {
5295 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005296}
5297
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005298HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5299 HLoadClass::LoadKind desired_class_load_kind) {
5300 if (kEmitCompilerReadBarrier) {
5301 switch (desired_class_load_kind) {
5302 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5303 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5304 case HLoadClass::LoadKind::kBootImageAddress:
5305 // TODO: Implement for read barrier.
5306 return HLoadClass::LoadKind::kDexCacheViaMethod;
5307 default:
5308 break;
5309 }
5310 }
5311 switch (desired_class_load_kind) {
5312 case HLoadClass::LoadKind::kReferrersClass:
5313 break;
5314 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5315 DCHECK(!GetCompilerOptions().GetCompilePic());
5316 break;
5317 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5318 DCHECK(GetCompilerOptions().GetCompilePic());
5319 break;
5320 case HLoadClass::LoadKind::kBootImageAddress:
5321 break;
5322 case HLoadClass::LoadKind::kDexCacheAddress:
5323 DCHECK(Runtime::Current()->UseJitCompilation());
5324 break;
5325 case HLoadClass::LoadKind::kDexCachePcRelative:
5326 DCHECK(!Runtime::Current()->UseJitCompilation());
5327 // We disable pc-relative load when there is an irreducible loop, as the optimization
5328 // is incompatible with it.
5329 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5330 // with irreducible loops.
5331 if (GetGraph()->HasIrreducibleLoops()) {
5332 return HLoadClass::LoadKind::kDexCacheViaMethod;
5333 }
5334 break;
5335 case HLoadClass::LoadKind::kDexCacheViaMethod:
5336 break;
5337 }
5338 return desired_class_load_kind;
5339}
5340
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005341void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005342 if (cls->NeedsAccessCheck()) {
5343 InvokeRuntimeCallingConvention calling_convention;
5344 CodeGenerator::CreateLoadClassLocationSummary(
5345 cls,
5346 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5347 Location::RegisterLocation(R0),
5348 /* code_generator_supports_read_barrier */ true);
5349 return;
5350 }
5351
5352 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5353 ? LocationSummary::kCallOnSlowPath
5354 : LocationSummary::kNoCall;
5355 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
5356 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5357 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5358 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5359 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5360 locations->SetInAt(0, Location::RequiresRegister());
5361 }
5362 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005363}
5364
5365void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005366 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005367 if (cls->NeedsAccessCheck()) {
5368 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
5369 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
5370 cls,
5371 cls->GetDexPc(),
5372 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005373 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005374 return;
5375 }
5376
Roland Levillain3b359c72015-11-17 19:35:12 +00005377 Location out_loc = locations->Out();
5378 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005379
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005380 bool generate_null_check = false;
5381 switch (cls->GetLoadKind()) {
5382 case HLoadClass::LoadKind::kReferrersClass: {
5383 DCHECK(!cls->CanCallRuntime());
5384 DCHECK(!cls->MustGenerateClinitCheck());
5385 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5386 Register current_method = locations->InAt(0).AsRegister<Register>();
5387 GenerateGcRootFieldLoad(
5388 cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5389 break;
5390 }
5391 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
5392 DCHECK(!kEmitCompilerReadBarrier);
5393 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5394 cls->GetTypeIndex()));
5395 break;
5396 }
5397 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
5398 DCHECK(!kEmitCompilerReadBarrier);
5399 CodeGeneratorARM::PcRelativePatchInfo* labels =
5400 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5401 __ BindTrackedLabel(&labels->movw_label);
5402 __ movw(out, /* placeholder */ 0u);
5403 __ BindTrackedLabel(&labels->movt_label);
5404 __ movt(out, /* placeholder */ 0u);
5405 __ BindTrackedLabel(&labels->add_pc_label);
5406 __ add(out, out, ShifterOperand(PC));
5407 break;
5408 }
5409 case HLoadClass::LoadKind::kBootImageAddress: {
5410 DCHECK(!kEmitCompilerReadBarrier);
5411 DCHECK_NE(cls->GetAddress(), 0u);
5412 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5413 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5414 break;
5415 }
5416 case HLoadClass::LoadKind::kDexCacheAddress: {
5417 DCHECK_NE(cls->GetAddress(), 0u);
5418 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5419 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5420 // a 128B range. To try and reduce the number of literals if we load multiple types,
5421 // simply split the dex cache address to a 128B aligned base loaded from a literal
5422 // and the remaining offset embedded in the load.
5423 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5424 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5425 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5426 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5427 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5428 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5429 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
5430 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5431 generate_null_check = !cls->IsInDexCache();
5432 break;
5433 }
5434 case HLoadClass::LoadKind::kDexCachePcRelative: {
5435 Register base_reg = locations->InAt(0).AsRegister<Register>();
5436 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5437 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5438 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
5439 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset);
5440 generate_null_check = !cls->IsInDexCache();
5441 break;
5442 }
5443 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5444 // /* GcRoot<mirror::Class>[] */ out =
5445 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5446 Register current_method = locations->InAt(0).AsRegister<Register>();
5447 __ LoadFromOffset(kLoadWord,
5448 out,
5449 current_method,
5450 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5451 // /* GcRoot<mirror::Class> */ out = out[type_index]
5452 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
5453 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5454 generate_null_check = !cls->IsInDexCache();
5455 }
5456 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005457
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005458 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5459 DCHECK(cls->CanCallRuntime());
5460 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
5461 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5462 codegen_->AddSlowPath(slow_path);
5463 if (generate_null_check) {
5464 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5465 }
5466 if (cls->MustGenerateClinitCheck()) {
5467 GenerateClassInitializationCheck(slow_path, out);
5468 } else {
5469 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005470 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005471 }
5472}
5473
5474void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5475 LocationSummary* locations =
5476 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5477 locations->SetInAt(0, Location::RequiresRegister());
5478 if (check->HasUses()) {
5479 locations->SetOut(Location::SameAsFirstInput());
5480 }
5481}
5482
5483void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005484 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07005485 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005486 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005487 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005488 GenerateClassInitializationCheck(slow_path,
5489 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005490}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005491
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005492void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07005493 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005494 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5495 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5496 __ b(slow_path->GetEntryLabel(), LT);
5497 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5498 // properly. Therefore, we do a memory fence.
5499 __ dmb(ISH);
5500 __ Bind(slow_path->GetExitLabel());
5501}
5502
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005503HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5504 HLoadString::LoadKind desired_string_load_kind) {
5505 if (kEmitCompilerReadBarrier) {
5506 switch (desired_string_load_kind) {
5507 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5508 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5509 case HLoadString::LoadKind::kBootImageAddress:
5510 // TODO: Implement for read barrier.
5511 return HLoadString::LoadKind::kDexCacheViaMethod;
5512 default:
5513 break;
5514 }
5515 }
5516 switch (desired_string_load_kind) {
5517 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5518 DCHECK(!GetCompilerOptions().GetCompilePic());
5519 break;
5520 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5521 DCHECK(GetCompilerOptions().GetCompilePic());
5522 break;
5523 case HLoadString::LoadKind::kBootImageAddress:
5524 break;
5525 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005526 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005527 break;
5528 case HLoadString::LoadKind::kDexCachePcRelative:
Calin Juravleffc87072016-04-20 14:22:09 +01005529 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005530 // We disable pc-relative load when there is an irreducible loop, as the optimization
5531 // is incompatible with it.
5532 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5533 // with irreducible loops.
5534 if (GetGraph()->HasIrreducibleLoops()) {
5535 return HLoadString::LoadKind::kDexCacheViaMethod;
5536 }
5537 break;
5538 case HLoadString::LoadKind::kDexCacheViaMethod:
5539 break;
5540 }
5541 return desired_string_load_kind;
5542}
5543
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005544void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005545 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005546 ? LocationSummary::kCallOnSlowPath
5547 : LocationSummary::kNoCall;
5548 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005549 HLoadString::LoadKind load_kind = load->GetLoadKind();
5550 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod ||
5551 load_kind == HLoadString::LoadKind::kDexCachePcRelative) {
5552 locations->SetInAt(0, Location::RequiresRegister());
5553 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005554 locations->SetOut(Location::RequiresRegister());
5555}
5556
5557void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005558 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005559 Location out_loc = locations->Out();
5560 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005561
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005562 switch (load->GetLoadKind()) {
5563 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
5564 DCHECK(!kEmitCompilerReadBarrier);
5565 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5566 load->GetStringIndex()));
5567 return; // No dex cache slow path.
5568 }
5569 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
5570 DCHECK(!kEmitCompilerReadBarrier);
5571 CodeGeneratorARM::PcRelativePatchInfo* labels =
5572 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5573 __ BindTrackedLabel(&labels->movw_label);
5574 __ movw(out, /* placeholder */ 0u);
5575 __ BindTrackedLabel(&labels->movt_label);
5576 __ movt(out, /* placeholder */ 0u);
5577 __ BindTrackedLabel(&labels->add_pc_label);
5578 __ add(out, out, ShifterOperand(PC));
5579 return; // No dex cache slow path.
5580 }
5581 case HLoadString::LoadKind::kBootImageAddress: {
5582 DCHECK(!kEmitCompilerReadBarrier);
5583 DCHECK_NE(load->GetAddress(), 0u);
5584 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5585 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5586 return; // No dex cache slow path.
5587 }
5588 case HLoadString::LoadKind::kDexCacheAddress: {
5589 DCHECK_NE(load->GetAddress(), 0u);
5590 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5591 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5592 // a 128B range. To try and reduce the number of literals if we load multiple strings,
5593 // simply split the dex cache address to a 128B aligned base loaded from a literal
5594 // and the remaining offset embedded in the load.
5595 static_assert(sizeof(GcRoot<mirror::String>) == 4u, "Expected GC root to be 4 bytes.");
5596 DCHECK_ALIGNED(load->GetAddress(), 4u);
5597 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5598 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5599 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5600 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005601 // /* GcRoot<mirror::String> */ out = *(base_address + offset)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005602 GenerateGcRootFieldLoad(load, out_loc, out, offset);
5603 break;
5604 }
5605 case HLoadString::LoadKind::kDexCachePcRelative: {
5606 Register base_reg = locations->InAt(0).AsRegister<Register>();
5607 HArmDexCacheArraysBase* base = load->InputAt(0)->AsArmDexCacheArraysBase();
5608 int32_t offset = load->GetDexCacheElementOffset() - base->GetElementOffset();
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005609 // /* GcRoot<mirror::String> */ out = *(dex_cache_arrays_base + offset)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005610 GenerateGcRootFieldLoad(load, out_loc, base_reg, offset);
5611 break;
5612 }
5613 case HLoadString::LoadKind::kDexCacheViaMethod: {
5614 Register current_method = locations->InAt(0).AsRegister<Register>();
5615
5616 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5617 GenerateGcRootFieldLoad(
5618 load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5619 // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_
5620 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
5621 // /* GcRoot<mirror::String> */ out = out[string_index]
5622 GenerateGcRootFieldLoad(
5623 load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
5624 break;
5625 }
5626 default:
5627 LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind();
5628 UNREACHABLE();
5629 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005630
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005631 if (!load->IsInDexCache()) {
5632 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5633 codegen_->AddSlowPath(slow_path);
5634 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5635 __ Bind(slow_path->GetExitLabel());
5636 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005637}
5638
David Brazdilcb1c0552015-08-04 16:22:25 +01005639static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005640 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005641}
5642
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005643void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5644 LocationSummary* locations =
5645 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5646 locations->SetOut(Location::RequiresRegister());
5647}
5648
5649void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005650 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005651 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5652}
5653
5654void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5655 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5656}
5657
5658void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005659 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005660 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005661}
5662
5663void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5664 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005665 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005666 InvokeRuntimeCallingConvention calling_convention;
5667 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5668}
5669
5670void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
5671 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00005672 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005673 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005674}
5675
Roland Levillainc9285912015-12-18 10:38:42 +00005676static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
5677 return kEmitCompilerReadBarrier &&
5678 (kUseBakerReadBarrier ||
5679 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5680 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5681 type_check_kind == TypeCheckKind::kArrayObjectCheck);
5682}
5683
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005684void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005685 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00005686 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5687 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005688 case TypeCheckKind::kExactCheck:
5689 case TypeCheckKind::kAbstractClassCheck:
5690 case TypeCheckKind::kClassHierarchyCheck:
5691 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005692 call_kind =
5693 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005694 break;
5695 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005696 case TypeCheckKind::kUnresolvedCheck:
5697 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005698 call_kind = LocationSummary::kCallOnSlowPath;
5699 break;
5700 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005701
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005702 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Roland Levillain3b359c72015-11-17 19:35:12 +00005703 locations->SetInAt(0, Location::RequiresRegister());
5704 locations->SetInAt(1, Location::RequiresRegister());
5705 // The "out" register is used as a temporary, so it overlaps with the inputs.
5706 // Note that TypeCheckSlowPathARM uses this register too.
5707 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5708 // When read barriers are enabled, we need a temporary register for
5709 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005710 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00005711 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005712 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005713}
5714
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005715void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005716 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005717 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005718 Location obj_loc = locations->InAt(0);
5719 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005720 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005721 Location out_loc = locations->Out();
5722 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005723 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005724 locations->GetTemp(0) :
5725 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005726 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005727 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5728 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5729 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005730 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07005731 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005732
5733 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005734 // avoid null check if we know obj is not null.
5735 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00005736 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005737 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005738
Roland Levillain3b359c72015-11-17 19:35:12 +00005739 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005740 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005741
Roland Levillainc9285912015-12-18 10:38:42 +00005742 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005743 case TypeCheckKind::kExactCheck: {
5744 __ cmp(out, ShifterOperand(cls));
5745 // Classes must be equal for the instanceof to succeed.
5746 __ b(&zero, NE);
5747 __ LoadImmediate(out, 1);
5748 __ b(&done);
5749 break;
5750 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005751
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005752 case TypeCheckKind::kAbstractClassCheck: {
5753 // If the class is abstract, we eagerly fetch the super class of the
5754 // object to avoid doing a comparison we know will fail.
5755 Label loop;
5756 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005757 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005758 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005759 // If `out` is null, we use it for the result, and jump to `done`.
5760 __ CompareAndBranchIfZero(out, &done);
5761 __ cmp(out, ShifterOperand(cls));
5762 __ b(&loop, NE);
5763 __ LoadImmediate(out, 1);
5764 if (zero.IsLinked()) {
5765 __ b(&done);
5766 }
5767 break;
5768 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005769
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005770 case TypeCheckKind::kClassHierarchyCheck: {
5771 // Walk over the class hierarchy to find a match.
5772 Label loop, success;
5773 __ Bind(&loop);
5774 __ cmp(out, ShifterOperand(cls));
5775 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005776 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005777 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005778 __ CompareAndBranchIfNonZero(out, &loop);
5779 // If `out` is null, we use it for the result, and jump to `done`.
5780 __ b(&done);
5781 __ Bind(&success);
5782 __ LoadImmediate(out, 1);
5783 if (zero.IsLinked()) {
5784 __ b(&done);
5785 }
5786 break;
5787 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005788
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005789 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005790 // Do an exact check.
5791 Label exact_check;
5792 __ cmp(out, ShifterOperand(cls));
5793 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005794 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005795 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005796 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005797 // If `out` is null, we use it for the result, and jump to `done`.
5798 __ CompareAndBranchIfZero(out, &done);
5799 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5800 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5801 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005802 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005803 __ LoadImmediate(out, 1);
5804 __ b(&done);
5805 break;
5806 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005807
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005808 case TypeCheckKind::kArrayCheck: {
5809 __ cmp(out, ShifterOperand(cls));
5810 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00005811 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5812 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005813 codegen_->AddSlowPath(slow_path);
5814 __ b(slow_path->GetEntryLabel(), NE);
5815 __ LoadImmediate(out, 1);
5816 if (zero.IsLinked()) {
5817 __ b(&done);
5818 }
5819 break;
5820 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005821
Calin Juravle98893e12015-10-02 21:05:03 +01005822 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005823 case TypeCheckKind::kInterfaceCheck: {
5824 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00005825 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00005826 // cases.
5827 //
5828 // We cannot directly call the InstanceofNonTrivial runtime
5829 // entry point without resorting to a type checking slow path
5830 // here (i.e. by calling InvokeRuntime directly), as it would
5831 // require to assign fixed registers for the inputs of this
5832 // HInstanceOf instruction (following the runtime calling
5833 // convention), which might be cluttered by the potential first
5834 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00005835 //
5836 // TODO: Introduce a new runtime entry point taking the object
5837 // to test (instead of its class) as argument, and let it deal
5838 // with the read barrier issues. This will let us refactor this
5839 // case of the `switch` code as it was previously (with a direct
5840 // call to the runtime not using a type checking slow path).
5841 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00005842 DCHECK(locations->OnlyCallsOnSlowPath());
5843 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5844 /* is_fatal */ false);
5845 codegen_->AddSlowPath(slow_path);
5846 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005847 if (zero.IsLinked()) {
5848 __ b(&done);
5849 }
5850 break;
5851 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005852 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005853
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005854 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005855 __ Bind(&zero);
5856 __ LoadImmediate(out, 0);
5857 }
5858
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005859 if (done.IsLinked()) {
5860 __ Bind(&done);
5861 }
5862
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005863 if (slow_path != nullptr) {
5864 __ Bind(slow_path->GetExitLabel());
5865 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005866}
5867
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005868void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005869 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5870 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
5871
Roland Levillain3b359c72015-11-17 19:35:12 +00005872 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
5873 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005874 case TypeCheckKind::kExactCheck:
5875 case TypeCheckKind::kAbstractClassCheck:
5876 case TypeCheckKind::kClassHierarchyCheck:
5877 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005878 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
5879 LocationSummary::kCallOnSlowPath :
5880 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005881 break;
5882 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005883 case TypeCheckKind::kUnresolvedCheck:
5884 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005885 call_kind = LocationSummary::kCallOnSlowPath;
5886 break;
5887 }
5888
Roland Levillain3b359c72015-11-17 19:35:12 +00005889 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
5890 locations->SetInAt(0, Location::RequiresRegister());
5891 locations->SetInAt(1, Location::RequiresRegister());
5892 // Note that TypeCheckSlowPathARM uses this "temp" register too.
5893 locations->AddTemp(Location::RequiresRegister());
5894 // When read barriers are enabled, we need an additional temporary
5895 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005896 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005897 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005898 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005899}
5900
5901void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005902 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005903 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005904 Location obj_loc = locations->InAt(0);
5905 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005906 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005907 Location temp_loc = locations->GetTemp(0);
5908 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005909 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005910 locations->GetTemp(1) :
5911 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005912 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005913 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5914 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5915 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005916
Roland Levillain3b359c72015-11-17 19:35:12 +00005917 bool is_type_check_slow_path_fatal =
5918 (type_check_kind == TypeCheckKind::kExactCheck ||
5919 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5920 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5921 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
5922 !instruction->CanThrowIntoCatchBlock();
5923 SlowPathCode* type_check_slow_path =
5924 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5925 is_type_check_slow_path_fatal);
5926 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005927
5928 Label done;
5929 // Avoid null check if we know obj is not null.
5930 if (instruction->MustDoNullCheck()) {
5931 __ CompareAndBranchIfZero(obj, &done);
5932 }
5933
Roland Levillain3b359c72015-11-17 19:35:12 +00005934 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005935 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005936
Roland Levillain3b359c72015-11-17 19:35:12 +00005937 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005938 case TypeCheckKind::kExactCheck:
5939 case TypeCheckKind::kArrayCheck: {
5940 __ cmp(temp, ShifterOperand(cls));
5941 // Jump to slow path for throwing the exception or doing a
5942 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005943 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005944 break;
5945 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005946
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005947 case TypeCheckKind::kAbstractClassCheck: {
5948 // If the class is abstract, we eagerly fetch the super class of the
5949 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00005950 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005951 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005952 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005953 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005954
5955 // If the class reference currently in `temp` is not null, jump
5956 // to the `compare_classes` label to compare it with the checked
5957 // class.
5958 __ CompareAndBranchIfNonZero(temp, &compare_classes);
5959 // Otherwise, jump to the slow path to throw the exception.
5960 //
5961 // But before, move back the object's class into `temp` before
5962 // going into the slow path, as it has been overwritten in the
5963 // meantime.
5964 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005965 GenerateReferenceLoadTwoRegisters(
5966 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005967 __ b(type_check_slow_path->GetEntryLabel());
5968
5969 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005970 __ cmp(temp, ShifterOperand(cls));
5971 __ b(&loop, NE);
5972 break;
5973 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005974
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005975 case TypeCheckKind::kClassHierarchyCheck: {
5976 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005977 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005978 __ Bind(&loop);
5979 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005980 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005981
Roland Levillain3b359c72015-11-17 19:35:12 +00005982 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005983 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005984
5985 // If the class reference currently in `temp` is not null, jump
5986 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005987 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005988 // Otherwise, jump to the slow path to throw the exception.
5989 //
5990 // But before, move back the object's class into `temp` before
5991 // going into the slow path, as it has been overwritten in the
5992 // meantime.
5993 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005994 GenerateReferenceLoadTwoRegisters(
5995 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005996 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005997 break;
5998 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005999
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006000 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006001 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00006002 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01006003 __ cmp(temp, ShifterOperand(cls));
6004 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00006005
6006 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00006007 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006008 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006009
6010 // If the component type is not null (i.e. the object is indeed
6011 // an array), jump to label `check_non_primitive_component_type`
6012 // to further check that this component type is not a primitive
6013 // type.
6014 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6015 // Otherwise, jump to the slow path to throw the exception.
6016 //
6017 // But before, move back the object's class into `temp` before
6018 // going into the slow path, as it has been overwritten in the
6019 // meantime.
6020 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006021 GenerateReferenceLoadTwoRegisters(
6022 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006023 __ b(type_check_slow_path->GetEntryLabel());
6024
6025 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006026 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006027 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6028 __ CompareAndBranchIfZero(temp, &done);
6029 // Same comment as above regarding `temp` and the slow path.
6030 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006031 GenerateReferenceLoadTwoRegisters(
6032 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006033 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006034 break;
6035 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006036
Calin Juravle98893e12015-10-02 21:05:03 +01006037 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006038 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006039 // We always go into the type check slow path for the unresolved
6040 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006041 //
6042 // We cannot directly call the CheckCast runtime entry point
6043 // without resorting to a type checking slow path here (i.e. by
6044 // calling InvokeRuntime directly), as it would require to
6045 // assign fixed registers for the inputs of this HInstanceOf
6046 // instruction (following the runtime calling convention), which
6047 // might be cluttered by the potential first read barrier
6048 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006049 //
6050 // TODO: Introduce a new runtime entry point taking the object
6051 // to test (instead of its class) as argument, and let it deal
6052 // with the read barrier issues. This will let us refactor this
6053 // case of the `switch` code as it was previously (with a direct
6054 // call to the runtime not using a type checking slow path).
6055 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006056 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006057 break;
6058 }
6059 __ Bind(&done);
6060
Roland Levillain3b359c72015-11-17 19:35:12 +00006061 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006062}
6063
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006064void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6065 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006066 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006067 InvokeRuntimeCallingConvention calling_convention;
6068 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6069}
6070
6071void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6072 codegen_->InvokeRuntime(instruction->IsEnter()
6073 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
6074 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00006075 instruction->GetDexPc(),
6076 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00006077 if (instruction->IsEnter()) {
6078 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6079 } else {
6080 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6081 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006082}
6083
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006084void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6085void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6086void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006087
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006088void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006089 LocationSummary* locations =
6090 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6091 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6092 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006093 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006094 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006095 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006096 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006097}
6098
6099void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6100 HandleBitwiseOperation(instruction);
6101}
6102
6103void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6104 HandleBitwiseOperation(instruction);
6105}
6106
6107void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6108 HandleBitwiseOperation(instruction);
6109}
6110
Artem Serov7fc63502016-02-09 17:15:29 +00006111
6112void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6113 LocationSummary* locations =
6114 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6115 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6116 || instruction->GetResultType() == Primitive::kPrimLong);
6117
6118 locations->SetInAt(0, Location::RequiresRegister());
6119 locations->SetInAt(1, Location::RequiresRegister());
6120 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6121}
6122
6123void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6124 LocationSummary* locations = instruction->GetLocations();
6125 Location first = locations->InAt(0);
6126 Location second = locations->InAt(1);
6127 Location out = locations->Out();
6128
6129 if (instruction->GetResultType() == Primitive::kPrimInt) {
6130 Register first_reg = first.AsRegister<Register>();
6131 ShifterOperand second_reg(second.AsRegister<Register>());
6132 Register out_reg = out.AsRegister<Register>();
6133
6134 switch (instruction->GetOpKind()) {
6135 case HInstruction::kAnd:
6136 __ bic(out_reg, first_reg, second_reg);
6137 break;
6138 case HInstruction::kOr:
6139 __ orn(out_reg, first_reg, second_reg);
6140 break;
6141 // There is no EON on arm.
6142 case HInstruction::kXor:
6143 default:
6144 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6145 UNREACHABLE();
6146 }
6147 return;
6148
6149 } else {
6150 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6151 Register first_low = first.AsRegisterPairLow<Register>();
6152 Register first_high = first.AsRegisterPairHigh<Register>();
6153 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6154 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6155 Register out_low = out.AsRegisterPairLow<Register>();
6156 Register out_high = out.AsRegisterPairHigh<Register>();
6157
6158 switch (instruction->GetOpKind()) {
6159 case HInstruction::kAnd:
6160 __ bic(out_low, first_low, second_low);
6161 __ bic(out_high, first_high, second_high);
6162 break;
6163 case HInstruction::kOr:
6164 __ orn(out_low, first_low, second_low);
6165 __ orn(out_high, first_high, second_high);
6166 break;
6167 // There is no EON on arm.
6168 case HInstruction::kXor:
6169 default:
6170 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6171 UNREACHABLE();
6172 }
6173 }
6174}
6175
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006176void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6177 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6178 if (value == 0xffffffffu) {
6179 if (out != first) {
6180 __ mov(out, ShifterOperand(first));
6181 }
6182 return;
6183 }
6184 if (value == 0u) {
6185 __ mov(out, ShifterOperand(0));
6186 return;
6187 }
6188 ShifterOperand so;
6189 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6190 __ and_(out, first, so);
6191 } else {
6192 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6193 __ bic(out, first, ShifterOperand(~value));
6194 }
6195}
6196
6197void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6198 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6199 if (value == 0u) {
6200 if (out != first) {
6201 __ mov(out, ShifterOperand(first));
6202 }
6203 return;
6204 }
6205 if (value == 0xffffffffu) {
6206 __ mvn(out, ShifterOperand(0));
6207 return;
6208 }
6209 ShifterOperand so;
6210 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6211 __ orr(out, first, so);
6212 } else {
6213 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6214 __ orn(out, first, ShifterOperand(~value));
6215 }
6216}
6217
6218void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6219 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6220 if (value == 0u) {
6221 if (out != first) {
6222 __ mov(out, ShifterOperand(first));
6223 }
6224 return;
6225 }
6226 __ eor(out, first, ShifterOperand(value));
6227}
6228
Vladimir Marko59751a72016-08-05 14:37:27 +01006229void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6230 Location first,
6231 uint64_t value) {
6232 Register out_low = out.AsRegisterPairLow<Register>();
6233 Register out_high = out.AsRegisterPairHigh<Register>();
6234 Register first_low = first.AsRegisterPairLow<Register>();
6235 Register first_high = first.AsRegisterPairHigh<Register>();
6236 uint32_t value_low = Low32Bits(value);
6237 uint32_t value_high = High32Bits(value);
6238 if (value_low == 0u) {
6239 if (out_low != first_low) {
6240 __ mov(out_low, ShifterOperand(first_low));
6241 }
6242 __ AddConstant(out_high, first_high, value_high);
6243 return;
6244 }
6245 __ AddConstantSetFlags(out_low, first_low, value_low);
6246 ShifterOperand so;
6247 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6248 __ adc(out_high, first_high, so);
6249 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6250 __ sbc(out_high, first_high, so);
6251 } else {
6252 LOG(FATAL) << "Unexpected constant " << value_high;
6253 UNREACHABLE();
6254 }
6255}
6256
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006257void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6258 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006259 Location first = locations->InAt(0);
6260 Location second = locations->InAt(1);
6261 Location out = locations->Out();
6262
6263 if (second.IsConstant()) {
6264 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6265 uint32_t value_low = Low32Bits(value);
6266 if (instruction->GetResultType() == Primitive::kPrimInt) {
6267 Register first_reg = first.AsRegister<Register>();
6268 Register out_reg = out.AsRegister<Register>();
6269 if (instruction->IsAnd()) {
6270 GenerateAndConst(out_reg, first_reg, value_low);
6271 } else if (instruction->IsOr()) {
6272 GenerateOrrConst(out_reg, first_reg, value_low);
6273 } else {
6274 DCHECK(instruction->IsXor());
6275 GenerateEorConst(out_reg, first_reg, value_low);
6276 }
6277 } else {
6278 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6279 uint32_t value_high = High32Bits(value);
6280 Register first_low = first.AsRegisterPairLow<Register>();
6281 Register first_high = first.AsRegisterPairHigh<Register>();
6282 Register out_low = out.AsRegisterPairLow<Register>();
6283 Register out_high = out.AsRegisterPairHigh<Register>();
6284 if (instruction->IsAnd()) {
6285 GenerateAndConst(out_low, first_low, value_low);
6286 GenerateAndConst(out_high, first_high, value_high);
6287 } else if (instruction->IsOr()) {
6288 GenerateOrrConst(out_low, first_low, value_low);
6289 GenerateOrrConst(out_high, first_high, value_high);
6290 } else {
6291 DCHECK(instruction->IsXor());
6292 GenerateEorConst(out_low, first_low, value_low);
6293 GenerateEorConst(out_high, first_high, value_high);
6294 }
6295 }
6296 return;
6297 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006298
6299 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006300 Register first_reg = first.AsRegister<Register>();
6301 ShifterOperand second_reg(second.AsRegister<Register>());
6302 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006303 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006304 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006305 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006306 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006307 } else {
6308 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006309 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006310 }
6311 } else {
6312 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006313 Register first_low = first.AsRegisterPairLow<Register>();
6314 Register first_high = first.AsRegisterPairHigh<Register>();
6315 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6316 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6317 Register out_low = out.AsRegisterPairLow<Register>();
6318 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006319 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006320 __ and_(out_low, first_low, second_low);
6321 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006322 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006323 __ orr(out_low, first_low, second_low);
6324 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006325 } else {
6326 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006327 __ eor(out_low, first_low, second_low);
6328 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006329 }
6330 }
6331}
6332
Roland Levillainc9285912015-12-18 10:38:42 +00006333void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6334 Location out,
6335 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006336 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006337 Register out_reg = out.AsRegister<Register>();
6338 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006339 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006340 if (kUseBakerReadBarrier) {
6341 // Load with fast path based Baker's read barrier.
6342 // /* HeapReference<Object> */ out = *(out + offset)
6343 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006344 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006345 } else {
6346 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006347 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006348 // in the following move operation, as we will need it for the
6349 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006350 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006351 // /* HeapReference<Object> */ out = *(out + offset)
6352 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006353 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006354 }
6355 } else {
6356 // Plain load with no read barrier.
6357 // /* HeapReference<Object> */ out = *(out + offset)
6358 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6359 __ MaybeUnpoisonHeapReference(out_reg);
6360 }
6361}
6362
6363void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6364 Location out,
6365 Location obj,
6366 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006367 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006368 Register out_reg = out.AsRegister<Register>();
6369 Register obj_reg = obj.AsRegister<Register>();
6370 if (kEmitCompilerReadBarrier) {
6371 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006372 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006373 // Load with fast path based Baker's read barrier.
6374 // /* HeapReference<Object> */ out = *(obj + offset)
6375 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006376 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006377 } else {
6378 // Load with slow path based read barrier.
6379 // /* HeapReference<Object> */ out = *(obj + offset)
6380 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6381 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6382 }
6383 } else {
6384 // Plain load with no read barrier.
6385 // /* HeapReference<Object> */ out = *(obj + offset)
6386 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6387 __ MaybeUnpoisonHeapReference(out_reg);
6388 }
6389}
6390
6391void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6392 Location root,
6393 Register obj,
6394 uint32_t offset) {
6395 Register root_reg = root.AsRegister<Register>();
6396 if (kEmitCompilerReadBarrier) {
6397 if (kUseBakerReadBarrier) {
6398 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6399 // Baker's read barrier are used:
6400 //
6401 // root = obj.field;
6402 // if (Thread::Current()->GetIsGcMarking()) {
6403 // root = ReadBarrier::Mark(root)
6404 // }
6405
6406 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6407 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6408 static_assert(
6409 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6410 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6411 "have different sizes.");
6412 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6413 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6414 "have different sizes.");
6415
6416 // Slow path used to mark the GC root `root`.
6417 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006418 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006419 codegen_->AddSlowPath(slow_path);
6420
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006421 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006422 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006423 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006424 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6425 __ Bind(slow_path->GetExitLabel());
6426 } else {
6427 // GC root loaded through a slow path for read barriers other
6428 // than Baker's.
6429 // /* GcRoot<mirror::Object>* */ root = obj + offset
6430 __ AddConstant(root_reg, obj, offset);
6431 // /* mirror::Object* */ root = root->Read()
6432 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6433 }
6434 } else {
6435 // Plain GC root load with no read barrier.
6436 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6437 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6438 // Note that GC roots are not affected by heap poisoning, thus we
6439 // do not have to unpoison `root_reg` here.
6440 }
6441}
6442
6443void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6444 Location ref,
6445 Register obj,
6446 uint32_t offset,
6447 Location temp,
6448 bool needs_null_check) {
6449 DCHECK(kEmitCompilerReadBarrier);
6450 DCHECK(kUseBakerReadBarrier);
6451
6452 // /* HeapReference<Object> */ ref = *(obj + offset)
6453 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006454 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006455 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006456 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006457}
6458
6459void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6460 Location ref,
6461 Register obj,
6462 uint32_t data_offset,
6463 Location index,
6464 Location temp,
6465 bool needs_null_check) {
6466 DCHECK(kEmitCompilerReadBarrier);
6467 DCHECK(kUseBakerReadBarrier);
6468
Roland Levillainbfea3352016-06-23 13:48:47 +01006469 static_assert(
6470 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6471 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006472 // /* HeapReference<Object> */ ref =
6473 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006474 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006475 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006476 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006477}
6478
6479void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6480 Location ref,
6481 Register obj,
6482 uint32_t offset,
6483 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006484 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006485 Location temp,
6486 bool needs_null_check) {
6487 DCHECK(kEmitCompilerReadBarrier);
6488 DCHECK(kUseBakerReadBarrier);
6489
6490 // In slow path based read barriers, the read barrier call is
6491 // inserted after the original load. However, in fast path based
6492 // Baker's read barriers, we need to perform the load of
6493 // mirror::Object::monitor_ *before* the original reference load.
6494 // This load-load ordering is required by the read barrier.
6495 // The fast path/slow path (for Baker's algorithm) should look like:
6496 //
6497 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6498 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6499 // HeapReference<Object> ref = *src; // Original reference load.
6500 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6501 // if (is_gray) {
6502 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6503 // }
6504 //
6505 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006506 // slightly more complex as it performs additional checks that we do
6507 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006508
6509 Register ref_reg = ref.AsRegister<Register>();
6510 Register temp_reg = temp.AsRegister<Register>();
6511 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6512
6513 // /* int32_t */ monitor = obj->monitor_
6514 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6515 if (needs_null_check) {
6516 MaybeRecordImplicitNullCheck(instruction);
6517 }
6518 // /* LockWord */ lock_word = LockWord(monitor)
6519 static_assert(sizeof(LockWord) == sizeof(int32_t),
6520 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006521
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006522 // Introduce a dependency on the lock_word including the rb_state,
6523 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006524 // a memory barrier (which would be more expensive).
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006525 // obj is unchanged by this operation, but its value now depends on temp_reg.
6526 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006527
6528 // The actual reference load.
6529 if (index.IsValid()) {
Roland Levillainbfea3352016-06-23 13:48:47 +01006530 // Load types involving an "index": ArrayGet and
6531 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
6532 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006533 if (index.IsConstant()) {
6534 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006535 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006536 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6537 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006538 // Handle the special case of the
6539 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use
6540 // a register pair as index ("long offset"), of which only the low
6541 // part contains data.
6542 Register index_reg = index.IsRegisterPair()
6543 ? index.AsRegisterPairLow<Register>()
6544 : index.AsRegister<Register>();
6545 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006546 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6547 }
6548 } else {
6549 // /* HeapReference<Object> */ ref = *(obj + offset)
6550 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6551 }
6552
6553 // Object* ref = ref_addr->AsMirrorPtr()
6554 __ MaybeUnpoisonHeapReference(ref_reg);
6555
6556 // Slow path used to mark the object `ref` when it is gray.
6557 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006558 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
Roland Levillainc9285912015-12-18 10:38:42 +00006559 AddSlowPath(slow_path);
6560
6561 // if (rb_state == ReadBarrier::gray_ptr_)
6562 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006563 // Given the numeric representation, it's enough to check the low bit of the
6564 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6565 // which can be a 16-bit instruction unlike the TST immediate.
6566 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6567 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6568 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6569 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6570 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006571 __ Bind(slow_path->GetExitLabel());
6572}
6573
6574void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6575 Location out,
6576 Location ref,
6577 Location obj,
6578 uint32_t offset,
6579 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006580 DCHECK(kEmitCompilerReadBarrier);
6581
Roland Levillainc9285912015-12-18 10:38:42 +00006582 // Insert a slow path based read barrier *after* the reference load.
6583 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006584 // If heap poisoning is enabled, the unpoisoning of the loaded
6585 // reference will be carried out by the runtime within the slow
6586 // path.
6587 //
6588 // Note that `ref` currently does not get unpoisoned (when heap
6589 // poisoning is enabled), which is alright as the `ref` argument is
6590 // not used by the artReadBarrierSlow entry point.
6591 //
6592 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
6593 SlowPathCode* slow_path = new (GetGraph()->GetArena())
6594 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6595 AddSlowPath(slow_path);
6596
Roland Levillain3b359c72015-11-17 19:35:12 +00006597 __ b(slow_path->GetEntryLabel());
6598 __ Bind(slow_path->GetExitLabel());
6599}
6600
Roland Levillainc9285912015-12-18 10:38:42 +00006601void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6602 Location out,
6603 Location ref,
6604 Location obj,
6605 uint32_t offset,
6606 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006607 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006608 // Baker's read barriers shall be handled by the fast path
6609 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6610 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006611 // If heap poisoning is enabled, unpoisoning will be taken care of
6612 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006613 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006614 } else if (kPoisonHeapReferences) {
6615 __ UnpoisonHeapReference(out.AsRegister<Register>());
6616 }
6617}
6618
Roland Levillainc9285912015-12-18 10:38:42 +00006619void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6620 Location out,
6621 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006622 DCHECK(kEmitCompilerReadBarrier);
6623
Roland Levillainc9285912015-12-18 10:38:42 +00006624 // Insert a slow path based read barrier *after* the GC root load.
6625 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006626 // Note that GC roots are not affected by heap poisoning, so we do
6627 // not need to do anything special for this here.
6628 SlowPathCode* slow_path =
6629 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6630 AddSlowPath(slow_path);
6631
Roland Levillain3b359c72015-11-17 19:35:12 +00006632 __ b(slow_path->GetEntryLabel());
6633 __ Bind(slow_path->GetExitLabel());
6634}
6635
Vladimir Markodc151b22015-10-15 18:02:30 +01006636HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6637 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
6638 MethodReference target_method) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006639 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6640 // We disable pc-relative load when there is an irreducible loop, as the optimization
6641 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006642 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6643 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006644 if (GetGraph()->HasIrreducibleLoops() &&
6645 (dispatch_info.method_load_kind ==
6646 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
6647 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
6648 }
6649
6650 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01006651 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
6652 if (&outer_dex_file != target_method.dex_file) {
6653 // Calls across dex files are more likely to exceed the available BL range,
6654 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
6655 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
6656 (desired_dispatch_info.method_load_kind ==
6657 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
6658 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
6659 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
6660 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006661 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01006662 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006663 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01006664 0u
6665 };
6666 }
6667 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006668 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006669}
6670
Vladimir Markob4536b72015-11-24 13:45:23 +00006671Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
6672 Register temp) {
6673 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
6674 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
6675 if (!invoke->GetLocations()->Intrinsified()) {
6676 return location.AsRegister<Register>();
6677 }
6678 // For intrinsics we allow any location, so it may be on the stack.
6679 if (!location.IsRegister()) {
6680 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
6681 return temp;
6682 }
6683 // For register locations, check if the register was saved. If so, get it from the stack.
6684 // Note: There is a chance that the register was saved but not overwritten, so we could
6685 // save one load. However, since this is just an intrinsic slow path we prefer this
6686 // simple and more robust approach rather that trying to determine if that's the case.
6687 SlowPathCode* slow_path = GetCurrentSlowPath();
6688 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
6689 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
6690 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
6691 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
6692 return temp;
6693 }
6694 return location.AsRegister<Register>();
6695}
6696
Nicolas Geoffray38207af2015-06-01 15:46:22 +01006697void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00006698 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00006699 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00006700 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6701 // LR = code address from literal pool with link-time patch.
6702 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00006703 break;
6704 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6705 // LR = invoke->GetDirectCodePtr();
6706 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00006707 break;
6708 default:
6709 break;
6710 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006711
Vladimir Marko58155012015-08-19 12:49:41 +00006712 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
6713 switch (invoke->GetMethodLoadKind()) {
6714 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
6715 // temp = thread->string_init_entrypoint
6716 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
6717 break;
6718 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006719 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006720 break;
6721 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
6722 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
6723 break;
6724 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
6725 __ LoadLiteral(temp.AsRegister<Register>(),
6726 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
6727 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00006728 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
6729 HArmDexCacheArraysBase* base =
6730 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
6731 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
6732 temp.AsRegister<Register>());
6733 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
6734 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
6735 break;
6736 }
Vladimir Marko58155012015-08-19 12:49:41 +00006737 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00006738 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006739 Register method_reg;
6740 Register reg = temp.AsRegister<Register>();
6741 if (current_method.IsRegister()) {
6742 method_reg = current_method.AsRegister<Register>();
6743 } else {
6744 DCHECK(invoke->GetLocations()->Intrinsified());
6745 DCHECK(!current_method.IsValid());
6746 method_reg = reg;
6747 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
6748 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006749 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
6750 __ LoadFromOffset(kLoadWord,
6751 reg,
6752 method_reg,
6753 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01006754 // temp = temp[index_in_cache];
6755 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
6756 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00006757 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
6758 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01006759 }
Vladimir Marko58155012015-08-19 12:49:41 +00006760 }
6761
6762 switch (invoke->GetCodePtrLocation()) {
6763 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
6764 __ bl(GetFrameEntryLabel());
6765 break;
6766 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01006767 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07006768 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01006769 // Arbitrarily branch to the BL itself, override at link time.
6770 __ bl(&relative_call_patches_.back().label);
6771 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006772 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6773 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6774 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00006775 // LR()
6776 __ blx(LR);
6777 break;
6778 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6779 // LR = callee_method->entry_point_from_quick_compiled_code_
6780 __ LoadFromOffset(
6781 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07006782 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006783 // LR()
6784 __ blx(LR);
6785 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006786 }
6787
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006788 DCHECK(!IsLeafMethod());
6789}
6790
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006791void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
6792 Register temp = temp_location.AsRegister<Register>();
6793 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6794 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006795
6796 // Use the calling convention instead of the location of the receiver, as
6797 // intrinsics may have put the receiver in a different register. In the intrinsics
6798 // slow path, the arguments have been moved to the right place, so here we are
6799 // guaranteed that the receiver is the first register of the calling convention.
6800 InvokeDexCallingConvention calling_convention;
6801 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006802 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00006803 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006804 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006805 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00006806 // Instead of simply (possibly) unpoisoning `temp` here, we should
6807 // emit a read barrier for the previous class reference load.
6808 // However this is not required in practice, as this is an
6809 // intermediate/temporary reference and because the current
6810 // concurrent copying collector keeps the from-space memory
6811 // intact/accessible until the end of the marking phase (the
6812 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006813 __ MaybeUnpoisonHeapReference(temp);
6814 // temp = temp->GetMethodAt(method_offset);
6815 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006816 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006817 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
6818 // LR = temp->GetEntryPoint();
6819 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
6820 // LR();
6821 __ blx(LR);
6822}
6823
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006824CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
6825 const DexFile& dex_file, uint32_t string_index) {
6826 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
6827}
6828
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006829CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
6830 const DexFile& dex_file, uint32_t type_index) {
6831 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
6832}
6833
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006834CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
6835 const DexFile& dex_file, uint32_t element_offset) {
6836 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
6837}
6838
6839CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
6840 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
6841 patches->emplace_back(dex_file, offset_or_index);
6842 return &patches->back();
6843}
6844
6845Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
6846 uint32_t string_index) {
6847 return boot_image_string_patches_.GetOrCreate(
6848 StringReference(&dex_file, string_index),
6849 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6850}
6851
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006852Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
6853 uint32_t type_index) {
6854 return boot_image_type_patches_.GetOrCreate(
6855 TypeReference(&dex_file, type_index),
6856 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6857}
6858
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006859Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
6860 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
6861 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
6862 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
6863}
6864
6865Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
6866 return DeduplicateUint32Literal(address, &uint32_literals_);
6867}
6868
Vladimir Marko58155012015-08-19 12:49:41 +00006869void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
6870 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00006871 size_t size =
6872 method_patches_.size() +
6873 call_patches_.size() +
6874 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006875 /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() +
6876 boot_image_string_patches_.size() +
6877 /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006878 boot_image_type_patches_.size() +
6879 /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006880 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00006881 linker_patches->reserve(size);
6882 for (const auto& entry : method_patches_) {
6883 const MethodReference& target_method = entry.first;
6884 Literal* literal = entry.second;
6885 DCHECK(literal->GetLabel()->IsBound());
6886 uint32_t literal_offset = literal->GetLabel()->Position();
6887 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
6888 target_method.dex_file,
6889 target_method.dex_method_index));
6890 }
6891 for (const auto& entry : call_patches_) {
6892 const MethodReference& target_method = entry.first;
6893 Literal* literal = entry.second;
6894 DCHECK(literal->GetLabel()->IsBound());
6895 uint32_t literal_offset = literal->GetLabel()->Position();
6896 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
6897 target_method.dex_file,
6898 target_method.dex_method_index));
6899 }
6900 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
6901 uint32_t literal_offset = info.label.Position();
6902 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
6903 info.target_method.dex_file,
6904 info.target_method.dex_method_index));
6905 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006906 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
6907 const DexFile& dex_file = info.target_dex_file;
6908 size_t base_element_offset = info.offset_or_index;
6909 DCHECK(info.add_pc_label.IsBound());
6910 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006911 // Add MOVW patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006912 DCHECK(info.movw_label.IsBound());
6913 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006914 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset,
6915 &dex_file,
6916 add_pc_offset,
6917 base_element_offset));
6918 // Add MOVT patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006919 DCHECK(info.movt_label.IsBound());
6920 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006921 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset,
6922 &dex_file,
6923 add_pc_offset,
6924 base_element_offset));
6925 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006926 for (const auto& entry : boot_image_string_patches_) {
6927 const StringReference& target_string = entry.first;
6928 Literal* literal = entry.second;
6929 DCHECK(literal->GetLabel()->IsBound());
6930 uint32_t literal_offset = literal->GetLabel()->Position();
6931 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
6932 target_string.dex_file,
6933 target_string.string_index));
6934 }
6935 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
6936 const DexFile& dex_file = info.target_dex_file;
6937 uint32_t string_index = info.offset_or_index;
6938 DCHECK(info.add_pc_label.IsBound());
6939 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6940 // Add MOVW patch.
6941 DCHECK(info.movw_label.IsBound());
6942 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6943 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset,
6944 &dex_file,
6945 add_pc_offset,
6946 string_index));
6947 // Add MOVT patch.
6948 DCHECK(info.movt_label.IsBound());
6949 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6950 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset,
6951 &dex_file,
6952 add_pc_offset,
6953 string_index));
6954 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006955 for (const auto& entry : boot_image_type_patches_) {
6956 const TypeReference& target_type = entry.first;
6957 Literal* literal = entry.second;
6958 DCHECK(literal->GetLabel()->IsBound());
6959 uint32_t literal_offset = literal->GetLabel()->Position();
6960 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
6961 target_type.dex_file,
6962 target_type.type_index));
6963 }
6964 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
6965 const DexFile& dex_file = info.target_dex_file;
6966 uint32_t type_index = info.offset_or_index;
6967 DCHECK(info.add_pc_label.IsBound());
6968 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6969 // Add MOVW patch.
6970 DCHECK(info.movw_label.IsBound());
6971 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6972 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset,
6973 &dex_file,
6974 add_pc_offset,
6975 type_index));
6976 // Add MOVT patch.
6977 DCHECK(info.movt_label.IsBound());
6978 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6979 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset,
6980 &dex_file,
6981 add_pc_offset,
6982 type_index));
6983 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006984 for (const auto& entry : boot_image_address_patches_) {
6985 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
6986 Literal* literal = entry.second;
6987 DCHECK(literal->GetLabel()->IsBound());
6988 uint32_t literal_offset = literal->GetLabel()->Position();
6989 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
6990 }
6991}
6992
6993Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
6994 return map->GetOrCreate(
6995 value,
6996 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00006997}
6998
6999Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
7000 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007001 return map->GetOrCreate(
7002 target_method,
7003 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00007004}
7005
7006Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
7007 return DeduplicateMethodLiteral(target_method, &method_patches_);
7008}
7009
7010Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
7011 return DeduplicateMethodLiteral(target_method, &call_patches_);
7012}
7013
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03007014void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7015 LocationSummary* locations =
7016 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7017 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7018 Location::RequiresRegister());
7019 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7020 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7021 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7022}
7023
7024void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7025 LocationSummary* locations = instr->GetLocations();
7026 Register res = locations->Out().AsRegister<Register>();
7027 Register accumulator =
7028 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7029 Register mul_left =
7030 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7031 Register mul_right =
7032 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7033
7034 if (instr->GetOpKind() == HInstruction::kAdd) {
7035 __ mla(res, mul_left, mul_right, accumulator);
7036 } else {
7037 __ mls(res, mul_left, mul_right, accumulator);
7038 }
7039}
7040
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007041void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007042 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007043 LOG(FATAL) << "Unreachable";
7044}
7045
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007046void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007047 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007048 LOG(FATAL) << "Unreachable";
7049}
7050
Mark Mendellfe57faa2015-09-18 09:26:15 -04007051// Simple implementation of packed switch - generate cascaded compare/jumps.
7052void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7053 LocationSummary* locations =
7054 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7055 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007056 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007057 codegen_->GetAssembler()->IsThumb()) {
7058 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7059 if (switch_instr->GetStartValue() != 0) {
7060 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7061 }
7062 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007063}
7064
7065void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7066 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007067 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007068 LocationSummary* locations = switch_instr->GetLocations();
7069 Register value_reg = locations->InAt(0).AsRegister<Register>();
7070 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7071
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007072 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007073 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007074 Register temp_reg = IP;
7075 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7076 // the immediate, because IP is used as the destination register. For the other
7077 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7078 // and they can be encoded in the instruction without making use of IP register.
7079 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7080
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007081 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007082 // Jump to successors[0] if value == lower_bound.
7083 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7084 int32_t last_index = 0;
7085 for (; num_entries - last_index > 2; last_index += 2) {
7086 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7087 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7088 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7089 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7090 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7091 }
7092 if (num_entries - last_index == 2) {
7093 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007094 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007095 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007096 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007097
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007098 // And the default for any other value.
7099 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7100 __ b(codegen_->GetLabelOf(default_block));
7101 }
7102 } else {
7103 // Create a table lookup.
7104 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7105
7106 // Materialize a pointer to the switch table
7107 std::vector<Label*> labels(num_entries);
7108 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7109 for (uint32_t i = 0; i < num_entries; i++) {
7110 labels[i] = codegen_->GetLabelOf(successors[i]);
7111 }
7112 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7113
7114 // Remove the bias.
7115 Register key_reg;
7116 if (lower_bound != 0) {
7117 key_reg = locations->GetTemp(1).AsRegister<Register>();
7118 __ AddConstant(key_reg, value_reg, -lower_bound);
7119 } else {
7120 key_reg = value_reg;
7121 }
7122
7123 // Check whether the value is in the table, jump to default block if not.
7124 __ CmpConstant(key_reg, num_entries - 1);
7125 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7126
7127 // Load the displacement from the table.
7128 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7129
7130 // Dispatch is a direct add to the PC (for Thumb2).
7131 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007132 }
7133}
7134
Vladimir Markob4536b72015-11-24 13:45:23 +00007135void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7136 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7137 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007138}
7139
7140void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7141 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007142 CodeGeneratorARM::PcRelativePatchInfo* labels =
7143 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007144 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007145 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007146 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007147 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007148 __ BindTrackedLabel(&labels->add_pc_label);
7149 __ add(base_reg, base_reg, ShifterOperand(PC));
7150}
7151
Andreas Gampe85b62f22015-09-09 13:15:38 -07007152void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7153 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007154 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007155 return;
7156 }
7157
7158 DCHECK_NE(type, Primitive::kPrimVoid);
7159
7160 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7161 if (return_loc.Equals(trg)) {
7162 return;
7163 }
7164
7165 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7166 // with the last branch.
7167 if (type == Primitive::kPrimLong) {
7168 HParallelMove parallel_move(GetGraph()->GetArena());
7169 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7170 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7171 GetMoveResolver()->EmitNativeCode(&parallel_move);
7172 } else if (type == Primitive::kPrimDouble) {
7173 HParallelMove parallel_move(GetGraph()->GetArena());
7174 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7175 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7176 GetMoveResolver()->EmitNativeCode(&parallel_move);
7177 } else {
7178 // Let the parallel move resolver take care of all of this.
7179 HParallelMove parallel_move(GetGraph()->GetArena());
7180 parallel_move.AddMove(return_loc, trg, type, nullptr);
7181 GetMoveResolver()->EmitNativeCode(&parallel_move);
7182 }
7183}
7184
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007185void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7186 LocationSummary* locations =
7187 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7188 locations->SetInAt(0, Location::RequiresRegister());
7189 locations->SetOut(Location::RequiresRegister());
7190}
7191
7192void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7193 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007194 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007195 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007196 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007197 __ LoadFromOffset(kLoadWord,
7198 locations->Out().AsRegister<Register>(),
7199 locations->InAt(0).AsRegister<Register>(),
7200 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007201 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007202 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007203 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007204 __ LoadFromOffset(kLoadWord,
7205 locations->Out().AsRegister<Register>(),
7206 locations->InAt(0).AsRegister<Register>(),
7207 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7208 __ LoadFromOffset(kLoadWord,
7209 locations->Out().AsRegister<Register>(),
7210 locations->Out().AsRegister<Register>(),
7211 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007212 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007213}
7214
Roland Levillain4d027112015-07-01 15:41:14 +01007215#undef __
7216#undef QUICK_ENTRY_POINT
7217
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007218} // namespace arm
7219} // namespace art