blob: e8328713501fe93c3aae3e2f7f8448ce0d3f5a9a [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"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070022#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010023#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080024#include "intrinsics.h"
25#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070026#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070027#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010029#include "utils/arm/assembler_arm.h"
30#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000031#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010032#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000033
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000034namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010035
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000036namespace arm {
37
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000038static bool ExpectedPairLayout(Location location) {
39 // We expected this for both core and fpu register pairs.
40 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
41}
42
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010043static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010044static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010045
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000046// We unconditionally allocate R5 to ensure we can do long operations
47// with baseline.
48static constexpr Register kCoreSavedRegisterForBaseline = R5;
49static constexpr Register kCoreCalleeSaves[] =
50 { R5, R6, R7, R8, R10, R11, PC };
51static constexpr SRegister kFpuCalleeSaves[] =
52 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000054// D31 cannot be split into two S registers, and the register allocator only works on
55// S registers. Therefore there is no need to block it.
56static constexpr DRegister DTMP = D31;
57
Roland Levillain62a46b22015-06-01 18:24:13 +010058#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010059#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010061class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010063 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Alexandre Rames67555f72014-11-18 10:55:16 +000065 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010066 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010068 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000069 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010070 }
71
Alexandre Rames9931f312015-06-19 14:47:01 +010072 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
73
Nicolas Geoffraye5038322014-07-04 09:41:32 +010074 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010075 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010076 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
77};
78
Calin Juravled0d48522014-11-04 16:40:20 +000079class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
80 public:
81 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
82
Alexandre Rames67555f72014-11-18 10:55:16 +000083 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
85 __ Bind(GetEntryLabel());
86 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000087 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000088 }
89
Alexandre Rames9931f312015-06-19 14:47:01 +010090 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
91
Calin Juravled0d48522014-11-04 16:40:20 +000092 private:
93 HDivZeroCheck* const instruction_;
94 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
95};
96
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010097class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000098 public:
Alexandre Rames67555f72014-11-18 10:55:16 +000099 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100100 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000101
Alexandre Rames67555f72014-11-18 10:55:16 +0000102 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100103 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000104 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000105 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100106 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000107 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000108 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100109 if (successor_ == nullptr) {
110 __ b(GetReturnLabel());
111 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100112 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100113 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000114 }
115
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100116 Label* GetReturnLabel() {
117 DCHECK(successor_ == nullptr);
118 return &return_label_;
119 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000120
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100121 HBasicBlock* GetSuccessor() const {
122 return successor_;
123 }
124
Alexandre Rames9931f312015-06-19 14:47:01 +0100125 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
126
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 private:
128 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 // If not null, the block to branch to after the suspend check.
130 HBasicBlock* const successor_;
131
132 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000133 Label return_label_;
134
135 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
136};
137
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100138class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100139 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100140 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
141 Location index_location,
142 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100143 : instruction_(instruction),
144 index_location_(index_location),
145 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100146
Alexandre Rames67555f72014-11-18 10:55:16 +0000147 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100148 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100149 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000150 // We're moving two locations to locations that could overlap, so we need a parallel
151 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000153 codegen->EmitParallelMoves(
154 index_location_,
155 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100156 Primitive::kPrimInt,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000157 length_location_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100158 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
159 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100160 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000161 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 }
163
Alexandre Rames9931f312015-06-19 14:47:01 +0100164 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
165
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100166 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100167 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168 const Location index_location_;
169 const Location length_location_;
170
171 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
172};
173
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000174class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100175 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000176 LoadClassSlowPathARM(HLoadClass* cls,
177 HInstruction* at,
178 uint32_t dex_pc,
179 bool do_clinit)
180 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
181 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
182 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100183
Alexandre Rames67555f72014-11-18 10:55:16 +0000184 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000185 LocationSummary* locations = at_->GetLocations();
186
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100187 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
188 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000189 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100191 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000192 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000193 int32_t entry_point_offset = do_clinit_
194 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
195 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000196 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000197
198 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000199 Location out = locations->Out();
200 if (out.IsValid()) {
201 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000202 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
203 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000204 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205 __ b(GetExitLabel());
206 }
207
Alexandre Rames9931f312015-06-19 14:47:01 +0100208 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 // The class this slow path will load.
212 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100213
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000214 // The instruction where this slow path is happening.
215 // (Might be the load class or an initialization check).
216 HInstruction* const at_;
217
218 // The dex PC of `at_`.
219 const uint32_t dex_pc_;
220
221 // Whether to initialize the class.
222 const bool do_clinit_;
223
224 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100225};
226
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000227class LoadStringSlowPathARM : public SlowPathCodeARM {
228 public:
229 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
230
Alexandre Rames67555f72014-11-18 10:55:16 +0000231 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000232 LocationSummary* locations = instruction_->GetLocations();
233 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
234
235 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
236 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000237 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000238
239 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800240 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000241 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000242 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000243 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
244
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000245 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000246 __ b(GetExitLabel());
247 }
248
Alexandre Rames9931f312015-06-19 14:47:01 +0100249 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
250
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000251 private:
252 HLoadString* const instruction_;
253
254 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
255};
256
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000257class TypeCheckSlowPathARM : public SlowPathCodeARM {
258 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000259 TypeCheckSlowPathARM(HInstruction* instruction,
260 Location class_to_check,
261 Location object_class,
262 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000263 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000264 class_to_check_(class_to_check),
265 object_class_(object_class),
266 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000267
Alexandre Rames67555f72014-11-18 10:55:16 +0000268 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000269 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000270 DCHECK(instruction_->IsCheckCast()
271 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000272
273 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
274 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000275 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000276
277 // We're moving two locations to locations that could overlap, so we need a parallel
278 // move resolver.
279 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000280 codegen->EmitParallelMoves(
281 class_to_check_,
282 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100283 Primitive::kPrimNot,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000284 object_class_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100285 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
286 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000287
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000289 arm_codegen->InvokeRuntime(
290 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000291 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
292 } else {
293 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000294 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000295 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000296
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000297 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000298 __ b(GetExitLabel());
299 }
300
Alexandre Rames9931f312015-06-19 14:47:01 +0100301 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
302
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000303 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000304 HInstruction* const instruction_;
305 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000306 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000307 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000308
309 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
310};
311
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700312class DeoptimizationSlowPathARM : public SlowPathCodeARM {
313 public:
314 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
315 : instruction_(instruction) {}
316
317 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
318 __ Bind(GetEntryLabel());
319 SaveLiveRegisters(codegen, instruction_->GetLocations());
320 DCHECK(instruction_->IsDeoptimize());
321 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
322 uint32_t dex_pc = deoptimize->GetDexPc();
323 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
324 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
325 }
326
Alexandre Rames9931f312015-06-19 14:47:01 +0100327 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
328
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700329 private:
330 HInstruction* const instruction_;
331 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
332};
333
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000334#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100335#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700336
Roland Levillain4fa13f62015-07-06 18:11:54 +0100337inline Condition ARMSignedOrFPCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700338 switch (cond) {
339 case kCondEQ: return EQ;
340 case kCondNE: return NE;
341 case kCondLT: return LT;
342 case kCondLE: return LE;
343 case kCondGT: return GT;
344 case kCondGE: return GE;
Dave Allison20dfc792014-06-16 20:44:29 -0700345 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100346 LOG(FATAL) << "Unreachable";
347 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700348}
349
Roland Levillain4fa13f62015-07-06 18:11:54 +0100350inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700351 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100352 case kCondEQ: return EQ;
353 case kCondNE: return NE;
354 case kCondLT: return LO;
355 case kCondLE: return LS;
356 case kCondGT: return HI;
357 case kCondGE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700358 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100359 LOG(FATAL) << "Unreachable";
360 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700361}
362
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100363void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100364 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100365}
366
367void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100368 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100369}
370
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100371size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
372 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
373 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100374}
375
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100376size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
377 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
378 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100379}
380
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000381size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
382 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
383 return kArmWordSize;
384}
385
386size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
387 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
388 return kArmWordSize;
389}
390
Calin Juravle34166012014-12-19 17:22:29 +0000391CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000392 const ArmInstructionSetFeatures& isa_features,
393 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000394 : CodeGenerator(graph,
395 kNumberOfCoreRegisters,
396 kNumberOfSRegisters,
397 kNumberOfRegisterPairs,
398 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
399 arraysize(kCoreCalleeSaves)),
400 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
401 arraysize(kFpuCalleeSaves)),
402 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100403 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100405 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100406 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000407 assembler_(),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000408 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000409 // Save the PC register to mimic Quick.
410 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100411}
412
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000413void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
414 // Ensure that we fix up branches and literal loads and emit the literal pool.
415 __ FinalizeCode();
416
417 // Adjust native pc offsets in stack maps.
418 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
419 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
420 uint32_t new_position = __ GetAdjustedPosition(old_position);
421 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
422 }
423 // Adjust native pc offsets of block labels.
424 for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) {
425 HBasicBlock* block = block_order_->Get(block_idx);
426 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
427 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
428 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
429 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000430 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000431 if (block_label->IsBound()) {
432 __ AdjustLabelPosition(block_label);
433 }
434 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100435 // Adjust pc offsets for the disassembly information.
436 if (disasm_info_ != nullptr) {
437 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
438 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
439 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
440 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
441 it.second.start = __ GetAdjustedPosition(it.second.start);
442 it.second.end = __ GetAdjustedPosition(it.second.end);
443 }
444 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
445 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
446 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
447 }
448 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000449
450 CodeGenerator::Finalize(allocator);
451}
452
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100453Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100454 switch (type) {
455 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100457 ArmManagedRegister pair =
458 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100459 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
460 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
461
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100462 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
463 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100464 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100465 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100466 }
467
468 case Primitive::kPrimByte:
469 case Primitive::kPrimBoolean:
470 case Primitive::kPrimChar:
471 case Primitive::kPrimShort:
472 case Primitive::kPrimInt:
473 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100474 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100475 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100476 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
477 ArmManagedRegister current =
478 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
479 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100480 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100481 }
482 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100483 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100484 }
485
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000486 case Primitive::kPrimFloat: {
487 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100488 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100489 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100490
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000491 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000492 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
493 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000494 return Location::FpuRegisterPairLocation(reg, reg + 1);
495 }
496
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100497 case Primitive::kPrimVoid:
498 LOG(FATAL) << "Unreachable type " << type;
499 }
500
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100501 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100502}
503
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000504void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100505 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100506 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100507
508 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100509 blocked_core_registers_[SP] = true;
510 blocked_core_registers_[LR] = true;
511 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100512
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100513 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100514 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100515
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100516 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100517 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100518
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000519 if (is_baseline) {
520 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
521 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
522 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000523
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000524 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
525
526 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
527 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
528 }
529 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100530
531 UpdateBlockedPairRegisters();
532}
533
534void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
535 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
536 ArmManagedRegister current =
537 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
538 if (blocked_core_registers_[current.AsRegisterPairLow()]
539 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
540 blocked_register_pairs_[i] = true;
541 }
542 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100543}
544
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100545InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
546 : HGraphVisitor(graph),
547 assembler_(codegen->GetAssembler()),
548 codegen_(codegen) {}
549
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000550void CodeGeneratorARM::ComputeSpillMask() {
551 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000552 // Save one extra register for baseline. Note that on thumb2, there is no easy
553 // instruction to restore just the PC, so this actually helps both baseline
554 // and non-baseline to save and restore at least two registers at entry and exit.
555 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000556 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
557 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
558 // We use vpush and vpop for saving and restoring floating point registers, which take
559 // a SRegister and the number of registers to save/restore after that SRegister. We
560 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
561 // but in the range.
562 if (fpu_spill_mask_ != 0) {
563 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
564 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
565 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
566 fpu_spill_mask_ |= (1 << i);
567 }
568 }
569}
570
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100571static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100572 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100573}
574
575static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100576 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100577}
578
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000579void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000580 bool skip_overflow_check =
581 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000582 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000583 __ Bind(&frame_entry_label_);
584
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000585 if (HasEmptyFrame()) {
586 return;
587 }
588
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100589 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000590 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
591 __ LoadFromOffset(kLoadWord, IP, IP, 0);
592 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100593 }
594
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000595 // PC is in the list of callee-save to mimic Quick, but we need to push
596 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100597 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
598 __ PushList(push_mask);
599 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100600 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000601 if (fpu_spill_mask_ != 0) {
602 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
603 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100604 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100605 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000606 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100607 int adjust = GetFrameSize() - FrameEntrySpillSize();
608 __ AddConstant(SP, -adjust);
609 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100610 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000611}
612
613void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000614 if (HasEmptyFrame()) {
615 __ bx(LR);
616 return;
617 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100618 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100619 int adjust = GetFrameSize() - FrameEntrySpillSize();
620 __ AddConstant(SP, adjust);
621 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000622 if (fpu_spill_mask_ != 0) {
623 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
624 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100625 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
626 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000627 }
628 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100629 __ cfi().RestoreState();
630 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000631}
632
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100633void CodeGeneratorARM::Bind(HBasicBlock* block) {
634 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000635}
636
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100637Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
638 switch (load->GetType()) {
639 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100640 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100641 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100642
643 case Primitive::kPrimInt:
644 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100645 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100646 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100647
648 case Primitive::kPrimBoolean:
649 case Primitive::kPrimByte:
650 case Primitive::kPrimChar:
651 case Primitive::kPrimShort:
652 case Primitive::kPrimVoid:
653 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700654 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100655 }
656
657 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700658 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100659}
660
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100661Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100662 switch (type) {
663 case Primitive::kPrimBoolean:
664 case Primitive::kPrimByte:
665 case Primitive::kPrimChar:
666 case Primitive::kPrimShort:
667 case Primitive::kPrimInt:
668 case Primitive::kPrimNot: {
669 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000670 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100671 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100672 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100673 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000674 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100675 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100676 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100677
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000678 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100679 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000680 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100681 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000682 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100683 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000684 if (calling_convention.GetRegisterAt(index) == R1) {
685 // Skip R1, and use R2_R3 instead.
686 gp_index_++;
687 index++;
688 }
689 }
690 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
691 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000692 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000693 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000694 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100695 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000696 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
697 }
698 }
699
700 case Primitive::kPrimFloat: {
701 uint32_t stack_index = stack_index_++;
702 if (float_index_ % 2 == 0) {
703 float_index_ = std::max(double_index_, float_index_);
704 }
705 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
706 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
707 } else {
708 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
709 }
710 }
711
712 case Primitive::kPrimDouble: {
713 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
714 uint32_t stack_index = stack_index_;
715 stack_index_ += 2;
716 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
717 uint32_t index = double_index_;
718 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000719 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000720 calling_convention.GetFpuRegisterAt(index),
721 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000722 DCHECK(ExpectedPairLayout(result));
723 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000724 } else {
725 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100726 }
727 }
728
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100729 case Primitive::kPrimVoid:
730 LOG(FATAL) << "Unexpected parameter type " << type;
731 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100732 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100733 return Location();
734}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100735
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100736Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000737 switch (type) {
738 case Primitive::kPrimBoolean:
739 case Primitive::kPrimByte:
740 case Primitive::kPrimChar:
741 case Primitive::kPrimShort:
742 case Primitive::kPrimInt:
743 case Primitive::kPrimNot: {
744 return Location::RegisterLocation(R0);
745 }
746
747 case Primitive::kPrimFloat: {
748 return Location::FpuRegisterLocation(S0);
749 }
750
751 case Primitive::kPrimLong: {
752 return Location::RegisterPairLocation(R0, R1);
753 }
754
755 case Primitive::kPrimDouble: {
756 return Location::FpuRegisterPairLocation(S0, S1);
757 }
758
759 case Primitive::kPrimVoid:
760 return Location();
761 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100762
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000763 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000764}
765
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100766Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
767 return Location::RegisterLocation(kMethodRegisterArgument);
768}
769
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100770void CodeGeneratorARM::Move32(Location destination, Location source) {
771 if (source.Equals(destination)) {
772 return;
773 }
774 if (destination.IsRegister()) {
775 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000776 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100777 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000778 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100779 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000780 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100781 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100782 } else if (destination.IsFpuRegister()) {
783 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000784 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100785 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000786 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100787 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000788 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100789 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100790 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000791 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100792 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000793 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100794 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000795 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100796 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000797 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100798 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
799 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100800 }
801 }
802}
803
804void CodeGeneratorARM::Move64(Location destination, Location source) {
805 if (source.Equals(destination)) {
806 return;
807 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100808 if (destination.IsRegisterPair()) {
809 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000810 EmitParallelMoves(
811 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
812 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100813 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000814 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100815 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
816 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100817 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000818 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100819 } else {
820 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000821 DCHECK(ExpectedPairLayout(destination));
822 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
823 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100824 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000825 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100826 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000827 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
828 SP,
829 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100830 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000831 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100832 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100833 } else {
834 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100835 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000836 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100837 if (source.AsRegisterPairLow<Register>() == R1) {
838 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100839 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
840 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100841 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100842 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100843 SP, destination.GetStackIndex());
844 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000845 } else if (source.IsFpuRegisterPair()) {
846 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
847 SP,
848 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 } else {
850 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000851 EmitParallelMoves(
852 Location::StackSlot(source.GetStackIndex()),
853 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100854 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000855 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100856 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
857 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100858 }
859 }
860}
861
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100862void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100863 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100864 if (instruction->IsCurrentMethod()) {
865 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
866 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100867 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100868 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000869 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000870 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
871 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000872 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000873 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000874 } else {
875 DCHECK(location.IsStackSlot());
876 __ LoadImmediate(IP, value);
877 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
878 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000879 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000880 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000881 int64_t value = const_to_move->AsLongConstant()->GetValue();
882 if (location.IsRegisterPair()) {
883 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
884 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
885 } else {
886 DCHECK(location.IsDoubleStackSlot());
887 __ LoadImmediate(IP, Low32Bits(value));
888 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
889 __ LoadImmediate(IP, High32Bits(value));
890 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
891 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100892 }
Roland Levillain476df552014-10-09 17:51:36 +0100893 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100894 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
895 switch (instruction->GetType()) {
896 case Primitive::kPrimBoolean:
897 case Primitive::kPrimByte:
898 case Primitive::kPrimChar:
899 case Primitive::kPrimShort:
900 case Primitive::kPrimInt:
901 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100902 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100903 Move32(location, Location::StackSlot(stack_slot));
904 break;
905
906 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100907 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100908 Move64(location, Location::DoubleStackSlot(stack_slot));
909 break;
910
911 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100912 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100913 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000914 } else if (instruction->IsTemporary()) {
915 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000916 if (temp_location.IsStackSlot()) {
917 Move32(location, temp_location);
918 } else {
919 DCHECK(temp_location.IsDoubleStackSlot());
920 Move64(location, temp_location);
921 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000922 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100923 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100924 switch (instruction->GetType()) {
925 case Primitive::kPrimBoolean:
926 case Primitive::kPrimByte:
927 case Primitive::kPrimChar:
928 case Primitive::kPrimShort:
929 case Primitive::kPrimNot:
930 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100931 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100932 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100933 break;
934
935 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100936 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100937 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100938 break;
939
940 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100941 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100942 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000943 }
944}
945
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100946void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
947 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000948 uint32_t dex_pc,
949 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100950 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
951 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000952 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100953 DCHECK(instruction->IsSuspendCheck()
954 || instruction->IsBoundsCheck()
955 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000956 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000957 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100958 || !IsLeafMethod());
959}
960
David Brazdilfc6a86a2015-06-26 10:33:45 +0000961void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100962 DCHECK(!successor->IsExitBlock());
963
964 HBasicBlock* block = got->GetBlock();
965 HInstruction* previous = got->GetPrevious();
966
967 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000968 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100969 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
970 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
971 return;
972 }
973
974 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
975 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
976 }
977 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000978 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000979 }
980}
981
David Brazdilfc6a86a2015-06-26 10:33:45 +0000982void LocationsBuilderARM::VisitGoto(HGoto* got) {
983 got->SetLocations(nullptr);
984}
985
986void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
987 HandleGoto(got, got->GetSuccessor());
988}
989
990void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
991 try_boundary->SetLocations(nullptr);
992}
993
994void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
995 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
996 if (!successor->IsExitBlock()) {
997 HandleGoto(try_boundary, successor);
998 }
999}
1000
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001001void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001002 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001003}
1004
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001005void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001006 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001007}
1008
Roland Levillain4fa13f62015-07-06 18:11:54 +01001009void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) {
1010 ShifterOperand operand;
1011 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) {
1012 __ cmp(left, operand);
1013 } else {
1014 Register temp = IP;
1015 __ LoadImmediate(temp, right);
1016 __ cmp(left, ShifterOperand(temp));
1017 }
1018}
1019
1020void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1021 Label* true_label,
1022 Label* false_label) {
1023 __ vmstat(); // transfer FP status register to ARM APSR.
1024 if (cond->IsFPConditionTrueIfNaN()) {
1025 __ b(true_label, VS); // VS for unordered.
1026 } else if (cond->IsFPConditionFalseIfNaN()) {
1027 __ b(false_label, VS); // VS for unordered.
1028 }
1029 __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition()));
1030}
1031
1032void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1033 Label* true_label,
1034 Label* false_label) {
1035 LocationSummary* locations = cond->GetLocations();
1036 Location left = locations->InAt(0);
1037 Location right = locations->InAt(1);
1038 IfCondition if_cond = cond->GetCondition();
1039
1040 Register left_high = left.AsRegisterPairHigh<Register>();
1041 Register left_low = left.AsRegisterPairLow<Register>();
1042 IfCondition true_high_cond = if_cond;
1043 IfCondition false_high_cond = cond->GetOppositeCondition();
1044 Condition final_condition = ARMUnsignedCondition(if_cond);
1045
1046 // Set the conditions for the test, remembering that == needs to be
1047 // decided using the low words.
1048 switch (if_cond) {
1049 case kCondEQ:
1050 case kCondNE:
1051 // Nothing to do.
1052 break;
1053 case kCondLT:
1054 false_high_cond = kCondGT;
1055 break;
1056 case kCondLE:
1057 true_high_cond = kCondLT;
1058 break;
1059 case kCondGT:
1060 false_high_cond = kCondLT;
1061 break;
1062 case kCondGE:
1063 true_high_cond = kCondGT;
1064 break;
1065 }
1066 if (right.IsConstant()) {
1067 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1068 int32_t val_low = Low32Bits(value);
1069 int32_t val_high = High32Bits(value);
1070
1071 GenerateCompareWithImmediate(left_high, val_high);
1072 if (if_cond == kCondNE) {
1073 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1074 } else if (if_cond == kCondEQ) {
1075 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1076 } else {
1077 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1078 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1079 }
1080 // Must be equal high, so compare the lows.
1081 GenerateCompareWithImmediate(left_low, val_low);
1082 } else {
1083 Register right_high = right.AsRegisterPairHigh<Register>();
1084 Register right_low = right.AsRegisterPairLow<Register>();
1085
1086 __ cmp(left_high, ShifterOperand(right_high));
1087 if (if_cond == kCondNE) {
1088 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1089 } else if (if_cond == kCondEQ) {
1090 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1091 } else {
1092 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1093 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1094 }
1095 // Must be equal high, so compare the lows.
1096 __ cmp(left_low, ShifterOperand(right_low));
1097 }
1098 // The last comparison might be unsigned.
1099 __ b(true_label, final_condition);
1100}
1101
1102void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr,
1103 HCondition* condition,
1104 Label* true_target,
1105 Label* false_target,
1106 Label* always_true_target) {
1107 LocationSummary* locations = condition->GetLocations();
1108 Location left = locations->InAt(0);
1109 Location right = locations->InAt(1);
1110
1111 // We don't want true_target as a nullptr.
1112 if (true_target == nullptr) {
1113 true_target = always_true_target;
1114 }
1115 bool falls_through = (false_target == nullptr);
1116
1117 // FP compares don't like null false_targets.
1118 if (false_target == nullptr) {
1119 false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1120 }
1121
1122 Primitive::Type type = condition->InputAt(0)->GetType();
1123 switch (type) {
1124 case Primitive::kPrimLong:
1125 GenerateLongComparesAndJumps(condition, true_target, false_target);
1126 break;
1127 case Primitive::kPrimFloat:
1128 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1129 GenerateFPJumps(condition, true_target, false_target);
1130 break;
1131 case Primitive::kPrimDouble:
1132 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1133 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1134 GenerateFPJumps(condition, true_target, false_target);
1135 break;
1136 default:
1137 LOG(FATAL) << "Unexpected compare type " << type;
1138 }
1139
1140 if (!falls_through) {
1141 __ b(false_target);
1142 }
1143}
1144
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001145void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1146 Label* true_target,
1147 Label* false_target,
1148 Label* always_true_target) {
1149 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001150 if (cond->IsIntConstant()) {
1151 // Constant condition, statically compared against 1.
1152 int32_t cond_value = cond->AsIntConstant()->GetValue();
1153 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001154 if (always_true_target != nullptr) {
1155 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001156 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001157 return;
1158 } else {
1159 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001160 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001161 } else {
1162 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1163 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001164 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001165 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1166 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001167 } else {
1168 // Condition has not been materialized, use its inputs as the
1169 // comparison and its condition as the branch condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001170 Primitive::Type type =
1171 cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt;
1172 // Is this a long or FP comparison that has been folded into the HCondition?
1173 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1174 // Generate the comparison directly.
1175 GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(),
1176 true_target, false_target, always_true_target);
1177 return;
1178 }
1179
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001180 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001181 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001182 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain4fa13f62015-07-06 18:11:54 +01001183 Location right = locations->InAt(1);
1184 if (right.IsRegister()) {
1185 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001186 } else {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001187 DCHECK(right.IsConstant());
1188 GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001189 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001190 __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001191 }
Dave Allison20dfc792014-06-16 20:44:29 -07001192 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001193 if (false_target != nullptr) {
1194 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001195 }
1196}
1197
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001198void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1199 LocationSummary* locations =
1200 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1201 HInstruction* cond = if_instr->InputAt(0);
1202 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1203 locations->SetInAt(0, Location::RequiresRegister());
1204 }
1205}
1206
1207void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1208 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1209 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1210 Label* always_true_target = true_target;
1211 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1212 if_instr->IfTrueSuccessor())) {
1213 always_true_target = nullptr;
1214 }
1215 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1216 if_instr->IfFalseSuccessor())) {
1217 false_target = nullptr;
1218 }
1219 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1220}
1221
1222void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1223 LocationSummary* locations = new (GetGraph()->GetArena())
1224 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1225 HInstruction* cond = deoptimize->InputAt(0);
1226 DCHECK(cond->IsCondition());
1227 if (cond->AsCondition()->NeedsMaterialization()) {
1228 locations->SetInAt(0, Location::RequiresRegister());
1229 }
1230}
1231
1232void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1233 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1234 DeoptimizationSlowPathARM(deoptimize);
1235 codegen_->AddSlowPath(slow_path);
1236 Label* slow_path_entry = slow_path->GetEntryLabel();
1237 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1238}
Dave Allison20dfc792014-06-16 20:44:29 -07001239
Roland Levillain0d37cd02015-05-27 16:39:19 +01001240void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001241 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001242 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001243 // Handle the long/FP comparisons made in instruction simplification.
1244 switch (cond->InputAt(0)->GetType()) {
1245 case Primitive::kPrimLong:
1246 locations->SetInAt(0, Location::RequiresRegister());
1247 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1248 if (cond->NeedsMaterialization()) {
1249 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1250 }
1251 break;
1252
1253 case Primitive::kPrimFloat:
1254 case Primitive::kPrimDouble:
1255 locations->SetInAt(0, Location::RequiresFpuRegister());
1256 locations->SetInAt(1, Location::RequiresFpuRegister());
1257 if (cond->NeedsMaterialization()) {
1258 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1259 }
1260 break;
1261
1262 default:
1263 locations->SetInAt(0, Location::RequiresRegister());
1264 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1265 if (cond->NeedsMaterialization()) {
1266 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1267 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001268 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001269}
1270
Roland Levillain0d37cd02015-05-27 16:39:19 +01001271void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001272 if (!cond->NeedsMaterialization()) {
1273 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001274 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001275
1276 LocationSummary* locations = cond->GetLocations();
1277 Location left = locations->InAt(0);
1278 Location right = locations->InAt(1);
1279 Register out = locations->Out().AsRegister<Register>();
1280 Label true_label, false_label;
1281
1282 switch (cond->InputAt(0)->GetType()) {
1283 default: {
1284 // Integer case.
1285 if (right.IsRegister()) {
1286 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1287 } else {
1288 DCHECK(right.IsConstant());
1289 GenerateCompareWithImmediate(left.AsRegister<Register>(),
1290 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
1291 }
1292 __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse);
1293 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
1294 ARMSignedOrFPCondition(cond->GetCondition()));
1295 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
1296 ARMSignedOrFPCondition(cond->GetOppositeCondition()));
1297 return;
1298 }
1299 case Primitive::kPrimLong:
1300 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1301 break;
1302 case Primitive::kPrimFloat:
1303 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1304 GenerateFPJumps(cond, &true_label, &false_label);
1305 break;
1306 case Primitive::kPrimDouble:
1307 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1308 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1309 GenerateFPJumps(cond, &true_label, &false_label);
1310 break;
1311 }
1312
1313 // Convert the jumps into the result.
1314 Label done_label;
1315
1316 // False case: result = 0.
1317 __ Bind(&false_label);
1318 __ LoadImmediate(out, 0);
1319 __ b(&done_label);
1320
1321 // True case: result = 1.
1322 __ Bind(&true_label);
1323 __ LoadImmediate(out, 1);
1324 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001325}
1326
1327void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1328 VisitCondition(comp);
1329}
1330
1331void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1332 VisitCondition(comp);
1333}
1334
1335void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1336 VisitCondition(comp);
1337}
1338
1339void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1340 VisitCondition(comp);
1341}
1342
1343void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1344 VisitCondition(comp);
1345}
1346
1347void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1348 VisitCondition(comp);
1349}
1350
1351void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1352 VisitCondition(comp);
1353}
1354
1355void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1356 VisitCondition(comp);
1357}
1358
1359void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1360 VisitCondition(comp);
1361}
1362
1363void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1364 VisitCondition(comp);
1365}
1366
1367void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1368 VisitCondition(comp);
1369}
1370
1371void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1372 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001373}
1374
1375void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001376 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001377}
1378
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001379void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1380 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001381}
1382
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001383void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001384 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001385}
1386
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001387void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001388 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001389 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001390}
1391
1392void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001393 LocationSummary* locations =
1394 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001395 switch (store->InputAt(1)->GetType()) {
1396 case Primitive::kPrimBoolean:
1397 case Primitive::kPrimByte:
1398 case Primitive::kPrimChar:
1399 case Primitive::kPrimShort:
1400 case Primitive::kPrimInt:
1401 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001402 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001403 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1404 break;
1405
1406 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001407 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001408 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1409 break;
1410
1411 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001412 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001413 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001414}
1415
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001416void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001417 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001418}
1419
1420void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001421 LocationSummary* locations =
1422 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001423 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001424}
1425
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001426void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001427 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001428 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001429}
1430
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001431void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1432 LocationSummary* locations =
1433 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1434 locations->SetOut(Location::ConstantLocation(constant));
1435}
1436
1437void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1438 // Will be generated at use site.
1439 UNUSED(constant);
1440}
1441
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001442void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001443 LocationSummary* locations =
1444 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001445 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001446}
1447
1448void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1449 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001450 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001451}
1452
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001453void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1454 LocationSummary* locations =
1455 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1456 locations->SetOut(Location::ConstantLocation(constant));
1457}
1458
1459void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1460 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001461 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001462}
1463
1464void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1465 LocationSummary* locations =
1466 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1467 locations->SetOut(Location::ConstantLocation(constant));
1468}
1469
1470void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1471 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001472 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001473}
1474
Calin Juravle27df7582015-04-17 19:12:31 +01001475void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1476 memory_barrier->SetLocations(nullptr);
1477}
1478
1479void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1480 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1481}
1482
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001483void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001484 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001485}
1486
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001487void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001488 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001489 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001490}
1491
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001492void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001493 LocationSummary* locations =
1494 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001495 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001496}
1497
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001498void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001499 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001500 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001501}
1502
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001503void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001504 // When we do not run baseline, explicit clinit checks triggered by static
1505 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1506 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001507
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001508 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1509 codegen_->GetInstructionSetFeatures());
1510 if (intrinsic.TryDispatch(invoke)) {
1511 return;
1512 }
1513
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001514 HandleInvoke(invoke);
1515}
1516
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001517static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1518 if (invoke->GetLocations()->Intrinsified()) {
1519 IntrinsicCodeGeneratorARM intrinsic(codegen);
1520 intrinsic.Dispatch(invoke);
1521 return true;
1522 }
1523 return false;
1524}
1525
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001526void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001527 // When we do not run baseline, explicit clinit checks triggered by static
1528 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1529 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001530
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001531 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1532 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001533 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001534
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001535 LocationSummary* locations = invoke->GetLocations();
1536 codegen_->GenerateStaticOrDirectCall(
1537 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001538 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001539}
1540
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001541void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001542 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001543 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001544}
1545
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001546void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001547 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1548 codegen_->GetInstructionSetFeatures());
1549 if (intrinsic.TryDispatch(invoke)) {
1550 return;
1551 }
1552
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001553 HandleInvoke(invoke);
1554}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001555
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001556void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001557 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1558 return;
1559 }
1560
Roland Levillain271ab9c2014-11-27 15:23:57 +00001561 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001562 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1563 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001564 LocationSummary* locations = invoke->GetLocations();
1565 Location receiver = locations->InAt(0);
1566 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1567 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001568 DCHECK(receiver.IsRegister());
1569 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001570 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001571 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001572 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001573 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001574 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001575 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001576 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001577 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001578 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001579 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001580 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001581 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001582}
1583
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001584void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1585 HandleInvoke(invoke);
1586 // Add the hidden argument.
1587 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1588}
1589
1590void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1591 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001592 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001593 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1594 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001595 LocationSummary* locations = invoke->GetLocations();
1596 Location receiver = locations->InAt(0);
1597 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1598
1599 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001600 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1601 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001602
1603 // temp = object->GetClass();
1604 if (receiver.IsStackSlot()) {
1605 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1606 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1607 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001608 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001609 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001610 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001611 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001612 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001613 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001614 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001615 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1616 // LR = temp->GetEntryPoint();
1617 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1618 // LR();
1619 __ blx(LR);
1620 DCHECK(!codegen_->IsLeafMethod());
1621 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1622}
1623
Roland Levillain88cb1752014-10-20 16:36:47 +01001624void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1625 LocationSummary* locations =
1626 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1627 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001628 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001629 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001630 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1631 break;
1632 }
1633 case Primitive::kPrimLong: {
1634 locations->SetInAt(0, Location::RequiresRegister());
1635 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001636 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001637 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001638
Roland Levillain88cb1752014-10-20 16:36:47 +01001639 case Primitive::kPrimFloat:
1640 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001641 locations->SetInAt(0, Location::RequiresFpuRegister());
1642 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001643 break;
1644
1645 default:
1646 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1647 }
1648}
1649
1650void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1651 LocationSummary* locations = neg->GetLocations();
1652 Location out = locations->Out();
1653 Location in = locations->InAt(0);
1654 switch (neg->GetResultType()) {
1655 case Primitive::kPrimInt:
1656 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001657 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001658 break;
1659
1660 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001661 DCHECK(in.IsRegisterPair());
1662 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1663 __ rsbs(out.AsRegisterPairLow<Register>(),
1664 in.AsRegisterPairLow<Register>(),
1665 ShifterOperand(0));
1666 // We cannot emit an RSC (Reverse Subtract with Carry)
1667 // instruction here, as it does not exist in the Thumb-2
1668 // instruction set. We use the following approach
1669 // using SBC and SUB instead.
1670 //
1671 // out.hi = -C
1672 __ sbc(out.AsRegisterPairHigh<Register>(),
1673 out.AsRegisterPairHigh<Register>(),
1674 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1675 // out.hi = out.hi - in.hi
1676 __ sub(out.AsRegisterPairHigh<Register>(),
1677 out.AsRegisterPairHigh<Register>(),
1678 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1679 break;
1680
Roland Levillain88cb1752014-10-20 16:36:47 +01001681 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001682 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001683 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001684 break;
1685
Roland Levillain88cb1752014-10-20 16:36:47 +01001686 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001687 DCHECK(in.IsFpuRegisterPair());
1688 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1689 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001690 break;
1691
1692 default:
1693 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1694 }
1695}
1696
Roland Levillaindff1f282014-11-05 14:15:05 +00001697void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001698 Primitive::Type result_type = conversion->GetResultType();
1699 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001700 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001701
Roland Levillain5b3ee562015-04-14 16:02:41 +01001702 // The float-to-long, double-to-long and long-to-float type conversions
1703 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001704 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001705 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1706 && result_type == Primitive::kPrimLong)
1707 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001708 ? LocationSummary::kCall
1709 : LocationSummary::kNoCall;
1710 LocationSummary* locations =
1711 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1712
David Brazdilb2bd1c52015-03-25 11:17:37 +00001713 // The Java language does not allow treating boolean as an integral type but
1714 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001715
Roland Levillaindff1f282014-11-05 14:15:05 +00001716 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001717 case Primitive::kPrimByte:
1718 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001719 case Primitive::kPrimBoolean:
1720 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001721 case Primitive::kPrimShort:
1722 case Primitive::kPrimInt:
1723 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001724 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001725 locations->SetInAt(0, Location::RequiresRegister());
1726 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1727 break;
1728
1729 default:
1730 LOG(FATAL) << "Unexpected type conversion from " << input_type
1731 << " to " << result_type;
1732 }
1733 break;
1734
Roland Levillain01a8d712014-11-14 16:27:39 +00001735 case Primitive::kPrimShort:
1736 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001737 case Primitive::kPrimBoolean:
1738 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001739 case Primitive::kPrimByte:
1740 case Primitive::kPrimInt:
1741 case Primitive::kPrimChar:
1742 // Processing a Dex `int-to-short' instruction.
1743 locations->SetInAt(0, Location::RequiresRegister());
1744 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1745 break;
1746
1747 default:
1748 LOG(FATAL) << "Unexpected type conversion from " << input_type
1749 << " to " << result_type;
1750 }
1751 break;
1752
Roland Levillain946e1432014-11-11 17:35:19 +00001753 case Primitive::kPrimInt:
1754 switch (input_type) {
1755 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001756 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001757 locations->SetInAt(0, Location::Any());
1758 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1759 break;
1760
1761 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001762 // Processing a Dex `float-to-int' instruction.
1763 locations->SetInAt(0, Location::RequiresFpuRegister());
1764 locations->SetOut(Location::RequiresRegister());
1765 locations->AddTemp(Location::RequiresFpuRegister());
1766 break;
1767
Roland Levillain946e1432014-11-11 17:35:19 +00001768 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001769 // Processing a Dex `double-to-int' instruction.
1770 locations->SetInAt(0, Location::RequiresFpuRegister());
1771 locations->SetOut(Location::RequiresRegister());
1772 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001773 break;
1774
1775 default:
1776 LOG(FATAL) << "Unexpected type conversion from " << input_type
1777 << " to " << result_type;
1778 }
1779 break;
1780
Roland Levillaindff1f282014-11-05 14:15:05 +00001781 case Primitive::kPrimLong:
1782 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001783 case Primitive::kPrimBoolean:
1784 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001785 case Primitive::kPrimByte:
1786 case Primitive::kPrimShort:
1787 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001788 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001789 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001790 locations->SetInAt(0, Location::RequiresRegister());
1791 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1792 break;
1793
Roland Levillain624279f2014-12-04 11:54:28 +00001794 case Primitive::kPrimFloat: {
1795 // Processing a Dex `float-to-long' instruction.
1796 InvokeRuntimeCallingConvention calling_convention;
1797 locations->SetInAt(0, Location::FpuRegisterLocation(
1798 calling_convention.GetFpuRegisterAt(0)));
1799 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1800 break;
1801 }
1802
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001803 case Primitive::kPrimDouble: {
1804 // Processing a Dex `double-to-long' instruction.
1805 InvokeRuntimeCallingConvention calling_convention;
1806 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1807 calling_convention.GetFpuRegisterAt(0),
1808 calling_convention.GetFpuRegisterAt(1)));
1809 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001810 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001811 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001812
1813 default:
1814 LOG(FATAL) << "Unexpected type conversion from " << input_type
1815 << " to " << result_type;
1816 }
1817 break;
1818
Roland Levillain981e4542014-11-14 11:47:14 +00001819 case Primitive::kPrimChar:
1820 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001821 case Primitive::kPrimBoolean:
1822 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001823 case Primitive::kPrimByte:
1824 case Primitive::kPrimShort:
1825 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001826 // Processing a Dex `int-to-char' instruction.
1827 locations->SetInAt(0, Location::RequiresRegister());
1828 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1829 break;
1830
1831 default:
1832 LOG(FATAL) << "Unexpected type conversion from " << input_type
1833 << " to " << result_type;
1834 }
1835 break;
1836
Roland Levillaindff1f282014-11-05 14:15:05 +00001837 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001838 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001839 case Primitive::kPrimBoolean:
1840 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001841 case Primitive::kPrimByte:
1842 case Primitive::kPrimShort:
1843 case Primitive::kPrimInt:
1844 case Primitive::kPrimChar:
1845 // Processing a Dex `int-to-float' instruction.
1846 locations->SetInAt(0, Location::RequiresRegister());
1847 locations->SetOut(Location::RequiresFpuRegister());
1848 break;
1849
Roland Levillain5b3ee562015-04-14 16:02:41 +01001850 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001851 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001852 InvokeRuntimeCallingConvention calling_convention;
1853 locations->SetInAt(0, Location::RegisterPairLocation(
1854 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1855 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001856 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001857 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001858
Roland Levillaincff13742014-11-17 14:32:17 +00001859 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001860 // Processing a Dex `double-to-float' instruction.
1861 locations->SetInAt(0, Location::RequiresFpuRegister());
1862 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001863 break;
1864
1865 default:
1866 LOG(FATAL) << "Unexpected type conversion from " << input_type
1867 << " to " << result_type;
1868 };
1869 break;
1870
Roland Levillaindff1f282014-11-05 14:15:05 +00001871 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001872 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001873 case Primitive::kPrimBoolean:
1874 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001875 case Primitive::kPrimByte:
1876 case Primitive::kPrimShort:
1877 case Primitive::kPrimInt:
1878 case Primitive::kPrimChar:
1879 // Processing a Dex `int-to-double' instruction.
1880 locations->SetInAt(0, Location::RequiresRegister());
1881 locations->SetOut(Location::RequiresFpuRegister());
1882 break;
1883
1884 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001885 // Processing a Dex `long-to-double' instruction.
1886 locations->SetInAt(0, Location::RequiresRegister());
1887 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001888 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001889 locations->AddTemp(Location::RequiresFpuRegister());
1890 break;
1891
Roland Levillaincff13742014-11-17 14:32:17 +00001892 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001893 // Processing a Dex `float-to-double' instruction.
1894 locations->SetInAt(0, Location::RequiresFpuRegister());
1895 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001896 break;
1897
1898 default:
1899 LOG(FATAL) << "Unexpected type conversion from " << input_type
1900 << " to " << result_type;
1901 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001902 break;
1903
1904 default:
1905 LOG(FATAL) << "Unexpected type conversion from " << input_type
1906 << " to " << result_type;
1907 }
1908}
1909
1910void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1911 LocationSummary* locations = conversion->GetLocations();
1912 Location out = locations->Out();
1913 Location in = locations->InAt(0);
1914 Primitive::Type result_type = conversion->GetResultType();
1915 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001916 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001917 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001918 case Primitive::kPrimByte:
1919 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001920 case Primitive::kPrimBoolean:
1921 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001922 case Primitive::kPrimShort:
1923 case Primitive::kPrimInt:
1924 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001925 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001926 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001927 break;
1928
1929 default:
1930 LOG(FATAL) << "Unexpected type conversion from " << input_type
1931 << " to " << result_type;
1932 }
1933 break;
1934
Roland Levillain01a8d712014-11-14 16:27:39 +00001935 case Primitive::kPrimShort:
1936 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001937 case Primitive::kPrimBoolean:
1938 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001939 case Primitive::kPrimByte:
1940 case Primitive::kPrimInt:
1941 case Primitive::kPrimChar:
1942 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001943 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001944 break;
1945
1946 default:
1947 LOG(FATAL) << "Unexpected type conversion from " << input_type
1948 << " to " << result_type;
1949 }
1950 break;
1951
Roland Levillain946e1432014-11-11 17:35:19 +00001952 case Primitive::kPrimInt:
1953 switch (input_type) {
1954 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001955 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001956 DCHECK(out.IsRegister());
1957 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001958 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001959 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001960 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001961 } else {
1962 DCHECK(in.IsConstant());
1963 DCHECK(in.GetConstant()->IsLongConstant());
1964 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001965 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001966 }
1967 break;
1968
Roland Levillain3f8f9362014-12-02 17:45:01 +00001969 case Primitive::kPrimFloat: {
1970 // Processing a Dex `float-to-int' instruction.
1971 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1972 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1973 __ vcvtis(temp, temp);
1974 __ vmovrs(out.AsRegister<Register>(), temp);
1975 break;
1976 }
1977
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001978 case Primitive::kPrimDouble: {
1979 // Processing a Dex `double-to-int' instruction.
1980 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1981 DRegister temp_d = FromLowSToD(temp_s);
1982 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1983 __ vcvtid(temp_s, temp_d);
1984 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001985 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001986 }
Roland Levillain946e1432014-11-11 17:35:19 +00001987
1988 default:
1989 LOG(FATAL) << "Unexpected type conversion from " << input_type
1990 << " to " << result_type;
1991 }
1992 break;
1993
Roland Levillaindff1f282014-11-05 14:15:05 +00001994 case Primitive::kPrimLong:
1995 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001996 case Primitive::kPrimBoolean:
1997 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001998 case Primitive::kPrimByte:
1999 case Primitive::kPrimShort:
2000 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002001 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002002 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002003 DCHECK(out.IsRegisterPair());
2004 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002005 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002006 // Sign extension.
2007 __ Asr(out.AsRegisterPairHigh<Register>(),
2008 out.AsRegisterPairLow<Register>(),
2009 31);
2010 break;
2011
2012 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002013 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002014 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2015 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002016 conversion->GetDexPc(),
2017 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00002018 break;
2019
Roland Levillaindff1f282014-11-05 14:15:05 +00002020 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002021 // Processing a Dex `double-to-long' instruction.
2022 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2023 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002024 conversion->GetDexPc(),
2025 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00002026 break;
2027
2028 default:
2029 LOG(FATAL) << "Unexpected type conversion from " << input_type
2030 << " to " << result_type;
2031 }
2032 break;
2033
Roland Levillain981e4542014-11-14 11:47:14 +00002034 case Primitive::kPrimChar:
2035 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002036 case Primitive::kPrimBoolean:
2037 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002038 case Primitive::kPrimByte:
2039 case Primitive::kPrimShort:
2040 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002041 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002042 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002043 break;
2044
2045 default:
2046 LOG(FATAL) << "Unexpected type conversion from " << input_type
2047 << " to " << result_type;
2048 }
2049 break;
2050
Roland Levillaindff1f282014-11-05 14:15:05 +00002051 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002052 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002053 case Primitive::kPrimBoolean:
2054 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002055 case Primitive::kPrimByte:
2056 case Primitive::kPrimShort:
2057 case Primitive::kPrimInt:
2058 case Primitive::kPrimChar: {
2059 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002060 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2061 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002062 break;
2063 }
2064
Roland Levillain5b3ee562015-04-14 16:02:41 +01002065 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002066 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002067 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2068 conversion,
2069 conversion->GetDexPc(),
2070 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002071 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002072
Roland Levillaincff13742014-11-17 14:32:17 +00002073 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002074 // Processing a Dex `double-to-float' instruction.
2075 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2076 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002077 break;
2078
2079 default:
2080 LOG(FATAL) << "Unexpected type conversion from " << input_type
2081 << " to " << result_type;
2082 };
2083 break;
2084
Roland Levillaindff1f282014-11-05 14:15:05 +00002085 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002086 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002087 case Primitive::kPrimBoolean:
2088 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002089 case Primitive::kPrimByte:
2090 case Primitive::kPrimShort:
2091 case Primitive::kPrimInt:
2092 case Primitive::kPrimChar: {
2093 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002094 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002095 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2096 out.AsFpuRegisterPairLow<SRegister>());
2097 break;
2098 }
2099
Roland Levillain647b9ed2014-11-27 12:06:00 +00002100 case Primitive::kPrimLong: {
2101 // Processing a Dex `long-to-double' instruction.
2102 Register low = in.AsRegisterPairLow<Register>();
2103 Register high = in.AsRegisterPairHigh<Register>();
2104 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2105 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002106 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002107 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002108 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2109 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002110
Roland Levillain682393c2015-04-14 15:57:52 +01002111 // temp_d = int-to-double(high)
2112 __ vmovsr(temp_s, high);
2113 __ vcvtdi(temp_d, temp_s);
2114 // constant_d = k2Pow32EncodingForDouble
2115 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2116 // out_d = unsigned-to-double(low)
2117 __ vmovsr(out_s, low);
2118 __ vcvtdu(out_d, out_s);
2119 // out_d += temp_d * constant_d
2120 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002121 break;
2122 }
2123
Roland Levillaincff13742014-11-17 14:32:17 +00002124 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002125 // Processing a Dex `float-to-double' instruction.
2126 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2127 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002128 break;
2129
2130 default:
2131 LOG(FATAL) << "Unexpected type conversion from " << input_type
2132 << " to " << result_type;
2133 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002134 break;
2135
2136 default:
2137 LOG(FATAL) << "Unexpected type conversion from " << input_type
2138 << " to " << result_type;
2139 }
2140}
2141
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002142void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002143 LocationSummary* locations =
2144 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002145 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002146 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002147 locations->SetInAt(0, Location::RequiresRegister());
2148 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002149 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2150 break;
2151 }
2152
2153 case Primitive::kPrimLong: {
2154 locations->SetInAt(0, Location::RequiresRegister());
2155 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002156 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002157 break;
2158 }
2159
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002160 case Primitive::kPrimFloat:
2161 case Primitive::kPrimDouble: {
2162 locations->SetInAt(0, Location::RequiresFpuRegister());
2163 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002164 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002165 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002166 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002167
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002168 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002169 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002170 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002171}
2172
2173void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2174 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002175 Location out = locations->Out();
2176 Location first = locations->InAt(0);
2177 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002178 switch (add->GetResultType()) {
2179 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002180 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002181 __ add(out.AsRegister<Register>(),
2182 first.AsRegister<Register>(),
2183 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002184 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002185 __ AddConstant(out.AsRegister<Register>(),
2186 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002187 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002188 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002189 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002190
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002191 case Primitive::kPrimLong: {
2192 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002193 __ adds(out.AsRegisterPairLow<Register>(),
2194 first.AsRegisterPairLow<Register>(),
2195 ShifterOperand(second.AsRegisterPairLow<Register>()));
2196 __ adc(out.AsRegisterPairHigh<Register>(),
2197 first.AsRegisterPairHigh<Register>(),
2198 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002199 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002200 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002201
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002202 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002203 __ vadds(out.AsFpuRegister<SRegister>(),
2204 first.AsFpuRegister<SRegister>(),
2205 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002206 break;
2207
2208 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002209 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2210 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2211 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002212 break;
2213
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002214 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002215 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002216 }
2217}
2218
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002219void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002220 LocationSummary* locations =
2221 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002222 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002223 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002224 locations->SetInAt(0, Location::RequiresRegister());
2225 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002226 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2227 break;
2228 }
2229
2230 case Primitive::kPrimLong: {
2231 locations->SetInAt(0, Location::RequiresRegister());
2232 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002233 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002234 break;
2235 }
Calin Juravle11351682014-10-23 15:38:15 +01002236 case Primitive::kPrimFloat:
2237 case Primitive::kPrimDouble: {
2238 locations->SetInAt(0, Location::RequiresFpuRegister());
2239 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002240 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002241 break;
Calin Juravle11351682014-10-23 15:38:15 +01002242 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002243 default:
Calin Juravle11351682014-10-23 15:38:15 +01002244 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002245 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002246}
2247
2248void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2249 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002250 Location out = locations->Out();
2251 Location first = locations->InAt(0);
2252 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002253 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002254 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002255 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002256 __ sub(out.AsRegister<Register>(),
2257 first.AsRegister<Register>(),
2258 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002259 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002260 __ AddConstant(out.AsRegister<Register>(),
2261 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002262 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002263 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002264 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002265 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002266
Calin Juravle11351682014-10-23 15:38:15 +01002267 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002268 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002269 __ subs(out.AsRegisterPairLow<Register>(),
2270 first.AsRegisterPairLow<Register>(),
2271 ShifterOperand(second.AsRegisterPairLow<Register>()));
2272 __ sbc(out.AsRegisterPairHigh<Register>(),
2273 first.AsRegisterPairHigh<Register>(),
2274 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002275 break;
Calin Juravle11351682014-10-23 15:38:15 +01002276 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002277
Calin Juravle11351682014-10-23 15:38:15 +01002278 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002279 __ vsubs(out.AsFpuRegister<SRegister>(),
2280 first.AsFpuRegister<SRegister>(),
2281 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002282 break;
Calin Juravle11351682014-10-23 15:38:15 +01002283 }
2284
2285 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002286 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2287 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2288 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002289 break;
2290 }
2291
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002292
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002293 default:
Calin Juravle11351682014-10-23 15:38:15 +01002294 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002295 }
2296}
2297
Calin Juravle34bacdf2014-10-07 20:23:36 +01002298void LocationsBuilderARM::VisitMul(HMul* mul) {
2299 LocationSummary* locations =
2300 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2301 switch (mul->GetResultType()) {
2302 case Primitive::kPrimInt:
2303 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002304 locations->SetInAt(0, Location::RequiresRegister());
2305 locations->SetInAt(1, Location::RequiresRegister());
2306 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002307 break;
2308 }
2309
Calin Juravleb5bfa962014-10-21 18:02:24 +01002310 case Primitive::kPrimFloat:
2311 case Primitive::kPrimDouble: {
2312 locations->SetInAt(0, Location::RequiresFpuRegister());
2313 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002314 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002315 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002316 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002317
2318 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002319 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002320 }
2321}
2322
2323void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2324 LocationSummary* locations = mul->GetLocations();
2325 Location out = locations->Out();
2326 Location first = locations->InAt(0);
2327 Location second = locations->InAt(1);
2328 switch (mul->GetResultType()) {
2329 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002330 __ mul(out.AsRegister<Register>(),
2331 first.AsRegister<Register>(),
2332 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002333 break;
2334 }
2335 case Primitive::kPrimLong: {
2336 Register out_hi = out.AsRegisterPairHigh<Register>();
2337 Register out_lo = out.AsRegisterPairLow<Register>();
2338 Register in1_hi = first.AsRegisterPairHigh<Register>();
2339 Register in1_lo = first.AsRegisterPairLow<Register>();
2340 Register in2_hi = second.AsRegisterPairHigh<Register>();
2341 Register in2_lo = second.AsRegisterPairLow<Register>();
2342
2343 // Extra checks to protect caused by the existence of R1_R2.
2344 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2345 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2346 DCHECK_NE(out_hi, in1_lo);
2347 DCHECK_NE(out_hi, in2_lo);
2348
2349 // input: in1 - 64 bits, in2 - 64 bits
2350 // output: out
2351 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2352 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2353 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2354
2355 // IP <- in1.lo * in2.hi
2356 __ mul(IP, in1_lo, in2_hi);
2357 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2358 __ mla(out_hi, in1_hi, in2_lo, IP);
2359 // out.lo <- (in1.lo * in2.lo)[31:0];
2360 __ umull(out_lo, IP, in1_lo, in2_lo);
2361 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2362 __ add(out_hi, out_hi, ShifterOperand(IP));
2363 break;
2364 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002365
2366 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002367 __ vmuls(out.AsFpuRegister<SRegister>(),
2368 first.AsFpuRegister<SRegister>(),
2369 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002370 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002371 }
2372
2373 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002374 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2375 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2376 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002377 break;
2378 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002379
2380 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002381 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002382 }
2383}
2384
Zheng Xuc6667102015-05-15 16:08:45 +08002385void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2386 DCHECK(instruction->IsDiv() || instruction->IsRem());
2387 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2388
2389 LocationSummary* locations = instruction->GetLocations();
2390 Location second = locations->InAt(1);
2391 DCHECK(second.IsConstant());
2392
2393 Register out = locations->Out().AsRegister<Register>();
2394 Register dividend = locations->InAt(0).AsRegister<Register>();
2395 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2396 DCHECK(imm == 1 || imm == -1);
2397
2398 if (instruction->IsRem()) {
2399 __ LoadImmediate(out, 0);
2400 } else {
2401 if (imm == 1) {
2402 __ Mov(out, dividend);
2403 } else {
2404 __ rsb(out, dividend, ShifterOperand(0));
2405 }
2406 }
2407}
2408
2409void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2410 DCHECK(instruction->IsDiv() || instruction->IsRem());
2411 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2412
2413 LocationSummary* locations = instruction->GetLocations();
2414 Location second = locations->InAt(1);
2415 DCHECK(second.IsConstant());
2416
2417 Register out = locations->Out().AsRegister<Register>();
2418 Register dividend = locations->InAt(0).AsRegister<Register>();
2419 Register temp = locations->GetTemp(0).AsRegister<Register>();
2420 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002421 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002422 DCHECK(IsPowerOfTwo(abs_imm));
2423 int ctz_imm = CTZ(abs_imm);
2424
2425 if (ctz_imm == 1) {
2426 __ Lsr(temp, dividend, 32 - ctz_imm);
2427 } else {
2428 __ Asr(temp, dividend, 31);
2429 __ Lsr(temp, temp, 32 - ctz_imm);
2430 }
2431 __ add(out, temp, ShifterOperand(dividend));
2432
2433 if (instruction->IsDiv()) {
2434 __ Asr(out, out, ctz_imm);
2435 if (imm < 0) {
2436 __ rsb(out, out, ShifterOperand(0));
2437 }
2438 } else {
2439 __ ubfx(out, out, 0, ctz_imm);
2440 __ sub(out, out, ShifterOperand(temp));
2441 }
2442}
2443
2444void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2445 DCHECK(instruction->IsDiv() || instruction->IsRem());
2446 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2447
2448 LocationSummary* locations = instruction->GetLocations();
2449 Location second = locations->InAt(1);
2450 DCHECK(second.IsConstant());
2451
2452 Register out = locations->Out().AsRegister<Register>();
2453 Register dividend = locations->InAt(0).AsRegister<Register>();
2454 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2455 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2456 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2457
2458 int64_t magic;
2459 int shift;
2460 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2461
2462 __ LoadImmediate(temp1, magic);
2463 __ smull(temp2, temp1, dividend, temp1);
2464
2465 if (imm > 0 && magic < 0) {
2466 __ add(temp1, temp1, ShifterOperand(dividend));
2467 } else if (imm < 0 && magic > 0) {
2468 __ sub(temp1, temp1, ShifterOperand(dividend));
2469 }
2470
2471 if (shift != 0) {
2472 __ Asr(temp1, temp1, shift);
2473 }
2474
2475 if (instruction->IsDiv()) {
2476 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2477 } else {
2478 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2479 // TODO: Strength reduction for mls.
2480 __ LoadImmediate(temp2, imm);
2481 __ mls(out, temp1, temp2, dividend);
2482 }
2483}
2484
2485void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2486 DCHECK(instruction->IsDiv() || instruction->IsRem());
2487 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2488
2489 LocationSummary* locations = instruction->GetLocations();
2490 Location second = locations->InAt(1);
2491 DCHECK(second.IsConstant());
2492
2493 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2494 if (imm == 0) {
2495 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2496 } else if (imm == 1 || imm == -1) {
2497 DivRemOneOrMinusOne(instruction);
2498 } else if (IsPowerOfTwo(std::abs(imm))) {
2499 DivRemByPowerOfTwo(instruction);
2500 } else {
2501 DCHECK(imm <= -2 || imm >= 2);
2502 GenerateDivRemWithAnyConstant(instruction);
2503 }
2504}
2505
Calin Juravle7c4954d2014-10-28 16:57:40 +00002506void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002507 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2508 if (div->GetResultType() == Primitive::kPrimLong) {
2509 // pLdiv runtime call.
2510 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002511 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2512 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002513 } else if (div->GetResultType() == Primitive::kPrimInt &&
2514 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2515 // pIdivmod runtime call.
2516 call_kind = LocationSummary::kCall;
2517 }
2518
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002519 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2520
Calin Juravle7c4954d2014-10-28 16:57:40 +00002521 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002522 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002523 if (div->InputAt(1)->IsConstant()) {
2524 locations->SetInAt(0, Location::RequiresRegister());
2525 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2526 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2527 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2528 if (abs_imm <= 1) {
2529 // No temp register required.
2530 } else {
2531 locations->AddTemp(Location::RequiresRegister());
2532 if (!IsPowerOfTwo(abs_imm)) {
2533 locations->AddTemp(Location::RequiresRegister());
2534 }
2535 }
2536 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002537 locations->SetInAt(0, Location::RequiresRegister());
2538 locations->SetInAt(1, Location::RequiresRegister());
2539 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2540 } else {
2541 InvokeRuntimeCallingConvention calling_convention;
2542 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2543 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2544 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2545 // we only need the former.
2546 locations->SetOut(Location::RegisterLocation(R0));
2547 }
Calin Juravled0d48522014-11-04 16:40:20 +00002548 break;
2549 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002550 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002551 InvokeRuntimeCallingConvention calling_convention;
2552 locations->SetInAt(0, Location::RegisterPairLocation(
2553 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2554 locations->SetInAt(1, Location::RegisterPairLocation(
2555 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002556 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002557 break;
2558 }
2559 case Primitive::kPrimFloat:
2560 case Primitive::kPrimDouble: {
2561 locations->SetInAt(0, Location::RequiresFpuRegister());
2562 locations->SetInAt(1, Location::RequiresFpuRegister());
2563 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2564 break;
2565 }
2566
2567 default:
2568 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2569 }
2570}
2571
2572void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2573 LocationSummary* locations = div->GetLocations();
2574 Location out = locations->Out();
2575 Location first = locations->InAt(0);
2576 Location second = locations->InAt(1);
2577
2578 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002579 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002580 if (second.IsConstant()) {
2581 GenerateDivRemConstantIntegral(div);
2582 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002583 __ sdiv(out.AsRegister<Register>(),
2584 first.AsRegister<Register>(),
2585 second.AsRegister<Register>());
2586 } else {
2587 InvokeRuntimeCallingConvention calling_convention;
2588 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2589 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2590 DCHECK_EQ(R0, out.AsRegister<Register>());
2591
2592 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2593 }
Calin Juravled0d48522014-11-04 16:40:20 +00002594 break;
2595 }
2596
Calin Juravle7c4954d2014-10-28 16:57:40 +00002597 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002598 InvokeRuntimeCallingConvention calling_convention;
2599 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2600 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2601 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2602 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2603 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002604 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002605
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002606 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002607 break;
2608 }
2609
2610 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002611 __ vdivs(out.AsFpuRegister<SRegister>(),
2612 first.AsFpuRegister<SRegister>(),
2613 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002614 break;
2615 }
2616
2617 case Primitive::kPrimDouble: {
2618 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2619 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2620 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2621 break;
2622 }
2623
2624 default:
2625 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2626 }
2627}
2628
Calin Juravlebacfec32014-11-14 15:54:36 +00002629void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002630 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002631
2632 // Most remainders are implemented in the runtime.
2633 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002634 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2635 // sdiv will be replaced by other instruction sequence.
2636 call_kind = LocationSummary::kNoCall;
2637 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2638 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002639 // Have hardware divide instruction for int, do it with three instructions.
2640 call_kind = LocationSummary::kNoCall;
2641 }
2642
Calin Juravlebacfec32014-11-14 15:54:36 +00002643 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2644
Calin Juravled2ec87d2014-12-08 14:24:46 +00002645 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002646 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002647 if (rem->InputAt(1)->IsConstant()) {
2648 locations->SetInAt(0, Location::RequiresRegister());
2649 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2650 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2651 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2652 if (abs_imm <= 1) {
2653 // No temp register required.
2654 } else {
2655 locations->AddTemp(Location::RequiresRegister());
2656 if (!IsPowerOfTwo(abs_imm)) {
2657 locations->AddTemp(Location::RequiresRegister());
2658 }
2659 }
2660 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002661 locations->SetInAt(0, Location::RequiresRegister());
2662 locations->SetInAt(1, Location::RequiresRegister());
2663 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2664 locations->AddTemp(Location::RequiresRegister());
2665 } else {
2666 InvokeRuntimeCallingConvention calling_convention;
2667 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2668 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2669 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2670 // we only need the latter.
2671 locations->SetOut(Location::RegisterLocation(R1));
2672 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002673 break;
2674 }
2675 case Primitive::kPrimLong: {
2676 InvokeRuntimeCallingConvention calling_convention;
2677 locations->SetInAt(0, Location::RegisterPairLocation(
2678 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2679 locations->SetInAt(1, Location::RegisterPairLocation(
2680 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2681 // The runtime helper puts the output in R2,R3.
2682 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2683 break;
2684 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002685 case Primitive::kPrimFloat: {
2686 InvokeRuntimeCallingConvention calling_convention;
2687 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2688 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2689 locations->SetOut(Location::FpuRegisterLocation(S0));
2690 break;
2691 }
2692
Calin Juravlebacfec32014-11-14 15:54:36 +00002693 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002694 InvokeRuntimeCallingConvention calling_convention;
2695 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2696 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2697 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2698 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2699 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002700 break;
2701 }
2702
2703 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002704 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002705 }
2706}
2707
2708void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2709 LocationSummary* locations = rem->GetLocations();
2710 Location out = locations->Out();
2711 Location first = locations->InAt(0);
2712 Location second = locations->InAt(1);
2713
Calin Juravled2ec87d2014-12-08 14:24:46 +00002714 Primitive::Type type = rem->GetResultType();
2715 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002716 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002717 if (second.IsConstant()) {
2718 GenerateDivRemConstantIntegral(rem);
2719 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002720 Register reg1 = first.AsRegister<Register>();
2721 Register reg2 = second.AsRegister<Register>();
2722 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002723
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002724 // temp = reg1 / reg2 (integer division)
2725 // temp = temp * reg2
2726 // dest = reg1 - temp
2727 __ sdiv(temp, reg1, reg2);
2728 __ mul(temp, temp, reg2);
2729 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2730 } else {
2731 InvokeRuntimeCallingConvention calling_convention;
2732 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2733 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2734 DCHECK_EQ(R1, out.AsRegister<Register>());
2735
2736 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2737 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002738 break;
2739 }
2740
2741 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002742 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002743 break;
2744 }
2745
Calin Juravled2ec87d2014-12-08 14:24:46 +00002746 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002747 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002748 break;
2749 }
2750
Calin Juravlebacfec32014-11-14 15:54:36 +00002751 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002752 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002753 break;
2754 }
2755
2756 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002757 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002758 }
2759}
2760
Calin Juravled0d48522014-11-04 16:40:20 +00002761void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2762 LocationSummary* locations =
2763 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002764 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002765 if (instruction->HasUses()) {
2766 locations->SetOut(Location::SameAsFirstInput());
2767 }
2768}
2769
2770void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2771 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2772 codegen_->AddSlowPath(slow_path);
2773
2774 LocationSummary* locations = instruction->GetLocations();
2775 Location value = locations->InAt(0);
2776
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002777 switch (instruction->GetType()) {
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002778 case Primitive::kPrimByte:
2779 case Primitive::kPrimChar:
2780 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002781 case Primitive::kPrimInt: {
2782 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002783 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002784 } else {
2785 DCHECK(value.IsConstant()) << value;
2786 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2787 __ b(slow_path->GetEntryLabel());
2788 }
2789 }
2790 break;
2791 }
2792 case Primitive::kPrimLong: {
2793 if (value.IsRegisterPair()) {
2794 __ orrs(IP,
2795 value.AsRegisterPairLow<Register>(),
2796 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2797 __ b(slow_path->GetEntryLabel(), EQ);
2798 } else {
2799 DCHECK(value.IsConstant()) << value;
2800 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2801 __ b(slow_path->GetEntryLabel());
2802 }
2803 }
2804 break;
2805 default:
2806 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2807 }
2808 }
Calin Juravled0d48522014-11-04 16:40:20 +00002809}
2810
Calin Juravle9aec02f2014-11-18 23:06:35 +00002811void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2812 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2813
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002814 LocationSummary* locations =
2815 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002816
2817 switch (op->GetResultType()) {
2818 case Primitive::kPrimInt: {
2819 locations->SetInAt(0, Location::RequiresRegister());
2820 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002821 // Make the output overlap, as it will be used to hold the masked
2822 // second input.
2823 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002824 break;
2825 }
2826 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002827 locations->SetInAt(0, Location::RequiresRegister());
2828 locations->SetInAt(1, Location::RequiresRegister());
2829 locations->AddTemp(Location::RequiresRegister());
2830 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002831 break;
2832 }
2833 default:
2834 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2835 }
2836}
2837
2838void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2839 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2840
2841 LocationSummary* locations = op->GetLocations();
2842 Location out = locations->Out();
2843 Location first = locations->InAt(0);
2844 Location second = locations->InAt(1);
2845
2846 Primitive::Type type = op->GetResultType();
2847 switch (type) {
2848 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002849 Register out_reg = out.AsRegister<Register>();
2850 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002851 // Arm doesn't mask the shift count so we need to do it ourselves.
2852 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002853 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002854 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002855 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002856 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002857 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002858 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002859 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002860 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002861 }
2862 } else {
2863 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2864 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2865 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2866 __ Mov(out_reg, first_reg);
2867 } else if (op->IsShl()) {
2868 __ Lsl(out_reg, first_reg, shift_value);
2869 } else if (op->IsShr()) {
2870 __ Asr(out_reg, first_reg, shift_value);
2871 } else {
2872 __ Lsr(out_reg, first_reg, shift_value);
2873 }
2874 }
2875 break;
2876 }
2877 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002878 Register o_h = out.AsRegisterPairHigh<Register>();
2879 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002880
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002881 Register temp = locations->GetTemp(0).AsRegister<Register>();
2882
2883 Register high = first.AsRegisterPairHigh<Register>();
2884 Register low = first.AsRegisterPairLow<Register>();
2885
2886 Register second_reg = second.AsRegister<Register>();
2887
Calin Juravle9aec02f2014-11-18 23:06:35 +00002888 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002889 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002890 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002891 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002892 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002893 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002894 __ Lsr(temp, low, temp);
2895 __ orr(o_h, o_h, ShifterOperand(temp));
2896 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002897 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002898 __ it(PL);
2899 __ Lsl(o_h, low, temp, false, PL);
2900 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002901 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002902 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002903 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002904 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002905 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002906 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002907 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002908 __ Lsl(temp, high, temp);
2909 __ orr(o_l, o_l, ShifterOperand(temp));
2910 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002911 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002912 __ it(PL);
2913 __ Asr(o_l, high, temp, false, PL);
2914 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002915 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002916 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002917 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002918 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002919 __ Lsr(o_l, low, o_h);
2920 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002921 __ Lsl(temp, high, temp);
2922 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002923 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002924 __ it(PL);
2925 __ Lsr(o_l, high, temp, false, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002926 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002927 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002928 break;
2929 }
2930 default:
2931 LOG(FATAL) << "Unexpected operation type " << type;
2932 }
2933}
2934
2935void LocationsBuilderARM::VisitShl(HShl* shl) {
2936 HandleShift(shl);
2937}
2938
2939void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2940 HandleShift(shl);
2941}
2942
2943void LocationsBuilderARM::VisitShr(HShr* shr) {
2944 HandleShift(shr);
2945}
2946
2947void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2948 HandleShift(shr);
2949}
2950
2951void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2952 HandleShift(ushr);
2953}
2954
2955void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2956 HandleShift(ushr);
2957}
2958
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002959void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002960 LocationSummary* locations =
2961 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002962 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002963 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002964 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002965 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002966}
2967
2968void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2969 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002970 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002971 // Note: if heap poisoning is enabled, the entry point takes cares
2972 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002973 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2974 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002975 instruction->GetDexPc(),
2976 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002977}
2978
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002979void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2980 LocationSummary* locations =
2981 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2982 InvokeRuntimeCallingConvention calling_convention;
2983 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002984 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002985 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002986 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002987}
2988
2989void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2990 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002991 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002992 // Note: if heap poisoning is enabled, the entry point takes cares
2993 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002994 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2995 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002996 instruction->GetDexPc(),
2997 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002998}
2999
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003000void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003001 LocationSummary* locations =
3002 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003003 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3004 if (location.IsStackSlot()) {
3005 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3006 } else if (location.IsDoubleStackSlot()) {
3007 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003008 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003009 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003010}
3011
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003012void InstructionCodeGeneratorARM::VisitParameterValue(
3013 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003014 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003015}
3016
3017void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3018 LocationSummary* locations =
3019 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3020 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3021}
3022
3023void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3024 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003025}
3026
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003027void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003028 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003029 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003030 locations->SetInAt(0, Location::RequiresRegister());
3031 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003032}
3033
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003034void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3035 LocationSummary* locations = not_->GetLocations();
3036 Location out = locations->Out();
3037 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003038 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003039 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003040 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003041 break;
3042
3043 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003044 __ mvn(out.AsRegisterPairLow<Register>(),
3045 ShifterOperand(in.AsRegisterPairLow<Register>()));
3046 __ mvn(out.AsRegisterPairHigh<Register>(),
3047 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003048 break;
3049
3050 default:
3051 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3052 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003053}
3054
David Brazdil66d126e2015-04-03 16:02:44 +01003055void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3056 LocationSummary* locations =
3057 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3058 locations->SetInAt(0, Location::RequiresRegister());
3059 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3060}
3061
3062void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003063 LocationSummary* locations = bool_not->GetLocations();
3064 Location out = locations->Out();
3065 Location in = locations->InAt(0);
3066 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3067}
3068
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003069void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003070 LocationSummary* locations =
3071 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003072 switch (compare->InputAt(0)->GetType()) {
3073 case Primitive::kPrimLong: {
3074 locations->SetInAt(0, Location::RequiresRegister());
3075 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003076 // Output overlaps because it is written before doing the low comparison.
3077 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003078 break;
3079 }
3080 case Primitive::kPrimFloat:
3081 case Primitive::kPrimDouble: {
3082 locations->SetInAt(0, Location::RequiresFpuRegister());
3083 locations->SetInAt(1, Location::RequiresFpuRegister());
3084 locations->SetOut(Location::RequiresRegister());
3085 break;
3086 }
3087 default:
3088 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3089 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003090}
3091
3092void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003093 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003094 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003095 Location left = locations->InAt(0);
3096 Location right = locations->InAt(1);
3097
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003098 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003099 Primitive::Type type = compare->InputAt(0)->GetType();
3100 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003101 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003102 __ cmp(left.AsRegisterPairHigh<Register>(),
3103 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003104 __ b(&less, LT);
3105 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003106 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003107 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003108 __ cmp(left.AsRegisterPairLow<Register>(),
3109 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00003110 break;
3111 }
3112 case Primitive::kPrimFloat:
3113 case Primitive::kPrimDouble: {
3114 __ LoadImmediate(out, 0);
3115 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003116 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00003117 } else {
3118 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
3119 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
3120 }
3121 __ vmstat(); // transfer FP status register to ARM APSR.
3122 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003123 break;
3124 }
3125 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003126 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003127 }
Calin Juravleddb7df22014-11-25 20:56:51 +00003128 __ b(&done, EQ);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003129 __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats.
Calin Juravleddb7df22014-11-25 20:56:51 +00003130
3131 __ Bind(&greater);
3132 __ LoadImmediate(out, 1);
3133 __ b(&done);
3134
3135 __ Bind(&less);
3136 __ LoadImmediate(out, -1);
3137
3138 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003139}
3140
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003141void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003142 LocationSummary* locations =
3143 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003144 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3145 locations->SetInAt(i, Location::Any());
3146 }
3147 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003148}
3149
3150void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003151 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003152 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003153}
3154
Calin Juravle52c48962014-12-16 17:02:57 +00003155void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3156 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07003157 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00003158 switch (kind) {
3159 case MemBarrierKind::kAnyStore:
3160 case MemBarrierKind::kLoadAny:
3161 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003162 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003163 break;
3164 }
3165 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003166 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003167 break;
3168 }
3169 default:
3170 LOG(FATAL) << "Unexpected memory barrier " << kind;
3171 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003172 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003173}
3174
3175void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3176 uint32_t offset,
3177 Register out_lo,
3178 Register out_hi) {
3179 if (offset != 0) {
3180 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003181 __ add(IP, addr, ShifterOperand(out_lo));
3182 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003183 }
3184 __ ldrexd(out_lo, out_hi, addr);
3185}
3186
3187void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3188 uint32_t offset,
3189 Register value_lo,
3190 Register value_hi,
3191 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003192 Register temp2,
3193 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003194 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003195 if (offset != 0) {
3196 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003197 __ add(IP, addr, ShifterOperand(temp1));
3198 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003199 }
3200 __ Bind(&fail);
3201 // We need a load followed by store. (The address used in a STREX instruction must
3202 // be the same as the address in the most recently executed LDREX instruction.)
3203 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003204 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003205 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003206 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003207}
3208
3209void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3210 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3211
Nicolas Geoffray39468442014-09-02 15:17:15 +01003212 LocationSummary* locations =
3213 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003214 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003215
Calin Juravle52c48962014-12-16 17:02:57 +00003216 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003217 if (Primitive::IsFloatingPointType(field_type)) {
3218 locations->SetInAt(1, Location::RequiresFpuRegister());
3219 } else {
3220 locations->SetInAt(1, Location::RequiresRegister());
3221 }
3222
Calin Juravle52c48962014-12-16 17:02:57 +00003223 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003224 bool generate_volatile = field_info.IsVolatile()
3225 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003226 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003227 bool needs_write_barrier =
3228 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003229 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003230 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003231 if (needs_write_barrier) {
3232 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003233 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003234 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003235 // Arm encoding have some additional constraints for ldrexd/strexd:
3236 // - registers need to be consecutive
3237 // - the first register should be even but not R14.
3238 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3239 // enable Arm encoding.
3240 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3241
3242 locations->AddTemp(Location::RequiresRegister());
3243 locations->AddTemp(Location::RequiresRegister());
3244 if (field_type == Primitive::kPrimDouble) {
3245 // For doubles we need two more registers to copy the value.
3246 locations->AddTemp(Location::RegisterLocation(R2));
3247 locations->AddTemp(Location::RegisterLocation(R3));
3248 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003249 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003250}
3251
Calin Juravle52c48962014-12-16 17:02:57 +00003252void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003253 const FieldInfo& field_info,
3254 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003255 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3256
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003257 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003258 Register base = locations->InAt(0).AsRegister<Register>();
3259 Location value = locations->InAt(1);
3260
3261 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003262 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003263 Primitive::Type field_type = field_info.GetFieldType();
3264 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003265 bool needs_write_barrier =
3266 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003267
3268 if (is_volatile) {
3269 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3270 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003271
3272 switch (field_type) {
3273 case Primitive::kPrimBoolean:
3274 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003275 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003276 break;
3277 }
3278
3279 case Primitive::kPrimShort:
3280 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003281 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003282 break;
3283 }
3284
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003285 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003286 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003287 if (kPoisonHeapReferences && needs_write_barrier) {
3288 // Note that in the case where `value` is a null reference,
3289 // we do not enter this block, as a null reference does not
3290 // need poisoning.
3291 DCHECK_EQ(field_type, Primitive::kPrimNot);
3292 Register temp = locations->GetTemp(0).AsRegister<Register>();
3293 __ Mov(temp, value.AsRegister<Register>());
3294 __ PoisonHeapReference(temp);
3295 __ StoreToOffset(kStoreWord, temp, base, offset);
3296 } else {
3297 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3298 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003299 break;
3300 }
3301
3302 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003303 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003304 GenerateWideAtomicStore(base, offset,
3305 value.AsRegisterPairLow<Register>(),
3306 value.AsRegisterPairHigh<Register>(),
3307 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003308 locations->GetTemp(1).AsRegister<Register>(),
3309 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003310 } else {
3311 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003312 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003313 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003314 break;
3315 }
3316
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003317 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003318 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003319 break;
3320 }
3321
3322 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003323 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003324 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003325 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3326 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3327
3328 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3329
3330 GenerateWideAtomicStore(base, offset,
3331 value_reg_lo,
3332 value_reg_hi,
3333 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003334 locations->GetTemp(3).AsRegister<Register>(),
3335 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003336 } else {
3337 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003338 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003339 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003340 break;
3341 }
3342
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003343 case Primitive::kPrimVoid:
3344 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003345 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003346 }
Calin Juravle52c48962014-12-16 17:02:57 +00003347
Calin Juravle77520bc2015-01-12 18:45:46 +00003348 // Longs and doubles are handled in the switch.
3349 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3350 codegen_->MaybeRecordImplicitNullCheck(instruction);
3351 }
3352
3353 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3354 Register temp = locations->GetTemp(0).AsRegister<Register>();
3355 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003356 codegen_->MarkGCCard(
3357 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003358 }
3359
Calin Juravle52c48962014-12-16 17:02:57 +00003360 if (is_volatile) {
3361 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3362 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003363}
3364
Calin Juravle52c48962014-12-16 17:02:57 +00003365void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3366 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003367 LocationSummary* locations =
3368 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003369 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003370
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003371 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003372 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003373 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003374 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003375
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003376 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3377 locations->SetOut(Location::RequiresFpuRegister());
3378 } else {
3379 locations->SetOut(Location::RequiresRegister(),
3380 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3381 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003382 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003383 // Arm encoding have some additional constraints for ldrexd/strexd:
3384 // - registers need to be consecutive
3385 // - the first register should be even but not R14.
3386 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3387 // enable Arm encoding.
3388 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3389 locations->AddTemp(Location::RequiresRegister());
3390 locations->AddTemp(Location::RequiresRegister());
3391 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003392}
3393
Calin Juravle52c48962014-12-16 17:02:57 +00003394void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3395 const FieldInfo& field_info) {
3396 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003397
Calin Juravle52c48962014-12-16 17:02:57 +00003398 LocationSummary* locations = instruction->GetLocations();
3399 Register base = locations->InAt(0).AsRegister<Register>();
3400 Location out = locations->Out();
3401 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003402 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003403 Primitive::Type field_type = field_info.GetFieldType();
3404 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3405
3406 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003407 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003408 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003409 break;
3410 }
3411
3412 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003413 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003414 break;
3415 }
3416
3417 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003418 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003419 break;
3420 }
3421
3422 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003423 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003424 break;
3425 }
3426
3427 case Primitive::kPrimInt:
3428 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003429 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003430 break;
3431 }
3432
3433 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003434 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003435 GenerateWideAtomicLoad(base, offset,
3436 out.AsRegisterPairLow<Register>(),
3437 out.AsRegisterPairHigh<Register>());
3438 } else {
3439 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3440 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003441 break;
3442 }
3443
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003444 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003445 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003446 break;
3447 }
3448
3449 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003450 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003451 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003452 Register lo = locations->GetTemp(0).AsRegister<Register>();
3453 Register hi = locations->GetTemp(1).AsRegister<Register>();
3454 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003455 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003456 __ vmovdrr(out_reg, lo, hi);
3457 } else {
3458 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003459 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003460 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003461 break;
3462 }
3463
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003464 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003465 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003466 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003467 }
Calin Juravle52c48962014-12-16 17:02:57 +00003468
Calin Juravle77520bc2015-01-12 18:45:46 +00003469 // Doubles are handled in the switch.
3470 if (field_type != Primitive::kPrimDouble) {
3471 codegen_->MaybeRecordImplicitNullCheck(instruction);
3472 }
3473
Calin Juravle52c48962014-12-16 17:02:57 +00003474 if (is_volatile) {
3475 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3476 }
Roland Levillain4d027112015-07-01 15:41:14 +01003477
3478 if (field_type == Primitive::kPrimNot) {
3479 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3480 }
Calin Juravle52c48962014-12-16 17:02:57 +00003481}
3482
3483void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3484 HandleFieldSet(instruction, instruction->GetFieldInfo());
3485}
3486
3487void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003488 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003489}
3490
3491void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3492 HandleFieldGet(instruction, instruction->GetFieldInfo());
3493}
3494
3495void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3496 HandleFieldGet(instruction, instruction->GetFieldInfo());
3497}
3498
3499void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3500 HandleFieldGet(instruction, instruction->GetFieldInfo());
3501}
3502
3503void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3504 HandleFieldGet(instruction, instruction->GetFieldInfo());
3505}
3506
3507void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3508 HandleFieldSet(instruction, instruction->GetFieldInfo());
3509}
3510
3511void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003512 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003513}
3514
3515void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003516 LocationSummary* locations =
3517 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003518 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003519 if (instruction->HasUses()) {
3520 locations->SetOut(Location::SameAsFirstInput());
3521 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003522}
3523
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003524void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003525 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3526 return;
3527 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003528 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003529
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003530 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3531 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3532}
3533
3534void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003535 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003536 codegen_->AddSlowPath(slow_path);
3537
3538 LocationSummary* locations = instruction->GetLocations();
3539 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003540
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003541 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003542}
3543
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003544void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3545 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3546 GenerateImplicitNullCheck(instruction);
3547 } else {
3548 GenerateExplicitNullCheck(instruction);
3549 }
3550}
3551
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003552void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003553 LocationSummary* locations =
3554 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003555 locations->SetInAt(0, Location::RequiresRegister());
3556 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003557 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3558 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3559 } else {
3560 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3561 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003562}
3563
3564void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3565 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003566 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003567 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003568 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003569
Roland Levillain4d027112015-07-01 15:41:14 +01003570 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003571 case Primitive::kPrimBoolean: {
3572 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003573 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003574 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003575 size_t offset =
3576 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003577 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3578 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003579 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003580 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3581 }
3582 break;
3583 }
3584
3585 case Primitive::kPrimByte: {
3586 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003587 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003588 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003589 size_t offset =
3590 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003591 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3592 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003593 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003594 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3595 }
3596 break;
3597 }
3598
3599 case Primitive::kPrimShort: {
3600 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003601 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003602 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003603 size_t offset =
3604 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003605 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3606 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003607 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003608 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3609 }
3610 break;
3611 }
3612
3613 case Primitive::kPrimChar: {
3614 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003615 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003616 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003617 size_t offset =
3618 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003619 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3620 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003621 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003622 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3623 }
3624 break;
3625 }
3626
3627 case Primitive::kPrimInt:
3628 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003629 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3630 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003631 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003632 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003633 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003634 size_t offset =
3635 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003636 __ LoadFromOffset(kLoadWord, out, obj, offset);
3637 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003638 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003639 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3640 }
3641 break;
3642 }
3643
3644 case Primitive::kPrimLong: {
3645 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003646 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003647 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003648 size_t offset =
3649 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003650 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003651 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003652 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003653 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003654 }
3655 break;
3656 }
3657
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003658 case Primitive::kPrimFloat: {
3659 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3660 Location out = locations->Out();
3661 DCHECK(out.IsFpuRegister());
3662 if (index.IsConstant()) {
3663 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3664 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3665 } else {
3666 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3667 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3668 }
3669 break;
3670 }
3671
3672 case Primitive::kPrimDouble: {
3673 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3674 Location out = locations->Out();
3675 DCHECK(out.IsFpuRegisterPair());
3676 if (index.IsConstant()) {
3677 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3678 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3679 } else {
3680 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3681 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3682 }
3683 break;
3684 }
3685
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003686 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003687 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003688 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003689 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003690 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003691
3692 if (type == Primitive::kPrimNot) {
3693 Register out = locations->Out().AsRegister<Register>();
3694 __ MaybeUnpoisonHeapReference(out);
3695 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003696}
3697
3698void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003699 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003700
3701 bool needs_write_barrier =
3702 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3703 bool needs_runtime_call = instruction->NeedsTypeCheck();
3704
Nicolas Geoffray39468442014-09-02 15:17:15 +01003705 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003706 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3707 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003708 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003709 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3710 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3711 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003712 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003713 locations->SetInAt(0, Location::RequiresRegister());
3714 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003715 if (Primitive::IsFloatingPointType(value_type)) {
3716 locations->SetInAt(2, Location::RequiresFpuRegister());
3717 } else {
3718 locations->SetInAt(2, Location::RequiresRegister());
3719 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003720
3721 if (needs_write_barrier) {
3722 // Temporary registers for the write barrier.
Roland Levillain4d027112015-07-01 15:41:14 +01003723 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003724 locations->AddTemp(Location::RequiresRegister());
3725 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003726 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003727}
3728
3729void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3730 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003731 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003732 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003733 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003734 bool needs_runtime_call = locations->WillCall();
3735 bool needs_write_barrier =
3736 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003737
3738 switch (value_type) {
3739 case Primitive::kPrimBoolean:
3740 case Primitive::kPrimByte: {
3741 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003742 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003743 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003744 size_t offset =
3745 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003746 __ StoreToOffset(kStoreByte, value, obj, offset);
3747 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003748 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003749 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3750 }
3751 break;
3752 }
3753
3754 case Primitive::kPrimShort:
3755 case Primitive::kPrimChar: {
3756 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003757 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003758 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003759 size_t offset =
3760 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003761 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3762 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003763 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003764 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3765 }
3766 break;
3767 }
3768
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003769 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003770 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003771 if (!needs_runtime_call) {
3772 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003773 Register value = locations->InAt(2).AsRegister<Register>();
Roland Levillain4d027112015-07-01 15:41:14 +01003774 Register source = value;
3775 if (kPoisonHeapReferences && needs_write_barrier) {
3776 // Note that in the case where `value` is a null reference,
3777 // we do not enter this block, as a null reference does not
3778 // need poisoning.
3779 DCHECK_EQ(value_type, Primitive::kPrimNot);
3780 Register temp = locations->GetTemp(0).AsRegister<Register>();
3781 __ Mov(temp, value);
3782 __ PoisonHeapReference(temp);
3783 source = temp;
3784 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003785 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003786 size_t offset =
3787 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillain4d027112015-07-01 15:41:14 +01003788 __ StoreToOffset(kStoreWord, source, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003789 } else {
3790 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003791 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01003792 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003793 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003794 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003795 if (needs_write_barrier) {
3796 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003797 Register temp = locations->GetTemp(0).AsRegister<Register>();
3798 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003799 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003800 }
3801 } else {
3802 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain4d027112015-07-01 15:41:14 +01003803 // Note: if heap poisoning is enabled, pAputObject takes cares
3804 // of poisoning the reference.
Roland Levillain199f3362014-11-27 17:15:16 +00003805 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3806 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003807 instruction->GetDexPc(),
3808 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003809 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003810 break;
3811 }
3812
3813 case Primitive::kPrimLong: {
3814 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003815 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003816 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003817 size_t offset =
3818 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003819 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003820 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003821 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003822 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003823 }
3824 break;
3825 }
3826
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003827 case Primitive::kPrimFloat: {
3828 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3829 Location value = locations->InAt(2);
3830 DCHECK(value.IsFpuRegister());
3831 if (index.IsConstant()) {
3832 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3833 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3834 } else {
3835 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3836 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3837 }
3838 break;
3839 }
3840
3841 case Primitive::kPrimDouble: {
3842 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3843 Location value = locations->InAt(2);
3844 DCHECK(value.IsFpuRegisterPair());
3845 if (index.IsConstant()) {
3846 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3847 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3848 } else {
3849 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3850 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3851 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003852
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003853 break;
3854 }
3855
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003856 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003857 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003858 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003859 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003860
3861 // Ints and objects are handled in the switch.
3862 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3863 codegen_->MaybeRecordImplicitNullCheck(instruction);
3864 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003865}
3866
3867void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003868 LocationSummary* locations =
3869 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003870 locations->SetInAt(0, Location::RequiresRegister());
3871 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003872}
3873
3874void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3875 LocationSummary* locations = instruction->GetLocations();
3876 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003877 Register obj = locations->InAt(0).AsRegister<Register>();
3878 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003879 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003880 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003881}
3882
3883void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003884 LocationSummary* locations =
3885 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003886 locations->SetInAt(0, Location::RequiresRegister());
3887 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003888 if (instruction->HasUses()) {
3889 locations->SetOut(Location::SameAsFirstInput());
3890 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003891}
3892
3893void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3894 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003895 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003896 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003897 codegen_->AddSlowPath(slow_path);
3898
Roland Levillain271ab9c2014-11-27 15:23:57 +00003899 Register index = locations->InAt(0).AsRegister<Register>();
3900 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003901
3902 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01003903 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003904}
3905
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003906void CodeGeneratorARM::MarkGCCard(Register temp,
3907 Register card,
3908 Register object,
3909 Register value,
3910 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003911 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003912 if (can_be_null) {
3913 __ CompareAndBranchIfZero(value, &is_null);
3914 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003915 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3916 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3917 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003918 if (can_be_null) {
3919 __ Bind(&is_null);
3920 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003921}
3922
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003923void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3924 temp->SetLocations(nullptr);
3925}
3926
3927void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3928 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003929 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003930}
3931
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003932void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003933 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003934 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003935}
3936
3937void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003938 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3939}
3940
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003941void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3942 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3943}
3944
3945void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003946 HBasicBlock* block = instruction->GetBlock();
3947 if (block->GetLoopInformation() != nullptr) {
3948 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3949 // The back edge will generate the suspend check.
3950 return;
3951 }
3952 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3953 // The goto will generate the suspend check.
3954 return;
3955 }
3956 GenerateSuspendCheck(instruction, nullptr);
3957}
3958
3959void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3960 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003961 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003962 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3963 if (slow_path == nullptr) {
3964 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3965 instruction->SetSlowPath(slow_path);
3966 codegen_->AddSlowPath(slow_path);
3967 if (successor != nullptr) {
3968 DCHECK(successor->IsLoopHeader());
3969 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3970 }
3971 } else {
3972 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3973 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003974
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003975 __ LoadFromOffset(
3976 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003977 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003978 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003979 __ Bind(slow_path->GetReturnLabel());
3980 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003981 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003982 __ b(slow_path->GetEntryLabel());
3983 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003984}
3985
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003986ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3987 return codegen_->GetAssembler();
3988}
3989
3990void ParallelMoveResolverARM::EmitMove(size_t index) {
3991 MoveOperands* move = moves_.Get(index);
3992 Location source = move->GetSource();
3993 Location destination = move->GetDestination();
3994
3995 if (source.IsRegister()) {
3996 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003997 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003998 } else {
3999 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00004000 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004001 SP, destination.GetStackIndex());
4002 }
4003 } else if (source.IsStackSlot()) {
4004 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004005 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004006 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004007 } else if (destination.IsFpuRegister()) {
4008 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004009 } else {
4010 DCHECK(destination.IsStackSlot());
4011 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
4012 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4013 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004014 } else if (source.IsFpuRegister()) {
4015 if (destination.IsFpuRegister()) {
4016 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004017 } else {
4018 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004019 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
4020 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004021 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004022 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004023 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
4024 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004025 } else if (destination.IsRegisterPair()) {
4026 DCHECK(ExpectedPairLayout(destination));
4027 __ LoadFromOffset(
4028 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
4029 } else {
4030 DCHECK(destination.IsFpuRegisterPair()) << destination;
4031 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4032 SP,
4033 source.GetStackIndex());
4034 }
4035 } else if (source.IsRegisterPair()) {
4036 if (destination.IsRegisterPair()) {
4037 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
4038 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
4039 } else {
4040 DCHECK(destination.IsDoubleStackSlot()) << destination;
4041 DCHECK(ExpectedPairLayout(source));
4042 __ StoreToOffset(
4043 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
4044 }
4045 } else if (source.IsFpuRegisterPair()) {
4046 if (destination.IsFpuRegisterPair()) {
4047 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4048 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
4049 } else {
4050 DCHECK(destination.IsDoubleStackSlot()) << destination;
4051 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
4052 SP,
4053 destination.GetStackIndex());
4054 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004055 } else {
4056 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00004057 HConstant* constant = source.GetConstant();
4058 if (constant->IsIntConstant() || constant->IsNullConstant()) {
4059 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004060 if (destination.IsRegister()) {
4061 __ LoadImmediate(destination.AsRegister<Register>(), value);
4062 } else {
4063 DCHECK(destination.IsStackSlot());
4064 __ LoadImmediate(IP, value);
4065 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4066 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004067 } else if (constant->IsLongConstant()) {
4068 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004069 if (destination.IsRegisterPair()) {
4070 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
4071 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004072 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004073 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004074 __ LoadImmediate(IP, Low32Bits(value));
4075 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4076 __ LoadImmediate(IP, High32Bits(value));
4077 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4078 }
4079 } else if (constant->IsDoubleConstant()) {
4080 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004081 if (destination.IsFpuRegisterPair()) {
4082 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004083 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004084 DCHECK(destination.IsDoubleStackSlot()) << destination;
4085 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004086 __ LoadImmediate(IP, Low32Bits(int_value));
4087 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4088 __ LoadImmediate(IP, High32Bits(int_value));
4089 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4090 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004091 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004092 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004093 float value = constant->AsFloatConstant()->GetValue();
4094 if (destination.IsFpuRegister()) {
4095 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
4096 } else {
4097 DCHECK(destination.IsStackSlot());
4098 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
4099 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4100 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004101 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004102 }
4103}
4104
4105void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
4106 __ Mov(IP, reg);
4107 __ LoadFromOffset(kLoadWord, reg, SP, mem);
4108 __ StoreToOffset(kStoreWord, IP, SP, mem);
4109}
4110
4111void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
4112 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
4113 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
4114 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
4115 SP, mem1 + stack_offset);
4116 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
4117 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
4118 SP, mem2 + stack_offset);
4119 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
4120}
4121
4122void ParallelMoveResolverARM::EmitSwap(size_t index) {
4123 MoveOperands* move = moves_.Get(index);
4124 Location source = move->GetSource();
4125 Location destination = move->GetDestination();
4126
4127 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004128 DCHECK_NE(source.AsRegister<Register>(), IP);
4129 DCHECK_NE(destination.AsRegister<Register>(), IP);
4130 __ Mov(IP, source.AsRegister<Register>());
4131 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
4132 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004133 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004134 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004135 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004136 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004137 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
4138 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004139 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004140 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004141 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004142 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004143 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004144 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004145 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004146 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004147 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
4148 destination.AsRegisterPairHigh<Register>(),
4149 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004150 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004151 Register low_reg = source.IsRegisterPair()
4152 ? source.AsRegisterPairLow<Register>()
4153 : destination.AsRegisterPairLow<Register>();
4154 int mem = source.IsRegisterPair()
4155 ? destination.GetStackIndex()
4156 : source.GetStackIndex();
4157 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004158 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004159 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004160 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004161 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004162 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
4163 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004164 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004165 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004166 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004167 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
4168 DRegister reg = source.IsFpuRegisterPair()
4169 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
4170 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
4171 int mem = source.IsFpuRegisterPair()
4172 ? destination.GetStackIndex()
4173 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004174 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004175 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004176 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004177 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
4178 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
4179 : destination.AsFpuRegister<SRegister>();
4180 int mem = source.IsFpuRegister()
4181 ? destination.GetStackIndex()
4182 : source.GetStackIndex();
4183
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004184 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004185 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004186 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004187 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004188 Exchange(source.GetStackIndex(), destination.GetStackIndex());
4189 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004190 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004191 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004192 }
4193}
4194
4195void ParallelMoveResolverARM::SpillScratch(int reg) {
4196 __ Push(static_cast<Register>(reg));
4197}
4198
4199void ParallelMoveResolverARM::RestoreScratch(int reg) {
4200 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004201}
4202
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004203void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004204 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
4205 ? LocationSummary::kCallOnSlowPath
4206 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004207 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004208 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004209 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004210 locations->SetOut(Location::RequiresRegister());
4211}
4212
4213void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004214 LocationSummary* locations = cls->GetLocations();
4215 Register out = locations->Out().AsRegister<Register>();
4216 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004217 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004218 DCHECK(!cls->CanCallRuntime());
4219 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004220 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004221 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004222 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004223 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004224 __ LoadFromOffset(kLoadWord,
4225 out,
4226 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004227 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004228 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004229 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004230
4231 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4232 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4233 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004234 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004235 if (cls->MustGenerateClinitCheck()) {
4236 GenerateClassInitializationCheck(slow_path, out);
4237 } else {
4238 __ Bind(slow_path->GetExitLabel());
4239 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004240 }
4241}
4242
4243void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4244 LocationSummary* locations =
4245 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4246 locations->SetInAt(0, Location::RequiresRegister());
4247 if (check->HasUses()) {
4248 locations->SetOut(Location::SameAsFirstInput());
4249 }
4250}
4251
4252void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004253 // We assume the class is not null.
4254 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4255 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004256 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004257 GenerateClassInitializationCheck(slow_path,
4258 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004259}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004260
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004261void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4262 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004263 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4264 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4265 __ b(slow_path->GetEntryLabel(), LT);
4266 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4267 // properly. Therefore, we do a memory fence.
4268 __ dmb(ISH);
4269 __ Bind(slow_path->GetExitLabel());
4270}
4271
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004272void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4273 LocationSummary* locations =
4274 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004275 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004276 locations->SetOut(Location::RequiresRegister());
4277}
4278
4279void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4280 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4281 codegen_->AddSlowPath(slow_path);
4282
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004283 LocationSummary* locations = load->GetLocations();
4284 Register out = locations->Out().AsRegister<Register>();
4285 Register current_method = locations->InAt(0).AsRegister<Register>();
4286 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004287 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004288 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Roland Levillain4d027112015-07-01 15:41:14 +01004289 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004290 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004291 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004292 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004293 __ Bind(slow_path->GetExitLabel());
4294}
4295
David Brazdilcb1c0552015-08-04 16:22:25 +01004296static int32_t GetExceptionTlsOffset() {
4297 return Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4298}
4299
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004300void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4301 LocationSummary* locations =
4302 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4303 locations->SetOut(Location::RequiresRegister());
4304}
4305
4306void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004307 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01004308 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4309}
4310
4311void LocationsBuilderARM::VisitClearException(HClearException* clear) {
4312 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4313}
4314
4315void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004316 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01004317 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004318}
4319
4320void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4321 LocationSummary* locations =
4322 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4323 InvokeRuntimeCallingConvention calling_convention;
4324 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4325}
4326
4327void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4328 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004329 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004330}
4331
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004332void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004333 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4334 ? LocationSummary::kNoCall
4335 : LocationSummary::kCallOnSlowPath;
4336 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4337 locations->SetInAt(0, Location::RequiresRegister());
4338 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004339 // The out register is used as a temporary, so it overlaps with the inputs.
4340 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004341}
4342
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004343void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004344 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004345 Register obj = locations->InAt(0).AsRegister<Register>();
4346 Register cls = locations->InAt(1).AsRegister<Register>();
4347 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004348 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004349 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004350 SlowPathCodeARM* slow_path = nullptr;
4351
4352 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004353 // avoid null check if we know obj is not null.
4354 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004355 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004356 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004357 // Compare the class of `obj` with `cls`.
4358 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004359 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004360 __ cmp(out, ShifterOperand(cls));
4361 if (instruction->IsClassFinal()) {
4362 // Classes must be equal for the instanceof to succeed.
4363 __ b(&zero, NE);
4364 __ LoadImmediate(out, 1);
4365 __ b(&done);
4366 } else {
4367 // If the classes are not equal, we go into a slow path.
4368 DCHECK(locations->OnlyCallsOnSlowPath());
4369 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004370 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004371 codegen_->AddSlowPath(slow_path);
4372 __ b(slow_path->GetEntryLabel(), NE);
4373 __ LoadImmediate(out, 1);
4374 __ b(&done);
4375 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004376
4377 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4378 __ Bind(&zero);
4379 __ LoadImmediate(out, 0);
4380 }
4381
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004382 if (slow_path != nullptr) {
4383 __ Bind(slow_path->GetExitLabel());
4384 }
4385 __ Bind(&done);
4386}
4387
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004388void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4389 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4390 instruction, LocationSummary::kCallOnSlowPath);
4391 locations->SetInAt(0, Location::RequiresRegister());
4392 locations->SetInAt(1, Location::RequiresRegister());
4393 locations->AddTemp(Location::RequiresRegister());
4394}
4395
4396void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4397 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004398 Register obj = locations->InAt(0).AsRegister<Register>();
4399 Register cls = locations->InAt(1).AsRegister<Register>();
4400 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004401 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4402
4403 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4404 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4405 codegen_->AddSlowPath(slow_path);
4406
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004407 // avoid null check if we know obj is not null.
4408 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004409 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004410 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004411 // Compare the class of `obj` with `cls`.
4412 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004413 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004414 __ cmp(temp, ShifterOperand(cls));
Roland Levillain4d027112015-07-01 15:41:14 +01004415 // The checkcast succeeds if the classes are equal (fast path).
4416 // Otherwise, we need to go into the slow path to check the types.
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004417 __ b(slow_path->GetEntryLabel(), NE);
4418 __ Bind(slow_path->GetExitLabel());
4419}
4420
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004421void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4422 LocationSummary* locations =
4423 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4424 InvokeRuntimeCallingConvention calling_convention;
4425 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4426}
4427
4428void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4429 codegen_->InvokeRuntime(instruction->IsEnter()
4430 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4431 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004432 instruction->GetDexPc(),
4433 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004434}
4435
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004436void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4437void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4438void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4439
4440void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4441 LocationSummary* locations =
4442 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4443 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4444 || instruction->GetResultType() == Primitive::kPrimLong);
4445 locations->SetInAt(0, Location::RequiresRegister());
4446 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004447 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004448}
4449
4450void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4451 HandleBitwiseOperation(instruction);
4452}
4453
4454void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4455 HandleBitwiseOperation(instruction);
4456}
4457
4458void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4459 HandleBitwiseOperation(instruction);
4460}
4461
4462void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4463 LocationSummary* locations = instruction->GetLocations();
4464
4465 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004466 Register first = locations->InAt(0).AsRegister<Register>();
4467 Register second = locations->InAt(1).AsRegister<Register>();
4468 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004469 if (instruction->IsAnd()) {
4470 __ and_(out, first, ShifterOperand(second));
4471 } else if (instruction->IsOr()) {
4472 __ orr(out, first, ShifterOperand(second));
4473 } else {
4474 DCHECK(instruction->IsXor());
4475 __ eor(out, first, ShifterOperand(second));
4476 }
4477 } else {
4478 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4479 Location first = locations->InAt(0);
4480 Location second = locations->InAt(1);
4481 Location out = locations->Out();
4482 if (instruction->IsAnd()) {
4483 __ and_(out.AsRegisterPairLow<Register>(),
4484 first.AsRegisterPairLow<Register>(),
4485 ShifterOperand(second.AsRegisterPairLow<Register>()));
4486 __ and_(out.AsRegisterPairHigh<Register>(),
4487 first.AsRegisterPairHigh<Register>(),
4488 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4489 } else if (instruction->IsOr()) {
4490 __ orr(out.AsRegisterPairLow<Register>(),
4491 first.AsRegisterPairLow<Register>(),
4492 ShifterOperand(second.AsRegisterPairLow<Register>()));
4493 __ orr(out.AsRegisterPairHigh<Register>(),
4494 first.AsRegisterPairHigh<Register>(),
4495 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4496 } else {
4497 DCHECK(instruction->IsXor());
4498 __ eor(out.AsRegisterPairLow<Register>(),
4499 first.AsRegisterPairLow<Register>(),
4500 ShifterOperand(second.AsRegisterPairLow<Register>()));
4501 __ eor(out.AsRegisterPairHigh<Register>(),
4502 first.AsRegisterPairHigh<Register>(),
4503 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4504 }
4505 }
4506}
4507
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004508void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004509 // TODO: Implement all kinds of calls:
4510 // 1) boot -> boot
4511 // 2) app -> boot
4512 // 3) app -> app
4513 //
4514 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4515
Jeff Hao848f70a2014-01-15 13:49:50 -08004516 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004517 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004518 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004519 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004520 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004521 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004522 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004523 kArmWordSize).Int32Value());
4524 // LR()
4525 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004526 } else if (invoke->IsRecursive()) {
4527 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004528 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004529 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4530 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004531 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004532 if (current_method.IsRegister()) {
4533 method_reg = current_method.AsRegister<Register>();
4534 } else {
4535 DCHECK(invoke->GetLocations()->Intrinsified());
4536 DCHECK(!current_method.IsValid());
4537 method_reg = reg;
4538 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4539 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004540 // reg = current_method->dex_cache_resolved_methods_;
4541 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004542 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004543 // reg = reg[index_in_cache]
4544 __ LoadFromOffset(
4545 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4546 // LR = reg[offset_of_quick_compiled_code]
4547 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4548 kArmWordSize).Int32Value());
4549 // LR()
4550 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004551 }
4552
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004553 DCHECK(!IsLeafMethod());
4554}
4555
Calin Juravleb1498f62015-02-16 13:13:29 +00004556void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4557 // Nothing to do, this should be removed during prepare for register allocator.
4558 UNUSED(instruction);
4559 LOG(FATAL) << "Unreachable";
4560}
4561
4562void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4563 // Nothing to do, this should be removed during prepare for register allocator.
4564 UNUSED(instruction);
4565 LOG(FATAL) << "Unreachable";
4566}
4567
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01004568void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
4569 DCHECK(codegen_->IsBaseline());
4570 LocationSummary* locations =
4571 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4572 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
4573}
4574
4575void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
4576 DCHECK(codegen_->IsBaseline());
4577 // Will be generated at use site.
4578}
4579
Roland Levillain4d027112015-07-01 15:41:14 +01004580#undef __
4581#undef QUICK_ENTRY_POINT
4582
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004583} // namespace arm
4584} // namespace art