blob: 7c2e80e741df734c4fbfc2ea15ab9b4fa207dbe7 [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 Levillain0b671c02016-08-19 12:02:34 +0100432 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
433 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
Roland Levillainc9285912015-12-18 10:38:42 +0000434 << "Unexpected instruction in read barrier marking slow path: "
435 << instruction_->DebugName();
436
437 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100438 // No need to save live registers; it's taken care of by the
439 // entrypoint. Also, there is no need to update the stack mask,
440 // as this runtime call will not trigger a garbage collection.
Roland Levillainc9285912015-12-18 10:38:42 +0000441 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Roland Levillain02b75802016-07-13 11:54:35 +0100442 DCHECK_NE(reg, SP);
443 DCHECK_NE(reg, LR);
444 DCHECK_NE(reg, PC);
Roland Levillain0b671c02016-08-19 12:02:34 +0100445 // IP is used internally by the ReadBarrierMarkRegX entry point
446 // as a temporary, it cannot be the entry point's input/output.
447 DCHECK_NE(reg, IP);
Roland Levillain02b75802016-07-13 11:54:35 +0100448 DCHECK(0 <= reg && reg < kNumberOfCoreRegisters) << reg;
449 // "Compact" slow path, saving two moves.
450 //
451 // Instead of using the standard runtime calling convention (input
452 // and output in R0):
453 //
454 // R0 <- obj
455 // R0 <- ReadBarrierMark(R0)
456 // obj <- R0
457 //
458 // we just use rX (the register holding `obj`) as input and output
459 // of a dedicated entrypoint:
460 //
461 // rX <- ReadBarrierMarkRegX(rX)
462 //
463 int32_t entry_point_offset =
Andreas Gampe542451c2016-07-26 09:02:02 -0700464 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(reg);
Roland Levillaindec8f632016-07-22 17:10:06 +0100465 // This runtime call does not require a stack map.
466 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
Roland Levillainc9285912015-12-18 10:38:42 +0000467 __ b(GetExitLabel());
468 }
469
470 private:
Roland Levillainc9285912015-12-18 10:38:42 +0000471 const Location obj_;
472
473 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM);
474};
475
Roland Levillain3b359c72015-11-17 19:35:12 +0000476// Slow path generating a read barrier for a heap reference.
477class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCode {
478 public:
479 ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction,
480 Location out,
481 Location ref,
482 Location obj,
483 uint32_t offset,
484 Location index)
David Srbecky9cd6d372016-02-09 15:24:47 +0000485 : SlowPathCode(instruction),
Roland Levillain3b359c72015-11-17 19:35:12 +0000486 out_(out),
487 ref_(ref),
488 obj_(obj),
489 offset_(offset),
490 index_(index) {
491 DCHECK(kEmitCompilerReadBarrier);
492 // If `obj` is equal to `out` or `ref`, it means the initial object
493 // has been overwritten by (or after) the heap object reference load
494 // to be instrumented, e.g.:
495 //
496 // __ LoadFromOffset(kLoadWord, out, out, offset);
Roland Levillainc9285912015-12-18 10:38:42 +0000497 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
Roland Levillain3b359c72015-11-17 19:35:12 +0000498 //
499 // In that case, we have lost the information about the original
500 // object, and the emitted read barrier cannot work properly.
501 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
502 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
503 }
504
505 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
506 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
507 LocationSummary* locations = instruction_->GetLocations();
508 Register reg_out = out_.AsRegister<Register>();
509 DCHECK(locations->CanCall());
510 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillain3d312422016-06-23 13:53:42 +0100511 DCHECK(instruction_->IsInstanceFieldGet() ||
512 instruction_->IsStaticFieldGet() ||
513 instruction_->IsArrayGet() ||
514 instruction_->IsInstanceOf() ||
515 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100516 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillainc9285912015-12-18 10:38:42 +0000517 << "Unexpected instruction in read barrier for heap reference slow path: "
518 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000519
520 __ Bind(GetEntryLabel());
521 SaveLiveRegisters(codegen, locations);
522
523 // We may have to change the index's value, but as `index_` is a
524 // constant member (like other "inputs" of this slow path),
525 // introduce a copy of it, `index`.
526 Location index = index_;
527 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100528 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain3b359c72015-11-17 19:35:12 +0000529 if (instruction_->IsArrayGet()) {
530 // Compute the actual memory offset and store it in `index`.
531 Register index_reg = index_.AsRegister<Register>();
532 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg));
533 if (codegen->IsCoreCalleeSaveRegister(index_reg)) {
534 // We are about to change the value of `index_reg` (see the
535 // calls to art::arm::Thumb2Assembler::Lsl and
536 // art::arm::Thumb2Assembler::AddConstant below), but it has
537 // not been saved by the previous call to
538 // art::SlowPathCode::SaveLiveRegisters, as it is a
539 // callee-save register --
540 // art::SlowPathCode::SaveLiveRegisters does not consider
541 // callee-save registers, as it has been designed with the
542 // assumption that callee-save registers are supposed to be
543 // handled by the called function. So, as a callee-save
544 // register, `index_reg` _would_ eventually be saved onto
545 // the stack, but it would be too late: we would have
546 // changed its value earlier. Therefore, we manually save
547 // it here into another freely available register,
548 // `free_reg`, chosen of course among the caller-save
549 // registers (as a callee-save `free_reg` register would
550 // exhibit the same problem).
551 //
552 // Note we could have requested a temporary register from
553 // the register allocator instead; but we prefer not to, as
554 // this is a slow path, and we know we can find a
555 // caller-save register that is available.
556 Register free_reg = FindAvailableCallerSaveRegister(codegen);
557 __ Mov(free_reg, index_reg);
558 index_reg = free_reg;
559 index = Location::RegisterLocation(index_reg);
560 } else {
561 // The initial register stored in `index_` has already been
562 // saved in the call to art::SlowPathCode::SaveLiveRegisters
563 // (as it is not a callee-save register), so we can freely
564 // use it.
565 }
566 // Shifting the index value contained in `index_reg` by the scale
567 // factor (2) cannot overflow in practice, as the runtime is
568 // unable to allocate object arrays with a size larger than
569 // 2^26 - 1 (that is, 2^28 - 4 bytes).
570 __ Lsl(index_reg, index_reg, TIMES_4);
571 static_assert(
572 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
573 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
574 __ AddConstant(index_reg, index_reg, offset_);
575 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100576 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
577 // intrinsics, `index_` is not shifted by a scale factor of 2
578 // (as in the case of ArrayGet), as it is actually an offset
579 // to an object field within an object.
580 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000581 DCHECK(instruction_->GetLocations()->Intrinsified());
582 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
583 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
584 << instruction_->AsInvoke()->GetIntrinsic();
585 DCHECK_EQ(offset_, 0U);
586 DCHECK(index_.IsRegisterPair());
587 // UnsafeGet's offset location is a register pair, the low
588 // part contains the correct offset.
589 index = index_.ToLow();
590 }
591 }
592
593 // We're moving two or three locations to locations that could
594 // overlap, so we need a parallel move resolver.
595 InvokeRuntimeCallingConvention calling_convention;
596 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
597 parallel_move.AddMove(ref_,
598 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
599 Primitive::kPrimNot,
600 nullptr);
601 parallel_move.AddMove(obj_,
602 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
603 Primitive::kPrimNot,
604 nullptr);
605 if (index.IsValid()) {
606 parallel_move.AddMove(index,
607 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
608 Primitive::kPrimInt,
609 nullptr);
610 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
611 } else {
612 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
613 __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_);
614 }
615 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow),
616 instruction_,
617 instruction_->GetDexPc(),
618 this);
619 CheckEntrypointTypes<
620 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
621 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
622
623 RestoreLiveRegisters(codegen, locations);
624 __ b(GetExitLabel());
625 }
626
627 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; }
628
629 private:
630 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
631 size_t ref = static_cast<int>(ref_.AsRegister<Register>());
632 size_t obj = static_cast<int>(obj_.AsRegister<Register>());
633 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
634 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
635 return static_cast<Register>(i);
636 }
637 }
638 // We shall never fail to find a free caller-save register, as
639 // there are more than two core caller-save registers on ARM
640 // (meaning it is possible to find one which is different from
641 // `ref` and `obj`).
642 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
643 LOG(FATAL) << "Could not find a free caller-save register";
644 UNREACHABLE();
645 }
646
Roland Levillain3b359c72015-11-17 19:35:12 +0000647 const Location out_;
648 const Location ref_;
649 const Location obj_;
650 const uint32_t offset_;
651 // An additional location containing an index to an array.
652 // Only used for HArrayGet and the UnsafeGetObject &
653 // UnsafeGetObjectVolatile intrinsics.
654 const Location index_;
655
656 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM);
657};
658
659// Slow path generating a read barrier for a GC root.
660class ReadBarrierForRootSlowPathARM : public SlowPathCode {
661 public:
662 ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root)
David Srbecky9cd6d372016-02-09 15:24:47 +0000663 : SlowPathCode(instruction), out_(out), root_(root) {
Roland Levillainc9285912015-12-18 10:38:42 +0000664 DCHECK(kEmitCompilerReadBarrier);
665 }
Roland Levillain3b359c72015-11-17 19:35:12 +0000666
667 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
668 LocationSummary* locations = instruction_->GetLocations();
669 Register reg_out = out_.AsRegister<Register>();
670 DCHECK(locations->CanCall());
671 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out));
Roland Levillainc9285912015-12-18 10:38:42 +0000672 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
673 << "Unexpected instruction in read barrier for GC root slow path: "
674 << instruction_->DebugName();
Roland Levillain3b359c72015-11-17 19:35:12 +0000675
676 __ Bind(GetEntryLabel());
677 SaveLiveRegisters(codegen, locations);
678
679 InvokeRuntimeCallingConvention calling_convention;
680 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
681 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_);
682 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow),
683 instruction_,
684 instruction_->GetDexPc(),
685 this);
686 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
687 arm_codegen->Move32(out_, Location::RegisterLocation(R0));
688
689 RestoreLiveRegisters(codegen, locations);
690 __ b(GetExitLabel());
691 }
692
693 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; }
694
695 private:
Roland Levillain3b359c72015-11-17 19:35:12 +0000696 const Location out_;
697 const Location root_;
698
699 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM);
700};
701
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000702#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100703// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
704#define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT
Dave Allison20dfc792014-06-16 20:44:29 -0700705
Aart Bike9f37602015-10-09 11:15:55 -0700706inline Condition ARMCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700707 switch (cond) {
708 case kCondEQ: return EQ;
709 case kCondNE: return NE;
710 case kCondLT: return LT;
711 case kCondLE: return LE;
712 case kCondGT: return GT;
713 case kCondGE: return GE;
Aart Bike9f37602015-10-09 11:15:55 -0700714 case kCondB: return LO;
715 case kCondBE: return LS;
716 case kCondA: return HI;
717 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700718 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100719 LOG(FATAL) << "Unreachable";
720 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700721}
722
Aart Bike9f37602015-10-09 11:15:55 -0700723// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100724inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700725 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100726 case kCondEQ: return EQ;
727 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -0700728 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100729 case kCondLT: return LO;
730 case kCondLE: return LS;
731 case kCondGT: return HI;
732 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -0700733 // Unsigned remain unchanged.
734 case kCondB: return LO;
735 case kCondBE: return LS;
736 case kCondA: return HI;
737 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700738 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100739 LOG(FATAL) << "Unreachable";
740 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700741}
742
Vladimir Markod6e069b2016-01-18 11:11:01 +0000743inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) {
744 // The ARM condition codes can express all the necessary branches, see the
745 // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual.
746 // There is no dex instruction or HIR that would need the missing conditions
747 // "equal or unordered" or "not equal".
748 switch (cond) {
749 case kCondEQ: return EQ;
750 case kCondNE: return NE /* unordered */;
751 case kCondLT: return gt_bias ? CC : LT /* unordered */;
752 case kCondLE: return gt_bias ? LS : LE /* unordered */;
753 case kCondGT: return gt_bias ? HI /* unordered */ : GT;
754 case kCondGE: return gt_bias ? CS /* unordered */ : GE;
755 default:
756 LOG(FATAL) << "UNREACHABLE";
757 UNREACHABLE();
758 }
759}
760
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100761void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100762 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100763}
764
765void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100766 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100767}
768
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100769size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
770 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
771 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100772}
773
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100774size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
775 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
776 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100777}
778
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000779size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
780 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
781 return kArmWordSize;
782}
783
784size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
785 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
786 return kArmWordSize;
787}
788
Calin Juravle34166012014-12-19 17:22:29 +0000789CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000790 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100791 const CompilerOptions& compiler_options,
792 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000793 : CodeGenerator(graph,
794 kNumberOfCoreRegisters,
795 kNumberOfSRegisters,
796 kNumberOfRegisterPairs,
797 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
798 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +0000799 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
800 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100801 compiler_options,
802 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100803 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100804 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100805 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100806 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100807 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +0000808 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000809 uint32_literals_(std::less<uint32_t>(),
810 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +0100811 method_patches_(MethodReferenceComparator(),
812 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
813 call_patches_(MethodReferenceComparator(),
814 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markob4536b72015-11-24 13:45:23 +0000815 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000816 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
817 boot_image_string_patches_(StringReferenceValueComparator(),
818 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
819 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100820 boot_image_type_patches_(TypeReferenceValueComparator(),
821 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
822 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000823 boot_image_address_patches_(std::less<uint32_t>(),
824 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700825 // Always save the LR register to mimic Quick.
826 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100827}
828
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000829void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
830 // Ensure that we fix up branches and literal loads and emit the literal pool.
831 __ FinalizeCode();
832
833 // Adjust native pc offsets in stack maps.
834 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
835 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
836 uint32_t new_position = __ GetAdjustedPosition(old_position);
837 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
838 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100839 // Adjust pc offsets for the disassembly information.
840 if (disasm_info_ != nullptr) {
841 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
842 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
843 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
844 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
845 it.second.start = __ GetAdjustedPosition(it.second.start);
846 it.second.end = __ GetAdjustedPosition(it.second.end);
847 }
848 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
849 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
850 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
851 }
852 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000853
854 CodeGenerator::Finalize(allocator);
855}
856
David Brazdil58282f42016-01-14 12:45:10 +0000857void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100858 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100859 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100860
861 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100862 blocked_core_registers_[SP] = true;
863 blocked_core_registers_[LR] = true;
864 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100865
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100866 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100867 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100868
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100869 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100870 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100871
David Brazdil58282f42016-01-14 12:45:10 +0000872 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100873 // Stubs do not save callee-save floating point registers. If the graph
874 // is debuggable, we need to deal with these registers differently. For
875 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000876 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
877 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
878 }
879 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100880
881 UpdateBlockedPairRegisters();
882}
883
884void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
885 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
886 ArmManagedRegister current =
887 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
888 if (blocked_core_registers_[current.AsRegisterPairLow()]
889 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
890 blocked_register_pairs_[i] = true;
891 }
892 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100893}
894
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100895InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
Aart Bik42249c32016-01-07 15:33:50 -0800896 : InstructionCodeGenerator(graph, codegen),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100897 assembler_(codegen->GetAssembler()),
898 codegen_(codegen) {}
899
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000900void CodeGeneratorARM::ComputeSpillMask() {
901 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
902 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
David Brazdil58282f42016-01-14 12:45:10 +0000903 // There is no easy instruction to restore just the PC on thumb2. We spill and
904 // restore another arbitrary register.
905 core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000906 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
907 // We use vpush and vpop for saving and restoring floating point registers, which take
908 // a SRegister and the number of registers to save/restore after that SRegister. We
909 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
910 // but in the range.
911 if (fpu_spill_mask_ != 0) {
912 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
913 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
914 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
915 fpu_spill_mask_ |= (1 << i);
916 }
917 }
918}
919
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100920static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100921 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100922}
923
924static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100925 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100926}
927
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000928void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000929 bool skip_overflow_check =
930 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000931 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000932 __ Bind(&frame_entry_label_);
933
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000934 if (HasEmptyFrame()) {
935 return;
936 }
937
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100938 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000939 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
940 __ LoadFromOffset(kLoadWord, IP, IP, 0);
941 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100942 }
943
Andreas Gampe501fd632015-09-10 16:11:06 -0700944 __ PushList(core_spill_mask_);
945 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
946 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000947 if (fpu_spill_mask_ != 0) {
948 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
949 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100950 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100951 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000952 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100953 int adjust = GetFrameSize() - FrameEntrySpillSize();
954 __ AddConstant(SP, -adjust);
955 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100956 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000957}
958
959void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000960 if (HasEmptyFrame()) {
961 __ bx(LR);
962 return;
963 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100964 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100965 int adjust = GetFrameSize() - FrameEntrySpillSize();
966 __ AddConstant(SP, adjust);
967 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000968 if (fpu_spill_mask_ != 0) {
969 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
970 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
Andreas Gampe542451c2016-07-26 09:02:02 -0700971 __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100972 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000973 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700974 // Pop LR into PC to return.
975 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
976 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
977 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100978 __ cfi().RestoreState();
979 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000980}
981
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100982void CodeGeneratorARM::Bind(HBasicBlock* block) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700983 Label* label = GetLabelOf(block);
984 __ BindTrackedLabel(label);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000985}
986
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100987Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100988 switch (type) {
989 case Primitive::kPrimBoolean:
990 case Primitive::kPrimByte:
991 case Primitive::kPrimChar:
992 case Primitive::kPrimShort:
993 case Primitive::kPrimInt:
994 case Primitive::kPrimNot: {
995 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000996 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100997 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100998 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100999 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001000 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001001 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001002 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001003
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001004 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001005 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001006 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001007 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001008 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001009 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001010 if (calling_convention.GetRegisterAt(index) == R1) {
1011 // Skip R1, and use R2_R3 instead.
1012 gp_index_++;
1013 index++;
1014 }
1015 }
1016 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
1017 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001018 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +01001019
Nicolas Geoffray69c15d32015-01-13 11:42:13 +00001020 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +00001021 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001022 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001023 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
1024 }
1025 }
1026
1027 case Primitive::kPrimFloat: {
1028 uint32_t stack_index = stack_index_++;
1029 if (float_index_ % 2 == 0) {
1030 float_index_ = std::max(double_index_, float_index_);
1031 }
1032 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
1033 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
1034 } else {
1035 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
1036 }
1037 }
1038
1039 case Primitive::kPrimDouble: {
1040 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
1041 uint32_t stack_index = stack_index_;
1042 stack_index_ += 2;
1043 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
1044 uint32_t index = double_index_;
1045 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001046 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001047 calling_convention.GetFpuRegisterAt(index),
1048 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001049 DCHECK(ExpectedPairLayout(result));
1050 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001051 } else {
1052 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001053 }
1054 }
1055
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001056 case Primitive::kPrimVoid:
1057 LOG(FATAL) << "Unexpected parameter type " << type;
1058 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001059 }
Roland Levillain3b359c72015-11-17 19:35:12 +00001060 return Location::NoLocation();
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001061}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001062
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001063Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001064 switch (type) {
1065 case Primitive::kPrimBoolean:
1066 case Primitive::kPrimByte:
1067 case Primitive::kPrimChar:
1068 case Primitive::kPrimShort:
1069 case Primitive::kPrimInt:
1070 case Primitive::kPrimNot: {
1071 return Location::RegisterLocation(R0);
1072 }
1073
1074 case Primitive::kPrimFloat: {
1075 return Location::FpuRegisterLocation(S0);
1076 }
1077
1078 case Primitive::kPrimLong: {
1079 return Location::RegisterPairLocation(R0, R1);
1080 }
1081
1082 case Primitive::kPrimDouble: {
1083 return Location::FpuRegisterPairLocation(S0, S1);
1084 }
1085
1086 case Primitive::kPrimVoid:
Roland Levillain3b359c72015-11-17 19:35:12 +00001087 return Location::NoLocation();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001088 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +01001089
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001090 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001091}
1092
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001093Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
1094 return Location::RegisterLocation(kMethodRegisterArgument);
1095}
1096
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001097void CodeGeneratorARM::Move32(Location destination, Location source) {
1098 if (source.Equals(destination)) {
1099 return;
1100 }
1101 if (destination.IsRegister()) {
1102 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001103 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001104 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001105 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001106 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001107 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001108 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001109 } else if (destination.IsFpuRegister()) {
1110 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001111 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001112 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001113 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001114 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001115 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001116 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001117 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001118 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001119 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001120 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001121 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001122 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001123 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +00001124 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001125 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1126 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001127 }
1128 }
1129}
1130
1131void CodeGeneratorARM::Move64(Location destination, Location source) {
1132 if (source.Equals(destination)) {
1133 return;
1134 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001135 if (destination.IsRegisterPair()) {
1136 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001137 EmitParallelMoves(
1138 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
1139 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001140 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001141 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001142 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
1143 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001144 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001145 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001146 } else if (source.IsFpuRegisterPair()) {
1147 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
1148 destination.AsRegisterPairHigh<Register>(),
1149 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001150 } else {
1151 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001152 DCHECK(ExpectedPairLayout(destination));
1153 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
1154 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001155 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001156 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001157 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001158 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1159 SP,
1160 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001161 } else if (source.IsRegisterPair()) {
1162 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1163 source.AsRegisterPairLow<Register>(),
1164 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001165 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001166 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001167 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001168 } else {
1169 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001170 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001171 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001172 if (source.AsRegisterPairLow<Register>() == R1) {
1173 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001174 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
1175 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001176 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001177 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001178 SP, destination.GetStackIndex());
1179 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001180 } else if (source.IsFpuRegisterPair()) {
1181 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
1182 SP,
1183 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001184 } else {
1185 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001186 EmitParallelMoves(
1187 Location::StackSlot(source.GetStackIndex()),
1188 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001189 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +00001190 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +01001191 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
1192 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001193 }
1194 }
1195}
1196
Calin Juravle175dc732015-08-25 15:42:32 +01001197void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1198 DCHECK(location.IsRegister());
1199 __ LoadImmediate(location.AsRegister<Register>(), value);
1200}
1201
Calin Juravlee460d1d2015-09-29 04:52:17 +01001202void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001203 HParallelMove move(GetGraph()->GetArena());
1204 move.AddMove(src, dst, dst_type, nullptr);
1205 GetMoveResolver()->EmitNativeCode(&move);
Calin Juravlee460d1d2015-09-29 04:52:17 +01001206}
1207
1208void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1209 if (location.IsRegister()) {
1210 locations->AddTemp(location);
1211 } else if (location.IsRegisterPair()) {
1212 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1213 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1214 } else {
1215 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1216 }
1217}
1218
Calin Juravle175dc732015-08-25 15:42:32 +01001219void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1220 HInstruction* instruction,
1221 uint32_t dex_pc,
1222 SlowPathCode* slow_path) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001223 InvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value(),
Calin Juravle175dc732015-08-25 15:42:32 +01001224 instruction,
1225 dex_pc,
1226 slow_path);
1227}
1228
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001229void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
1230 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001231 uint32_t dex_pc,
1232 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001233 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001234 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1235 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001236 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001237}
1238
Roland Levillaindec8f632016-07-22 17:10:06 +01001239void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1240 HInstruction* instruction,
1241 SlowPathCode* slow_path) {
1242 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
1243 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1244 __ blx(LR);
1245}
1246
David Brazdilfc6a86a2015-06-26 10:33:45 +00001247void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001248 DCHECK(!successor->IsExitBlock());
1249
1250 HBasicBlock* block = got->GetBlock();
1251 HInstruction* previous = got->GetPrevious();
1252
1253 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001254 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001255 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1256 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1257 return;
1258 }
1259
1260 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1261 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1262 }
1263 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001264 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001265 }
1266}
1267
David Brazdilfc6a86a2015-06-26 10:33:45 +00001268void LocationsBuilderARM::VisitGoto(HGoto* got) {
1269 got->SetLocations(nullptr);
1270}
1271
1272void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1273 HandleGoto(got, got->GetSuccessor());
1274}
1275
1276void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1277 try_boundary->SetLocations(nullptr);
1278}
1279
1280void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1281 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1282 if (!successor->IsExitBlock()) {
1283 HandleGoto(try_boundary, successor);
1284 }
1285}
1286
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001287void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001288 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001289}
1290
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001291void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001292}
1293
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001294void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) {
1295 Primitive::Type type = instruction->InputAt(0)->GetType();
1296 Location lhs_loc = instruction->GetLocations()->InAt(0);
1297 Location rhs_loc = instruction->GetLocations()->InAt(1);
1298 if (rhs_loc.IsConstant()) {
1299 // 0.0 is the only immediate that can be encoded directly in
1300 // a VCMP instruction.
1301 //
1302 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
1303 // specify that in a floating-point comparison, positive zero
1304 // and negative zero are considered equal, so we can use the
1305 // literal 0.0 for both cases here.
1306 //
1307 // Note however that some methods (Float.equal, Float.compare,
1308 // Float.compareTo, Double.equal, Double.compare,
1309 // Double.compareTo, Math.max, Math.min, StrictMath.max,
1310 // StrictMath.min) consider 0.0 to be (strictly) greater than
1311 // -0.0. So if we ever translate calls to these methods into a
1312 // HCompare instruction, we must handle the -0.0 case with
1313 // care here.
1314 DCHECK(rhs_loc.GetConstant()->IsArithmeticZero());
1315 if (type == Primitive::kPrimFloat) {
1316 __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>());
1317 } else {
1318 DCHECK_EQ(type, Primitive::kPrimDouble);
1319 __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()));
1320 }
1321 } else {
1322 if (type == Primitive::kPrimFloat) {
1323 __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>());
1324 } else {
1325 DCHECK_EQ(type, Primitive::kPrimDouble);
1326 __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()),
1327 FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>()));
1328 }
1329 }
1330}
1331
Roland Levillain4fa13f62015-07-06 18:11:54 +01001332void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1333 Label* true_label,
Vladimir Markod6e069b2016-01-18 11:11:01 +00001334 Label* false_label ATTRIBUTE_UNUSED) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001335 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00001336 __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001337}
1338
1339void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1340 Label* true_label,
1341 Label* false_label) {
1342 LocationSummary* locations = cond->GetLocations();
1343 Location left = locations->InAt(0);
1344 Location right = locations->InAt(1);
1345 IfCondition if_cond = cond->GetCondition();
1346
1347 Register left_high = left.AsRegisterPairHigh<Register>();
1348 Register left_low = left.AsRegisterPairLow<Register>();
1349 IfCondition true_high_cond = if_cond;
1350 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001351 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001352
1353 // Set the conditions for the test, remembering that == needs to be
1354 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001355 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001356 switch (if_cond) {
1357 case kCondEQ:
1358 case kCondNE:
1359 // Nothing to do.
1360 break;
1361 case kCondLT:
1362 false_high_cond = kCondGT;
1363 break;
1364 case kCondLE:
1365 true_high_cond = kCondLT;
1366 break;
1367 case kCondGT:
1368 false_high_cond = kCondLT;
1369 break;
1370 case kCondGE:
1371 true_high_cond = kCondGT;
1372 break;
Aart Bike9f37602015-10-09 11:15:55 -07001373 case kCondB:
1374 false_high_cond = kCondA;
1375 break;
1376 case kCondBE:
1377 true_high_cond = kCondB;
1378 break;
1379 case kCondA:
1380 false_high_cond = kCondB;
1381 break;
1382 case kCondAE:
1383 true_high_cond = kCondA;
1384 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001385 }
1386 if (right.IsConstant()) {
1387 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1388 int32_t val_low = Low32Bits(value);
1389 int32_t val_high = High32Bits(value);
1390
Vladimir Markoac6ac102015-12-17 12:14:00 +00001391 __ CmpConstant(left_high, val_high);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001392 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001393 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001394 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001395 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001396 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001397 __ b(true_label, ARMCondition(true_high_cond));
1398 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001399 }
1400 // Must be equal high, so compare the lows.
Vladimir Markoac6ac102015-12-17 12:14:00 +00001401 __ CmpConstant(left_low, val_low);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001402 } else {
1403 Register right_high = right.AsRegisterPairHigh<Register>();
1404 Register right_low = right.AsRegisterPairLow<Register>();
1405
1406 __ cmp(left_high, ShifterOperand(right_high));
1407 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001408 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001409 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001410 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001411 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001412 __ b(true_label, ARMCondition(true_high_cond));
1413 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001414 }
1415 // Must be equal high, so compare the lows.
1416 __ cmp(left_low, ShifterOperand(right_low));
1417 }
1418 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001419 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001420 __ b(true_label, final_condition);
1421}
1422
David Brazdil0debae72015-11-12 18:37:00 +00001423void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition,
1424 Label* true_target_in,
1425 Label* false_target_in) {
1426 // Generated branching requires both targets to be explicit. If either of the
1427 // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead.
1428 Label fallthrough_target;
1429 Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in;
1430 Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in;
1431
Roland Levillain4fa13f62015-07-06 18:11:54 +01001432 Primitive::Type type = condition->InputAt(0)->GetType();
1433 switch (type) {
1434 case Primitive::kPrimLong:
1435 GenerateLongComparesAndJumps(condition, true_target, false_target);
1436 break;
1437 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001438 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001439 GenerateVcmp(condition);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001440 GenerateFPJumps(condition, true_target, false_target);
1441 break;
1442 default:
1443 LOG(FATAL) << "Unexpected compare type " << type;
1444 }
1445
David Brazdil0debae72015-11-12 18:37:00 +00001446 if (false_target != &fallthrough_target) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001447 __ b(false_target);
1448 }
David Brazdil0debae72015-11-12 18:37:00 +00001449
1450 if (fallthrough_target.IsLinked()) {
1451 __ Bind(&fallthrough_target);
1452 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001453}
1454
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001455void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00001456 size_t condition_input_index,
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001457 Label* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00001458 Label* false_target) {
1459 HInstruction* cond = instruction->InputAt(condition_input_index);
1460
1461 if (true_target == nullptr && false_target == nullptr) {
1462 // Nothing to do. The code always falls through.
1463 return;
1464 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00001465 // Constant condition, statically compared against "true" (integer value 1).
1466 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00001467 if (true_target != nullptr) {
1468 __ b(true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001469 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001470 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00001471 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00001472 if (false_target != nullptr) {
1473 __ b(false_target);
1474 }
1475 }
1476 return;
1477 }
1478
1479 // The following code generates these patterns:
1480 // (1) true_target == nullptr && false_target != nullptr
1481 // - opposite condition true => branch to false_target
1482 // (2) true_target != nullptr && false_target == nullptr
1483 // - condition true => branch to true_target
1484 // (3) true_target != nullptr && false_target != nullptr
1485 // - condition true => branch to true_target
1486 // - branch to false_target
1487 if (IsBooleanValueOrMaterializedCondition(cond)) {
1488 // Condition has been materialized, compare the output to 0.
1489 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
1490 DCHECK(cond_val.IsRegister());
1491 if (true_target == nullptr) {
1492 __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target);
1493 } else {
1494 __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001495 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001496 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001497 // Condition has not been materialized. Use its inputs as the comparison and
1498 // its condition as the branch condition.
Mark Mendellb8b97692015-05-22 16:58:19 -04001499 HCondition* condition = cond->AsCondition();
David Brazdil0debae72015-11-12 18:37:00 +00001500
1501 // If this is a long or FP comparison that has been folded into
1502 // the HCondition, generate the comparison directly.
1503 Primitive::Type type = condition->InputAt(0)->GetType();
1504 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1505 GenerateCompareTestAndBranch(condition, true_target, false_target);
1506 return;
1507 }
1508
1509 LocationSummary* locations = cond->GetLocations();
1510 DCHECK(locations->InAt(0).IsRegister());
1511 Register left = locations->InAt(0).AsRegister<Register>();
1512 Location right = locations->InAt(1);
1513 if (right.IsRegister()) {
1514 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001515 } else {
David Brazdil0debae72015-11-12 18:37:00 +00001516 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001517 __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
David Brazdil0debae72015-11-12 18:37:00 +00001518 }
1519 if (true_target == nullptr) {
1520 __ b(false_target, ARMCondition(condition->GetOppositeCondition()));
1521 } else {
Mark Mendellb8b97692015-05-22 16:58:19 -04001522 __ b(true_target, ARMCondition(condition->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001523 }
Dave Allison20dfc792014-06-16 20:44:29 -07001524 }
David Brazdil0debae72015-11-12 18:37:00 +00001525
1526 // If neither branch falls through (case 3), the conditional branch to `true_target`
1527 // was already emitted (case 2) and we need to emit a jump to `false_target`.
1528 if (true_target != nullptr && false_target != nullptr) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001529 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001530 }
1531}
1532
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001533void LocationsBuilderARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001534 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1535 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001536 locations->SetInAt(0, Location::RequiresRegister());
1537 }
1538}
1539
1540void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00001541 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
1542 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
1543 Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
1544 nullptr : codegen_->GetLabelOf(true_successor);
1545 Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
1546 nullptr : codegen_->GetLabelOf(false_successor);
1547 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001548}
1549
1550void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1551 LocationSummary* locations = new (GetGraph()->GetArena())
1552 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
David Brazdil0debae72015-11-12 18:37:00 +00001553 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001554 locations->SetInAt(0, Location::RequiresRegister());
1555 }
1556}
1557
1558void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08001559 SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00001560 GenerateTestAndBranch(deoptimize,
1561 /* condition_input_index */ 0,
1562 slow_path->GetEntryLabel(),
1563 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001564}
Dave Allison20dfc792014-06-16 20:44:29 -07001565
David Brazdil74eb1b22015-12-14 11:44:01 +00001566void LocationsBuilderARM::VisitSelect(HSelect* select) {
1567 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
1568 if (Primitive::IsFloatingPointType(select->GetType())) {
1569 locations->SetInAt(0, Location::RequiresFpuRegister());
1570 locations->SetInAt(1, Location::RequiresFpuRegister());
1571 } else {
1572 locations->SetInAt(0, Location::RequiresRegister());
1573 locations->SetInAt(1, Location::RequiresRegister());
1574 }
1575 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
1576 locations->SetInAt(2, Location::RequiresRegister());
1577 }
1578 locations->SetOut(Location::SameAsFirstInput());
1579}
1580
1581void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) {
1582 LocationSummary* locations = select->GetLocations();
1583 Label false_target;
1584 GenerateTestAndBranch(select,
1585 /* condition_input_index */ 2,
1586 /* true_target */ nullptr,
1587 &false_target);
1588 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
1589 __ Bind(&false_target);
1590}
1591
David Srbecky0cf44932015-12-09 14:09:59 +00001592void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) {
1593 new (GetGraph()->GetArena()) LocationSummary(info);
1594}
1595
David Srbeckyd28f4a02016-03-14 17:14:24 +00001596void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) {
1597 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00001598}
1599
1600void CodeGeneratorARM::GenerateNop() {
1601 __ nop();
David Srbecky0cf44932015-12-09 14:09:59 +00001602}
1603
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001604void LocationsBuilderARM::HandleCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001605 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001606 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001607 // Handle the long/FP comparisons made in instruction simplification.
1608 switch (cond->InputAt(0)->GetType()) {
1609 case Primitive::kPrimLong:
1610 locations->SetInAt(0, Location::RequiresRegister());
1611 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001612 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001613 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1614 }
1615 break;
1616
1617 case Primitive::kPrimFloat:
1618 case Primitive::kPrimDouble:
1619 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001620 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001621 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001622 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1623 }
1624 break;
1625
1626 default:
1627 locations->SetInAt(0, Location::RequiresRegister());
1628 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
David Brazdilb3e773e2016-01-26 11:28:37 +00001629 if (!cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001630 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1631 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001632 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001633}
1634
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001635void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) {
David Brazdilb3e773e2016-01-26 11:28:37 +00001636 if (cond->IsEmittedAtUseSite()) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001637 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001638 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001639
1640 LocationSummary* locations = cond->GetLocations();
1641 Location left = locations->InAt(0);
1642 Location right = locations->InAt(1);
1643 Register out = locations->Out().AsRegister<Register>();
1644 Label true_label, false_label;
1645
1646 switch (cond->InputAt(0)->GetType()) {
1647 default: {
1648 // Integer case.
1649 if (right.IsRegister()) {
1650 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1651 } else {
1652 DCHECK(right.IsConstant());
Vladimir Markoac6ac102015-12-17 12:14:00 +00001653 __ CmpConstant(left.AsRegister<Register>(),
1654 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001655 }
Aart Bike9f37602015-10-09 11:15:55 -07001656 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001657 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001658 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001659 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001660 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001661 return;
1662 }
1663 case Primitive::kPrimLong:
1664 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1665 break;
1666 case Primitive::kPrimFloat:
Roland Levillain4fa13f62015-07-06 18:11:54 +01001667 case Primitive::kPrimDouble:
Vladimir Marko37dd80d2016-08-01 17:41:45 +01001668 GenerateVcmp(cond);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001669 GenerateFPJumps(cond, &true_label, &false_label);
1670 break;
1671 }
1672
1673 // Convert the jumps into the result.
1674 Label done_label;
1675
1676 // False case: result = 0.
1677 __ Bind(&false_label);
1678 __ LoadImmediate(out, 0);
1679 __ b(&done_label);
1680
1681 // True case: result = 1.
1682 __ Bind(&true_label);
1683 __ LoadImmediate(out, 1);
1684 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001685}
1686
1687void LocationsBuilderARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001688 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001689}
1690
1691void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001692 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001693}
1694
1695void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001696 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001697}
1698
1699void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001700 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001701}
1702
1703void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001704 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001705}
1706
1707void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001708 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001709}
1710
1711void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001712 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001713}
1714
1715void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001716 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001717}
1718
1719void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001720 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001721}
1722
1723void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001724 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001725}
1726
1727void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001728 HandleCondition(comp);
Dave Allison20dfc792014-06-16 20:44:29 -07001729}
1730
1731void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001732 HandleCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001733}
1734
Aart Bike9f37602015-10-09 11:15:55 -07001735void LocationsBuilderARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001736 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001737}
1738
1739void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001740 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001741}
1742
1743void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001744 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001745}
1746
1747void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001748 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001749}
1750
1751void LocationsBuilderARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001752 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001753}
1754
1755void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001756 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001757}
1758
1759void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001760 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001761}
1762
1763void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00001764 HandleCondition(comp);
Aart Bike9f37602015-10-09 11:15:55 -07001765}
1766
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001767void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001768 LocationSummary* locations =
1769 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001770 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001771}
1772
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001773void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001774 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001775}
1776
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001777void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1778 LocationSummary* locations =
1779 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1780 locations->SetOut(Location::ConstantLocation(constant));
1781}
1782
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001783void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001784 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001785}
1786
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001787void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001788 LocationSummary* locations =
1789 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001790 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001791}
1792
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001793void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001794 // Will be generated at use site.
1795}
1796
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001797void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1798 LocationSummary* locations =
1799 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1800 locations->SetOut(Location::ConstantLocation(constant));
1801}
1802
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001803void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001804 // Will be generated at use site.
1805}
1806
1807void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1808 LocationSummary* locations =
1809 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1810 locations->SetOut(Location::ConstantLocation(constant));
1811}
1812
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001813void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001814 // Will be generated at use site.
1815}
1816
Calin Juravle27df7582015-04-17 19:12:31 +01001817void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1818 memory_barrier->SetLocations(nullptr);
1819}
1820
1821void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00001822 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01001823}
1824
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001825void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001826 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001827}
1828
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001829void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001830 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001831}
1832
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001833void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001834 LocationSummary* locations =
1835 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001836 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001837}
1838
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001839void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001840 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001841}
1842
Calin Juravle175dc732015-08-25 15:42:32 +01001843void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1844 // The trampoline uses the same calling convention as dex calling conventions,
1845 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1846 // the method_idx.
1847 HandleInvoke(invoke);
1848}
1849
1850void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1851 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1852}
1853
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001854void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001855 // Explicit clinit checks triggered by static invokes must have been pruned by
1856 // art::PrepareForRegisterAllocation.
1857 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001858
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001859 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001860 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001861 codegen_->GetInstructionSetFeatures());
1862 if (intrinsic.TryDispatch(invoke)) {
Vladimir Markob4536b72015-11-24 13:45:23 +00001863 if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) {
1864 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
1865 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001866 return;
1867 }
1868
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001869 HandleInvoke(invoke);
Vladimir Markob4536b72015-11-24 13:45:23 +00001870
1871 // For PC-relative dex cache the invoke has an extra input, the PC-relative address base.
1872 if (invoke->HasPcRelativeDexCache()) {
1873 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
1874 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001875}
1876
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001877static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1878 if (invoke->GetLocations()->Intrinsified()) {
1879 IntrinsicCodeGeneratorARM intrinsic(codegen);
1880 intrinsic.Dispatch(invoke);
1881 return true;
1882 }
1883 return false;
1884}
1885
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001886void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00001887 // Explicit clinit checks triggered by static invokes must have been pruned by
1888 // art::PrepareForRegisterAllocation.
1889 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001890
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001891 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1892 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001893 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001894
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001895 LocationSummary* locations = invoke->GetLocations();
1896 codegen_->GenerateStaticOrDirectCall(
1897 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001898 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001899}
1900
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001901void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001902 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001903 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001904}
1905
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001906void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001907 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001908 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001909 codegen_->GetInstructionSetFeatures());
1910 if (intrinsic.TryDispatch(invoke)) {
1911 return;
1912 }
1913
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001914 HandleInvoke(invoke);
1915}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001916
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001917void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001918 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1919 return;
1920 }
1921
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001922 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001923 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001924 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001925}
1926
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001927void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1928 HandleInvoke(invoke);
1929 // Add the hidden argument.
1930 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1931}
1932
1933void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1934 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain3b359c72015-11-17 19:35:12 +00001935 LocationSummary* locations = invoke->GetLocations();
1936 Register temp = locations->GetTemp(0).AsRegister<Register>();
1937 Register hidden_reg = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001938 Location receiver = locations->InAt(0);
1939 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1940
Roland Levillain3b359c72015-11-17 19:35:12 +00001941 // Set the hidden argument. This is safe to do this here, as R12
1942 // won't be modified thereafter, before the `blx` (call) instruction.
1943 DCHECK_EQ(R12, hidden_reg);
1944 __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001945
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001946 if (receiver.IsStackSlot()) {
1947 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
Roland Levillain3b359c72015-11-17 19:35:12 +00001948 // /* HeapReference<Class> */ temp = temp->klass_
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001949 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1950 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00001951 // /* HeapReference<Class> */ temp = receiver->klass_
Roland Levillain271ab9c2014-11-27 15:23:57 +00001952 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001953 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001954 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00001955 // Instead of simply (possibly) unpoisoning `temp` here, we should
1956 // emit a read barrier for the previous class reference load.
1957 // However this is not required in practice, as this is an
1958 // intermediate/temporary reference and because the current
1959 // concurrent copying collector keeps the from-space memory
1960 // intact/accessible until the end of the marking phase (the
1961 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01001962 __ MaybeUnpoisonHeapReference(temp);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001963 __ LoadFromOffset(kLoadWord, temp, temp,
1964 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
1965 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00001966 invoke->GetImtIndex(), kArmPointerSize));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001967 // temp = temp->GetImtEntryAt(method_offset);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001968 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00001969 uint32_t entry_point =
Andreas Gampe542451c2016-07-26 09:02:02 -07001970 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001971 // LR = temp->GetEntryPoint();
1972 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1973 // LR();
1974 __ blx(LR);
1975 DCHECK(!codegen_->IsLeafMethod());
1976 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1977}
1978
Roland Levillain88cb1752014-10-20 16:36:47 +01001979void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1980 LocationSummary* locations =
1981 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1982 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001983 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001984 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001985 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1986 break;
1987 }
1988 case Primitive::kPrimLong: {
1989 locations->SetInAt(0, Location::RequiresRegister());
1990 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001991 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001992 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001993
Roland Levillain88cb1752014-10-20 16:36:47 +01001994 case Primitive::kPrimFloat:
1995 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001996 locations->SetInAt(0, Location::RequiresFpuRegister());
1997 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001998 break;
1999
2000 default:
2001 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2002 }
2003}
2004
2005void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
2006 LocationSummary* locations = neg->GetLocations();
2007 Location out = locations->Out();
2008 Location in = locations->InAt(0);
2009 switch (neg->GetResultType()) {
2010 case Primitive::kPrimInt:
2011 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002012 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01002013 break;
2014
2015 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002016 DCHECK(in.IsRegisterPair());
2017 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
2018 __ rsbs(out.AsRegisterPairLow<Register>(),
2019 in.AsRegisterPairLow<Register>(),
2020 ShifterOperand(0));
2021 // We cannot emit an RSC (Reverse Subtract with Carry)
2022 // instruction here, as it does not exist in the Thumb-2
2023 // instruction set. We use the following approach
2024 // using SBC and SUB instead.
2025 //
2026 // out.hi = -C
2027 __ sbc(out.AsRegisterPairHigh<Register>(),
2028 out.AsRegisterPairHigh<Register>(),
2029 ShifterOperand(out.AsRegisterPairHigh<Register>()));
2030 // out.hi = out.hi - in.hi
2031 __ sub(out.AsRegisterPairHigh<Register>(),
2032 out.AsRegisterPairHigh<Register>(),
2033 ShifterOperand(in.AsRegisterPairHigh<Register>()));
2034 break;
2035
Roland Levillain88cb1752014-10-20 16:36:47 +01002036 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002037 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002038 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00002039 break;
2040
Roland Levillain88cb1752014-10-20 16:36:47 +01002041 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00002042 DCHECK(in.IsFpuRegisterPair());
2043 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2044 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01002045 break;
2046
2047 default:
2048 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2049 }
2050}
2051
Roland Levillaindff1f282014-11-05 14:15:05 +00002052void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002053 Primitive::Type result_type = conversion->GetResultType();
2054 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002055 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00002056
Roland Levillain5b3ee562015-04-14 16:02:41 +01002057 // The float-to-long, double-to-long and long-to-float type conversions
2058 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00002059 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01002060 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
2061 && result_type == Primitive::kPrimLong)
2062 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002063 ? LocationSummary::kCallOnMainOnly
Roland Levillain624279f2014-12-04 11:54:28 +00002064 : LocationSummary::kNoCall;
2065 LocationSummary* locations =
2066 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
2067
David Brazdilb2bd1c52015-03-25 11:17:37 +00002068 // The Java language does not allow treating boolean as an integral type but
2069 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00002070
Roland Levillaindff1f282014-11-05 14:15:05 +00002071 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002072 case Primitive::kPrimByte:
2073 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002074 case Primitive::kPrimLong:
2075 // Type conversion from long to byte is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002076 case Primitive::kPrimBoolean:
2077 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002078 case Primitive::kPrimShort:
2079 case Primitive::kPrimInt:
2080 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002081 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002082 locations->SetInAt(0, Location::RequiresRegister());
2083 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2084 break;
2085
2086 default:
2087 LOG(FATAL) << "Unexpected type conversion from " << input_type
2088 << " to " << result_type;
2089 }
2090 break;
2091
Roland Levillain01a8d712014-11-14 16:27:39 +00002092 case Primitive::kPrimShort:
2093 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002094 case Primitive::kPrimLong:
2095 // Type conversion from long to short is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002096 case Primitive::kPrimBoolean:
2097 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002098 case Primitive::kPrimByte:
2099 case Primitive::kPrimInt:
2100 case Primitive::kPrimChar:
2101 // Processing a Dex `int-to-short' instruction.
2102 locations->SetInAt(0, Location::RequiresRegister());
2103 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2104 break;
2105
2106 default:
2107 LOG(FATAL) << "Unexpected type conversion from " << input_type
2108 << " to " << result_type;
2109 }
2110 break;
2111
Roland Levillain946e1432014-11-11 17:35:19 +00002112 case Primitive::kPrimInt:
2113 switch (input_type) {
2114 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002115 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002116 locations->SetInAt(0, Location::Any());
2117 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2118 break;
2119
2120 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00002121 // Processing a Dex `float-to-int' instruction.
2122 locations->SetInAt(0, Location::RequiresFpuRegister());
2123 locations->SetOut(Location::RequiresRegister());
2124 locations->AddTemp(Location::RequiresFpuRegister());
2125 break;
2126
Roland Levillain946e1432014-11-11 17:35:19 +00002127 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002128 // Processing a Dex `double-to-int' instruction.
2129 locations->SetInAt(0, Location::RequiresFpuRegister());
2130 locations->SetOut(Location::RequiresRegister());
2131 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00002132 break;
2133
2134 default:
2135 LOG(FATAL) << "Unexpected type conversion from " << input_type
2136 << " to " << result_type;
2137 }
2138 break;
2139
Roland Levillaindff1f282014-11-05 14:15:05 +00002140 case Primitive::kPrimLong:
2141 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002142 case Primitive::kPrimBoolean:
2143 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002144 case Primitive::kPrimByte:
2145 case Primitive::kPrimShort:
2146 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002147 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002148 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002149 locations->SetInAt(0, Location::RequiresRegister());
2150 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2151 break;
2152
Roland Levillain624279f2014-12-04 11:54:28 +00002153 case Primitive::kPrimFloat: {
2154 // Processing a Dex `float-to-long' instruction.
2155 InvokeRuntimeCallingConvention calling_convention;
2156 locations->SetInAt(0, Location::FpuRegisterLocation(
2157 calling_convention.GetFpuRegisterAt(0)));
2158 locations->SetOut(Location::RegisterPairLocation(R0, R1));
2159 break;
2160 }
2161
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002162 case Primitive::kPrimDouble: {
2163 // Processing a Dex `double-to-long' instruction.
2164 InvokeRuntimeCallingConvention calling_convention;
2165 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2166 calling_convention.GetFpuRegisterAt(0),
2167 calling_convention.GetFpuRegisterAt(1)));
2168 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00002169 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002170 }
Roland Levillaindff1f282014-11-05 14:15:05 +00002171
2172 default:
2173 LOG(FATAL) << "Unexpected type conversion from " << input_type
2174 << " to " << result_type;
2175 }
2176 break;
2177
Roland Levillain981e4542014-11-14 11:47:14 +00002178 case Primitive::kPrimChar:
2179 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002180 case Primitive::kPrimLong:
2181 // Type conversion from long to char is a result of code transformations.
David Brazdil46e2a392015-03-16 17:31:52 +00002182 case Primitive::kPrimBoolean:
2183 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002184 case Primitive::kPrimByte:
2185 case Primitive::kPrimShort:
2186 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002187 // Processing a Dex `int-to-char' instruction.
2188 locations->SetInAt(0, Location::RequiresRegister());
2189 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2190 break;
2191
2192 default:
2193 LOG(FATAL) << "Unexpected type conversion from " << input_type
2194 << " to " << result_type;
2195 }
2196 break;
2197
Roland Levillaindff1f282014-11-05 14:15:05 +00002198 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002199 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002200 case Primitive::kPrimBoolean:
2201 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002202 case Primitive::kPrimByte:
2203 case Primitive::kPrimShort:
2204 case Primitive::kPrimInt:
2205 case Primitive::kPrimChar:
2206 // Processing a Dex `int-to-float' instruction.
2207 locations->SetInAt(0, Location::RequiresRegister());
2208 locations->SetOut(Location::RequiresFpuRegister());
2209 break;
2210
Roland Levillain5b3ee562015-04-14 16:02:41 +01002211 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002212 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002213 InvokeRuntimeCallingConvention calling_convention;
2214 locations->SetInAt(0, Location::RegisterPairLocation(
2215 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2216 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002217 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002218 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002219
Roland Levillaincff13742014-11-17 14:32:17 +00002220 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002221 // Processing a Dex `double-to-float' instruction.
2222 locations->SetInAt(0, Location::RequiresFpuRegister());
2223 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002224 break;
2225
2226 default:
2227 LOG(FATAL) << "Unexpected type conversion from " << input_type
2228 << " to " << result_type;
2229 };
2230 break;
2231
Roland Levillaindff1f282014-11-05 14:15:05 +00002232 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002233 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002234 case Primitive::kPrimBoolean:
2235 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002236 case Primitive::kPrimByte:
2237 case Primitive::kPrimShort:
2238 case Primitive::kPrimInt:
2239 case Primitive::kPrimChar:
2240 // Processing a Dex `int-to-double' instruction.
2241 locations->SetInAt(0, Location::RequiresRegister());
2242 locations->SetOut(Location::RequiresFpuRegister());
2243 break;
2244
2245 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002246 // Processing a Dex `long-to-double' instruction.
2247 locations->SetInAt(0, Location::RequiresRegister());
2248 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002249 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002250 locations->AddTemp(Location::RequiresFpuRegister());
2251 break;
2252
Roland Levillaincff13742014-11-17 14:32:17 +00002253 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002254 // Processing a Dex `float-to-double' instruction.
2255 locations->SetInAt(0, Location::RequiresFpuRegister());
2256 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002257 break;
2258
2259 default:
2260 LOG(FATAL) << "Unexpected type conversion from " << input_type
2261 << " to " << result_type;
2262 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002263 break;
2264
2265 default:
2266 LOG(FATAL) << "Unexpected type conversion from " << input_type
2267 << " to " << result_type;
2268 }
2269}
2270
2271void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2272 LocationSummary* locations = conversion->GetLocations();
2273 Location out = locations->Out();
2274 Location in = locations->InAt(0);
2275 Primitive::Type result_type = conversion->GetResultType();
2276 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002277 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002278 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002279 case Primitive::kPrimByte:
2280 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002281 case Primitive::kPrimLong:
2282 // Type conversion from long to byte is a result of code transformations.
2283 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8);
2284 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002285 case Primitive::kPrimBoolean:
2286 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002287 case Primitive::kPrimShort:
2288 case Primitive::kPrimInt:
2289 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002290 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002291 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002292 break;
2293
2294 default:
2295 LOG(FATAL) << "Unexpected type conversion from " << input_type
2296 << " to " << result_type;
2297 }
2298 break;
2299
Roland Levillain01a8d712014-11-14 16:27:39 +00002300 case Primitive::kPrimShort:
2301 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002302 case Primitive::kPrimLong:
2303 // Type conversion from long to short is a result of code transformations.
2304 __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2305 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002306 case Primitive::kPrimBoolean:
2307 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002308 case Primitive::kPrimByte:
2309 case Primitive::kPrimInt:
2310 case Primitive::kPrimChar:
2311 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002312 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002313 break;
2314
2315 default:
2316 LOG(FATAL) << "Unexpected type conversion from " << input_type
2317 << " to " << result_type;
2318 }
2319 break;
2320
Roland Levillain946e1432014-11-11 17:35:19 +00002321 case Primitive::kPrimInt:
2322 switch (input_type) {
2323 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002324 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002325 DCHECK(out.IsRegister());
2326 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002327 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002328 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002329 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002330 } else {
2331 DCHECK(in.IsConstant());
2332 DCHECK(in.GetConstant()->IsLongConstant());
2333 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002334 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002335 }
2336 break;
2337
Roland Levillain3f8f9362014-12-02 17:45:01 +00002338 case Primitive::kPrimFloat: {
2339 // Processing a Dex `float-to-int' instruction.
2340 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002341 __ vcvtis(temp, in.AsFpuRegister<SRegister>());
Roland Levillain3f8f9362014-12-02 17:45:01 +00002342 __ vmovrs(out.AsRegister<Register>(), temp);
2343 break;
2344 }
2345
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002346 case Primitive::kPrimDouble: {
2347 // Processing a Dex `double-to-int' instruction.
2348 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Vladimir Marko8c5d3102016-07-07 12:07:44 +01002349 __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002350 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002351 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002352 }
Roland Levillain946e1432014-11-11 17:35:19 +00002353
2354 default:
2355 LOG(FATAL) << "Unexpected type conversion from " << input_type
2356 << " to " << result_type;
2357 }
2358 break;
2359
Roland Levillaindff1f282014-11-05 14:15:05 +00002360 case Primitive::kPrimLong:
2361 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002362 case Primitive::kPrimBoolean:
2363 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002364 case Primitive::kPrimByte:
2365 case Primitive::kPrimShort:
2366 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002367 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002368 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002369 DCHECK(out.IsRegisterPair());
2370 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002371 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002372 // Sign extension.
2373 __ Asr(out.AsRegisterPairHigh<Register>(),
2374 out.AsRegisterPairLow<Register>(),
2375 31);
2376 break;
2377
2378 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002379 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002380 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2381 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002382 conversion->GetDexPc(),
2383 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002384 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
Roland Levillain624279f2014-12-04 11:54:28 +00002385 break;
2386
Roland Levillaindff1f282014-11-05 14:15:05 +00002387 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002388 // Processing a Dex `double-to-long' instruction.
2389 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2390 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002391 conversion->GetDexPc(),
2392 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002393 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
Roland Levillaindff1f282014-11-05 14:15:05 +00002394 break;
2395
2396 default:
2397 LOG(FATAL) << "Unexpected type conversion from " << input_type
2398 << " to " << result_type;
2399 }
2400 break;
2401
Roland Levillain981e4542014-11-14 11:47:14 +00002402 case Primitive::kPrimChar:
2403 switch (input_type) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00002404 case Primitive::kPrimLong:
2405 // Type conversion from long to char is a result of code transformations.
2406 __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16);
2407 break;
David Brazdil46e2a392015-03-16 17:31:52 +00002408 case Primitive::kPrimBoolean:
2409 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002410 case Primitive::kPrimByte:
2411 case Primitive::kPrimShort:
2412 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002413 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002414 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002415 break;
2416
2417 default:
2418 LOG(FATAL) << "Unexpected type conversion from " << input_type
2419 << " to " << result_type;
2420 }
2421 break;
2422
Roland Levillaindff1f282014-11-05 14:15:05 +00002423 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002424 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002425 case Primitive::kPrimBoolean:
2426 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002427 case Primitive::kPrimByte:
2428 case Primitive::kPrimShort:
2429 case Primitive::kPrimInt:
2430 case Primitive::kPrimChar: {
2431 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002432 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2433 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002434 break;
2435 }
2436
Roland Levillain5b3ee562015-04-14 16:02:41 +01002437 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002438 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002439 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2440 conversion,
2441 conversion->GetDexPc(),
2442 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002443 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
Roland Levillain6d0e4832014-11-27 18:31:21 +00002444 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002445
Roland Levillaincff13742014-11-17 14:32:17 +00002446 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002447 // Processing a Dex `double-to-float' instruction.
2448 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2449 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002450 break;
2451
2452 default:
2453 LOG(FATAL) << "Unexpected type conversion from " << input_type
2454 << " to " << result_type;
2455 };
2456 break;
2457
Roland Levillaindff1f282014-11-05 14:15:05 +00002458 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002459 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002460 case Primitive::kPrimBoolean:
2461 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002462 case Primitive::kPrimByte:
2463 case Primitive::kPrimShort:
2464 case Primitive::kPrimInt:
2465 case Primitive::kPrimChar: {
2466 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002467 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002468 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2469 out.AsFpuRegisterPairLow<SRegister>());
2470 break;
2471 }
2472
Roland Levillain647b9ed2014-11-27 12:06:00 +00002473 case Primitive::kPrimLong: {
2474 // Processing a Dex `long-to-double' instruction.
2475 Register low = in.AsRegisterPairLow<Register>();
2476 Register high = in.AsRegisterPairHigh<Register>();
2477 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2478 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002479 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002480 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002481 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2482 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002483
Roland Levillain682393c2015-04-14 15:57:52 +01002484 // temp_d = int-to-double(high)
2485 __ vmovsr(temp_s, high);
2486 __ vcvtdi(temp_d, temp_s);
2487 // constant_d = k2Pow32EncodingForDouble
2488 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2489 // out_d = unsigned-to-double(low)
2490 __ vmovsr(out_s, low);
2491 __ vcvtdu(out_d, out_s);
2492 // out_d += temp_d * constant_d
2493 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002494 break;
2495 }
2496
Roland Levillaincff13742014-11-17 14:32:17 +00002497 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002498 // Processing a Dex `float-to-double' instruction.
2499 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2500 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002501 break;
2502
2503 default:
2504 LOG(FATAL) << "Unexpected type conversion from " << input_type
2505 << " to " << result_type;
2506 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002507 break;
2508
2509 default:
2510 LOG(FATAL) << "Unexpected type conversion from " << input_type
2511 << " to " << result_type;
2512 }
2513}
2514
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002515void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002516 LocationSummary* locations =
2517 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002518 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002519 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002520 locations->SetInAt(0, Location::RequiresRegister());
2521 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002522 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2523 break;
2524 }
2525
2526 case Primitive::kPrimLong: {
2527 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002528 locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002529 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002530 break;
2531 }
2532
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002533 case Primitive::kPrimFloat:
2534 case Primitive::kPrimDouble: {
2535 locations->SetInAt(0, Location::RequiresFpuRegister());
2536 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002537 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002538 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002539 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002540
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002541 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002542 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002543 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002544}
2545
2546void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2547 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002548 Location out = locations->Out();
2549 Location first = locations->InAt(0);
2550 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002551 switch (add->GetResultType()) {
2552 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002553 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002554 __ add(out.AsRegister<Register>(),
2555 first.AsRegister<Register>(),
2556 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002557 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002558 __ AddConstant(out.AsRegister<Register>(),
2559 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002560 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002561 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002562 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002563
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002564 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002565 if (second.IsConstant()) {
2566 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2567 GenerateAddLongConst(out, first, value);
2568 } else {
2569 DCHECK(second.IsRegisterPair());
2570 __ adds(out.AsRegisterPairLow<Register>(),
2571 first.AsRegisterPairLow<Register>(),
2572 ShifterOperand(second.AsRegisterPairLow<Register>()));
2573 __ adc(out.AsRegisterPairHigh<Register>(),
2574 first.AsRegisterPairHigh<Register>(),
2575 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2576 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002577 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002578 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002579
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002580 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002581 __ vadds(out.AsFpuRegister<SRegister>(),
2582 first.AsFpuRegister<SRegister>(),
2583 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002584 break;
2585
2586 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002587 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2588 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2589 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002590 break;
2591
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002592 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002593 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002594 }
2595}
2596
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002597void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002598 LocationSummary* locations =
2599 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002600 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002601 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002602 locations->SetInAt(0, Location::RequiresRegister());
2603 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002604 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2605 break;
2606 }
2607
2608 case Primitive::kPrimLong: {
2609 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko59751a72016-08-05 14:37:27 +01002610 locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002611 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002612 break;
2613 }
Calin Juravle11351682014-10-23 15:38:15 +01002614 case Primitive::kPrimFloat:
2615 case Primitive::kPrimDouble: {
2616 locations->SetInAt(0, Location::RequiresFpuRegister());
2617 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002618 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002619 break;
Calin Juravle11351682014-10-23 15:38:15 +01002620 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002621 default:
Calin Juravle11351682014-10-23 15:38:15 +01002622 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002623 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002624}
2625
2626void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2627 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002628 Location out = locations->Out();
2629 Location first = locations->InAt(0);
2630 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002631 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002632 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002633 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002634 __ sub(out.AsRegister<Register>(),
2635 first.AsRegister<Register>(),
2636 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002637 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002638 __ AddConstant(out.AsRegister<Register>(),
2639 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002640 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002641 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002642 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002643 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002644
Calin Juravle11351682014-10-23 15:38:15 +01002645 case Primitive::kPrimLong: {
Vladimir Marko59751a72016-08-05 14:37:27 +01002646 if (second.IsConstant()) {
2647 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
2648 GenerateAddLongConst(out, first, -value);
2649 } else {
2650 DCHECK(second.IsRegisterPair());
2651 __ subs(out.AsRegisterPairLow<Register>(),
2652 first.AsRegisterPairLow<Register>(),
2653 ShifterOperand(second.AsRegisterPairLow<Register>()));
2654 __ sbc(out.AsRegisterPairHigh<Register>(),
2655 first.AsRegisterPairHigh<Register>(),
2656 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2657 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002658 break;
Calin Juravle11351682014-10-23 15:38:15 +01002659 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002660
Calin Juravle11351682014-10-23 15:38:15 +01002661 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002662 __ vsubs(out.AsFpuRegister<SRegister>(),
2663 first.AsFpuRegister<SRegister>(),
2664 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002665 break;
Calin Juravle11351682014-10-23 15:38:15 +01002666 }
2667
2668 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002669 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2670 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2671 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002672 break;
2673 }
2674
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002675
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002676 default:
Calin Juravle11351682014-10-23 15:38:15 +01002677 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002678 }
2679}
2680
Calin Juravle34bacdf2014-10-07 20:23:36 +01002681void LocationsBuilderARM::VisitMul(HMul* mul) {
2682 LocationSummary* locations =
2683 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2684 switch (mul->GetResultType()) {
2685 case Primitive::kPrimInt:
2686 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002687 locations->SetInAt(0, Location::RequiresRegister());
2688 locations->SetInAt(1, Location::RequiresRegister());
2689 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002690 break;
2691 }
2692
Calin Juravleb5bfa962014-10-21 18:02:24 +01002693 case Primitive::kPrimFloat:
2694 case Primitive::kPrimDouble: {
2695 locations->SetInAt(0, Location::RequiresFpuRegister());
2696 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002697 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002698 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002699 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002700
2701 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002702 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002703 }
2704}
2705
2706void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2707 LocationSummary* locations = mul->GetLocations();
2708 Location out = locations->Out();
2709 Location first = locations->InAt(0);
2710 Location second = locations->InAt(1);
2711 switch (mul->GetResultType()) {
2712 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002713 __ mul(out.AsRegister<Register>(),
2714 first.AsRegister<Register>(),
2715 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002716 break;
2717 }
2718 case Primitive::kPrimLong: {
2719 Register out_hi = out.AsRegisterPairHigh<Register>();
2720 Register out_lo = out.AsRegisterPairLow<Register>();
2721 Register in1_hi = first.AsRegisterPairHigh<Register>();
2722 Register in1_lo = first.AsRegisterPairLow<Register>();
2723 Register in2_hi = second.AsRegisterPairHigh<Register>();
2724 Register in2_lo = second.AsRegisterPairLow<Register>();
2725
2726 // Extra checks to protect caused by the existence of R1_R2.
2727 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2728 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2729 DCHECK_NE(out_hi, in1_lo);
2730 DCHECK_NE(out_hi, in2_lo);
2731
2732 // input: in1 - 64 bits, in2 - 64 bits
2733 // output: out
2734 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2735 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2736 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2737
2738 // IP <- in1.lo * in2.hi
2739 __ mul(IP, in1_lo, in2_hi);
2740 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2741 __ mla(out_hi, in1_hi, in2_lo, IP);
2742 // out.lo <- (in1.lo * in2.lo)[31:0];
2743 __ umull(out_lo, IP, in1_lo, in2_lo);
2744 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2745 __ add(out_hi, out_hi, ShifterOperand(IP));
2746 break;
2747 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002748
2749 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002750 __ vmuls(out.AsFpuRegister<SRegister>(),
2751 first.AsFpuRegister<SRegister>(),
2752 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002753 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002754 }
2755
2756 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002757 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2758 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2759 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002760 break;
2761 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002762
2763 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002764 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002765 }
2766}
2767
Zheng Xuc6667102015-05-15 16:08:45 +08002768void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2769 DCHECK(instruction->IsDiv() || instruction->IsRem());
2770 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2771
2772 LocationSummary* locations = instruction->GetLocations();
2773 Location second = locations->InAt(1);
2774 DCHECK(second.IsConstant());
2775
2776 Register out = locations->Out().AsRegister<Register>();
2777 Register dividend = locations->InAt(0).AsRegister<Register>();
2778 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2779 DCHECK(imm == 1 || imm == -1);
2780
2781 if (instruction->IsRem()) {
2782 __ LoadImmediate(out, 0);
2783 } else {
2784 if (imm == 1) {
2785 __ Mov(out, dividend);
2786 } else {
2787 __ rsb(out, dividend, ShifterOperand(0));
2788 }
2789 }
2790}
2791
2792void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2793 DCHECK(instruction->IsDiv() || instruction->IsRem());
2794 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2795
2796 LocationSummary* locations = instruction->GetLocations();
2797 Location second = locations->InAt(1);
2798 DCHECK(second.IsConstant());
2799
2800 Register out = locations->Out().AsRegister<Register>();
2801 Register dividend = locations->InAt(0).AsRegister<Register>();
2802 Register temp = locations->GetTemp(0).AsRegister<Register>();
2803 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002804 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002805 int ctz_imm = CTZ(abs_imm);
2806
2807 if (ctz_imm == 1) {
2808 __ Lsr(temp, dividend, 32 - ctz_imm);
2809 } else {
2810 __ Asr(temp, dividend, 31);
2811 __ Lsr(temp, temp, 32 - ctz_imm);
2812 }
2813 __ add(out, temp, ShifterOperand(dividend));
2814
2815 if (instruction->IsDiv()) {
2816 __ Asr(out, out, ctz_imm);
2817 if (imm < 0) {
2818 __ rsb(out, out, ShifterOperand(0));
2819 }
2820 } else {
2821 __ ubfx(out, out, 0, ctz_imm);
2822 __ sub(out, out, ShifterOperand(temp));
2823 }
2824}
2825
2826void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2827 DCHECK(instruction->IsDiv() || instruction->IsRem());
2828 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2829
2830 LocationSummary* locations = instruction->GetLocations();
2831 Location second = locations->InAt(1);
2832 DCHECK(second.IsConstant());
2833
2834 Register out = locations->Out().AsRegister<Register>();
2835 Register dividend = locations->InAt(0).AsRegister<Register>();
2836 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2837 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2838 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2839
2840 int64_t magic;
2841 int shift;
2842 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2843
2844 __ LoadImmediate(temp1, magic);
2845 __ smull(temp2, temp1, dividend, temp1);
2846
2847 if (imm > 0 && magic < 0) {
2848 __ add(temp1, temp1, ShifterOperand(dividend));
2849 } else if (imm < 0 && magic > 0) {
2850 __ sub(temp1, temp1, ShifterOperand(dividend));
2851 }
2852
2853 if (shift != 0) {
2854 __ Asr(temp1, temp1, shift);
2855 }
2856
2857 if (instruction->IsDiv()) {
2858 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2859 } else {
2860 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2861 // TODO: Strength reduction for mls.
2862 __ LoadImmediate(temp2, imm);
2863 __ mls(out, temp1, temp2, dividend);
2864 }
2865}
2866
2867void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2868 DCHECK(instruction->IsDiv() || instruction->IsRem());
2869 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2870
2871 LocationSummary* locations = instruction->GetLocations();
2872 Location second = locations->InAt(1);
2873 DCHECK(second.IsConstant());
2874
2875 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2876 if (imm == 0) {
2877 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2878 } else if (imm == 1 || imm == -1) {
2879 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002880 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002881 DivRemByPowerOfTwo(instruction);
2882 } else {
2883 DCHECK(imm <= -2 || imm >= 2);
2884 GenerateDivRemWithAnyConstant(instruction);
2885 }
2886}
2887
Calin Juravle7c4954d2014-10-28 16:57:40 +00002888void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002889 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2890 if (div->GetResultType() == Primitive::kPrimLong) {
2891 // pLdiv runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002892 call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08002893 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2894 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002895 } else if (div->GetResultType() == Primitive::kPrimInt &&
2896 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2897 // pIdivmod runtime call.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002898 call_kind = LocationSummary::kCallOnMainOnly;
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002899 }
2900
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002901 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2902
Calin Juravle7c4954d2014-10-28 16:57:40 +00002903 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002904 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002905 if (div->InputAt(1)->IsConstant()) {
2906 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00002907 locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08002908 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002909 int32_t value = div->InputAt(1)->AsIntConstant()->GetValue();
2910 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08002911 // No temp register required.
2912 } else {
2913 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002914 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002915 locations->AddTemp(Location::RequiresRegister());
2916 }
2917 }
2918 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002919 locations->SetInAt(0, Location::RequiresRegister());
2920 locations->SetInAt(1, Location::RequiresRegister());
2921 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2922 } else {
2923 InvokeRuntimeCallingConvention calling_convention;
2924 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2925 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2926 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2927 // we only need the former.
2928 locations->SetOut(Location::RegisterLocation(R0));
2929 }
Calin Juravled0d48522014-11-04 16:40:20 +00002930 break;
2931 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002932 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002933 InvokeRuntimeCallingConvention calling_convention;
2934 locations->SetInAt(0, Location::RegisterPairLocation(
2935 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2936 locations->SetInAt(1, Location::RegisterPairLocation(
2937 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002938 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002939 break;
2940 }
2941 case Primitive::kPrimFloat:
2942 case Primitive::kPrimDouble: {
2943 locations->SetInAt(0, Location::RequiresFpuRegister());
2944 locations->SetInAt(1, Location::RequiresFpuRegister());
2945 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2946 break;
2947 }
2948
2949 default:
2950 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2951 }
2952}
2953
2954void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2955 LocationSummary* locations = div->GetLocations();
2956 Location out = locations->Out();
2957 Location first = locations->InAt(0);
2958 Location second = locations->InAt(1);
2959
2960 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002961 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002962 if (second.IsConstant()) {
2963 GenerateDivRemConstantIntegral(div);
2964 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002965 __ sdiv(out.AsRegister<Register>(),
2966 first.AsRegister<Register>(),
2967 second.AsRegister<Register>());
2968 } else {
2969 InvokeRuntimeCallingConvention calling_convention;
2970 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2971 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2972 DCHECK_EQ(R0, out.AsRegister<Register>());
2973
2974 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002975 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002976 }
Calin Juravled0d48522014-11-04 16:40:20 +00002977 break;
2978 }
2979
Calin Juravle7c4954d2014-10-28 16:57:40 +00002980 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002981 InvokeRuntimeCallingConvention calling_convention;
2982 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2983 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2984 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2985 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2986 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002987 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002988
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002989 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00002990 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002991 break;
2992 }
2993
2994 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002995 __ vdivs(out.AsFpuRegister<SRegister>(),
2996 first.AsFpuRegister<SRegister>(),
2997 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002998 break;
2999 }
3000
3001 case Primitive::kPrimDouble: {
3002 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
3003 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
3004 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
3005 break;
3006 }
3007
3008 default:
3009 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
3010 }
3011}
3012
Calin Juravlebacfec32014-11-14 15:54:36 +00003013void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003014 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003015
3016 // Most remainders are implemented in the runtime.
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003017 LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly;
Zheng Xuc6667102015-05-15 16:08:45 +08003018 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
3019 // sdiv will be replaced by other instruction sequence.
3020 call_kind = LocationSummary::kNoCall;
3021 } else if ((rem->GetResultType() == Primitive::kPrimInt)
3022 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003023 // Have hardware divide instruction for int, do it with three instructions.
3024 call_kind = LocationSummary::kNoCall;
3025 }
3026
Calin Juravlebacfec32014-11-14 15:54:36 +00003027 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
3028
Calin Juravled2ec87d2014-12-08 14:24:46 +00003029 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003030 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003031 if (rem->InputAt(1)->IsConstant()) {
3032 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko13c86fd2015-11-11 12:37:46 +00003033 locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant()));
Zheng Xuc6667102015-05-15 16:08:45 +08003034 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003035 int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue();
3036 if (value == 1 || value == 0 || value == -1) {
Zheng Xuc6667102015-05-15 16:08:45 +08003037 // No temp register required.
3038 } else {
3039 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00003040 if (!IsPowerOfTwo(AbsOrMin(value))) {
Zheng Xuc6667102015-05-15 16:08:45 +08003041 locations->AddTemp(Location::RequiresRegister());
3042 }
3043 }
3044 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003045 locations->SetInAt(0, Location::RequiresRegister());
3046 locations->SetInAt(1, Location::RequiresRegister());
3047 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3048 locations->AddTemp(Location::RequiresRegister());
3049 } else {
3050 InvokeRuntimeCallingConvention calling_convention;
3051 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3052 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3053 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
3054 // we only need the latter.
3055 locations->SetOut(Location::RegisterLocation(R1));
3056 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003057 break;
3058 }
3059 case Primitive::kPrimLong: {
3060 InvokeRuntimeCallingConvention calling_convention;
3061 locations->SetInAt(0, Location::RegisterPairLocation(
3062 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
3063 locations->SetInAt(1, Location::RegisterPairLocation(
3064 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
3065 // The runtime helper puts the output in R2,R3.
3066 locations->SetOut(Location::RegisterPairLocation(R2, R3));
3067 break;
3068 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00003069 case Primitive::kPrimFloat: {
3070 InvokeRuntimeCallingConvention calling_convention;
3071 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
3072 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
3073 locations->SetOut(Location::FpuRegisterLocation(S0));
3074 break;
3075 }
3076
Calin Juravlebacfec32014-11-14 15:54:36 +00003077 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00003078 InvokeRuntimeCallingConvention calling_convention;
3079 locations->SetInAt(0, Location::FpuRegisterPairLocation(
3080 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
3081 locations->SetInAt(1, Location::FpuRegisterPairLocation(
3082 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
3083 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00003084 break;
3085 }
3086
3087 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003088 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003089 }
3090}
3091
3092void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
3093 LocationSummary* locations = rem->GetLocations();
3094 Location out = locations->Out();
3095 Location first = locations->InAt(0);
3096 Location second = locations->InAt(1);
3097
Calin Juravled2ec87d2014-12-08 14:24:46 +00003098 Primitive::Type type = rem->GetResultType();
3099 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00003100 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08003101 if (second.IsConstant()) {
3102 GenerateDivRemConstantIntegral(rem);
3103 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003104 Register reg1 = first.AsRegister<Register>();
3105 Register reg2 = second.AsRegister<Register>();
3106 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003107
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003108 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003109 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003110 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003111 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003112 } else {
3113 InvokeRuntimeCallingConvention calling_convention;
3114 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
3115 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
3116 DCHECK_EQ(R1, out.AsRegister<Register>());
3117
3118 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003119 CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07003120 }
Calin Juravlebacfec32014-11-14 15:54:36 +00003121 break;
3122 }
3123
3124 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003125 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003126 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003127 break;
3128 }
3129
Calin Juravled2ec87d2014-12-08 14:24:46 +00003130 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003131 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003132 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Calin Juravled2ec87d2014-12-08 14:24:46 +00003133 break;
3134 }
3135
Calin Juravlebacfec32014-11-14 15:54:36 +00003136 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003137 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003138 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Calin Juravlebacfec32014-11-14 15:54:36 +00003139 break;
3140 }
3141
3142 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00003143 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00003144 }
3145}
3146
Calin Juravled0d48522014-11-04 16:40:20 +00003147void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003148 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3149 ? LocationSummary::kCallOnSlowPath
3150 : LocationSummary::kNoCall;
3151 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003152 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00003153 if (instruction->HasUses()) {
3154 locations->SetOut(Location::SameAsFirstInput());
3155 }
3156}
3157
3158void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003159 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00003160 codegen_->AddSlowPath(slow_path);
3161
3162 LocationSummary* locations = instruction->GetLocations();
3163 Location value = locations->InAt(0);
3164
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003165 switch (instruction->GetType()) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00003166 case Primitive::kPrimBoolean:
Serguei Katkov8c0676c2015-08-03 13:55:33 +06003167 case Primitive::kPrimByte:
3168 case Primitive::kPrimChar:
3169 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003170 case Primitive::kPrimInt: {
3171 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003172 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00003173 } else {
3174 DCHECK(value.IsConstant()) << value;
3175 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
3176 __ b(slow_path->GetEntryLabel());
3177 }
3178 }
3179 break;
3180 }
3181 case Primitive::kPrimLong: {
3182 if (value.IsRegisterPair()) {
3183 __ orrs(IP,
3184 value.AsRegisterPairLow<Register>(),
3185 ShifterOperand(value.AsRegisterPairHigh<Register>()));
3186 __ b(slow_path->GetEntryLabel(), EQ);
3187 } else {
3188 DCHECK(value.IsConstant()) << value;
3189 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
3190 __ b(slow_path->GetEntryLabel());
3191 }
3192 }
3193 break;
3194 default:
3195 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
3196 }
3197 }
Calin Juravled0d48522014-11-04 16:40:20 +00003198}
3199
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003200void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) {
3201 Register in = locations->InAt(0).AsRegister<Register>();
3202 Location rhs = locations->InAt(1);
3203 Register out = locations->Out().AsRegister<Register>();
3204
3205 if (rhs.IsConstant()) {
3206 // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31],
3207 // so map all rotations to a +ve. equivalent in that range.
3208 // (e.g. left *or* right by -2 bits == 30 bits in the same direction.)
3209 uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F;
3210 if (rot) {
3211 // Rotate, mapping left rotations to right equivalents if necessary.
3212 // (e.g. left by 2 bits == right by 30.)
3213 __ Ror(out, in, rot);
3214 } else if (out != in) {
3215 __ Mov(out, in);
3216 }
3217 } else {
3218 __ Ror(out, in, rhs.AsRegister<Register>());
3219 }
3220}
3221
3222// Gain some speed by mapping all Long rotates onto equivalent pairs of Integer
3223// rotates by swapping input regs (effectively rotating by the first 32-bits of
3224// a larger rotation) or flipping direction (thus treating larger right/left
3225// rotations as sub-word sized rotations in the other direction) as appropriate.
3226void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) {
3227 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
3228 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
3229 Location rhs = locations->InAt(1);
3230 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
3231 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
3232
3233 if (rhs.IsConstant()) {
3234 uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant());
3235 // Map all rotations to +ve. equivalents on the interval [0,63].
Roland Levillain5b5b9312016-03-22 14:57:31 +00003236 rot &= kMaxLongShiftDistance;
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003237 // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate
3238 // logic below to a simple pair of binary orr.
3239 // (e.g. 34 bits == in_reg swap + 2 bits right.)
3240 if (rot >= kArmBitsPerWord) {
3241 rot -= kArmBitsPerWord;
3242 std::swap(in_reg_hi, in_reg_lo);
3243 }
3244 // Rotate, or mov to out for zero or word size rotations.
3245 if (rot != 0u) {
3246 __ Lsr(out_reg_hi, in_reg_hi, rot);
3247 __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot));
3248 __ Lsr(out_reg_lo, in_reg_lo, rot);
3249 __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot));
3250 } else {
3251 __ Mov(out_reg_lo, in_reg_lo);
3252 __ Mov(out_reg_hi, in_reg_hi);
3253 }
3254 } else {
3255 Register shift_right = locations->GetTemp(0).AsRegister<Register>();
3256 Register shift_left = locations->GetTemp(1).AsRegister<Register>();
3257 Label end;
3258 Label shift_by_32_plus_shift_right;
3259
3260 __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F));
3261 __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6);
3262 __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep);
3263 __ b(&shift_by_32_plus_shift_right, CC);
3264
3265 // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right).
3266 // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right).
3267 __ Lsl(out_reg_hi, in_reg_hi, shift_left);
3268 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3269 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3270 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3271 __ Lsr(shift_left, in_reg_hi, shift_right);
3272 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left));
3273 __ b(&end);
3274
3275 __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right.
3276 // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left).
3277 // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left).
3278 __ Lsr(out_reg_hi, in_reg_hi, shift_right);
3279 __ Lsl(out_reg_lo, in_reg_lo, shift_left);
3280 __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo));
3281 __ Lsr(out_reg_lo, in_reg_lo, shift_right);
3282 __ Lsl(shift_right, in_reg_hi, shift_left);
3283 __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right));
3284
3285 __ Bind(&end);
3286 }
3287}
Roland Levillain22c49222016-03-18 14:04:28 +00003288
3289void LocationsBuilderARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003290 LocationSummary* locations =
3291 new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall);
3292 switch (ror->GetResultType()) {
3293 case Primitive::kPrimInt: {
3294 locations->SetInAt(0, Location::RequiresRegister());
3295 locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1)));
3296 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3297 break;
3298 }
3299 case Primitive::kPrimLong: {
3300 locations->SetInAt(0, Location::RequiresRegister());
3301 if (ror->InputAt(1)->IsConstant()) {
3302 locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant()));
3303 } else {
3304 locations->SetInAt(1, Location::RequiresRegister());
3305 locations->AddTemp(Location::RequiresRegister());
3306 locations->AddTemp(Location::RequiresRegister());
3307 }
3308 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3309 break;
3310 }
3311 default:
3312 LOG(FATAL) << "Unexpected operation type " << ror->GetResultType();
3313 }
3314}
3315
Roland Levillain22c49222016-03-18 14:04:28 +00003316void InstructionCodeGeneratorARM::VisitRor(HRor* ror) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003317 LocationSummary* locations = ror->GetLocations();
3318 Primitive::Type type = ror->GetResultType();
3319 switch (type) {
3320 case Primitive::kPrimInt: {
3321 HandleIntegerRotate(locations);
3322 break;
3323 }
3324 case Primitive::kPrimLong: {
3325 HandleLongRotate(locations);
3326 break;
3327 }
3328 default:
3329 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00003330 UNREACHABLE();
Scott Wakeling40a04bf2015-12-11 09:50:36 +00003331 }
3332}
3333
Calin Juravle9aec02f2014-11-18 23:06:35 +00003334void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
3335 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3336
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003337 LocationSummary* locations =
3338 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003339
3340 switch (op->GetResultType()) {
3341 case Primitive::kPrimInt: {
3342 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003343 if (op->InputAt(1)->IsConstant()) {
3344 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3345 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3346 } else {
3347 locations->SetInAt(1, Location::RequiresRegister());
3348 // Make the output overlap, as it will be used to hold the masked
3349 // second input.
3350 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3351 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003352 break;
3353 }
3354 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003355 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003356 if (op->InputAt(1)->IsConstant()) {
3357 locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant()));
3358 // For simplicity, use kOutputOverlap even though we only require that low registers
3359 // don't clash with high registers which the register allocator currently guarantees.
3360 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3361 } else {
3362 locations->SetInAt(1, Location::RequiresRegister());
3363 locations->AddTemp(Location::RequiresRegister());
3364 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
3365 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003366 break;
3367 }
3368 default:
3369 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3370 }
3371}
3372
3373void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3374 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3375
3376 LocationSummary* locations = op->GetLocations();
3377 Location out = locations->Out();
3378 Location first = locations->InAt(0);
3379 Location second = locations->InAt(1);
3380
3381 Primitive::Type type = op->GetResultType();
3382 switch (type) {
3383 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003384 Register out_reg = out.AsRegister<Register>();
3385 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003386 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003387 Register second_reg = second.AsRegister<Register>();
Roland Levillainc9285912015-12-18 10:38:42 +00003388 // ARM doesn't mask the shift count so we need to do it ourselves.
Roland Levillain5b5b9312016-03-22 14:57:31 +00003389 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003390 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003391 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003392 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003393 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003394 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003395 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003396 }
3397 } else {
3398 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003399 uint32_t shift_value = cst & kMaxIntShiftDistance;
Roland Levillainc9285912015-12-18 10:38:42 +00003400 if (shift_value == 0) { // ARM does not support shifting with 0 immediate.
Calin Juravle9aec02f2014-11-18 23:06:35 +00003401 __ Mov(out_reg, first_reg);
3402 } else if (op->IsShl()) {
3403 __ Lsl(out_reg, first_reg, shift_value);
3404 } else if (op->IsShr()) {
3405 __ Asr(out_reg, first_reg, shift_value);
3406 } else {
3407 __ Lsr(out_reg, first_reg, shift_value);
3408 }
3409 }
3410 break;
3411 }
3412 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003413 Register o_h = out.AsRegisterPairHigh<Register>();
3414 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003415
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003416 Register high = first.AsRegisterPairHigh<Register>();
3417 Register low = first.AsRegisterPairLow<Register>();
3418
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003419 if (second.IsRegister()) {
3420 Register temp = locations->GetTemp(0).AsRegister<Register>();
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003421
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003422 Register second_reg = second.AsRegister<Register>();
3423
3424 if (op->IsShl()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003425 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003426 // Shift the high part
3427 __ Lsl(o_h, high, o_l);
3428 // Shift the low part and `or` what overflew on the high part
3429 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
3430 __ Lsr(temp, low, temp);
3431 __ orr(o_h, o_h, ShifterOperand(temp));
3432 // If the shift is > 32 bits, override the high part
3433 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
3434 __ it(PL);
3435 __ Lsl(o_h, low, temp, PL);
3436 // Shift the low part
3437 __ Lsl(o_l, low, o_l);
3438 } else if (op->IsShr()) {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003439 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003440 // Shift the low part
3441 __ Lsr(o_l, low, o_h);
3442 // Shift the high part and `or` what underflew on the low part
3443 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3444 __ Lsl(temp, high, temp);
3445 __ orr(o_l, o_l, ShifterOperand(temp));
3446 // If the shift is > 32 bits, override the low part
3447 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3448 __ it(PL);
3449 __ Asr(o_l, high, temp, PL);
3450 // Shift the high part
3451 __ Asr(o_h, high, o_h);
3452 } else {
Roland Levillain5b5b9312016-03-22 14:57:31 +00003453 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance));
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003454 // same as Shr except we use `Lsr`s and not `Asr`s
3455 __ Lsr(o_l, low, o_h);
3456 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
3457 __ Lsl(temp, high, temp);
3458 __ orr(o_l, o_l, ShifterOperand(temp));
3459 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
3460 __ it(PL);
3461 __ Lsr(o_l, high, temp, PL);
3462 __ Lsr(o_h, high, o_h);
3463 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003464 } else {
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003465 // Register allocator doesn't create partial overlap.
3466 DCHECK_NE(o_l, high);
3467 DCHECK_NE(o_h, low);
3468 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain5b5b9312016-03-22 14:57:31 +00003469 uint32_t shift_value = cst & kMaxLongShiftDistance;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003470 if (shift_value > 32) {
3471 if (op->IsShl()) {
3472 __ Lsl(o_h, low, shift_value - 32);
3473 __ LoadImmediate(o_l, 0);
3474 } else if (op->IsShr()) {
3475 __ Asr(o_l, high, shift_value - 32);
3476 __ Asr(o_h, high, 31);
3477 } else {
3478 __ Lsr(o_l, high, shift_value - 32);
3479 __ LoadImmediate(o_h, 0);
3480 }
3481 } else if (shift_value == 32) {
3482 if (op->IsShl()) {
3483 __ mov(o_h, ShifterOperand(low));
3484 __ LoadImmediate(o_l, 0);
3485 } else if (op->IsShr()) {
3486 __ mov(o_l, ShifterOperand(high));
3487 __ Asr(o_h, high, 31);
3488 } else {
3489 __ mov(o_l, ShifterOperand(high));
3490 __ LoadImmediate(o_h, 0);
3491 }
Vladimir Markof9d741e2015-11-20 15:08:11 +00003492 } else if (shift_value == 1) {
3493 if (op->IsShl()) {
3494 __ Lsls(o_l, low, 1);
3495 __ adc(o_h, high, ShifterOperand(high));
3496 } else if (op->IsShr()) {
3497 __ Asrs(o_h, high, 1);
3498 __ Rrx(o_l, low);
3499 } else {
3500 __ Lsrs(o_h, high, 1);
3501 __ Rrx(o_l, low);
3502 }
3503 } else {
3504 DCHECK(2 <= shift_value && shift_value < 32) << shift_value;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003505 if (op->IsShl()) {
3506 __ Lsl(o_h, high, shift_value);
3507 __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value));
3508 __ Lsl(o_l, low, shift_value);
3509 } else if (op->IsShr()) {
3510 __ Lsr(o_l, low, shift_value);
3511 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3512 __ Asr(o_h, high, shift_value);
3513 } else {
3514 __ Lsr(o_l, low, shift_value);
3515 __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value));
3516 __ Lsr(o_h, high, shift_value);
3517 }
3518 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003519 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003520 break;
3521 }
3522 default:
3523 LOG(FATAL) << "Unexpected operation type " << type;
Vladimir Marko33ad10e2015-11-10 19:31:26 +00003524 UNREACHABLE();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003525 }
3526}
3527
3528void LocationsBuilderARM::VisitShl(HShl* shl) {
3529 HandleShift(shl);
3530}
3531
3532void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3533 HandleShift(shl);
3534}
3535
3536void LocationsBuilderARM::VisitShr(HShr* shr) {
3537 HandleShift(shr);
3538}
3539
3540void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3541 HandleShift(shr);
3542}
3543
3544void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3545 HandleShift(ushr);
3546}
3547
3548void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3549 HandleShift(ushr);
3550}
3551
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003552void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003553 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003554 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
David Brazdil6de19382016-01-08 17:37:10 +00003555 if (instruction->IsStringAlloc()) {
3556 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
3557 } else {
3558 InvokeRuntimeCallingConvention calling_convention;
3559 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3560 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3561 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003562 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003563}
3564
3565void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01003566 // Note: if heap poisoning is enabled, the entry point takes cares
3567 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00003568 if (instruction->IsStringAlloc()) {
3569 // String is allocated through StringFactory. Call NewEmptyString entry point.
3570 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07003571 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00003572 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
3573 __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value());
3574 __ blx(LR);
3575 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3576 } else {
3577 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
3578 instruction,
3579 instruction->GetDexPc(),
3580 nullptr);
3581 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
3582 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003583}
3584
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003585void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3586 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003587 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003588 InvokeRuntimeCallingConvention calling_convention;
3589 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003590 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003591 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003592 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003593}
3594
3595void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3596 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003597 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003598 // Note: if heap poisoning is enabled, the entry point takes cares
3599 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003600 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003601 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003602 instruction->GetDexPc(),
3603 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00003604 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003605}
3606
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003607void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003608 LocationSummary* locations =
3609 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003610 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3611 if (location.IsStackSlot()) {
3612 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3613 } else if (location.IsDoubleStackSlot()) {
3614 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003615 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003616 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003617}
3618
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003619void InstructionCodeGeneratorARM::VisitParameterValue(
3620 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003621 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003622}
3623
3624void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3625 LocationSummary* locations =
3626 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3627 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3628}
3629
3630void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3631 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003632}
3633
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003634void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003635 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003636 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003637 locations->SetInAt(0, Location::RequiresRegister());
3638 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003639}
3640
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003641void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3642 LocationSummary* locations = not_->GetLocations();
3643 Location out = locations->Out();
3644 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003645 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003646 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003647 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003648 break;
3649
3650 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003651 __ mvn(out.AsRegisterPairLow<Register>(),
3652 ShifterOperand(in.AsRegisterPairLow<Register>()));
3653 __ mvn(out.AsRegisterPairHigh<Register>(),
3654 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003655 break;
3656
3657 default:
3658 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3659 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003660}
3661
David Brazdil66d126e2015-04-03 16:02:44 +01003662void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3663 LocationSummary* locations =
3664 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3665 locations->SetInAt(0, Location::RequiresRegister());
3666 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3667}
3668
3669void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003670 LocationSummary* locations = bool_not->GetLocations();
3671 Location out = locations->Out();
3672 Location in = locations->InAt(0);
3673 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3674}
3675
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003676void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003677 LocationSummary* locations =
3678 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003679 switch (compare->InputAt(0)->GetType()) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003680 case Primitive::kPrimBoolean:
3681 case Primitive::kPrimByte:
3682 case Primitive::kPrimShort:
3683 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003684 case Primitive::kPrimInt:
Calin Juravleddb7df22014-11-25 20:56:51 +00003685 case Primitive::kPrimLong: {
3686 locations->SetInAt(0, Location::RequiresRegister());
3687 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003688 // Output overlaps because it is written before doing the low comparison.
3689 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003690 break;
3691 }
3692 case Primitive::kPrimFloat:
3693 case Primitive::kPrimDouble: {
3694 locations->SetInAt(0, Location::RequiresFpuRegister());
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003695 locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1)));
Calin Juravleddb7df22014-11-25 20:56:51 +00003696 locations->SetOut(Location::RequiresRegister());
3697 break;
3698 }
3699 default:
3700 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3701 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003702}
3703
3704void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003705 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003706 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003707 Location left = locations->InAt(0);
3708 Location right = locations->InAt(1);
3709
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003710 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003711 Primitive::Type type = compare->InputAt(0)->GetType();
Vladimir Markod6e069b2016-01-18 11:11:01 +00003712 Condition less_cond;
Calin Juravleddb7df22014-11-25 20:56:51 +00003713 switch (type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00003714 case Primitive::kPrimBoolean:
3715 case Primitive::kPrimByte:
3716 case Primitive::kPrimShort:
3717 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08003718 case Primitive::kPrimInt: {
3719 __ LoadImmediate(out, 0);
3720 __ cmp(left.AsRegister<Register>(),
3721 ShifterOperand(right.AsRegister<Register>())); // Signed compare.
3722 less_cond = LT;
3723 break;
3724 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003725 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003726 __ cmp(left.AsRegisterPairHigh<Register>(),
3727 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003728 __ b(&less, LT);
3729 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003730 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003731 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003732 __ cmp(left.AsRegisterPairLow<Register>(),
3733 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003734 less_cond = LO;
Calin Juravleddb7df22014-11-25 20:56:51 +00003735 break;
3736 }
3737 case Primitive::kPrimFloat:
3738 case Primitive::kPrimDouble: {
3739 __ LoadImmediate(out, 0);
Vladimir Marko37dd80d2016-08-01 17:41:45 +01003740 GenerateVcmp(compare);
Calin Juravleddb7df22014-11-25 20:56:51 +00003741 __ vmstat(); // transfer FP status register to ARM APSR.
Vladimir Markod6e069b2016-01-18 11:11:01 +00003742 less_cond = ARMFPCondition(kCondLT, compare->IsGtBias());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003743 break;
3744 }
3745 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003746 LOG(FATAL) << "Unexpected compare type " << type;
Vladimir Markod6e069b2016-01-18 11:11:01 +00003747 UNREACHABLE();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003748 }
Aart Bika19616e2016-02-01 18:57:58 -08003749
Calin Juravleddb7df22014-11-25 20:56:51 +00003750 __ b(&done, EQ);
Vladimir Markod6e069b2016-01-18 11:11:01 +00003751 __ b(&less, less_cond);
Calin Juravleddb7df22014-11-25 20:56:51 +00003752
3753 __ Bind(&greater);
3754 __ LoadImmediate(out, 1);
3755 __ b(&done);
3756
3757 __ Bind(&less);
3758 __ LoadImmediate(out, -1);
3759
3760 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003761}
3762
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003763void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003764 LocationSummary* locations =
3765 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Vladimir Marko372f10e2016-05-17 16:30:10 +01003766 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003767 locations->SetInAt(i, Location::Any());
3768 }
3769 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003770}
3771
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003772void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003773 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003774}
3775
Roland Levillainc9285912015-12-18 10:38:42 +00003776void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3777 // TODO (ported from quick): revisit ARM barrier kinds.
3778 DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings.
Calin Juravle52c48962014-12-16 17:02:57 +00003779 switch (kind) {
3780 case MemBarrierKind::kAnyStore:
3781 case MemBarrierKind::kLoadAny:
3782 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003783 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003784 break;
3785 }
3786 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003787 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003788 break;
3789 }
3790 default:
3791 LOG(FATAL) << "Unexpected memory barrier " << kind;
3792 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003793 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003794}
3795
3796void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3797 uint32_t offset,
3798 Register out_lo,
3799 Register out_hi) {
3800 if (offset != 0) {
Roland Levillain3b359c72015-11-17 19:35:12 +00003801 // Ensure `out_lo` is different from `addr`, so that loading
3802 // `offset` into `out_lo` does not clutter `addr`.
3803 DCHECK_NE(out_lo, addr);
Calin Juravle52c48962014-12-16 17:02:57 +00003804 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003805 __ add(IP, addr, ShifterOperand(out_lo));
3806 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003807 }
3808 __ ldrexd(out_lo, out_hi, addr);
3809}
3810
3811void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3812 uint32_t offset,
3813 Register value_lo,
3814 Register value_hi,
3815 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003816 Register temp2,
3817 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003818 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003819 if (offset != 0) {
3820 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003821 __ add(IP, addr, ShifterOperand(temp1));
3822 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003823 }
3824 __ Bind(&fail);
3825 // We need a load followed by store. (The address used in a STREX instruction must
3826 // be the same as the address in the most recently executed LDREX instruction.)
3827 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003828 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003829 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003830 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003831}
3832
3833void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3834 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3835
Nicolas Geoffray39468442014-09-02 15:17:15 +01003836 LocationSummary* locations =
3837 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003838 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003839
Calin Juravle52c48962014-12-16 17:02:57 +00003840 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003841 if (Primitive::IsFloatingPointType(field_type)) {
3842 locations->SetInAt(1, Location::RequiresFpuRegister());
3843 } else {
3844 locations->SetInAt(1, Location::RequiresRegister());
3845 }
3846
Calin Juravle52c48962014-12-16 17:02:57 +00003847 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003848 bool generate_volatile = field_info.IsVolatile()
3849 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003850 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003851 bool needs_write_barrier =
3852 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003853 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003854 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003855 if (needs_write_barrier) {
3856 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003857 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003858 } else if (generate_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003859 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00003860 // - registers need to be consecutive
3861 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00003862 // We don't test for ARM yet, and the assertion makes sure that we
3863 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00003864 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3865
3866 locations->AddTemp(Location::RequiresRegister());
3867 locations->AddTemp(Location::RequiresRegister());
3868 if (field_type == Primitive::kPrimDouble) {
3869 // For doubles we need two more registers to copy the value.
3870 locations->AddTemp(Location::RegisterLocation(R2));
3871 locations->AddTemp(Location::RegisterLocation(R3));
3872 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003873 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003874}
3875
Calin Juravle52c48962014-12-16 17:02:57 +00003876void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003877 const FieldInfo& field_info,
3878 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003879 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3880
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003881 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003882 Register base = locations->InAt(0).AsRegister<Register>();
3883 Location value = locations->InAt(1);
3884
3885 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003886 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003887 Primitive::Type field_type = field_info.GetFieldType();
3888 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003889 bool needs_write_barrier =
3890 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003891
3892 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003893 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
Calin Juravle52c48962014-12-16 17:02:57 +00003894 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003895
3896 switch (field_type) {
3897 case Primitive::kPrimBoolean:
3898 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003899 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003900 break;
3901 }
3902
3903 case Primitive::kPrimShort:
3904 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003905 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003906 break;
3907 }
3908
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003909 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003910 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003911 if (kPoisonHeapReferences && needs_write_barrier) {
3912 // Note that in the case where `value` is a null reference,
3913 // we do not enter this block, as a null reference does not
3914 // need poisoning.
3915 DCHECK_EQ(field_type, Primitive::kPrimNot);
3916 Register temp = locations->GetTemp(0).AsRegister<Register>();
3917 __ Mov(temp, value.AsRegister<Register>());
3918 __ PoisonHeapReference(temp);
3919 __ StoreToOffset(kStoreWord, temp, base, offset);
3920 } else {
3921 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3922 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003923 break;
3924 }
3925
3926 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003927 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003928 GenerateWideAtomicStore(base, offset,
3929 value.AsRegisterPairLow<Register>(),
3930 value.AsRegisterPairHigh<Register>(),
3931 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003932 locations->GetTemp(1).AsRegister<Register>(),
3933 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003934 } else {
3935 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003936 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003937 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003938 break;
3939 }
3940
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003941 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003942 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003943 break;
3944 }
3945
3946 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003947 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003948 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003949 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3950 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3951
3952 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3953
3954 GenerateWideAtomicStore(base, offset,
3955 value_reg_lo,
3956 value_reg_hi,
3957 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003958 locations->GetTemp(3).AsRegister<Register>(),
3959 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003960 } else {
3961 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003962 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003963 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003964 break;
3965 }
3966
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003967 case Primitive::kPrimVoid:
3968 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003969 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003970 }
Calin Juravle52c48962014-12-16 17:02:57 +00003971
Calin Juravle77520bc2015-01-12 18:45:46 +00003972 // Longs and doubles are handled in the switch.
3973 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3974 codegen_->MaybeRecordImplicitNullCheck(instruction);
3975 }
3976
3977 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3978 Register temp = locations->GetTemp(0).AsRegister<Register>();
3979 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003980 codegen_->MarkGCCard(
3981 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003982 }
3983
Calin Juravle52c48962014-12-16 17:02:57 +00003984 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00003985 codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
Calin Juravle52c48962014-12-16 17:02:57 +00003986 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003987}
3988
Calin Juravle52c48962014-12-16 17:02:57 +00003989void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3990 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain3b359c72015-11-17 19:35:12 +00003991
3992 bool object_field_get_with_read_barrier =
3993 kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003994 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00003995 new (GetGraph()->GetArena()) LocationSummary(instruction,
3996 object_field_get_with_read_barrier ?
3997 LocationSummary::kCallOnSlowPath :
3998 LocationSummary::kNoCall);
Vladimir Marko70e97462016-08-09 11:04:26 +01003999 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4000 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
4001 }
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004002 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004003
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004004 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00004005 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004006 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain3b359c72015-11-17 19:35:12 +00004007 // The output overlaps in case of volatile long: we don't want the
4008 // code generated by GenerateWideAtomicLoad to overwrite the
4009 // object's location. Likewise, in the case of an object field get
4010 // with read barriers enabled, we do not want the load to overwrite
4011 // the object's location, as we need it to emit the read barrier.
4012 bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) ||
4013 object_field_get_with_read_barrier;
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01004014
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004015 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4016 locations->SetOut(Location::RequiresFpuRegister());
4017 } else {
4018 locations->SetOut(Location::RequiresRegister(),
4019 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
4020 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004021 if (volatile_for_double) {
Roland Levillainc9285912015-12-18 10:38:42 +00004022 // ARM encoding have some additional constraints for ldrexd/strexd:
Calin Juravle52c48962014-12-16 17:02:57 +00004023 // - registers need to be consecutive
4024 // - the first register should be even but not R14.
Roland Levillainc9285912015-12-18 10:38:42 +00004025 // We don't test for ARM yet, and the assertion makes sure that we
4026 // revisit this if we ever enable ARM encoding.
Calin Juravle52c48962014-12-16 17:02:57 +00004027 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
4028 locations->AddTemp(Location::RequiresRegister());
4029 locations->AddTemp(Location::RequiresRegister());
Roland Levillainc9285912015-12-18 10:38:42 +00004030 } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
4031 // We need a temporary register for the read barrier marking slow
4032 // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier.
4033 locations->AddTemp(Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00004034 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004035}
4036
Vladimir Marko37dd80d2016-08-01 17:41:45 +01004037Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) {
4038 DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat)
4039 << input->GetType();
4040 if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) ||
4041 (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) {
4042 return Location::ConstantLocation(input->AsConstant());
4043 } else {
4044 return Location::RequiresFpuRegister();
4045 }
4046}
4047
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004048Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
4049 Opcode opcode) {
4050 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
4051 if (constant->IsConstant() &&
4052 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
4053 return Location::ConstantLocation(constant->AsConstant());
4054 }
4055 return Location::RequiresRegister();
4056}
4057
4058bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
4059 Opcode opcode) {
4060 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
4061 if (Primitive::Is64BitType(input_cst->GetType())) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004062 Opcode high_opcode = opcode;
4063 SetCc low_set_cc = kCcDontCare;
4064 switch (opcode) {
4065 case SUB:
4066 // Flip the operation to an ADD.
4067 value = -value;
4068 opcode = ADD;
4069 FALLTHROUGH_INTENDED;
4070 case ADD:
4071 if (Low32Bits(value) == 0u) {
4072 return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare);
4073 }
4074 high_opcode = ADC;
4075 low_set_cc = kCcSet;
4076 break;
4077 default:
4078 break;
4079 }
4080 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) &&
4081 CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004082 } else {
4083 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
4084 }
4085}
4086
Vladimir Marko59751a72016-08-05 14:37:27 +01004087bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value,
4088 Opcode opcode,
4089 SetCc set_cc) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004090 ShifterOperand so;
4091 ArmAssembler* assembler = codegen_->GetAssembler();
Vladimir Marko59751a72016-08-05 14:37:27 +01004092 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004093 return true;
4094 }
4095 Opcode neg_opcode = kNoOperand;
4096 switch (opcode) {
Vladimir Marko59751a72016-08-05 14:37:27 +01004097 case AND: neg_opcode = BIC; value = ~value; break;
4098 case ORR: neg_opcode = ORN; value = ~value; break;
4099 case ADD: neg_opcode = SUB; value = -value; break;
4100 case ADC: neg_opcode = SBC; value = ~value; break;
4101 case SUB: neg_opcode = ADD; value = -value; break;
4102 case SBC: neg_opcode = ADC; value = ~value; break;
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004103 default:
4104 return false;
4105 }
Vladimir Marko59751a72016-08-05 14:37:27 +01004106 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01004107}
4108
Calin Juravle52c48962014-12-16 17:02:57 +00004109void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
4110 const FieldInfo& field_info) {
4111 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004112
Calin Juravle52c48962014-12-16 17:02:57 +00004113 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004114 Location base_loc = locations->InAt(0);
4115 Register base = base_loc.AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00004116 Location out = locations->Out();
4117 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004118 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00004119 Primitive::Type field_type = field_info.GetFieldType();
4120 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
4121
4122 switch (field_type) {
Roland Levillainc9285912015-12-18 10:38:42 +00004123 case Primitive::kPrimBoolean:
Calin Juravle52c48962014-12-16 17:02:57 +00004124 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004125 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004126
Roland Levillainc9285912015-12-18 10:38:42 +00004127 case Primitive::kPrimByte:
Calin Juravle52c48962014-12-16 17:02:57 +00004128 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004129 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004130
Roland Levillainc9285912015-12-18 10:38:42 +00004131 case Primitive::kPrimShort:
Calin Juravle52c48962014-12-16 17:02:57 +00004132 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004133 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004134
Roland Levillainc9285912015-12-18 10:38:42 +00004135 case Primitive::kPrimChar:
Calin Juravle52c48962014-12-16 17:02:57 +00004136 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004137 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004138
4139 case Primitive::kPrimInt:
Calin Juravle52c48962014-12-16 17:02:57 +00004140 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004141 break;
Roland Levillainc9285912015-12-18 10:38:42 +00004142
4143 case Primitive::kPrimNot: {
4144 // /* HeapReference<Object> */ out = *(base + offset)
4145 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4146 Location temp_loc = locations->GetTemp(0);
4147 // Note that a potential implicit null check is handled in this
4148 // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call.
4149 codegen_->GenerateFieldLoadWithBakerReadBarrier(
4150 instruction, out, base, offset, temp_loc, /* needs_null_check */ true);
4151 if (is_volatile) {
4152 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4153 }
4154 } else {
4155 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
4156 codegen_->MaybeRecordImplicitNullCheck(instruction);
4157 if (is_volatile) {
4158 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4159 }
4160 // If read barriers are enabled, emit read barriers other than
4161 // Baker's using a slow path (and also unpoison the loaded
4162 // reference, if heap poisoning is enabled).
4163 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
4164 }
4165 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004166 }
4167
Roland Levillainc9285912015-12-18 10:38:42 +00004168 case Primitive::kPrimLong:
Calin Juravle34166012014-12-19 17:22:29 +00004169 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004170 GenerateWideAtomicLoad(base, offset,
4171 out.AsRegisterPairLow<Register>(),
4172 out.AsRegisterPairHigh<Register>());
4173 } else {
4174 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
4175 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004176 break;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004177
Roland Levillainc9285912015-12-18 10:38:42 +00004178 case Primitive::kPrimFloat:
Calin Juravle52c48962014-12-16 17:02:57 +00004179 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004180 break;
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004181
4182 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00004183 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00004184 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00004185 Register lo = locations->GetTemp(0).AsRegister<Register>();
4186 Register hi = locations->GetTemp(1).AsRegister<Register>();
4187 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00004188 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004189 __ vmovdrr(out_reg, lo, hi);
4190 } else {
4191 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004192 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00004193 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00004194 break;
4195 }
4196
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004197 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00004198 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004199 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004200 }
Calin Juravle52c48962014-12-16 17:02:57 +00004201
Roland Levillainc9285912015-12-18 10:38:42 +00004202 if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) {
4203 // Potential implicit null checks, in the case of reference or
4204 // double fields, are handled in the previous switch statement.
4205 } else {
Calin Juravle77520bc2015-01-12 18:45:46 +00004206 codegen_->MaybeRecordImplicitNullCheck(instruction);
4207 }
4208
Calin Juravle52c48962014-12-16 17:02:57 +00004209 if (is_volatile) {
Roland Levillainc9285912015-12-18 10:38:42 +00004210 if (field_type == Primitive::kPrimNot) {
4211 // Memory barriers, in the case of references, are also handled
4212 // in the previous switch statement.
4213 } else {
4214 codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4215 }
Roland Levillain4d027112015-07-01 15:41:14 +01004216 }
Calin Juravle52c48962014-12-16 17:02:57 +00004217}
4218
4219void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4220 HandleFieldSet(instruction, instruction->GetFieldInfo());
4221}
4222
4223void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004224 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00004225}
4226
4227void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4228 HandleFieldGet(instruction, instruction->GetFieldInfo());
4229}
4230
4231void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4232 HandleFieldGet(instruction, instruction->GetFieldInfo());
4233}
4234
4235void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4236 HandleFieldGet(instruction, instruction->GetFieldInfo());
4237}
4238
4239void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
4240 HandleFieldGet(instruction, instruction->GetFieldInfo());
4241}
4242
4243void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
4244 HandleFieldSet(instruction, instruction->GetFieldInfo());
4245}
4246
4247void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004248 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004249}
4250
Calin Juravlee460d1d2015-09-29 04:52:17 +01004251void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
4252 HUnresolvedInstanceFieldGet* instruction) {
4253 FieldAccessCallingConventionARM calling_convention;
4254 codegen_->CreateUnresolvedFieldLocationSummary(
4255 instruction, instruction->GetFieldType(), calling_convention);
4256}
4257
4258void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
4259 HUnresolvedInstanceFieldGet* instruction) {
4260 FieldAccessCallingConventionARM calling_convention;
4261 codegen_->GenerateUnresolvedFieldAccess(instruction,
4262 instruction->GetFieldType(),
4263 instruction->GetFieldIndex(),
4264 instruction->GetDexPc(),
4265 calling_convention);
4266}
4267
4268void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
4269 HUnresolvedInstanceFieldSet* instruction) {
4270 FieldAccessCallingConventionARM calling_convention;
4271 codegen_->CreateUnresolvedFieldLocationSummary(
4272 instruction, instruction->GetFieldType(), calling_convention);
4273}
4274
4275void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
4276 HUnresolvedInstanceFieldSet* instruction) {
4277 FieldAccessCallingConventionARM calling_convention;
4278 codegen_->GenerateUnresolvedFieldAccess(instruction,
4279 instruction->GetFieldType(),
4280 instruction->GetFieldIndex(),
4281 instruction->GetDexPc(),
4282 calling_convention);
4283}
4284
4285void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
4286 HUnresolvedStaticFieldGet* instruction) {
4287 FieldAccessCallingConventionARM calling_convention;
4288 codegen_->CreateUnresolvedFieldLocationSummary(
4289 instruction, instruction->GetFieldType(), calling_convention);
4290}
4291
4292void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
4293 HUnresolvedStaticFieldGet* instruction) {
4294 FieldAccessCallingConventionARM calling_convention;
4295 codegen_->GenerateUnresolvedFieldAccess(instruction,
4296 instruction->GetFieldType(),
4297 instruction->GetFieldIndex(),
4298 instruction->GetDexPc(),
4299 calling_convention);
4300}
4301
4302void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
4303 HUnresolvedStaticFieldSet* instruction) {
4304 FieldAccessCallingConventionARM calling_convention;
4305 codegen_->CreateUnresolvedFieldLocationSummary(
4306 instruction, instruction->GetFieldType(), calling_convention);
4307}
4308
4309void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
4310 HUnresolvedStaticFieldSet* instruction) {
4311 FieldAccessCallingConventionARM calling_convention;
4312 codegen_->GenerateUnresolvedFieldAccess(instruction,
4313 instruction->GetFieldType(),
4314 instruction->GetFieldIndex(),
4315 instruction->GetDexPc(),
4316 calling_convention);
4317}
4318
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004319void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004320 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4321 ? LocationSummary::kCallOnSlowPath
4322 : LocationSummary::kNoCall;
4323 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00004324 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004325 if (instruction->HasUses()) {
4326 locations->SetOut(Location::SameAsFirstInput());
4327 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004328}
4329
Calin Juravle2ae48182016-03-16 14:05:09 +00004330void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
4331 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004332 return;
4333 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004334 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004335
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004336 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00004337 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004338}
4339
Calin Juravle2ae48182016-03-16 14:05:09 +00004340void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004341 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004342 AddSlowPath(slow_path);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004343
4344 LocationSummary* locations = instruction->GetLocations();
4345 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004346
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004347 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004348}
4349
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004350void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004351 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004352}
4353
Artem Serov6c916792016-07-11 14:02:34 +01004354static LoadOperandType GetLoadOperandType(Primitive::Type type) {
4355 switch (type) {
4356 case Primitive::kPrimNot:
4357 return kLoadWord;
4358 case Primitive::kPrimBoolean:
4359 return kLoadUnsignedByte;
4360 case Primitive::kPrimByte:
4361 return kLoadSignedByte;
4362 case Primitive::kPrimChar:
4363 return kLoadUnsignedHalfword;
4364 case Primitive::kPrimShort:
4365 return kLoadSignedHalfword;
4366 case Primitive::kPrimInt:
4367 return kLoadWord;
4368 case Primitive::kPrimLong:
4369 return kLoadWordPair;
4370 case Primitive::kPrimFloat:
4371 return kLoadSWord;
4372 case Primitive::kPrimDouble:
4373 return kLoadDWord;
4374 default:
4375 LOG(FATAL) << "Unreachable type " << type;
4376 UNREACHABLE();
4377 }
4378}
4379
4380static StoreOperandType GetStoreOperandType(Primitive::Type type) {
4381 switch (type) {
4382 case Primitive::kPrimNot:
4383 return kStoreWord;
4384 case Primitive::kPrimBoolean:
4385 case Primitive::kPrimByte:
4386 return kStoreByte;
4387 case Primitive::kPrimChar:
4388 case Primitive::kPrimShort:
4389 return kStoreHalfword;
4390 case Primitive::kPrimInt:
4391 return kStoreWord;
4392 case Primitive::kPrimLong:
4393 return kStoreWordPair;
4394 case Primitive::kPrimFloat:
4395 return kStoreSWord;
4396 case Primitive::kPrimDouble:
4397 return kStoreDWord;
4398 default:
4399 LOG(FATAL) << "Unreachable type " << type;
4400 UNREACHABLE();
4401 }
4402}
4403
4404void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type,
4405 Location out_loc,
4406 Register base,
4407 Register reg_offset,
4408 Condition cond) {
4409 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4410 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4411
4412 switch (type) {
4413 case Primitive::kPrimByte:
4414 __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond);
4415 break;
4416 case Primitive::kPrimBoolean:
4417 __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond);
4418 break;
4419 case Primitive::kPrimShort:
4420 __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond);
4421 break;
4422 case Primitive::kPrimChar:
4423 __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond);
4424 break;
4425 case Primitive::kPrimNot:
4426 case Primitive::kPrimInt:
4427 __ ldr(out_loc.AsRegister<Register>(), mem_address, cond);
4428 break;
4429 // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types.
4430 case Primitive::kPrimLong:
4431 case Primitive::kPrimFloat:
4432 case Primitive::kPrimDouble:
4433 default:
4434 LOG(FATAL) << "Unreachable type " << type;
4435 UNREACHABLE();
4436 }
4437}
4438
4439void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type,
4440 Location loc,
4441 Register base,
4442 Register reg_offset,
4443 Condition cond) {
4444 uint32_t shift_count = Primitive::ComponentSizeShift(type);
4445 Address mem_address(base, reg_offset, Shift::LSL, shift_count);
4446
4447 switch (type) {
4448 case Primitive::kPrimByte:
4449 case Primitive::kPrimBoolean:
4450 __ strb(loc.AsRegister<Register>(), mem_address, cond);
4451 break;
4452 case Primitive::kPrimShort:
4453 case Primitive::kPrimChar:
4454 __ strh(loc.AsRegister<Register>(), mem_address, cond);
4455 break;
4456 case Primitive::kPrimNot:
4457 case Primitive::kPrimInt:
4458 __ str(loc.AsRegister<Register>(), mem_address, cond);
4459 break;
4460 // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types.
4461 case Primitive::kPrimLong:
4462 case Primitive::kPrimFloat:
4463 case Primitive::kPrimDouble:
4464 default:
4465 LOG(FATAL) << "Unreachable type " << type;
4466 UNREACHABLE();
4467 }
4468}
4469
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004470void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain3b359c72015-11-17 19:35:12 +00004471 bool object_array_get_with_read_barrier =
4472 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004473 LocationSummary* locations =
Roland Levillain3b359c72015-11-17 19:35:12 +00004474 new (GetGraph()->GetArena()) LocationSummary(instruction,
4475 object_array_get_with_read_barrier ?
4476 LocationSummary::kCallOnSlowPath :
4477 LocationSummary::kNoCall);
Vladimir Marko70e97462016-08-09 11:04:26 +01004478 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4479 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
4480 }
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004481 locations->SetInAt(0, Location::RequiresRegister());
4482 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004483 if (Primitive::IsFloatingPointType(instruction->GetType())) {
4484 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4485 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004486 // The output overlaps in the case of an object array get with
4487 // read barriers enabled: we do not want the move to overwrite the
4488 // array's location, as we need it to emit the read barrier.
4489 locations->SetOut(
4490 Location::RequiresRegister(),
4491 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01004492 }
Roland Levillainc9285912015-12-18 10:38:42 +00004493 // We need a temporary register for the read barrier marking slow
4494 // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
4495 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
4496 locations->AddTemp(Location::RequiresRegister());
4497 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004498}
4499
4500void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
4501 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004502 Location obj_loc = locations->InAt(0);
4503 Register obj = obj_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004504 Location index = locations->InAt(1);
Roland Levillainc9285912015-12-18 10:38:42 +00004505 Location out_loc = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01004506 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Roland Levillainc9285912015-12-18 10:38:42 +00004507 Primitive::Type type = instruction->GetType();
Artem Serov328429f2016-07-06 16:23:04 +01004508 HInstruction* array_instr = instruction->GetArray();
4509 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004510 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4511 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Artem Serov6c916792016-07-11 14:02:34 +01004512
Roland Levillain4d027112015-07-01 15:41:14 +01004513 switch (type) {
Artem Serov6c916792016-07-11 14:02:34 +01004514 case Primitive::kPrimBoolean:
4515 case Primitive::kPrimByte:
4516 case Primitive::kPrimShort:
4517 case Primitive::kPrimChar:
Roland Levillainc9285912015-12-18 10:38:42 +00004518 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004519 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004520 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4521 uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type));
4522
4523 LoadOperandType load_type = GetLoadOperandType(type);
4524 __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004525 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004526 Register temp = IP;
4527
4528 if (has_intermediate_address) {
4529 // We do not need to compute the intermediate address from the array: the
4530 // input instruction has done it already. See the comment in
4531 // `TryExtractArrayAccessAddress()`.
4532 if (kIsDebugBuild) {
4533 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4534 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4535 }
4536 temp = obj;
4537 } else {
4538 __ add(temp, obj, ShifterOperand(data_offset));
4539 }
4540 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004541 }
4542 break;
4543 }
4544
Roland Levillainc9285912015-12-18 10:38:42 +00004545 case Primitive::kPrimNot: {
4546 static_assert(
4547 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
4548 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00004549 // /* HeapReference<Object> */ out =
4550 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
4551 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
4552 Location temp = locations->GetTemp(0);
4553 // Note that a potential implicit null check is handled in this
4554 // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call.
4555 codegen_->GenerateArrayLoadWithBakerReadBarrier(
4556 instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true);
4557 } else {
4558 Register out = out_loc.AsRegister<Register>();
4559 if (index.IsConstant()) {
4560 size_t offset =
4561 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4562 __ LoadFromOffset(kLoadWord, out, obj, offset);
4563 codegen_->MaybeRecordImplicitNullCheck(instruction);
4564 // If read barriers are enabled, emit read barriers other than
4565 // Baker's using a slow path (and also unpoison the loaded
4566 // reference, if heap poisoning is enabled).
4567 codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset);
4568 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004569 Register temp = IP;
4570
4571 if (has_intermediate_address) {
4572 // We do not need to compute the intermediate address from the array: the
4573 // input instruction has done it already. See the comment in
4574 // `TryExtractArrayAccessAddress()`.
4575 if (kIsDebugBuild) {
4576 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4577 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset);
4578 }
4579 temp = obj;
4580 } else {
4581 __ add(temp, obj, ShifterOperand(data_offset));
4582 }
4583 codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>());
Artem Serov6c916792016-07-11 14:02:34 +01004584
Roland Levillainc9285912015-12-18 10:38:42 +00004585 codegen_->MaybeRecordImplicitNullCheck(instruction);
4586 // If read barriers are enabled, emit read barriers other than
4587 // Baker's using a slow path (and also unpoison the loaded
4588 // reference, if heap poisoning is enabled).
4589 codegen_->MaybeGenerateReadBarrierSlow(
4590 instruction, out_loc, out_loc, obj_loc, data_offset, index);
4591 }
4592 }
4593 break;
4594 }
4595
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004596 case Primitive::kPrimLong: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004597 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004598 size_t offset =
4599 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004600 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004601 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004602 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004603 __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004604 }
4605 break;
4606 }
4607
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004608 case Primitive::kPrimFloat: {
Roland Levillainc9285912015-12-18 10:38:42 +00004609 SRegister out = out_loc.AsFpuRegister<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004610 if (index.IsConstant()) {
4611 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004612 __ LoadSFromOffset(out, obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004613 } else {
4614 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillainc9285912015-12-18 10:38:42 +00004615 __ LoadSFromOffset(out, IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004616 }
4617 break;
4618 }
4619
4620 case Primitive::kPrimDouble: {
Roland Levillainc9285912015-12-18 10:38:42 +00004621 SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004622 if (index.IsConstant()) {
4623 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Roland Levillainc9285912015-12-18 10:38:42 +00004624 __ LoadDFromOffset(FromLowSToD(out), obj, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004625 } else {
4626 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Roland Levillainc9285912015-12-18 10:38:42 +00004627 __ LoadDFromOffset(FromLowSToD(out), IP, data_offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004628 }
4629 break;
4630 }
4631
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004632 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01004633 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004634 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004635 }
Roland Levillain4d027112015-07-01 15:41:14 +01004636
4637 if (type == Primitive::kPrimNot) {
Roland Levillainc9285912015-12-18 10:38:42 +00004638 // Potential implicit null checks, in the case of reference
4639 // arrays, are handled in the previous switch statement.
4640 } else {
4641 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01004642 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004643}
4644
4645void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004646 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004647
4648 bool needs_write_barrier =
4649 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Roland Levillain3b359c72015-11-17 19:35:12 +00004650 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004651
Nicolas Geoffray39468442014-09-02 15:17:15 +01004652 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004653 instruction,
Vladimir Marko8d49fd72016-08-25 15:20:47 +01004654 may_need_runtime_call_for_type_check ?
Roland Levillain3b359c72015-11-17 19:35:12 +00004655 LocationSummary::kCallOnSlowPath :
4656 LocationSummary::kNoCall);
4657
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004658 locations->SetInAt(0, Location::RequiresRegister());
4659 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
4660 if (Primitive::IsFloatingPointType(value_type)) {
4661 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004662 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004663 locations->SetInAt(2, Location::RequiresRegister());
4664 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004665 if (needs_write_barrier) {
4666 // Temporary registers for the write barrier.
4667 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Roland Levillain4f6b0b52015-11-23 19:29:22 +00004668 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004669 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004670}
4671
4672void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4673 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00004674 Location array_loc = locations->InAt(0);
4675 Register array = array_loc.AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004676 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004677 Primitive::Type value_type = instruction->GetComponentType();
Roland Levillain3b359c72015-11-17 19:35:12 +00004678 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004679 bool needs_write_barrier =
4680 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Artem Serov6c916792016-07-11 14:02:34 +01004681 uint32_t data_offset =
4682 mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
4683 Location value_loc = locations->InAt(2);
Artem Serov328429f2016-07-06 16:23:04 +01004684 HInstruction* array_instr = instruction->GetArray();
4685 bool has_intermediate_address = array_instr->IsIntermediateAddress();
Roland Levillain4a3aa572016-08-15 13:17:06 +00004686 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4687 DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004688
4689 switch (value_type) {
4690 case Primitive::kPrimBoolean:
Artem Serov6c916792016-07-11 14:02:34 +01004691 case Primitive::kPrimByte:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004692 case Primitive::kPrimShort:
Artem Serov6c916792016-07-11 14:02:34 +01004693 case Primitive::kPrimChar:
4694 case Primitive::kPrimInt: {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004695 if (index.IsConstant()) {
Artem Serov6c916792016-07-11 14:02:34 +01004696 int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue();
4697 uint32_t full_offset =
4698 data_offset + (const_index << Primitive::ComponentSizeShift(value_type));
4699 StoreOperandType store_type = GetStoreOperandType(value_type);
4700 __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004701 } else {
Artem Serov328429f2016-07-06 16:23:04 +01004702 Register temp = IP;
4703
4704 if (has_intermediate_address) {
4705 // We do not need to compute the intermediate address from the array: the
4706 // input instruction has done it already. See the comment in
4707 // `TryExtractArrayAccessAddress()`.
4708 if (kIsDebugBuild) {
4709 HIntermediateAddress* tmp = array_instr->AsIntermediateAddress();
4710 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset);
4711 }
4712 temp = array;
4713 } else {
4714 __ add(temp, array, ShifterOperand(data_offset));
4715 }
Artem Serov6c916792016-07-11 14:02:34 +01004716 codegen_->StoreToShiftedRegOffset(value_type,
4717 value_loc,
Artem Serov328429f2016-07-06 16:23:04 +01004718 temp,
Artem Serov6c916792016-07-11 14:02:34 +01004719 index.AsRegister<Register>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004720 }
4721 break;
4722 }
4723
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004724 case Primitive::kPrimNot: {
Roland Levillain3b359c72015-11-17 19:35:12 +00004725 Register value = value_loc.AsRegister<Register>();
Artem Serov328429f2016-07-06 16:23:04 +01004726 // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet.
4727 // See the comment in instruction_simplifier_shared.cc.
4728 DCHECK(!has_intermediate_address);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004729
4730 if (instruction->InputAt(2)->IsNullConstant()) {
4731 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004732 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004733 size_t offset =
4734 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Artem Serov6c916792016-07-11 14:02:34 +01004735 __ StoreToOffset(kStoreWord, value, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004736 } else {
4737 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004738 __ add(IP, array, ShifterOperand(data_offset));
4739 codegen_->StoreToShiftedRegOffset(value_type,
4740 value_loc,
4741 IP,
4742 index.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004743 }
Roland Levillain1407ee72016-01-08 15:56:19 +00004744 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain3b359c72015-11-17 19:35:12 +00004745 DCHECK(!needs_write_barrier);
4746 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004747 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004748 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004749
4750 DCHECK(needs_write_barrier);
4751 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
4752 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
4753 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4754 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4755 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4756 Label done;
4757 SlowPathCode* slow_path = nullptr;
4758
Roland Levillain3b359c72015-11-17 19:35:12 +00004759 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004760 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4761 codegen_->AddSlowPath(slow_path);
4762 if (instruction->GetValueCanBeNull()) {
4763 Label non_zero;
4764 __ CompareAndBranchIfNonZero(value, &non_zero);
4765 if (index.IsConstant()) {
4766 size_t offset =
4767 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4768 __ StoreToOffset(kStoreWord, value, array, offset);
4769 } else {
4770 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004771 __ add(IP, array, ShifterOperand(data_offset));
4772 codegen_->StoreToShiftedRegOffset(value_type,
4773 value_loc,
4774 IP,
4775 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004776 }
4777 codegen_->MaybeRecordImplicitNullCheck(instruction);
4778 __ b(&done);
4779 __ Bind(&non_zero);
4780 }
4781
Roland Levillain3b359c72015-11-17 19:35:12 +00004782 if (kEmitCompilerReadBarrier) {
4783 // When read barriers are enabled, the type checking
4784 // instrumentation requires two read barriers:
4785 //
4786 // __ Mov(temp2, temp1);
4787 // // /* HeapReference<Class> */ temp1 = temp1->component_type_
4788 // __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
Roland Levillainc9285912015-12-18 10:38:42 +00004789 // codegen_->GenerateReadBarrierSlow(
Roland Levillain3b359c72015-11-17 19:35:12 +00004790 // instruction, temp1_loc, temp1_loc, temp2_loc, component_offset);
4791 //
4792 // // /* HeapReference<Class> */ temp2 = value->klass_
4793 // __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
Roland Levillainc9285912015-12-18 10:38:42 +00004794 // codegen_->GenerateReadBarrierSlow(
Roland Levillain3b359c72015-11-17 19:35:12 +00004795 // instruction, temp2_loc, temp2_loc, value_loc, class_offset, temp1_loc);
4796 //
4797 // __ cmp(temp1, ShifterOperand(temp2));
4798 //
4799 // However, the second read barrier may trash `temp`, as it
4800 // is a temporary register, and as such would not be saved
4801 // along with live registers before calling the runtime (nor
4802 // restored afterwards). So in this case, we bail out and
4803 // delegate the work to the array set slow path.
4804 //
4805 // TODO: Extend the register allocator to support a new
4806 // "(locally) live temp" location so as to avoid always
4807 // going into the slow path when read barriers are enabled.
4808 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004809 } else {
Roland Levillain3b359c72015-11-17 19:35:12 +00004810 // /* HeapReference<Class> */ temp1 = array->klass_
4811 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4812 codegen_->MaybeRecordImplicitNullCheck(instruction);
4813 __ MaybeUnpoisonHeapReference(temp1);
4814
4815 // /* HeapReference<Class> */ temp1 = temp1->component_type_
4816 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4817 // /* HeapReference<Class> */ temp2 = value->klass_
4818 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4819 // If heap poisoning is enabled, no need to unpoison `temp1`
4820 // nor `temp2`, as we are comparing two poisoned references.
4821 __ cmp(temp1, ShifterOperand(temp2));
4822
4823 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4824 Label do_put;
4825 __ b(&do_put, EQ);
4826 // If heap poisoning is enabled, the `temp1` reference has
4827 // not been unpoisoned yet; unpoison it now.
4828 __ MaybeUnpoisonHeapReference(temp1);
4829
4830 // /* HeapReference<Class> */ temp1 = temp1->super_class_
4831 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4832 // If heap poisoning is enabled, no need to unpoison
4833 // `temp1`, as we are comparing against null below.
4834 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4835 __ Bind(&do_put);
4836 } else {
4837 __ b(slow_path->GetEntryLabel(), NE);
4838 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004839 }
4840 }
4841
Artem Serov6c916792016-07-11 14:02:34 +01004842 Register source = value;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004843 if (kPoisonHeapReferences) {
4844 // Note that in the case where `value` is a null reference,
4845 // we do not enter this block, as a null reference does not
4846 // need poisoning.
4847 DCHECK_EQ(value_type, Primitive::kPrimNot);
4848 __ Mov(temp1, value);
4849 __ PoisonHeapReference(temp1);
4850 source = temp1;
4851 }
4852
4853 if (index.IsConstant()) {
4854 size_t offset =
4855 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4856 __ StoreToOffset(kStoreWord, source, array, offset);
4857 } else {
4858 DCHECK(index.IsRegister()) << index;
Artem Serov6c916792016-07-11 14:02:34 +01004859
4860 __ add(IP, array, ShifterOperand(data_offset));
4861 codegen_->StoreToShiftedRegOffset(value_type,
4862 Location::RegisterLocation(source),
4863 IP,
4864 index.AsRegister<Register>());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004865 }
4866
Roland Levillain3b359c72015-11-17 19:35:12 +00004867 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004868 codegen_->MaybeRecordImplicitNullCheck(instruction);
4869 }
4870
4871 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4872
4873 if (done.IsLinked()) {
4874 __ Bind(&done);
4875 }
4876
4877 if (slow_path != nullptr) {
4878 __ Bind(slow_path->GetExitLabel());
4879 }
4880
4881 break;
4882 }
4883
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004884 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004885 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004886 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004887 size_t offset =
4888 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004889 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004890 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004891 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004892 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004893 }
4894 break;
4895 }
4896
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004897 case Primitive::kPrimFloat: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004898 Location value = locations->InAt(2);
4899 DCHECK(value.IsFpuRegister());
4900 if (index.IsConstant()) {
4901 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004902 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004903 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004904 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004905 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4906 }
4907 break;
4908 }
4909
4910 case Primitive::kPrimDouble: {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004911 Location value = locations->InAt(2);
4912 DCHECK(value.IsFpuRegisterPair());
4913 if (index.IsConstant()) {
4914 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004915 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004916 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004917 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004918 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4919 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004920
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004921 break;
4922 }
4923
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004924 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004925 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004926 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004927 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004928
Roland Levillain80e67092016-01-08 16:04:55 +00004929 // Objects are handled in the switch.
4930 if (value_type != Primitive::kPrimNot) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004931 codegen_->MaybeRecordImplicitNullCheck(instruction);
4932 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004933}
4934
4935void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004936 LocationSummary* locations =
4937 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004938 locations->SetInAt(0, Location::RequiresRegister());
4939 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004940}
4941
4942void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4943 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01004944 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Roland Levillain271ab9c2014-11-27 15:23:57 +00004945 Register obj = locations->InAt(0).AsRegister<Register>();
4946 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004947 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004948 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004949}
4950
Artem Serov328429f2016-07-06 16:23:04 +01004951void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Roland Levillain4a3aa572016-08-15 13:17:06 +00004952 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4953 DCHECK(!kEmitCompilerReadBarrier);
Artem Serov328429f2016-07-06 16:23:04 +01004954 LocationSummary* locations =
4955 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4956
4957 locations->SetInAt(0, Location::RequiresRegister());
4958 locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset()));
4959 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4960}
4961
4962void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) {
4963 LocationSummary* locations = instruction->GetLocations();
4964 Location out = locations->Out();
4965 Location first = locations->InAt(0);
4966 Location second = locations->InAt(1);
4967
Roland Levillain4a3aa572016-08-15 13:17:06 +00004968 // The read barrier instrumentation does not support the HIntermediateAddress instruction yet.
4969 DCHECK(!kEmitCompilerReadBarrier);
4970
Artem Serov328429f2016-07-06 16:23:04 +01004971 if (second.IsRegister()) {
4972 __ add(out.AsRegister<Register>(),
4973 first.AsRegister<Register>(),
4974 ShifterOperand(second.AsRegister<Register>()));
4975 } else {
4976 __ AddConstant(out.AsRegister<Register>(),
4977 first.AsRegister<Register>(),
4978 second.GetConstant()->AsIntConstant()->GetValue());
4979 }
4980}
4981
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004982void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004983 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4984 ? LocationSummary::kCallOnSlowPath
4985 : LocationSummary::kNoCall;
4986 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004987 locations->SetInAt(0, Location::RequiresRegister());
4988 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004989 if (instruction->HasUses()) {
4990 locations->SetOut(Location::SameAsFirstInput());
4991 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004992}
4993
4994void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
4995 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07004996 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004997 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004998 codegen_->AddSlowPath(slow_path);
4999
Roland Levillain271ab9c2014-11-27 15:23:57 +00005000 Register index = locations->InAt(0).AsRegister<Register>();
5001 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005002
5003 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01005004 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005005}
5006
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005007void CodeGeneratorARM::MarkGCCard(Register temp,
5008 Register card,
5009 Register object,
5010 Register value,
5011 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005012 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005013 if (can_be_null) {
5014 __ CompareAndBranchIfZero(value, &is_null);
5015 }
Andreas Gampe542451c2016-07-26 09:02:02 -07005016 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005017 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
5018 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005019 if (can_be_null) {
5020 __ Bind(&is_null);
5021 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01005022}
5023
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005024void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005025 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005026}
5027
5028void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005029 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5030}
5031
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005032void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01005033 LocationSummary* locations =
5034 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
5035 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005036}
5037
5038void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005039 HBasicBlock* block = instruction->GetBlock();
5040 if (block->GetLoopInformation() != nullptr) {
5041 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5042 // The back edge will generate the suspend check.
5043 return;
5044 }
5045 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5046 // The goto will generate the suspend check.
5047 return;
5048 }
5049 GenerateSuspendCheck(instruction, nullptr);
5050}
5051
5052void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
5053 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005054 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01005055 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
5056 if (slow_path == nullptr) {
5057 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
5058 instruction->SetSlowPath(slow_path);
5059 codegen_->AddSlowPath(slow_path);
5060 if (successor != nullptr) {
5061 DCHECK(successor->IsLoopHeader());
5062 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
5063 }
5064 } else {
5065 DCHECK_EQ(slow_path->GetSuccessor(), successor);
5066 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005067
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00005068 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07005069 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005070 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005071 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005072 __ Bind(slow_path->GetReturnLabel());
5073 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01005074 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01005075 __ b(slow_path->GetEntryLabel());
5076 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00005077}
5078
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005079ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
5080 return codegen_->GetAssembler();
5081}
5082
5083void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005084 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005085 Location source = move->GetSource();
5086 Location destination = move->GetDestination();
5087
5088 if (source.IsRegister()) {
5089 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005090 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005091 } else if (destination.IsFpuRegister()) {
5092 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005093 } else {
5094 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00005095 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005096 SP, destination.GetStackIndex());
5097 }
5098 } else if (source.IsStackSlot()) {
5099 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005100 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005101 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005102 } else if (destination.IsFpuRegister()) {
5103 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005104 } else {
5105 DCHECK(destination.IsStackSlot());
5106 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
5107 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5108 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005109 } else if (source.IsFpuRegister()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005110 if (destination.IsRegister()) {
5111 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
5112 } else if (destination.IsFpuRegister()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005113 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005114 } else {
5115 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005116 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
5117 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005118 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005119 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005120 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
5121 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005122 } else if (destination.IsRegisterPair()) {
5123 DCHECK(ExpectedPairLayout(destination));
5124 __ LoadFromOffset(
5125 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
5126 } else {
5127 DCHECK(destination.IsFpuRegisterPair()) << destination;
5128 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5129 SP,
5130 source.GetStackIndex());
5131 }
5132 } else if (source.IsRegisterPair()) {
5133 if (destination.IsRegisterPair()) {
5134 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
5135 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
David Brazdil74eb1b22015-12-14 11:44:01 +00005136 } else if (destination.IsFpuRegisterPair()) {
5137 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5138 source.AsRegisterPairLow<Register>(),
5139 source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005140 } else {
5141 DCHECK(destination.IsDoubleStackSlot()) << destination;
5142 DCHECK(ExpectedPairLayout(source));
5143 __ StoreToOffset(
5144 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
5145 }
5146 } else if (source.IsFpuRegisterPair()) {
David Brazdil74eb1b22015-12-14 11:44:01 +00005147 if (destination.IsRegisterPair()) {
5148 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5149 destination.AsRegisterPairHigh<Register>(),
5150 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5151 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005152 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
5153 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
5154 } else {
5155 DCHECK(destination.IsDoubleStackSlot()) << destination;
5156 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
5157 SP,
5158 destination.GetStackIndex());
5159 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005160 } else {
5161 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00005162 HConstant* constant = source.GetConstant();
5163 if (constant->IsIntConstant() || constant->IsNullConstant()) {
5164 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005165 if (destination.IsRegister()) {
5166 __ LoadImmediate(destination.AsRegister<Register>(), value);
5167 } else {
5168 DCHECK(destination.IsStackSlot());
5169 __ LoadImmediate(IP, value);
5170 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5171 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005172 } else if (constant->IsLongConstant()) {
5173 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005174 if (destination.IsRegisterPair()) {
5175 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
5176 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005177 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005178 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005179 __ LoadImmediate(IP, Low32Bits(value));
5180 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5181 __ LoadImmediate(IP, High32Bits(value));
5182 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5183 }
5184 } else if (constant->IsDoubleConstant()) {
5185 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005186 if (destination.IsFpuRegisterPair()) {
5187 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005188 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005189 DCHECK(destination.IsDoubleStackSlot()) << destination;
5190 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005191 __ LoadImmediate(IP, Low32Bits(int_value));
5192 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5193 __ LoadImmediate(IP, High32Bits(int_value));
5194 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
5195 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005196 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00005197 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005198 float value = constant->AsFloatConstant()->GetValue();
5199 if (destination.IsFpuRegister()) {
5200 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
5201 } else {
5202 DCHECK(destination.IsStackSlot());
5203 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
5204 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
5205 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01005206 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005207 }
5208}
5209
5210void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
5211 __ Mov(IP, reg);
5212 __ LoadFromOffset(kLoadWord, reg, SP, mem);
5213 __ StoreToOffset(kStoreWord, IP, SP, mem);
5214}
5215
5216void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
5217 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
5218 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
5219 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
5220 SP, mem1 + stack_offset);
5221 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
5222 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
5223 SP, mem2 + stack_offset);
5224 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
5225}
5226
5227void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01005228 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005229 Location source = move->GetSource();
5230 Location destination = move->GetDestination();
5231
5232 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005233 DCHECK_NE(source.AsRegister<Register>(), IP);
5234 DCHECK_NE(destination.AsRegister<Register>(), IP);
5235 __ Mov(IP, source.AsRegister<Register>());
5236 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
5237 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005238 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005239 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005240 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005241 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005242 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
5243 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005244 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005245 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005246 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005247 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005248 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005249 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005250 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005251 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005252 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
5253 destination.AsRegisterPairHigh<Register>(),
5254 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005255 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005256 Register low_reg = source.IsRegisterPair()
5257 ? source.AsRegisterPairLow<Register>()
5258 : destination.AsRegisterPairLow<Register>();
5259 int mem = source.IsRegisterPair()
5260 ? destination.GetStackIndex()
5261 : source.GetStackIndex();
5262 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005263 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005264 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005265 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005266 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005267 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
5268 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005269 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005270 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005271 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005272 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
5273 DRegister reg = source.IsFpuRegisterPair()
5274 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
5275 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
5276 int mem = source.IsFpuRegisterPair()
5277 ? destination.GetStackIndex()
5278 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005279 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005280 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00005281 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00005282 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
5283 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
5284 : destination.AsFpuRegister<SRegister>();
5285 int mem = source.IsFpuRegister()
5286 ? destination.GetStackIndex()
5287 : source.GetStackIndex();
5288
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005289 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00005290 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00005291 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005292 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005293 Exchange(source.GetStackIndex(), destination.GetStackIndex());
5294 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005295 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00005296 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01005297 }
5298}
5299
5300void ParallelMoveResolverARM::SpillScratch(int reg) {
5301 __ Push(static_cast<Register>(reg));
5302}
5303
5304void ParallelMoveResolverARM::RestoreScratch(int reg) {
5305 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01005306}
5307
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005308HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind(
5309 HLoadClass::LoadKind desired_class_load_kind) {
5310 if (kEmitCompilerReadBarrier) {
5311 switch (desired_class_load_kind) {
5312 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5313 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5314 case HLoadClass::LoadKind::kBootImageAddress:
5315 // TODO: Implement for read barrier.
5316 return HLoadClass::LoadKind::kDexCacheViaMethod;
5317 default:
5318 break;
5319 }
5320 }
5321 switch (desired_class_load_kind) {
5322 case HLoadClass::LoadKind::kReferrersClass:
5323 break;
5324 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
5325 DCHECK(!GetCompilerOptions().GetCompilePic());
5326 break;
5327 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
5328 DCHECK(GetCompilerOptions().GetCompilePic());
5329 break;
5330 case HLoadClass::LoadKind::kBootImageAddress:
5331 break;
5332 case HLoadClass::LoadKind::kDexCacheAddress:
5333 DCHECK(Runtime::Current()->UseJitCompilation());
5334 break;
5335 case HLoadClass::LoadKind::kDexCachePcRelative:
5336 DCHECK(!Runtime::Current()->UseJitCompilation());
5337 // We disable pc-relative load when there is an irreducible loop, as the optimization
5338 // is incompatible with it.
5339 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5340 // with irreducible loops.
5341 if (GetGraph()->HasIrreducibleLoops()) {
5342 return HLoadClass::LoadKind::kDexCacheViaMethod;
5343 }
5344 break;
5345 case HLoadClass::LoadKind::kDexCacheViaMethod:
5346 break;
5347 }
5348 return desired_class_load_kind;
5349}
5350
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005351void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005352 if (cls->NeedsAccessCheck()) {
5353 InvokeRuntimeCallingConvention calling_convention;
5354 CodeGenerator::CreateLoadClassLocationSummary(
5355 cls,
5356 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
5357 Location::RegisterLocation(R0),
5358 /* code_generator_supports_read_barrier */ true);
5359 return;
5360 }
5361
5362 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
5363 ? LocationSummary::kCallOnSlowPath
5364 : LocationSummary::kNoCall;
5365 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Vladimir Marko70e97462016-08-09 11:04:26 +01005366 if (kUseBakerReadBarrier && !cls->NeedsEnvironment()) {
5367 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
5368 }
5369
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005370 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
5371 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
5372 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod ||
5373 load_kind == HLoadClass::LoadKind::kDexCachePcRelative) {
5374 locations->SetInAt(0, Location::RequiresRegister());
5375 }
5376 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005377}
5378
5379void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01005380 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01005381 if (cls->NeedsAccessCheck()) {
5382 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
5383 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
5384 cls,
5385 cls->GetDexPc(),
5386 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005387 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01005388 return;
5389 }
5390
Roland Levillain3b359c72015-11-17 19:35:12 +00005391 Location out_loc = locations->Out();
5392 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005393
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005394 bool generate_null_check = false;
5395 switch (cls->GetLoadKind()) {
5396 case HLoadClass::LoadKind::kReferrersClass: {
5397 DCHECK(!cls->CanCallRuntime());
5398 DCHECK(!cls->MustGenerateClinitCheck());
5399 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
5400 Register current_method = locations->InAt(0).AsRegister<Register>();
5401 GenerateGcRootFieldLoad(
5402 cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
5403 break;
5404 }
5405 case HLoadClass::LoadKind::kBootImageLinkTimeAddress: {
5406 DCHECK(!kEmitCompilerReadBarrier);
5407 __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
5408 cls->GetTypeIndex()));
5409 break;
5410 }
5411 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
5412 DCHECK(!kEmitCompilerReadBarrier);
5413 CodeGeneratorARM::PcRelativePatchInfo* labels =
5414 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
5415 __ BindTrackedLabel(&labels->movw_label);
5416 __ movw(out, /* placeholder */ 0u);
5417 __ BindTrackedLabel(&labels->movt_label);
5418 __ movt(out, /* placeholder */ 0u);
5419 __ BindTrackedLabel(&labels->add_pc_label);
5420 __ add(out, out, ShifterOperand(PC));
5421 break;
5422 }
5423 case HLoadClass::LoadKind::kBootImageAddress: {
5424 DCHECK(!kEmitCompilerReadBarrier);
5425 DCHECK_NE(cls->GetAddress(), 0u);
5426 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5427 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5428 break;
5429 }
5430 case HLoadClass::LoadKind::kDexCacheAddress: {
5431 DCHECK_NE(cls->GetAddress(), 0u);
5432 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
5433 // 16-bit LDR immediate has a 5-bit offset multiplied by the size and that gives
5434 // a 128B range. To try and reduce the number of literals if we load multiple types,
5435 // simply split the dex cache address to a 128B aligned base loaded from a literal
5436 // and the remaining offset embedded in the load.
5437 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
5438 DCHECK_ALIGNED(cls->GetAddress(), 4u);
5439 constexpr size_t offset_bits = /* encoded bits */ 5 + /* scale */ 2;
5440 uint32_t base_address = address & ~MaxInt<uint32_t>(offset_bits);
5441 uint32_t offset = address & MaxInt<uint32_t>(offset_bits);
5442 __ LoadLiteral(out, codegen_->DeduplicateDexCacheAddressLiteral(base_address));
5443 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
5444 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5445 generate_null_check = !cls->IsInDexCache();
5446 break;
5447 }
5448 case HLoadClass::LoadKind::kDexCachePcRelative: {
5449 Register base_reg = locations->InAt(0).AsRegister<Register>();
5450 HArmDexCacheArraysBase* base = cls->InputAt(0)->AsArmDexCacheArraysBase();
5451 int32_t offset = cls->GetDexCacheElementOffset() - base->GetElementOffset();
5452 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
5453 GenerateGcRootFieldLoad(cls, out_loc, base_reg, offset);
5454 generate_null_check = !cls->IsInDexCache();
5455 break;
5456 }
5457 case HLoadClass::LoadKind::kDexCacheViaMethod: {
5458 // /* GcRoot<mirror::Class>[] */ out =
5459 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
5460 Register current_method = locations->InAt(0).AsRegister<Register>();
5461 __ LoadFromOffset(kLoadWord,
5462 out,
5463 current_method,
5464 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
5465 // /* GcRoot<mirror::Class> */ out = out[type_index]
5466 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
5467 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
5468 generate_null_check = !cls->IsInDexCache();
5469 }
5470 }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005471
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01005472 if (generate_null_check || cls->MustGenerateClinitCheck()) {
5473 DCHECK(cls->CanCallRuntime());
5474 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
5475 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
5476 codegen_->AddSlowPath(slow_path);
5477 if (generate_null_check) {
5478 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
5479 }
5480 if (cls->MustGenerateClinitCheck()) {
5481 GenerateClassInitializationCheck(slow_path, out);
5482 } else {
5483 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005484 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005485 }
5486}
5487
5488void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
5489 LocationSummary* locations =
5490 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
5491 locations->SetInAt(0, Location::RequiresRegister());
5492 if (check->HasUses()) {
5493 locations->SetOut(Location::SameAsFirstInput());
5494 }
5495}
5496
5497void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005498 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07005499 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005500 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005501 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00005502 GenerateClassInitializationCheck(slow_path,
5503 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005504}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005505
Nicolas Geoffray424f6762014-11-03 14:51:25 +00005506void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07005507 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01005508 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
5509 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
5510 __ b(slow_path->GetEntryLabel(), LT);
5511 // Even if the initialized flag is set, we may be in a situation where caches are not synced
5512 // properly. Therefore, we do a memory fence.
5513 __ dmb(ISH);
5514 __ Bind(slow_path->GetExitLabel());
5515}
5516
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005517HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind(
5518 HLoadString::LoadKind desired_string_load_kind) {
5519 if (kEmitCompilerReadBarrier) {
5520 switch (desired_string_load_kind) {
5521 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5522 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5523 case HLoadString::LoadKind::kBootImageAddress:
5524 // TODO: Implement for read barrier.
5525 return HLoadString::LoadKind::kDexCacheViaMethod;
5526 default:
5527 break;
5528 }
5529 }
5530 switch (desired_string_load_kind) {
5531 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
5532 DCHECK(!GetCompilerOptions().GetCompilePic());
5533 break;
5534 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
5535 DCHECK(GetCompilerOptions().GetCompilePic());
5536 break;
5537 case HLoadString::LoadKind::kBootImageAddress:
5538 break;
5539 case HLoadString::LoadKind::kDexCacheAddress:
Calin Juravleffc87072016-04-20 14:22:09 +01005540 DCHECK(Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005541 break;
5542 case HLoadString::LoadKind::kDexCachePcRelative:
Calin Juravleffc87072016-04-20 14:22:09 +01005543 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005544 // We disable pc-relative load when there is an irreducible loop, as the optimization
5545 // is incompatible with it.
5546 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
5547 // with irreducible loops.
5548 if (GetGraph()->HasIrreducibleLoops()) {
5549 return HLoadString::LoadKind::kDexCacheViaMethod;
5550 }
5551 break;
5552 case HLoadString::LoadKind::kDexCacheViaMethod:
5553 break;
5554 }
5555 return desired_string_load_kind;
5556}
5557
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005558void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005559 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00005560 ? LocationSummary::kCallOnSlowPath
5561 : LocationSummary::kNoCall;
5562 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Marko70e97462016-08-09 11:04:26 +01005563 if (kUseBakerReadBarrier && !load->NeedsEnvironment()) {
5564 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
5565 }
5566
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005567 HLoadString::LoadKind load_kind = load->GetLoadKind();
5568 if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod ||
5569 load_kind == HLoadString::LoadKind::kDexCachePcRelative) {
5570 locations->SetInAt(0, Location::RequiresRegister());
5571 }
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005572 locations->SetOut(Location::RequiresRegister());
5573}
5574
5575void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01005576 LocationSummary* locations = load->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005577 Location out_loc = locations->Out();
5578 Register out = out_loc.AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005579
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005580 switch (load->GetLoadKind()) {
5581 case HLoadString::LoadKind::kBootImageLinkTimeAddress: {
5582 DCHECK(!kEmitCompilerReadBarrier);
5583 __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
5584 load->GetStringIndex()));
5585 return; // No dex cache slow path.
5586 }
5587 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
5588 DCHECK(!kEmitCompilerReadBarrier);
5589 CodeGeneratorARM::PcRelativePatchInfo* labels =
5590 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
5591 __ BindTrackedLabel(&labels->movw_label);
5592 __ movw(out, /* placeholder */ 0u);
5593 __ BindTrackedLabel(&labels->movt_label);
5594 __ movt(out, /* placeholder */ 0u);
5595 __ BindTrackedLabel(&labels->add_pc_label);
5596 __ add(out, out, ShifterOperand(PC));
5597 return; // No dex cache slow path.
5598 }
5599 case HLoadString::LoadKind::kBootImageAddress: {
5600 DCHECK(!kEmitCompilerReadBarrier);
5601 DCHECK_NE(load->GetAddress(), 0u);
5602 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
5603 __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address));
5604 return; // No dex cache slow path.
5605 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005606 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005607 break;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005608 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005609
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07005610 // TODO: Re-add the compiler code to do string dex cache lookup again.
5611 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
5612 codegen_->AddSlowPath(slow_path);
5613 __ b(slow_path->GetEntryLabel());
5614 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00005615}
5616
David Brazdilcb1c0552015-08-04 16:22:25 +01005617static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07005618 return Thread::ExceptionOffset<kArmPointerSize>().Int32Value();
David Brazdilcb1c0552015-08-04 16:22:25 +01005619}
5620
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005621void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
5622 LocationSummary* locations =
5623 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
5624 locations->SetOut(Location::RequiresRegister());
5625}
5626
5627void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00005628 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01005629 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
5630}
5631
5632void LocationsBuilderARM::VisitClearException(HClearException* clear) {
5633 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
5634}
5635
5636void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005637 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01005638 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005639}
5640
5641void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
5642 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005643 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005644 InvokeRuntimeCallingConvention calling_convention;
5645 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5646}
5647
5648void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
5649 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00005650 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00005651 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00005652}
5653
Roland Levillainc9285912015-12-18 10:38:42 +00005654static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) {
5655 return kEmitCompilerReadBarrier &&
5656 (kUseBakerReadBarrier ||
5657 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5658 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5659 type_check_kind == TypeCheckKind::kArrayObjectCheck);
5660}
5661
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005662void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005663 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain3b359c72015-11-17 19:35:12 +00005664 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Vladimir Marko70e97462016-08-09 11:04:26 +01005665 bool baker_read_barrier_slow_path = false;
Roland Levillain3b359c72015-11-17 19:35:12 +00005666 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005667 case TypeCheckKind::kExactCheck:
5668 case TypeCheckKind::kAbstractClassCheck:
5669 case TypeCheckKind::kClassHierarchyCheck:
5670 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005671 call_kind =
5672 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Vladimir Marko70e97462016-08-09 11:04:26 +01005673 baker_read_barrier_slow_path = kUseBakerReadBarrier;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005674 break;
5675 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005676 case TypeCheckKind::kUnresolvedCheck:
5677 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005678 call_kind = LocationSummary::kCallOnSlowPath;
5679 break;
5680 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005681
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005682 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Vladimir Marko70e97462016-08-09 11:04:26 +01005683 if (baker_read_barrier_slow_path) {
5684 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
5685 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005686 locations->SetInAt(0, Location::RequiresRegister());
5687 locations->SetInAt(1, Location::RequiresRegister());
5688 // The "out" register is used as a temporary, so it overlaps with the inputs.
5689 // Note that TypeCheckSlowPathARM uses this register too.
5690 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
5691 // When read barriers are enabled, we need a temporary register for
5692 // some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005693 if (TypeCheckNeedsATemporary(type_check_kind)) {
Roland Levillain3b359c72015-11-17 19:35:12 +00005694 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005695 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005696}
5697
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005698void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005699 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005700 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005701 Location obj_loc = locations->InAt(0);
5702 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005703 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005704 Location out_loc = locations->Out();
5705 Register out = out_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005706 Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005707 locations->GetTemp(0) :
5708 Location::NoLocation();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005709 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005710 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5711 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5712 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00005713 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07005714 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005715
5716 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005717 // avoid null check if we know obj is not null.
5718 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00005719 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005720 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005721
Roland Levillain3b359c72015-11-17 19:35:12 +00005722 // /* HeapReference<Class> */ out = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005723 GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005724
Roland Levillainc9285912015-12-18 10:38:42 +00005725 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005726 case TypeCheckKind::kExactCheck: {
5727 __ cmp(out, ShifterOperand(cls));
5728 // Classes must be equal for the instanceof to succeed.
5729 __ b(&zero, NE);
5730 __ LoadImmediate(out, 1);
5731 __ b(&done);
5732 break;
5733 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005734
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005735 case TypeCheckKind::kAbstractClassCheck: {
5736 // If the class is abstract, we eagerly fetch the super class of the
5737 // object to avoid doing a comparison we know will fail.
5738 Label loop;
5739 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005740 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005741 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005742 // If `out` is null, we use it for the result, and jump to `done`.
5743 __ CompareAndBranchIfZero(out, &done);
5744 __ cmp(out, ShifterOperand(cls));
5745 __ b(&loop, NE);
5746 __ LoadImmediate(out, 1);
5747 if (zero.IsLinked()) {
5748 __ b(&done);
5749 }
5750 break;
5751 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005752
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005753 case TypeCheckKind::kClassHierarchyCheck: {
5754 // Walk over the class hierarchy to find a match.
5755 Label loop, success;
5756 __ Bind(&loop);
5757 __ cmp(out, ShifterOperand(cls));
5758 __ b(&success, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005759 // /* HeapReference<Class> */ out = out->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005760 GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005761 __ CompareAndBranchIfNonZero(out, &loop);
5762 // If `out` is null, we use it for the result, and jump to `done`.
5763 __ b(&done);
5764 __ Bind(&success);
5765 __ LoadImmediate(out, 1);
5766 if (zero.IsLinked()) {
5767 __ b(&done);
5768 }
5769 break;
5770 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005771
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005772 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005773 // Do an exact check.
5774 Label exact_check;
5775 __ cmp(out, ShifterOperand(cls));
5776 __ b(&exact_check, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005777 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005778 // /* HeapReference<Class> */ out = out->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005779 GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005780 // If `out` is null, we use it for the result, and jump to `done`.
5781 __ CompareAndBranchIfZero(out, &done);
5782 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
5783 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
5784 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005785 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005786 __ LoadImmediate(out, 1);
5787 __ b(&done);
5788 break;
5789 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005790
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005791 case TypeCheckKind::kArrayCheck: {
5792 __ cmp(out, ShifterOperand(cls));
5793 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain3b359c72015-11-17 19:35:12 +00005794 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5795 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005796 codegen_->AddSlowPath(slow_path);
5797 __ b(slow_path->GetEntryLabel(), NE);
5798 __ LoadImmediate(out, 1);
5799 if (zero.IsLinked()) {
5800 __ b(&done);
5801 }
5802 break;
5803 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005804
Calin Juravle98893e12015-10-02 21:05:03 +01005805 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005806 case TypeCheckKind::kInterfaceCheck: {
5807 // Note that we indeed only call on slow path, but we always go
Roland Levillaine3f43ac2016-01-19 15:07:47 +00005808 // into the slow path for the unresolved and interface check
Roland Levillain3b359c72015-11-17 19:35:12 +00005809 // cases.
5810 //
5811 // We cannot directly call the InstanceofNonTrivial runtime
5812 // entry point without resorting to a type checking slow path
5813 // here (i.e. by calling InvokeRuntime directly), as it would
5814 // require to assign fixed registers for the inputs of this
5815 // HInstanceOf instruction (following the runtime calling
5816 // convention), which might be cluttered by the potential first
5817 // read barrier emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00005818 //
5819 // TODO: Introduce a new runtime entry point taking the object
5820 // to test (instead of its class) as argument, and let it deal
5821 // with the read barrier issues. This will let us refactor this
5822 // case of the `switch` code as it was previously (with a direct
5823 // call to the runtime not using a type checking slow path).
5824 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00005825 DCHECK(locations->OnlyCallsOnSlowPath());
5826 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5827 /* is_fatal */ false);
5828 codegen_->AddSlowPath(slow_path);
5829 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005830 if (zero.IsLinked()) {
5831 __ b(&done);
5832 }
5833 break;
5834 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005835 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005836
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005837 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01005838 __ Bind(&zero);
5839 __ LoadImmediate(out, 0);
5840 }
5841
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005842 if (done.IsLinked()) {
5843 __ Bind(&done);
5844 }
5845
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005846 if (slow_path != nullptr) {
5847 __ Bind(slow_path->GetExitLabel());
5848 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00005849}
5850
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005851void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005852 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
5853 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
5854
Roland Levillain3b359c72015-11-17 19:35:12 +00005855 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Vladimir Marko70e97462016-08-09 11:04:26 +01005856 bool baker_read_barrier_slow_path = false;
Roland Levillain3b359c72015-11-17 19:35:12 +00005857 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005858 case TypeCheckKind::kExactCheck:
5859 case TypeCheckKind::kAbstractClassCheck:
5860 case TypeCheckKind::kClassHierarchyCheck:
5861 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005862 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
5863 LocationSummary::kCallOnSlowPath :
5864 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Vladimir Marko70e97462016-08-09 11:04:26 +01005865 baker_read_barrier_slow_path = kUseBakerReadBarrier && !throws_into_catch;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005866 break;
5867 case TypeCheckKind::kArrayCheck:
Roland Levillain3b359c72015-11-17 19:35:12 +00005868 case TypeCheckKind::kUnresolvedCheck:
5869 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005870 call_kind = LocationSummary::kCallOnSlowPath;
5871 break;
5872 }
5873
Roland Levillain3b359c72015-11-17 19:35:12 +00005874 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Vladimir Marko70e97462016-08-09 11:04:26 +01005875 if (baker_read_barrier_slow_path) {
5876 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
5877 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005878 locations->SetInAt(0, Location::RequiresRegister());
5879 locations->SetInAt(1, Location::RequiresRegister());
5880 // Note that TypeCheckSlowPathARM uses this "temp" register too.
5881 locations->AddTemp(Location::RequiresRegister());
5882 // When read barriers are enabled, we need an additional temporary
5883 // register for some cases.
Roland Levillainc9285912015-12-18 10:38:42 +00005884 if (TypeCheckNeedsATemporary(type_check_kind)) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005885 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005886 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005887}
5888
5889void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
Roland Levillainc9285912015-12-18 10:38:42 +00005890 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005891 LocationSummary* locations = instruction->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +00005892 Location obj_loc = locations->InAt(0);
5893 Register obj = obj_loc.AsRegister<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00005894 Register cls = locations->InAt(1).AsRegister<Register>();
Roland Levillain3b359c72015-11-17 19:35:12 +00005895 Location temp_loc = locations->GetTemp(0);
5896 Register temp = temp_loc.AsRegister<Register>();
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005897 Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ?
Roland Levillainc9285912015-12-18 10:38:42 +00005898 locations->GetTemp(1) :
5899 Location::NoLocation();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005900 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005901 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
5902 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
5903 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00005904
Roland Levillain3b359c72015-11-17 19:35:12 +00005905 bool is_type_check_slow_path_fatal =
5906 (type_check_kind == TypeCheckKind::kExactCheck ||
5907 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
5908 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
5909 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
5910 !instruction->CanThrowIntoCatchBlock();
5911 SlowPathCode* type_check_slow_path =
5912 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction,
5913 is_type_check_slow_path_fatal);
5914 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005915
5916 Label done;
5917 // Avoid null check if we know obj is not null.
5918 if (instruction->MustDoNullCheck()) {
5919 __ CompareAndBranchIfZero(obj, &done);
5920 }
5921
Roland Levillain3b359c72015-11-17 19:35:12 +00005922 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005923 GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005924
Roland Levillain3b359c72015-11-17 19:35:12 +00005925 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005926 case TypeCheckKind::kExactCheck:
5927 case TypeCheckKind::kArrayCheck: {
5928 __ cmp(temp, ShifterOperand(cls));
5929 // Jump to slow path for throwing the exception or doing a
5930 // more involved array check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005931 __ b(type_check_slow_path->GetEntryLabel(), NE);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005932 break;
5933 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005934
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005935 case TypeCheckKind::kAbstractClassCheck: {
5936 // If the class is abstract, we eagerly fetch the super class of the
5937 // object to avoid doing a comparison we know will fail.
Roland Levillain3b359c72015-11-17 19:35:12 +00005938 Label loop, compare_classes;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005939 __ Bind(&loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005940 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005941 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005942
5943 // If the class reference currently in `temp` is not null, jump
5944 // to the `compare_classes` label to compare it with the checked
5945 // class.
5946 __ CompareAndBranchIfNonZero(temp, &compare_classes);
5947 // Otherwise, jump to the slow path to throw the exception.
5948 //
5949 // But before, move back the object's class into `temp` before
5950 // going into the slow path, as it has been overwritten in the
5951 // meantime.
5952 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005953 GenerateReferenceLoadTwoRegisters(
5954 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005955 __ b(type_check_slow_path->GetEntryLabel());
5956
5957 __ Bind(&compare_classes);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005958 __ cmp(temp, ShifterOperand(cls));
5959 __ b(&loop, NE);
5960 break;
5961 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005962
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005963 case TypeCheckKind::kClassHierarchyCheck: {
5964 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005965 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005966 __ Bind(&loop);
5967 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005968 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005969
Roland Levillain3b359c72015-11-17 19:35:12 +00005970 // /* HeapReference<Class> */ temp = temp->super_class_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005971 GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005972
5973 // If the class reference currently in `temp` is not null, jump
5974 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005975 __ CompareAndBranchIfNonZero(temp, &loop);
Roland Levillain3b359c72015-11-17 19:35:12 +00005976 // Otherwise, jump to the slow path to throw the exception.
5977 //
5978 // But before, move back the object's class into `temp` before
5979 // going into the slow path, as it has been overwritten in the
5980 // meantime.
5981 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005982 GenerateReferenceLoadTwoRegisters(
5983 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005984 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005985 break;
5986 }
Roland Levillain3b359c72015-11-17 19:35:12 +00005987
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00005988 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005989 // Do an exact check.
Roland Levillain3b359c72015-11-17 19:35:12 +00005990 Label check_non_primitive_component_type;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01005991 __ cmp(temp, ShifterOperand(cls));
5992 __ b(&done, EQ);
Roland Levillain3b359c72015-11-17 19:35:12 +00005993
5994 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain3b359c72015-11-17 19:35:12 +00005995 // /* HeapReference<Class> */ temp = temp->component_type_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00005996 GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00005997
5998 // If the component type is not null (i.e. the object is indeed
5999 // an array), jump to label `check_non_primitive_component_type`
6000 // to further check that this component type is not a primitive
6001 // type.
6002 __ CompareAndBranchIfNonZero(temp, &check_non_primitive_component_type);
6003 // Otherwise, jump to the slow path to throw the exception.
6004 //
6005 // But before, move back the object's class into `temp` before
6006 // going into the slow path, as it has been overwritten in the
6007 // meantime.
6008 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006009 GenerateReferenceLoadTwoRegisters(
6010 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006011 __ b(type_check_slow_path->GetEntryLabel());
6012
6013 __ Bind(&check_non_primitive_component_type);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006014 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
Roland Levillain3b359c72015-11-17 19:35:12 +00006015 static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot");
6016 __ CompareAndBranchIfZero(temp, &done);
6017 // Same comment as above regarding `temp` and the slow path.
6018 // /* HeapReference<Class> */ temp = obj->klass_
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006019 GenerateReferenceLoadTwoRegisters(
6020 instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc);
Roland Levillain3b359c72015-11-17 19:35:12 +00006021 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006022 break;
6023 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006024
Calin Juravle98893e12015-10-02 21:05:03 +01006025 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006026 case TypeCheckKind::kInterfaceCheck:
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006027 // We always go into the type check slow path for the unresolved
6028 // and interface check cases.
Roland Levillain3b359c72015-11-17 19:35:12 +00006029 //
6030 // We cannot directly call the CheckCast runtime entry point
6031 // without resorting to a type checking slow path here (i.e. by
6032 // calling InvokeRuntime directly), as it would require to
6033 // assign fixed registers for the inputs of this HInstanceOf
6034 // instruction (following the runtime calling convention), which
6035 // might be cluttered by the potential first read barrier
6036 // emission at the beginning of this method.
Roland Levillainc9285912015-12-18 10:38:42 +00006037 //
6038 // TODO: Introduce a new runtime entry point taking the object
6039 // to test (instead of its class) as argument, and let it deal
6040 // with the read barrier issues. This will let us refactor this
6041 // case of the `switch` code as it was previously (with a direct
6042 // call to the runtime not using a type checking slow path).
6043 // This should also be beneficial for the other cases above.
Roland Levillain3b359c72015-11-17 19:35:12 +00006044 __ b(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00006045 break;
6046 }
6047 __ Bind(&done);
6048
Roland Levillain3b359c72015-11-17 19:35:12 +00006049 __ Bind(type_check_slow_path->GetExitLabel());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00006050}
6051
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006052void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6053 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01006054 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006055 InvokeRuntimeCallingConvention calling_convention;
6056 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
6057}
6058
6059void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
6060 codegen_->InvokeRuntime(instruction->IsEnter()
6061 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
6062 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00006063 instruction->GetDexPc(),
6064 nullptr);
Roland Levillain888d0672015-11-23 18:53:50 +00006065 if (instruction->IsEnter()) {
6066 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
6067 } else {
6068 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
6069 }
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00006070}
6071
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006072void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
6073void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
6074void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006075
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006076void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006077 LocationSummary* locations =
6078 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6079 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6080 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006081 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006082 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006083 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00006084 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006085}
6086
6087void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
6088 HandleBitwiseOperation(instruction);
6089}
6090
6091void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
6092 HandleBitwiseOperation(instruction);
6093}
6094
6095void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
6096 HandleBitwiseOperation(instruction);
6097}
6098
Artem Serov7fc63502016-02-09 17:15:29 +00006099
6100void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6101 LocationSummary* locations =
6102 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6103 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
6104 || instruction->GetResultType() == Primitive::kPrimLong);
6105
6106 locations->SetInAt(0, Location::RequiresRegister());
6107 locations->SetInAt(1, Location::RequiresRegister());
6108 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
6109}
6110
6111void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) {
6112 LocationSummary* locations = instruction->GetLocations();
6113 Location first = locations->InAt(0);
6114 Location second = locations->InAt(1);
6115 Location out = locations->Out();
6116
6117 if (instruction->GetResultType() == Primitive::kPrimInt) {
6118 Register first_reg = first.AsRegister<Register>();
6119 ShifterOperand second_reg(second.AsRegister<Register>());
6120 Register out_reg = out.AsRegister<Register>();
6121
6122 switch (instruction->GetOpKind()) {
6123 case HInstruction::kAnd:
6124 __ bic(out_reg, first_reg, second_reg);
6125 break;
6126 case HInstruction::kOr:
6127 __ orn(out_reg, first_reg, second_reg);
6128 break;
6129 // There is no EON on arm.
6130 case HInstruction::kXor:
6131 default:
6132 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6133 UNREACHABLE();
6134 }
6135 return;
6136
6137 } else {
6138 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6139 Register first_low = first.AsRegisterPairLow<Register>();
6140 Register first_high = first.AsRegisterPairHigh<Register>();
6141 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6142 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6143 Register out_low = out.AsRegisterPairLow<Register>();
6144 Register out_high = out.AsRegisterPairHigh<Register>();
6145
6146 switch (instruction->GetOpKind()) {
6147 case HInstruction::kAnd:
6148 __ bic(out_low, first_low, second_low);
6149 __ bic(out_high, first_high, second_high);
6150 break;
6151 case HInstruction::kOr:
6152 __ orn(out_low, first_low, second_low);
6153 __ orn(out_high, first_high, second_high);
6154 break;
6155 // There is no EON on arm.
6156 case HInstruction::kXor:
6157 default:
6158 LOG(FATAL) << "Unexpected instruction " << instruction->DebugName();
6159 UNREACHABLE();
6160 }
6161 }
6162}
6163
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006164void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
6165 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
6166 if (value == 0xffffffffu) {
6167 if (out != first) {
6168 __ mov(out, ShifterOperand(first));
6169 }
6170 return;
6171 }
6172 if (value == 0u) {
6173 __ mov(out, ShifterOperand(0));
6174 return;
6175 }
6176 ShifterOperand so;
6177 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
6178 __ and_(out, first, so);
6179 } else {
6180 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
6181 __ bic(out, first, ShifterOperand(~value));
6182 }
6183}
6184
6185void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
6186 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
6187 if (value == 0u) {
6188 if (out != first) {
6189 __ mov(out, ShifterOperand(first));
6190 }
6191 return;
6192 }
6193 if (value == 0xffffffffu) {
6194 __ mvn(out, ShifterOperand(0));
6195 return;
6196 }
6197 ShifterOperand so;
6198 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
6199 __ orr(out, first, so);
6200 } else {
6201 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
6202 __ orn(out, first, ShifterOperand(~value));
6203 }
6204}
6205
6206void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
6207 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
6208 if (value == 0u) {
6209 if (out != first) {
6210 __ mov(out, ShifterOperand(first));
6211 }
6212 return;
6213 }
6214 __ eor(out, first, ShifterOperand(value));
6215}
6216
Vladimir Marko59751a72016-08-05 14:37:27 +01006217void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out,
6218 Location first,
6219 uint64_t value) {
6220 Register out_low = out.AsRegisterPairLow<Register>();
6221 Register out_high = out.AsRegisterPairHigh<Register>();
6222 Register first_low = first.AsRegisterPairLow<Register>();
6223 Register first_high = first.AsRegisterPairHigh<Register>();
6224 uint32_t value_low = Low32Bits(value);
6225 uint32_t value_high = High32Bits(value);
6226 if (value_low == 0u) {
6227 if (out_low != first_low) {
6228 __ mov(out_low, ShifterOperand(first_low));
6229 }
6230 __ AddConstant(out_high, first_high, value_high);
6231 return;
6232 }
6233 __ AddConstantSetFlags(out_low, first_low, value_low);
6234 ShifterOperand so;
6235 if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) {
6236 __ adc(out_high, first_high, so);
6237 } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) {
6238 __ sbc(out_high, first_high, so);
6239 } else {
6240 LOG(FATAL) << "Unexpected constant " << value_high;
6241 UNREACHABLE();
6242 }
6243}
6244
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006245void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
6246 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006247 Location first = locations->InAt(0);
6248 Location second = locations->InAt(1);
6249 Location out = locations->Out();
6250
6251 if (second.IsConstant()) {
6252 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
6253 uint32_t value_low = Low32Bits(value);
6254 if (instruction->GetResultType() == Primitive::kPrimInt) {
6255 Register first_reg = first.AsRegister<Register>();
6256 Register out_reg = out.AsRegister<Register>();
6257 if (instruction->IsAnd()) {
6258 GenerateAndConst(out_reg, first_reg, value_low);
6259 } else if (instruction->IsOr()) {
6260 GenerateOrrConst(out_reg, first_reg, value_low);
6261 } else {
6262 DCHECK(instruction->IsXor());
6263 GenerateEorConst(out_reg, first_reg, value_low);
6264 }
6265 } else {
6266 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
6267 uint32_t value_high = High32Bits(value);
6268 Register first_low = first.AsRegisterPairLow<Register>();
6269 Register first_high = first.AsRegisterPairHigh<Register>();
6270 Register out_low = out.AsRegisterPairLow<Register>();
6271 Register out_high = out.AsRegisterPairHigh<Register>();
6272 if (instruction->IsAnd()) {
6273 GenerateAndConst(out_low, first_low, value_low);
6274 GenerateAndConst(out_high, first_high, value_high);
6275 } else if (instruction->IsOr()) {
6276 GenerateOrrConst(out_low, first_low, value_low);
6277 GenerateOrrConst(out_high, first_high, value_high);
6278 } else {
6279 DCHECK(instruction->IsXor());
6280 GenerateEorConst(out_low, first_low, value_low);
6281 GenerateEorConst(out_high, first_high, value_high);
6282 }
6283 }
6284 return;
6285 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006286
6287 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006288 Register first_reg = first.AsRegister<Register>();
6289 ShifterOperand second_reg(second.AsRegister<Register>());
6290 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006291 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006292 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006293 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006294 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006295 } else {
6296 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006297 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006298 }
6299 } else {
6300 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006301 Register first_low = first.AsRegisterPairLow<Register>();
6302 Register first_high = first.AsRegisterPairHigh<Register>();
6303 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
6304 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
6305 Register out_low = out.AsRegisterPairLow<Register>();
6306 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006307 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006308 __ and_(out_low, first_low, second_low);
6309 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006310 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006311 __ orr(out_low, first_low, second_low);
6312 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006313 } else {
6314 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01006315 __ eor(out_low, first_low, second_low);
6316 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00006317 }
6318 }
6319}
6320
Roland Levillainc9285912015-12-18 10:38:42 +00006321void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister(HInstruction* instruction,
6322 Location out,
6323 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006324 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006325 Register out_reg = out.AsRegister<Register>();
6326 if (kEmitCompilerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006327 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006328 if (kUseBakerReadBarrier) {
6329 // Load with fast path based Baker's read barrier.
6330 // /* HeapReference<Object> */ out = *(out + offset)
6331 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006332 instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006333 } else {
6334 // Load with slow path based read barrier.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006335 // Save the value of `out` into `maybe_temp` before overwriting it
Roland Levillainc9285912015-12-18 10:38:42 +00006336 // in the following move operation, as we will need it for the
6337 // read barrier below.
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006338 __ Mov(maybe_temp.AsRegister<Register>(), out_reg);
Roland Levillainc9285912015-12-18 10:38:42 +00006339 // /* HeapReference<Object> */ out = *(out + offset)
6340 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006341 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
Roland Levillainc9285912015-12-18 10:38:42 +00006342 }
6343 } else {
6344 // Plain load with no read barrier.
6345 // /* HeapReference<Object> */ out = *(out + offset)
6346 __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset);
6347 __ MaybeUnpoisonHeapReference(out_reg);
6348 }
6349}
6350
6351void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
6352 Location out,
6353 Location obj,
6354 uint32_t offset,
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006355 Location maybe_temp) {
Roland Levillainc9285912015-12-18 10:38:42 +00006356 Register out_reg = out.AsRegister<Register>();
6357 Register obj_reg = obj.AsRegister<Register>();
6358 if (kEmitCompilerReadBarrier) {
6359 if (kUseBakerReadBarrier) {
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006360 DCHECK(maybe_temp.IsRegister()) << maybe_temp;
Roland Levillainc9285912015-12-18 10:38:42 +00006361 // Load with fast path based Baker's read barrier.
6362 // /* HeapReference<Object> */ out = *(obj + offset)
6363 codegen_->GenerateFieldLoadWithBakerReadBarrier(
Roland Levillain95e7ffc2016-01-22 11:57:25 +00006364 instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +00006365 } else {
6366 // Load with slow path based read barrier.
6367 // /* HeapReference<Object> */ out = *(obj + offset)
6368 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6369 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
6370 }
6371 } else {
6372 // Plain load with no read barrier.
6373 // /* HeapReference<Object> */ out = *(obj + offset)
6374 __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset);
6375 __ MaybeUnpoisonHeapReference(out_reg);
6376 }
6377}
6378
6379void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction,
6380 Location root,
6381 Register obj,
6382 uint32_t offset) {
6383 Register root_reg = root.AsRegister<Register>();
6384 if (kEmitCompilerReadBarrier) {
6385 if (kUseBakerReadBarrier) {
6386 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
6387 // Baker's read barrier are used:
6388 //
6389 // root = obj.field;
6390 // if (Thread::Current()->GetIsGcMarking()) {
6391 // root = ReadBarrier::Mark(root)
6392 // }
6393
6394 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6395 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6396 static_assert(
6397 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
6398 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
6399 "have different sizes.");
6400 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
6401 "art::mirror::CompressedReference<mirror::Object> and int32_t "
6402 "have different sizes.");
6403
Vladimir Marko953437b2016-08-24 08:30:46 +00006404 // Slow path marking the GC root `root`.
Roland Levillainc9285912015-12-18 10:38:42 +00006405 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006406 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, root);
Roland Levillainc9285912015-12-18 10:38:42 +00006407 codegen_->AddSlowPath(slow_path);
6408
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006409 // IP = Thread::Current()->GetIsGcMarking()
Roland Levillainc9285912015-12-18 10:38:42 +00006410 __ LoadFromOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006411 kLoadWord, IP, TR, Thread::IsGcMarkingOffset<kArmPointerSize>().Int32Value());
Roland Levillainc9285912015-12-18 10:38:42 +00006412 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
6413 __ Bind(slow_path->GetExitLabel());
6414 } else {
6415 // GC root loaded through a slow path for read barriers other
6416 // than Baker's.
6417 // /* GcRoot<mirror::Object>* */ root = obj + offset
6418 __ AddConstant(root_reg, obj, offset);
6419 // /* mirror::Object* */ root = root->Read()
6420 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
6421 }
6422 } else {
6423 // Plain GC root load with no read barrier.
6424 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
6425 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
6426 // Note that GC roots are not affected by heap poisoning, thus we
6427 // do not have to unpoison `root_reg` here.
6428 }
6429}
6430
6431void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
6432 Location ref,
6433 Register obj,
6434 uint32_t offset,
6435 Location temp,
6436 bool needs_null_check) {
6437 DCHECK(kEmitCompilerReadBarrier);
6438 DCHECK(kUseBakerReadBarrier);
6439
6440 // /* HeapReference<Object> */ ref = *(obj + offset)
6441 Location no_index = Location::NoLocation();
Roland Levillainbfea3352016-06-23 13:48:47 +01006442 ScaleFactor no_scale_factor = TIMES_1;
Roland Levillainc9285912015-12-18 10:38:42 +00006443 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006444 instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006445}
6446
6447void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
6448 Location ref,
6449 Register obj,
6450 uint32_t data_offset,
6451 Location index,
6452 Location temp,
6453 bool needs_null_check) {
6454 DCHECK(kEmitCompilerReadBarrier);
6455 DCHECK(kUseBakerReadBarrier);
6456
Roland Levillainbfea3352016-06-23 13:48:47 +01006457 static_assert(
6458 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
6459 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006460 // /* HeapReference<Object> */ ref =
6461 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01006462 ScaleFactor scale_factor = TIMES_4;
Roland Levillainc9285912015-12-18 10:38:42 +00006463 GenerateReferenceLoadWithBakerReadBarrier(
Roland Levillainbfea3352016-06-23 13:48:47 +01006464 instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check);
Roland Levillainc9285912015-12-18 10:38:42 +00006465}
6466
6467void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
6468 Location ref,
6469 Register obj,
6470 uint32_t offset,
6471 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01006472 ScaleFactor scale_factor,
Roland Levillainc9285912015-12-18 10:38:42 +00006473 Location temp,
6474 bool needs_null_check) {
6475 DCHECK(kEmitCompilerReadBarrier);
6476 DCHECK(kUseBakerReadBarrier);
6477
6478 // In slow path based read barriers, the read barrier call is
6479 // inserted after the original load. However, in fast path based
6480 // Baker's read barriers, we need to perform the load of
6481 // mirror::Object::monitor_ *before* the original reference load.
6482 // This load-load ordering is required by the read barrier.
6483 // The fast path/slow path (for Baker's algorithm) should look like:
6484 //
6485 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
6486 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
6487 // HeapReference<Object> ref = *src; // Original reference load.
6488 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
6489 // if (is_gray) {
6490 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
6491 // }
6492 //
6493 // Note: the original implementation in ReadBarrier::Barrier is
Roland Levillaine3f43ac2016-01-19 15:07:47 +00006494 // slightly more complex as it performs additional checks that we do
6495 // not do here for performance reasons.
Roland Levillainc9285912015-12-18 10:38:42 +00006496
6497 Register ref_reg = ref.AsRegister<Register>();
6498 Register temp_reg = temp.AsRegister<Register>();
6499 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
6500
6501 // /* int32_t */ monitor = obj->monitor_
6502 __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset);
6503 if (needs_null_check) {
6504 MaybeRecordImplicitNullCheck(instruction);
6505 }
6506 // /* LockWord */ lock_word = LockWord(monitor)
6507 static_assert(sizeof(LockWord) == sizeof(int32_t),
6508 "art::LockWord and int32_t have different sizes.");
Roland Levillainc9285912015-12-18 10:38:42 +00006509
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006510 // Introduce a dependency on the lock_word including the rb_state,
6511 // which shall prevent load-load reordering without using
Roland Levillainc9285912015-12-18 10:38:42 +00006512 // a memory barrier (which would be more expensive).
Roland Levillain0b671c02016-08-19 12:02:34 +01006513 // `obj` is unchanged by this operation, but its value now depends
6514 // on `temp_reg`.
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006515 __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32));
Roland Levillainc9285912015-12-18 10:38:42 +00006516
6517 // The actual reference load.
6518 if (index.IsValid()) {
Roland Levillainbfea3352016-06-23 13:48:47 +01006519 // Load types involving an "index": ArrayGet and
6520 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
6521 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
Roland Levillainc9285912015-12-18 10:38:42 +00006522 if (index.IsConstant()) {
6523 size_t computed_offset =
Roland Levillainbfea3352016-06-23 13:48:47 +01006524 (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset;
Roland Levillainc9285912015-12-18 10:38:42 +00006525 __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset);
6526 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01006527 // Handle the special case of the
6528 // UnsafeGetObject/UnsafeGetObjectVolatile intrinsics, which use
6529 // a register pair as index ("long offset"), of which only the low
6530 // part contains data.
6531 Register index_reg = index.IsRegisterPair()
6532 ? index.AsRegisterPairLow<Register>()
6533 : index.AsRegister<Register>();
6534 __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor));
Roland Levillainc9285912015-12-18 10:38:42 +00006535 __ LoadFromOffset(kLoadWord, ref_reg, IP, offset);
6536 }
6537 } else {
6538 // /* HeapReference<Object> */ ref = *(obj + offset)
6539 __ LoadFromOffset(kLoadWord, ref_reg, obj, offset);
6540 }
6541
6542 // Object* ref = ref_addr->AsMirrorPtr()
6543 __ MaybeUnpoisonHeapReference(ref_reg);
6544
Vladimir Marko953437b2016-08-24 08:30:46 +00006545 // Slow path marking the object `ref` when it is gray.
Roland Levillainc9285912015-12-18 10:38:42 +00006546 SlowPathCode* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01006547 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref);
Roland Levillainc9285912015-12-18 10:38:42 +00006548 AddSlowPath(slow_path);
6549
6550 // if (rb_state == ReadBarrier::gray_ptr_)
6551 // ref = ReadBarrier::Mark(ref);
Vladimir Marko194bcfe2016-07-11 15:52:00 +01006552 // Given the numeric representation, it's enough to check the low bit of the
6553 // rb_state. We do that by shifting the bit out of the lock word with LSRS
6554 // which can be a 16-bit instruction unlike the TST immediate.
6555 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
6556 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
6557 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
6558 __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1);
6559 __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS.
Roland Levillainc9285912015-12-18 10:38:42 +00006560 __ Bind(slow_path->GetExitLabel());
6561}
6562
6563void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction,
6564 Location out,
6565 Location ref,
6566 Location obj,
6567 uint32_t offset,
6568 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006569 DCHECK(kEmitCompilerReadBarrier);
6570
Roland Levillainc9285912015-12-18 10:38:42 +00006571 // Insert a slow path based read barrier *after* the reference load.
6572 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006573 // If heap poisoning is enabled, the unpoisoning of the loaded
6574 // reference will be carried out by the runtime within the slow
6575 // path.
6576 //
6577 // Note that `ref` currently does not get unpoisoned (when heap
6578 // poisoning is enabled), which is alright as the `ref` argument is
6579 // not used by the artReadBarrierSlow entry point.
6580 //
6581 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
6582 SlowPathCode* slow_path = new (GetGraph()->GetArena())
6583 ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index);
6584 AddSlowPath(slow_path);
6585
Roland Levillain3b359c72015-11-17 19:35:12 +00006586 __ b(slow_path->GetEntryLabel());
6587 __ Bind(slow_path->GetExitLabel());
6588}
6589
Roland Levillainc9285912015-12-18 10:38:42 +00006590void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
6591 Location out,
6592 Location ref,
6593 Location obj,
6594 uint32_t offset,
6595 Location index) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006596 if (kEmitCompilerReadBarrier) {
Roland Levillainc9285912015-12-18 10:38:42 +00006597 // Baker's read barriers shall be handled by the fast path
6598 // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier).
6599 DCHECK(!kUseBakerReadBarrier);
Roland Levillain3b359c72015-11-17 19:35:12 +00006600 // If heap poisoning is enabled, unpoisoning will be taken care of
6601 // by the runtime within the slow path.
Roland Levillainc9285912015-12-18 10:38:42 +00006602 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain3b359c72015-11-17 19:35:12 +00006603 } else if (kPoisonHeapReferences) {
6604 __ UnpoisonHeapReference(out.AsRegister<Register>());
6605 }
6606}
6607
Roland Levillainc9285912015-12-18 10:38:42 +00006608void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction,
6609 Location out,
6610 Location root) {
Roland Levillain3b359c72015-11-17 19:35:12 +00006611 DCHECK(kEmitCompilerReadBarrier);
6612
Roland Levillainc9285912015-12-18 10:38:42 +00006613 // Insert a slow path based read barrier *after* the GC root load.
6614 //
Roland Levillain3b359c72015-11-17 19:35:12 +00006615 // Note that GC roots are not affected by heap poisoning, so we do
6616 // not need to do anything special for this here.
6617 SlowPathCode* slow_path =
6618 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root);
6619 AddSlowPath(slow_path);
6620
Roland Levillain3b359c72015-11-17 19:35:12 +00006621 __ b(slow_path->GetEntryLabel());
6622 __ Bind(slow_path->GetExitLabel());
6623}
6624
Vladimir Markodc151b22015-10-15 18:02:30 +01006625HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
6626 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
6627 MethodReference target_method) {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006628 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
6629 // We disable pc-relative load when there is an irreducible loop, as the optimization
6630 // is incompatible with it.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006631 // TODO: Create as many ArmDexCacheArraysBase instructions as needed for methods
6632 // with irreducible loops.
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006633 if (GetGraph()->HasIrreducibleLoops() &&
6634 (dispatch_info.method_load_kind ==
6635 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) {
6636 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
6637 }
6638
6639 if (dispatch_info.code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
Vladimir Markodc151b22015-10-15 18:02:30 +01006640 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
6641 if (&outer_dex_file != target_method.dex_file) {
6642 // Calls across dex files are more likely to exceed the available BL range,
6643 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
6644 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
6645 (desired_dispatch_info.method_load_kind ==
6646 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
6647 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
6648 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
6649 return HInvokeStaticOrDirect::DispatchInfo {
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006650 dispatch_info.method_load_kind,
Vladimir Markodc151b22015-10-15 18:02:30 +01006651 code_ptr_location,
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006652 dispatch_info.method_load_data,
Vladimir Markodc151b22015-10-15 18:02:30 +01006653 0u
6654 };
6655 }
6656 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +00006657 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01006658}
6659
Vladimir Markob4536b72015-11-24 13:45:23 +00006660Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
6661 Register temp) {
6662 DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
6663 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
6664 if (!invoke->GetLocations()->Intrinsified()) {
6665 return location.AsRegister<Register>();
6666 }
6667 // For intrinsics we allow any location, so it may be on the stack.
6668 if (!location.IsRegister()) {
6669 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
6670 return temp;
6671 }
6672 // For register locations, check if the register was saved. If so, get it from the stack.
6673 // Note: There is a chance that the register was saved but not overwritten, so we could
6674 // save one load. However, since this is just an intrinsic slow path we prefer this
6675 // simple and more robust approach rather that trying to determine if that's the case.
6676 SlowPathCode* slow_path = GetCurrentSlowPath();
6677 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
6678 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
6679 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
6680 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
6681 return temp;
6682 }
6683 return location.AsRegister<Register>();
6684}
6685
Nicolas Geoffray38207af2015-06-01 15:46:22 +01006686void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00006687 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00006688 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00006689 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6690 // LR = code address from literal pool with link-time patch.
6691 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00006692 break;
6693 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6694 // LR = invoke->GetDirectCodePtr();
6695 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00006696 break;
6697 default:
6698 break;
6699 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006700
Vladimir Marko58155012015-08-19 12:49:41 +00006701 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
6702 switch (invoke->GetMethodLoadKind()) {
6703 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
6704 // temp = thread->string_init_entrypoint
6705 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
6706 break;
6707 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00006708 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006709 break;
6710 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
6711 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
6712 break;
6713 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
6714 __ LoadLiteral(temp.AsRegister<Register>(),
6715 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
6716 break;
Vladimir Markob4536b72015-11-24 13:45:23 +00006717 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
6718 HArmDexCacheArraysBase* base =
6719 invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase();
6720 Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke,
6721 temp.AsRegister<Register>());
6722 int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset();
6723 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
6724 break;
6725 }
Vladimir Marko58155012015-08-19 12:49:41 +00006726 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00006727 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00006728 Register method_reg;
6729 Register reg = temp.AsRegister<Register>();
6730 if (current_method.IsRegister()) {
6731 method_reg = current_method.AsRegister<Register>();
6732 } else {
6733 DCHECK(invoke->GetLocations()->Intrinsified());
6734 DCHECK(!current_method.IsValid());
6735 method_reg = reg;
6736 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
6737 }
Roland Levillain3b359c72015-11-17 19:35:12 +00006738 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
6739 __ LoadFromOffset(kLoadWord,
6740 reg,
6741 method_reg,
6742 ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01006743 // temp = temp[index_in_cache];
6744 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
6745 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00006746 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
6747 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01006748 }
Vladimir Marko58155012015-08-19 12:49:41 +00006749 }
6750
6751 switch (invoke->GetCodePtrLocation()) {
6752 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
6753 __ bl(GetFrameEntryLabel());
6754 break;
6755 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01006756 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07006757 __ BindTrackedLabel(&relative_call_patches_.back().label);
Vladimir Markodc151b22015-10-15 18:02:30 +01006758 // Arbitrarily branch to the BL itself, override at link time.
6759 __ bl(&relative_call_patches_.back().label);
6760 break;
Vladimir Marko58155012015-08-19 12:49:41 +00006761 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
6762 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
6763 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00006764 // LR()
6765 __ blx(LR);
6766 break;
6767 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
6768 // LR = callee_method->entry_point_from_quick_compiled_code_
6769 __ LoadFromOffset(
6770 kLoadWord, LR, callee_method.AsRegister<Register>(),
Andreas Gampe542451c2016-07-26 09:02:02 -07006771 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00006772 // LR()
6773 __ blx(LR);
6774 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006775 }
6776
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08006777 DCHECK(!IsLeafMethod());
6778}
6779
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006780void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
6781 Register temp = temp_location.AsRegister<Register>();
6782 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
6783 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006784
6785 // Use the calling convention instead of the location of the receiver, as
6786 // intrinsics may have put the receiver in a different register. In the intrinsics
6787 // slow path, the arguments have been moved to the right place, so here we are
6788 // guaranteed that the receiver is the first register of the calling convention.
6789 InvokeDexCallingConvention calling_convention;
6790 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006791 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Roland Levillain3b359c72015-11-17 19:35:12 +00006792 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00006793 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006794 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain3b359c72015-11-17 19:35:12 +00006795 // Instead of simply (possibly) unpoisoning `temp` here, we should
6796 // emit a read barrier for the previous class reference load.
6797 // However this is not required in practice, as this is an
6798 // intermediate/temporary reference and because the current
6799 // concurrent copying collector keeps the from-space memory
6800 // intact/accessible until the end of the marking phase (the
6801 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006802 __ MaybeUnpoisonHeapReference(temp);
6803 // temp = temp->GetMethodAt(method_offset);
6804 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07006805 kArmPointerSize).Int32Value();
Andreas Gampebfb5ba92015-09-01 15:45:02 +00006806 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
6807 // LR = temp->GetEntryPoint();
6808 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
6809 // LR();
6810 __ blx(LR);
6811}
6812
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006813CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch(
6814 const DexFile& dex_file, uint32_t string_index) {
6815 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
6816}
6817
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006818CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch(
6819 const DexFile& dex_file, uint32_t type_index) {
6820 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
6821}
6822
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006823CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch(
6824 const DexFile& dex_file, uint32_t element_offset) {
6825 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
6826}
6827
6828CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch(
6829 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
6830 patches->emplace_back(dex_file, offset_or_index);
6831 return &patches->back();
6832}
6833
6834Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
6835 uint32_t string_index) {
6836 return boot_image_string_patches_.GetOrCreate(
6837 StringReference(&dex_file, string_index),
6838 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6839}
6840
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006841Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
6842 uint32_t type_index) {
6843 return boot_image_type_patches_.GetOrCreate(
6844 TypeReference(&dex_file, type_index),
6845 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
6846}
6847
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006848Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) {
6849 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
6850 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
6851 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
6852}
6853
6854Literal* CodeGeneratorARM::DeduplicateDexCacheAddressLiteral(uint32_t address) {
6855 return DeduplicateUint32Literal(address, &uint32_literals_);
6856}
6857
Vladimir Marko58155012015-08-19 12:49:41 +00006858void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
6859 DCHECK(linker_patches->empty());
Vladimir Markob4536b72015-11-24 13:45:23 +00006860 size_t size =
6861 method_patches_.size() +
6862 call_patches_.size() +
6863 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006864 /* MOVW+MOVT for each base */ 2u * pc_relative_dex_cache_patches_.size() +
6865 boot_image_string_patches_.size() +
6866 /* MOVW+MOVT for each base */ 2u * pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006867 boot_image_type_patches_.size() +
6868 /* MOVW+MOVT for each base */ 2u * pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006869 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00006870 linker_patches->reserve(size);
6871 for (const auto& entry : method_patches_) {
6872 const MethodReference& target_method = entry.first;
6873 Literal* literal = entry.second;
6874 DCHECK(literal->GetLabel()->IsBound());
6875 uint32_t literal_offset = literal->GetLabel()->Position();
6876 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
6877 target_method.dex_file,
6878 target_method.dex_method_index));
6879 }
6880 for (const auto& entry : call_patches_) {
6881 const MethodReference& target_method = entry.first;
6882 Literal* literal = entry.second;
6883 DCHECK(literal->GetLabel()->IsBound());
6884 uint32_t literal_offset = literal->GetLabel()->Position();
6885 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
6886 target_method.dex_file,
6887 target_method.dex_method_index));
6888 }
6889 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
6890 uint32_t literal_offset = info.label.Position();
6891 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
6892 info.target_method.dex_file,
6893 info.target_method.dex_method_index));
6894 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006895 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
6896 const DexFile& dex_file = info.target_dex_file;
6897 size_t base_element_offset = info.offset_or_index;
6898 DCHECK(info.add_pc_label.IsBound());
6899 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006900 // Add MOVW patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006901 DCHECK(info.movw_label.IsBound());
6902 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006903 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movw_offset,
6904 &dex_file,
6905 add_pc_offset,
6906 base_element_offset));
6907 // Add MOVT patch.
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006908 DCHECK(info.movt_label.IsBound());
6909 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
Vladimir Markob4536b72015-11-24 13:45:23 +00006910 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(movt_offset,
6911 &dex_file,
6912 add_pc_offset,
6913 base_element_offset));
6914 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006915 for (const auto& entry : boot_image_string_patches_) {
6916 const StringReference& target_string = entry.first;
6917 Literal* literal = entry.second;
6918 DCHECK(literal->GetLabel()->IsBound());
6919 uint32_t literal_offset = literal->GetLabel()->Position();
6920 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
6921 target_string.dex_file,
6922 target_string.string_index));
6923 }
6924 for (const PcRelativePatchInfo& info : pc_relative_string_patches_) {
6925 const DexFile& dex_file = info.target_dex_file;
6926 uint32_t string_index = info.offset_or_index;
6927 DCHECK(info.add_pc_label.IsBound());
6928 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6929 // Add MOVW patch.
6930 DCHECK(info.movw_label.IsBound());
6931 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6932 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movw_offset,
6933 &dex_file,
6934 add_pc_offset,
6935 string_index));
6936 // Add MOVT patch.
6937 DCHECK(info.movt_label.IsBound());
6938 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6939 linker_patches->push_back(LinkerPatch::RelativeStringPatch(movt_offset,
6940 &dex_file,
6941 add_pc_offset,
6942 string_index));
6943 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01006944 for (const auto& entry : boot_image_type_patches_) {
6945 const TypeReference& target_type = entry.first;
6946 Literal* literal = entry.second;
6947 DCHECK(literal->GetLabel()->IsBound());
6948 uint32_t literal_offset = literal->GetLabel()->Position();
6949 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
6950 target_type.dex_file,
6951 target_type.type_index));
6952 }
6953 for (const PcRelativePatchInfo& info : pc_relative_type_patches_) {
6954 const DexFile& dex_file = info.target_dex_file;
6955 uint32_t type_index = info.offset_or_index;
6956 DCHECK(info.add_pc_label.IsBound());
6957 uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position());
6958 // Add MOVW patch.
6959 DCHECK(info.movw_label.IsBound());
6960 uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position());
6961 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movw_offset,
6962 &dex_file,
6963 add_pc_offset,
6964 type_index));
6965 // Add MOVT patch.
6966 DCHECK(info.movt_label.IsBound());
6967 uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position());
6968 linker_patches->push_back(LinkerPatch::RelativeTypePatch(movt_offset,
6969 &dex_file,
6970 add_pc_offset,
6971 type_index));
6972 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006973 for (const auto& entry : boot_image_address_patches_) {
6974 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
6975 Literal* literal = entry.second;
6976 DCHECK(literal->GetLabel()->IsBound());
6977 uint32_t literal_offset = literal->GetLabel()->Position();
6978 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
6979 }
6980}
6981
6982Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
6983 return map->GetOrCreate(
6984 value,
6985 [this, value]() { return __ NewLiteral<uint32_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00006986}
6987
6988Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
6989 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00006990 return map->GetOrCreate(
6991 target_method,
6992 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00006993}
6994
6995Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
6996 return DeduplicateMethodLiteral(target_method, &method_patches_);
6997}
6998
6999Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
7000 return DeduplicateMethodLiteral(target_method, &call_patches_);
7001}
7002
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03007003void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7004 LocationSummary* locations =
7005 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
7006 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
7007 Location::RequiresRegister());
7008 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
7009 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
7010 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
7011}
7012
7013void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
7014 LocationSummary* locations = instr->GetLocations();
7015 Register res = locations->Out().AsRegister<Register>();
7016 Register accumulator =
7017 locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>();
7018 Register mul_left =
7019 locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>();
7020 Register mul_right =
7021 locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>();
7022
7023 if (instr->GetOpKind() == HInstruction::kAdd) {
7024 __ mla(res, mul_left, mul_right, accumulator);
7025 } else {
7026 __ mls(res, mul_left, mul_right, accumulator);
7027 }
7028}
7029
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007030void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007031 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007032 LOG(FATAL) << "Unreachable";
7033}
7034
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01007035void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00007036 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00007037 LOG(FATAL) << "Unreachable";
7038}
7039
Mark Mendellfe57faa2015-09-18 09:26:15 -04007040// Simple implementation of packed switch - generate cascaded compare/jumps.
7041void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7042 LocationSummary* locations =
7043 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
7044 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007045 if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold &&
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007046 codegen_->GetAssembler()->IsThumb()) {
7047 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base.
7048 if (switch_instr->GetStartValue() != 0) {
7049 locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias.
7050 }
7051 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007052}
7053
7054void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
7055 int32_t lower_bound = switch_instr->GetStartValue();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007056 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04007057 LocationSummary* locations = switch_instr->GetLocations();
7058 Register value_reg = locations->InAt(0).AsRegister<Register>();
7059 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
7060
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007061 if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) {
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007062 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007063 Register temp_reg = IP;
7064 // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store
7065 // the immediate, because IP is used as the destination register. For the other
7066 // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant,
7067 // and they can be encoded in the instruction without making use of IP register.
7068 __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound);
7069
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007070 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007071 // Jump to successors[0] if value == lower_bound.
7072 __ b(codegen_->GetLabelOf(successors[0]), EQ);
7073 int32_t last_index = 0;
7074 for (; num_entries - last_index > 2; last_index += 2) {
7075 __ AddConstantSetFlags(temp_reg, temp_reg, -2);
7076 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
7077 __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO);
7078 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
7079 __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ);
7080 }
7081 if (num_entries - last_index == 2) {
7082 // The last missing case_value.
Vladimir Markoac6ac102015-12-17 12:14:00 +00007083 __ CmpConstant(temp_reg, 1);
Vladimir Markof3e0ee22015-12-17 15:23:13 +00007084 __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007085 }
Mark Mendellfe57faa2015-09-18 09:26:15 -04007086
Andreas Gampe7cffc3b2015-10-19 21:31:53 -07007087 // And the default for any other value.
7088 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
7089 __ b(codegen_->GetLabelOf(default_block));
7090 }
7091 } else {
7092 // Create a table lookup.
7093 Register temp_reg = locations->GetTemp(0).AsRegister<Register>();
7094
7095 // Materialize a pointer to the switch table
7096 std::vector<Label*> labels(num_entries);
7097 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
7098 for (uint32_t i = 0; i < num_entries; i++) {
7099 labels[i] = codegen_->GetLabelOf(successors[i]);
7100 }
7101 JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg);
7102
7103 // Remove the bias.
7104 Register key_reg;
7105 if (lower_bound != 0) {
7106 key_reg = locations->GetTemp(1).AsRegister<Register>();
7107 __ AddConstant(key_reg, value_reg, -lower_bound);
7108 } else {
7109 key_reg = value_reg;
7110 }
7111
7112 // Check whether the value is in the table, jump to default block if not.
7113 __ CmpConstant(key_reg, num_entries - 1);
7114 __ b(codegen_->GetLabelOf(default_block), Condition::HI);
7115
7116 // Load the displacement from the table.
7117 __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2));
7118
7119 // Dispatch is a direct add to the PC (for Thumb2).
7120 __ EmitJumpTableDispatch(table, temp_reg);
Mark Mendellfe57faa2015-09-18 09:26:15 -04007121 }
7122}
7123
Vladimir Markob4536b72015-11-24 13:45:23 +00007124void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7125 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
7126 locations->SetOut(Location::RequiresRegister());
Vladimir Markob4536b72015-11-24 13:45:23 +00007127}
7128
7129void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) {
7130 Register base_reg = base->GetLocations()->Out().AsRegister<Register>();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007131 CodeGeneratorARM::PcRelativePatchInfo* labels =
7132 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markob4536b72015-11-24 13:45:23 +00007133 __ BindTrackedLabel(&labels->movw_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007134 __ movw(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007135 __ BindTrackedLabel(&labels->movt_label);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00007136 __ movt(base_reg, /* placeholder */ 0u);
Vladimir Markob4536b72015-11-24 13:45:23 +00007137 __ BindTrackedLabel(&labels->add_pc_label);
7138 __ add(base_reg, base_reg, ShifterOperand(PC));
7139}
7140
Andreas Gampe85b62f22015-09-09 13:15:38 -07007141void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
7142 if (!trg.IsValid()) {
Roland Levillainc9285912015-12-18 10:38:42 +00007143 DCHECK_EQ(type, Primitive::kPrimVoid);
Andreas Gampe85b62f22015-09-09 13:15:38 -07007144 return;
7145 }
7146
7147 DCHECK_NE(type, Primitive::kPrimVoid);
7148
7149 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
7150 if (return_loc.Equals(trg)) {
7151 return;
7152 }
7153
7154 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
7155 // with the last branch.
7156 if (type == Primitive::kPrimLong) {
7157 HParallelMove parallel_move(GetGraph()->GetArena());
7158 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
7159 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
7160 GetMoveResolver()->EmitNativeCode(&parallel_move);
7161 } else if (type == Primitive::kPrimDouble) {
7162 HParallelMove parallel_move(GetGraph()->GetArena());
7163 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
7164 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
7165 GetMoveResolver()->EmitNativeCode(&parallel_move);
7166 } else {
7167 // Let the parallel move resolver take care of all of this.
7168 HParallelMove parallel_move(GetGraph()->GetArena());
7169 parallel_move.AddMove(return_loc, trg, type, nullptr);
7170 GetMoveResolver()->EmitNativeCode(&parallel_move);
7171 }
7172}
7173
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007174void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) {
7175 LocationSummary* locations =
7176 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
7177 locations->SetInAt(0, Location::RequiresRegister());
7178 locations->SetOut(Location::RequiresRegister());
7179}
7180
7181void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) {
7182 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00007183 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007184 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007185 instruction->GetIndex(), kArmPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007186 __ LoadFromOffset(kLoadWord,
7187 locations->Out().AsRegister<Register>(),
7188 locations->InAt(0).AsRegister<Register>(),
7189 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007190 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007191 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00007192 instruction->GetIndex(), kArmPointerSize));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01007193 __ LoadFromOffset(kLoadWord,
7194 locations->Out().AsRegister<Register>(),
7195 locations->InAt(0).AsRegister<Register>(),
7196 mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value());
7197 __ LoadFromOffset(kLoadWord,
7198 locations->Out().AsRegister<Register>(),
7199 locations->Out().AsRegister<Register>(),
7200 method_offset);
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007201 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00007202}
7203
Roland Levillain4d027112015-07-01 15:41:14 +01007204#undef __
7205#undef QUICK_ENTRY_POINT
7206
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00007207} // namespace arm
7208} // namespace art