blob: 123f6907633e2847bcbac7e6905712af9bd33b2d [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"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070020#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010021#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080022#include "intrinsics.h"
23#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070024#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000025#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010026#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070027#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010028#include "utils/arm/assembler_arm.h"
29#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000030#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010031#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000032
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace arm {
36
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000037static bool ExpectedPairLayout(Location location) {
38 // We expected this for both core and fpu register pairs.
39 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
40}
41
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010042static constexpr int kCurrentMethodStackOffset = 0;
43
Calin Juravled6fb6cf2014-11-11 19:07:44 +000044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010045static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
Calin Juravled2ec87d2014-12-08 14:24:46 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000048static constexpr size_t kRuntimeParameterFpuRegistersLength =
49 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000050// We unconditionally allocate R5 to ensure we can do long operations
51// with baseline.
52static constexpr Register kCoreSavedRegisterForBaseline = R5;
53static constexpr Register kCoreCalleeSaves[] =
54 { R5, R6, R7, R8, R10, R11, PC };
55static constexpr SRegister kFpuCalleeSaves[] =
56 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010057
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000058// D31 cannot be split into two S registers, and the register allocator only works on
59// S registers. Therefore there is no need to block it.
60static constexpr DRegister DTMP = D31;
61
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000062class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010063 public:
64 InvokeRuntimeCallingConvention()
65 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010066 kRuntimeParameterCoreRegistersLength,
67 kRuntimeParameterFpuRegisters,
68 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010069
70 private:
71 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
72};
73
Nicolas Geoffraye5038322014-07-04 09:41:32 +010074#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010075#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010076
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010077class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010078 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010079 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080
Alexandre Rames67555f72014-11-18 10:55:16 +000081 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010082 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010083 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010084 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000085 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086 }
87
88 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010089 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010090 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
91};
92
Calin Juravled0d48522014-11-04 16:40:20 +000093class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
94 public:
95 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
96
Alexandre Rames67555f72014-11-18 10:55:16 +000097 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000098 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
99 __ Bind(GetEntryLabel());
100 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000101 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +0000102 }
103
104 private:
105 HDivZeroCheck* const instruction_;
106 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
107};
108
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100109class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000110 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000111 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100112 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000113
Alexandre Rames67555f72014-11-18 10:55:16 +0000114 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000117 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100118 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000119 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000120 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121 if (successor_ == nullptr) {
122 __ b(GetReturnLabel());
123 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100124 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 }
127
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100128 Label* GetReturnLabel() {
129 DCHECK(successor_ == nullptr);
130 return &return_label_;
131 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132
133 private:
134 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100135 // If not null, the block to branch to after the suspend check.
136 HBasicBlock* const successor_;
137
138 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000139 Label return_label_;
140
141 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
142};
143
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100144class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100145 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100146 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
147 Location index_location,
148 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100149 : instruction_(instruction),
150 index_location_(index_location),
151 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152
Alexandre Rames67555f72014-11-18 10:55:16 +0000153 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100154 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000156 // We're moving two locations to locations that could overlap, so we need a parallel
157 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100158 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000159 codegen->EmitParallelMoves(
160 index_location_,
161 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
162 length_location_,
163 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100164 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000165 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100166 }
167
168 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100169 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100170 const Location index_location_;
171 const Location length_location_;
172
173 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
174};
175
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000176class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100177 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000178 LoadClassSlowPathARM(HLoadClass* cls,
179 HInstruction* at,
180 uint32_t dex_pc,
181 bool do_clinit)
182 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
183 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
184 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100185
Alexandre Rames67555f72014-11-18 10:55:16 +0000186 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000187 LocationSummary* locations = at_->GetLocations();
188
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100189 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
190 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000191 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100192
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100193 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100195 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000196 int32_t entry_point_offset = do_clinit_
197 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
198 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000199 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200
201 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000202 Location out = locations->Out();
203 if (out.IsValid()) {
204 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000205 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
206 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000207 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208 __ b(GetExitLabel());
209 }
210
211 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 // The class this slow path will load.
213 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100214
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000215 // The instruction where this slow path is happening.
216 // (Might be the load class or an initialization check).
217 HInstruction* const at_;
218
219 // The dex PC of `at_`.
220 const uint32_t dex_pc_;
221
222 // Whether to initialize the class.
223 const bool do_clinit_;
224
225 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100226};
227
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000228class LoadStringSlowPathARM : public SlowPathCodeARM {
229 public:
230 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
231
Alexandre Rames67555f72014-11-18 10:55:16 +0000232 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000233 LocationSummary* locations = instruction_->GetLocations();
234 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
235
236 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
237 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000238 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000239
240 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800241 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
242 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000243 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000244 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000245 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
246
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000247 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000248 __ b(GetExitLabel());
249 }
250
251 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)),
283 object_class_,
284 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000286 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000287 arm_codegen->InvokeRuntime(
288 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000289 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
290 } else {
291 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000292 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000293 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000294
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000295 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000296 __ b(GetExitLabel());
297 }
298
299 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000300 HInstruction* const instruction_;
301 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000302 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000303 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000304
305 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
306};
307
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000308#undef __
309
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100310#undef __
311#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700312
313inline Condition ARMCondition(IfCondition cond) {
314 switch (cond) {
315 case kCondEQ: return EQ;
316 case kCondNE: return NE;
317 case kCondLT: return LT;
318 case kCondLE: return LE;
319 case kCondGT: return GT;
320 case kCondGE: return GE;
321 default:
322 LOG(FATAL) << "Unknown if condition";
323 }
324 return EQ; // Unreachable.
325}
326
327inline Condition ARMOppositeCondition(IfCondition cond) {
328 switch (cond) {
329 case kCondEQ: return NE;
330 case kCondNE: return EQ;
331 case kCondLT: return GE;
332 case kCondLE: return GT;
333 case kCondGT: return LE;
334 case kCondGE: return LT;
335 default:
336 LOG(FATAL) << "Unknown if condition";
337 }
338 return EQ; // Unreachable.
339}
340
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100341void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
342 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
343}
344
345void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000346 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100347}
348
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100349size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
350 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
351 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100352}
353
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100354size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
355 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
356 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100357}
358
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000359size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
360 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
361 return kArmWordSize;
362}
363
364size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
365 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
366 return kArmWordSize;
367}
368
Calin Juravle34166012014-12-19 17:22:29 +0000369CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000370 const ArmInstructionSetFeatures& isa_features,
371 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000372 : CodeGenerator(graph,
373 kNumberOfCoreRegisters,
374 kNumberOfSRegisters,
375 kNumberOfRegisterPairs,
376 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
377 arraysize(kCoreCalleeSaves)),
378 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
379 arraysize(kFpuCalleeSaves)),
380 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100381 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100382 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100383 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100384 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000385 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000386 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000387 // Save the PC register to mimic Quick.
388 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100389}
390
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100391Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 switch (type) {
393 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100394 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100395 ArmManagedRegister pair =
396 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100397 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
398 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
399
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100400 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
401 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100402 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100403 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 }
405
406 case Primitive::kPrimByte:
407 case Primitive::kPrimBoolean:
408 case Primitive::kPrimChar:
409 case Primitive::kPrimShort:
410 case Primitive::kPrimInt:
411 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100412 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100413 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100414 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
415 ArmManagedRegister current =
416 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
417 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100418 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100419 }
420 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100421 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100422 }
423
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000424 case Primitive::kPrimFloat: {
425 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100426 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100427 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100428
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000429 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000430 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
431 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000432 return Location::FpuRegisterPairLocation(reg, reg + 1);
433 }
434
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100435 case Primitive::kPrimVoid:
436 LOG(FATAL) << "Unreachable type " << type;
437 }
438
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100439 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440}
441
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000442void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100443 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100444 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100445
446 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100447 blocked_core_registers_[SP] = true;
448 blocked_core_registers_[LR] = true;
449 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100450
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100451 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100452 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100453
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100454 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100455 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100456
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000457 if (is_baseline) {
458 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
459 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
460 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000461
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000462 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
463
464 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
465 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
466 }
467 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100468
469 UpdateBlockedPairRegisters();
470}
471
472void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
473 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
474 ArmManagedRegister current =
475 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
476 if (blocked_core_registers_[current.AsRegisterPairLow()]
477 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
478 blocked_register_pairs_[i] = true;
479 }
480 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100481}
482
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100483InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
484 : HGraphVisitor(graph),
485 assembler_(codegen->GetAssembler()),
486 codegen_(codegen) {}
487
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000488static uint32_t LeastSignificantBit(uint32_t mask) {
489 // ffs starts at 1.
490 return ffs(mask) - 1;
491}
492
493void CodeGeneratorARM::ComputeSpillMask() {
494 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000495 // Save one extra register for baseline. Note that on thumb2, there is no easy
496 // instruction to restore just the PC, so this actually helps both baseline
497 // and non-baseline to save and restore at least two registers at entry and exit.
498 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000499 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
500 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
501 // We use vpush and vpop for saving and restoring floating point registers, which take
502 // a SRegister and the number of registers to save/restore after that SRegister. We
503 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
504 // but in the range.
505 if (fpu_spill_mask_ != 0) {
506 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
507 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
508 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
509 fpu_spill_mask_ |= (1 << i);
510 }
511 }
512}
513
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000514void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000515 bool skip_overflow_check =
516 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000517 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000518 __ Bind(&frame_entry_label_);
519
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000520 if (HasEmptyFrame()) {
521 return;
522 }
523
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100524 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000525 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
526 __ LoadFromOffset(kLoadWord, IP, IP, 0);
527 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100528 }
529
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000530 // PC is in the list of callee-save to mimic Quick, but we need to push
531 // LR at entry instead.
532 __ PushList((core_spill_mask_ & (~(1 << PC))) | 1 << LR);
533 if (fpu_spill_mask_ != 0) {
534 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
535 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
536 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000537 __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize()));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100538 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000539}
540
541void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000542 if (HasEmptyFrame()) {
543 __ bx(LR);
544 return;
545 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000546 __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000547 if (fpu_spill_mask_ != 0) {
548 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
549 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
550 }
551 __ PopList(core_spill_mask_);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000552}
553
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100554void CodeGeneratorARM::Bind(HBasicBlock* block) {
555 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000556}
557
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100558Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
559 switch (load->GetType()) {
560 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100561 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100562 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
563 break;
564
565 case Primitive::kPrimInt:
566 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100567 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100568 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100569
570 case Primitive::kPrimBoolean:
571 case Primitive::kPrimByte:
572 case Primitive::kPrimChar:
573 case Primitive::kPrimShort:
574 case Primitive::kPrimVoid:
575 LOG(FATAL) << "Unexpected type " << load->GetType();
576 }
577
578 LOG(FATAL) << "Unreachable";
579 return Location();
580}
581
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100582Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
583 switch (type) {
584 case Primitive::kPrimBoolean:
585 case Primitive::kPrimByte:
586 case Primitive::kPrimChar:
587 case Primitive::kPrimShort:
588 case Primitive::kPrimInt:
589 case Primitive::kPrimNot: {
590 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000591 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100592 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100593 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100594 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000595 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100596 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100597 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100598
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000599 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100600 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000601 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100602 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000603 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100604 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000605 if (calling_convention.GetRegisterAt(index) == R1) {
606 // Skip R1, and use R2_R3 instead.
607 gp_index_++;
608 index++;
609 }
610 }
611 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
612 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000613 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000614 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000615 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100616 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000617 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
618 }
619 }
620
621 case Primitive::kPrimFloat: {
622 uint32_t stack_index = stack_index_++;
623 if (float_index_ % 2 == 0) {
624 float_index_ = std::max(double_index_, float_index_);
625 }
626 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
627 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
628 } else {
629 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
630 }
631 }
632
633 case Primitive::kPrimDouble: {
634 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
635 uint32_t stack_index = stack_index_;
636 stack_index_ += 2;
637 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
638 uint32_t index = double_index_;
639 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000640 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000641 calling_convention.GetFpuRegisterAt(index),
642 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000643 DCHECK(ExpectedPairLayout(result));
644 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000645 } else {
646 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100647 }
648 }
649
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100650 case Primitive::kPrimVoid:
651 LOG(FATAL) << "Unexpected parameter type " << type;
652 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100653 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100654 return Location();
655}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100656
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000657Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
658 switch (type) {
659 case Primitive::kPrimBoolean:
660 case Primitive::kPrimByte:
661 case Primitive::kPrimChar:
662 case Primitive::kPrimShort:
663 case Primitive::kPrimInt:
664 case Primitive::kPrimNot: {
665 return Location::RegisterLocation(R0);
666 }
667
668 case Primitive::kPrimFloat: {
669 return Location::FpuRegisterLocation(S0);
670 }
671
672 case Primitive::kPrimLong: {
673 return Location::RegisterPairLocation(R0, R1);
674 }
675
676 case Primitive::kPrimDouble: {
677 return Location::FpuRegisterPairLocation(S0, S1);
678 }
679
680 case Primitive::kPrimVoid:
681 return Location();
682 }
683 UNREACHABLE();
684 return Location();
685}
686
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100687void CodeGeneratorARM::Move32(Location destination, Location source) {
688 if (source.Equals(destination)) {
689 return;
690 }
691 if (destination.IsRegister()) {
692 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000693 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100694 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000695 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100696 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000697 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100698 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100699 } else if (destination.IsFpuRegister()) {
700 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000701 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100702 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000703 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100704 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000705 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100706 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100707 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000708 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100709 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000710 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100711 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000712 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100713 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000714 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100715 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
716 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100717 }
718 }
719}
720
721void CodeGeneratorARM::Move64(Location destination, Location source) {
722 if (source.Equals(destination)) {
723 return;
724 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100725 if (destination.IsRegisterPair()) {
726 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000727 EmitParallelMoves(
728 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
729 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
730 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
731 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100732 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000733 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100734 } else {
735 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000736 DCHECK(ExpectedPairLayout(destination));
737 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
738 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100739 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000740 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100741 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000742 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
743 SP,
744 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100745 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000746 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100747 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100748 } else {
749 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100750 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000751 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100752 if (source.AsRegisterPairLow<Register>() == R1) {
753 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100754 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
755 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100756 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100757 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100758 SP, destination.GetStackIndex());
759 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000760 } else if (source.IsFpuRegisterPair()) {
761 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
762 SP,
763 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100764 } else {
765 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000766 EmitParallelMoves(
767 Location::StackSlot(source.GetStackIndex()),
768 Location::StackSlot(destination.GetStackIndex()),
769 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
770 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100771 }
772 }
773}
774
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100775void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100776 LocationSummary* locations = instruction->GetLocations();
777 if (locations != nullptr && locations->Out().Equals(location)) {
778 return;
779 }
780
Calin Juravlea21f5982014-11-13 15:53:04 +0000781 if (locations != nullptr && locations->Out().IsConstant()) {
782 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000783 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
784 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000785 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000786 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000787 } else {
788 DCHECK(location.IsStackSlot());
789 __ LoadImmediate(IP, value);
790 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
791 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000792 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000793 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000794 int64_t value = const_to_move->AsLongConstant()->GetValue();
795 if (location.IsRegisterPair()) {
796 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
797 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
798 } else {
799 DCHECK(location.IsDoubleStackSlot());
800 __ LoadImmediate(IP, Low32Bits(value));
801 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
802 __ LoadImmediate(IP, High32Bits(value));
803 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
804 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100805 }
Roland Levillain476df552014-10-09 17:51:36 +0100806 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100807 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
808 switch (instruction->GetType()) {
809 case Primitive::kPrimBoolean:
810 case Primitive::kPrimByte:
811 case Primitive::kPrimChar:
812 case Primitive::kPrimShort:
813 case Primitive::kPrimInt:
814 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100815 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100816 Move32(location, Location::StackSlot(stack_slot));
817 break;
818
819 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100820 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100821 Move64(location, Location::DoubleStackSlot(stack_slot));
822 break;
823
824 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100825 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100826 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000827 } else if (instruction->IsTemporary()) {
828 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000829 if (temp_location.IsStackSlot()) {
830 Move32(location, temp_location);
831 } else {
832 DCHECK(temp_location.IsDoubleStackSlot());
833 Move64(location, temp_location);
834 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000835 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100836 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100837 switch (instruction->GetType()) {
838 case Primitive::kPrimBoolean:
839 case Primitive::kPrimByte:
840 case Primitive::kPrimChar:
841 case Primitive::kPrimShort:
842 case Primitive::kPrimNot:
843 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100844 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100845 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100846 break;
847
848 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100849 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100850 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100851 break;
852
853 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100854 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100855 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000856 }
857}
858
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100859void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
860 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000861 uint32_t dex_pc,
862 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100863 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
864 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000865 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100866 DCHECK(instruction->IsSuspendCheck()
867 || instruction->IsBoundsCheck()
868 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000869 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000870 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100871 || !IsLeafMethod());
872}
873
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000874void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000875 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000876}
877
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000878void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000879 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100880 DCHECK(!successor->IsExitBlock());
881
882 HBasicBlock* block = got->GetBlock();
883 HInstruction* previous = got->GetPrevious();
884
885 HLoopInformation* info = block->GetLoopInformation();
886 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
887 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
888 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
889 return;
890 }
891
892 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
893 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
894 }
895 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000896 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000897 }
898}
899
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000900void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000901 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000902}
903
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000904void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700905 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000906 if (kIsDebugBuild) {
907 __ Comment("Unreachable");
908 __ bkpt(0);
909 }
910}
911
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000912void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100913 LocationSummary* locations =
914 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100915 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100916 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100917 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100918 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000919}
920
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000921void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700922 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100923 if (cond->IsIntConstant()) {
924 // Constant condition, statically compared against 1.
925 int32_t cond_value = cond->AsIntConstant()->GetValue();
926 if (cond_value == 1) {
927 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
928 if_instr->IfTrueSuccessor())) {
929 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100930 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100931 return;
932 } else {
933 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100934 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100935 } else {
936 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
937 // Condition has been materialized, compare the output to 0
938 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000939 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100940 ShifterOperand(0));
941 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
942 } else {
943 // Condition has not been materialized, use its inputs as the
944 // comparison and its condition as the branch condition.
945 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000946 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000947 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100948 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000949 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100950 } else {
951 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000952 HConstant* constant = locations->InAt(1).GetConstant();
953 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100954 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000955 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
956 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100957 } else {
958 Register temp = IP;
959 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000960 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100961 }
962 }
963 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
964 ARMCondition(cond->AsCondition()->GetCondition()));
965 }
Dave Allison20dfc792014-06-16 20:44:29 -0700966 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100967 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
968 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700969 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000970 }
971}
972
Dave Allison20dfc792014-06-16 20:44:29 -0700973
974void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100975 LocationSummary* locations =
976 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100977 locations->SetInAt(0, Location::RequiresRegister());
978 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100979 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100980 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100981 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000982}
983
Dave Allison20dfc792014-06-16 20:44:29 -0700984void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100985 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100986 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000987 Register left = locations->InAt(0).AsRegister<Register>();
988
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100989 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000990 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100991 } else {
992 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -0800993 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100994 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000995 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
996 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 } else {
998 Register temp = IP;
999 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001000 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001001 }
Dave Allison20dfc792014-06-16 20:44:29 -07001002 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001003 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001004 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001005 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001006 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001007 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001008}
1009
1010void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1011 VisitCondition(comp);
1012}
1013
1014void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1015 VisitCondition(comp);
1016}
1017
1018void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1019 VisitCondition(comp);
1020}
1021
1022void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1023 VisitCondition(comp);
1024}
1025
1026void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1027 VisitCondition(comp);
1028}
1029
1030void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1031 VisitCondition(comp);
1032}
1033
1034void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1035 VisitCondition(comp);
1036}
1037
1038void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1039 VisitCondition(comp);
1040}
1041
1042void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1043 VisitCondition(comp);
1044}
1045
1046void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1047 VisitCondition(comp);
1048}
1049
1050void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1051 VisitCondition(comp);
1052}
1053
1054void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1055 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001056}
1057
1058void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001059 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001060}
1061
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001062void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1063 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001064}
1065
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001066void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001067 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001068}
1069
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001070void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001071 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001072 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001073}
1074
1075void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001076 LocationSummary* locations =
1077 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001078 switch (store->InputAt(1)->GetType()) {
1079 case Primitive::kPrimBoolean:
1080 case Primitive::kPrimByte:
1081 case Primitive::kPrimChar:
1082 case Primitive::kPrimShort:
1083 case Primitive::kPrimInt:
1084 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001085 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001086 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1087 break;
1088
1089 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001090 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001091 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1092 break;
1093
1094 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001095 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001096 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001097}
1098
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001099void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001100 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001101}
1102
1103void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001104 LocationSummary* locations =
1105 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001106 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001107}
1108
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001109void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001110 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001111 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001112}
1113
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001114void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1115 LocationSummary* locations =
1116 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1117 locations->SetOut(Location::ConstantLocation(constant));
1118}
1119
1120void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1121 // Will be generated at use site.
1122 UNUSED(constant);
1123}
1124
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001125void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001126 LocationSummary* locations =
1127 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001128 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001129}
1130
1131void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1132 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001133 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001134}
1135
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001136void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1137 LocationSummary* locations =
1138 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1139 locations->SetOut(Location::ConstantLocation(constant));
1140}
1141
1142void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1143 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001144 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001145}
1146
1147void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1148 LocationSummary* locations =
1149 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1150 locations->SetOut(Location::ConstantLocation(constant));
1151}
1152
1153void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1154 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001155 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001156}
1157
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001158void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001159 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001160}
1161
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001162void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001163 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001164 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001165}
1166
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001167void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001168 LocationSummary* locations =
1169 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001170 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001171}
1172
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001173void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001174 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001175 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001176}
1177
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001178void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001179 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1180 codegen_->GetInstructionSetFeatures());
1181 if (intrinsic.TryDispatch(invoke)) {
1182 return;
1183 }
1184
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001185 HandleInvoke(invoke);
1186}
1187
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001188void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001189 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001190 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001191}
1192
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001193static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1194 if (invoke->GetLocations()->Intrinsified()) {
1195 IntrinsicCodeGeneratorARM intrinsic(codegen);
1196 intrinsic.Dispatch(invoke);
1197 return true;
1198 }
1199 return false;
1200}
1201
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001202void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001203 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1204 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001205 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001206
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001207 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1208
1209 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001210 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001211}
1212
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001213void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001214 LocationSummary* locations =
1215 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001216 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001217
1218 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001219 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001220 HInstruction* input = invoke->InputAt(i);
1221 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1222 }
1223
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001224 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001225}
1226
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001227void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001228 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1229 codegen_->GetInstructionSetFeatures());
1230 if (intrinsic.TryDispatch(invoke)) {
1231 return;
1232 }
1233
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001234 HandleInvoke(invoke);
1235}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001236
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001237void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001238 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1239 return;
1240 }
1241
Roland Levillain271ab9c2014-11-27 15:23:57 +00001242 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001243 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1244 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1245 LocationSummary* locations = invoke->GetLocations();
1246 Location receiver = locations->InAt(0);
1247 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1248 // temp = object->GetClass();
1249 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001250 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1251 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001252 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001253 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001254 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001255 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001256 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001257 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001258 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001259 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001260 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001261 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001262 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001263 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001264 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001265 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001266}
1267
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001268void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1269 HandleInvoke(invoke);
1270 // Add the hidden argument.
1271 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1272}
1273
1274void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1275 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001276 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001277 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1278 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1279 LocationSummary* locations = invoke->GetLocations();
1280 Location receiver = locations->InAt(0);
1281 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1282
1283 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001284 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1285 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001286
1287 // temp = object->GetClass();
1288 if (receiver.IsStackSlot()) {
1289 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1290 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1291 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001292 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001293 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001294 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001295 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001296 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001297 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001298 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1299 // LR = temp->GetEntryPoint();
1300 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1301 // LR();
1302 __ blx(LR);
1303 DCHECK(!codegen_->IsLeafMethod());
1304 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1305}
1306
Roland Levillain88cb1752014-10-20 16:36:47 +01001307void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1308 LocationSummary* locations =
1309 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1310 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001311 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001312 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001313 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1314 break;
1315 }
1316 case Primitive::kPrimLong: {
1317 locations->SetInAt(0, Location::RequiresRegister());
1318 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001319 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001320 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001321
Roland Levillain88cb1752014-10-20 16:36:47 +01001322 case Primitive::kPrimFloat:
1323 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001324 locations->SetInAt(0, Location::RequiresFpuRegister());
1325 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001326 break;
1327
1328 default:
1329 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1330 }
1331}
1332
1333void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1334 LocationSummary* locations = neg->GetLocations();
1335 Location out = locations->Out();
1336 Location in = locations->InAt(0);
1337 switch (neg->GetResultType()) {
1338 case Primitive::kPrimInt:
1339 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001340 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001341 break;
1342
1343 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001344 DCHECK(in.IsRegisterPair());
1345 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1346 __ rsbs(out.AsRegisterPairLow<Register>(),
1347 in.AsRegisterPairLow<Register>(),
1348 ShifterOperand(0));
1349 // We cannot emit an RSC (Reverse Subtract with Carry)
1350 // instruction here, as it does not exist in the Thumb-2
1351 // instruction set. We use the following approach
1352 // using SBC and SUB instead.
1353 //
1354 // out.hi = -C
1355 __ sbc(out.AsRegisterPairHigh<Register>(),
1356 out.AsRegisterPairHigh<Register>(),
1357 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1358 // out.hi = out.hi - in.hi
1359 __ sub(out.AsRegisterPairHigh<Register>(),
1360 out.AsRegisterPairHigh<Register>(),
1361 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1362 break;
1363
Roland Levillain88cb1752014-10-20 16:36:47 +01001364 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001365 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001366 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001367 break;
1368
Roland Levillain88cb1752014-10-20 16:36:47 +01001369 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001370 DCHECK(in.IsFpuRegisterPair());
1371 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1372 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001373 break;
1374
1375 default:
1376 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1377 }
1378}
1379
Roland Levillaindff1f282014-11-05 14:15:05 +00001380void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001381 Primitive::Type result_type = conversion->GetResultType();
1382 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001383 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001384
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001385 // The float-to-long and double-to-long type conversions rely on a
1386 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001387 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001388 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1389 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001390 ? LocationSummary::kCall
1391 : LocationSummary::kNoCall;
1392 LocationSummary* locations =
1393 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1394
Roland Levillaindff1f282014-11-05 14:15:05 +00001395 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001396 case Primitive::kPrimByte:
1397 switch (input_type) {
1398 case Primitive::kPrimShort:
1399 case Primitive::kPrimInt:
1400 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001401 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001402 locations->SetInAt(0, Location::RequiresRegister());
1403 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1404 break;
1405
1406 default:
1407 LOG(FATAL) << "Unexpected type conversion from " << input_type
1408 << " to " << result_type;
1409 }
1410 break;
1411
Roland Levillain01a8d712014-11-14 16:27:39 +00001412 case Primitive::kPrimShort:
1413 switch (input_type) {
1414 case Primitive::kPrimByte:
1415 case Primitive::kPrimInt:
1416 case Primitive::kPrimChar:
1417 // Processing a Dex `int-to-short' instruction.
1418 locations->SetInAt(0, Location::RequiresRegister());
1419 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1420 break;
1421
1422 default:
1423 LOG(FATAL) << "Unexpected type conversion from " << input_type
1424 << " to " << result_type;
1425 }
1426 break;
1427
Roland Levillain946e1432014-11-11 17:35:19 +00001428 case Primitive::kPrimInt:
1429 switch (input_type) {
1430 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001431 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001432 locations->SetInAt(0, Location::Any());
1433 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1434 break;
1435
1436 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001437 // Processing a Dex `float-to-int' instruction.
1438 locations->SetInAt(0, Location::RequiresFpuRegister());
1439 locations->SetOut(Location::RequiresRegister());
1440 locations->AddTemp(Location::RequiresFpuRegister());
1441 break;
1442
Roland Levillain946e1432014-11-11 17:35:19 +00001443 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001444 // Processing a Dex `double-to-int' instruction.
1445 locations->SetInAt(0, Location::RequiresFpuRegister());
1446 locations->SetOut(Location::RequiresRegister());
1447 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001448 break;
1449
1450 default:
1451 LOG(FATAL) << "Unexpected type conversion from " << input_type
1452 << " to " << result_type;
1453 }
1454 break;
1455
Roland Levillaindff1f282014-11-05 14:15:05 +00001456 case Primitive::kPrimLong:
1457 switch (input_type) {
1458 case Primitive::kPrimByte:
1459 case Primitive::kPrimShort:
1460 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001461 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001462 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001463 locations->SetInAt(0, Location::RequiresRegister());
1464 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1465 break;
1466
Roland Levillain624279f2014-12-04 11:54:28 +00001467 case Primitive::kPrimFloat: {
1468 // Processing a Dex `float-to-long' instruction.
1469 InvokeRuntimeCallingConvention calling_convention;
1470 locations->SetInAt(0, Location::FpuRegisterLocation(
1471 calling_convention.GetFpuRegisterAt(0)));
1472 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1473 break;
1474 }
1475
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001476 case Primitive::kPrimDouble: {
1477 // Processing a Dex `double-to-long' instruction.
1478 InvokeRuntimeCallingConvention calling_convention;
1479 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1480 calling_convention.GetFpuRegisterAt(0),
1481 calling_convention.GetFpuRegisterAt(1)));
1482 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001483 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001484 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001485
1486 default:
1487 LOG(FATAL) << "Unexpected type conversion from " << input_type
1488 << " to " << result_type;
1489 }
1490 break;
1491
Roland Levillain981e4542014-11-14 11:47:14 +00001492 case Primitive::kPrimChar:
1493 switch (input_type) {
1494 case Primitive::kPrimByte:
1495 case Primitive::kPrimShort:
1496 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001497 // Processing a Dex `int-to-char' instruction.
1498 locations->SetInAt(0, Location::RequiresRegister());
1499 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1500 break;
1501
1502 default:
1503 LOG(FATAL) << "Unexpected type conversion from " << input_type
1504 << " to " << result_type;
1505 }
1506 break;
1507
Roland Levillaindff1f282014-11-05 14:15:05 +00001508 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001509 switch (input_type) {
1510 case Primitive::kPrimByte:
1511 case Primitive::kPrimShort:
1512 case Primitive::kPrimInt:
1513 case Primitive::kPrimChar:
1514 // Processing a Dex `int-to-float' instruction.
1515 locations->SetInAt(0, Location::RequiresRegister());
1516 locations->SetOut(Location::RequiresFpuRegister());
1517 break;
1518
1519 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001520 // Processing a Dex `long-to-float' instruction.
1521 locations->SetInAt(0, Location::RequiresRegister());
1522 locations->SetOut(Location::RequiresFpuRegister());
1523 locations->AddTemp(Location::RequiresRegister());
1524 locations->AddTemp(Location::RequiresRegister());
1525 locations->AddTemp(Location::RequiresFpuRegister());
1526 locations->AddTemp(Location::RequiresFpuRegister());
1527 break;
1528
Roland Levillaincff13742014-11-17 14:32:17 +00001529 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001530 // Processing a Dex `double-to-float' instruction.
1531 locations->SetInAt(0, Location::RequiresFpuRegister());
1532 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001533 break;
1534
1535 default:
1536 LOG(FATAL) << "Unexpected type conversion from " << input_type
1537 << " to " << result_type;
1538 };
1539 break;
1540
Roland Levillaindff1f282014-11-05 14:15:05 +00001541 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001542 switch (input_type) {
1543 case Primitive::kPrimByte:
1544 case Primitive::kPrimShort:
1545 case Primitive::kPrimInt:
1546 case Primitive::kPrimChar:
1547 // Processing a Dex `int-to-double' instruction.
1548 locations->SetInAt(0, Location::RequiresRegister());
1549 locations->SetOut(Location::RequiresFpuRegister());
1550 break;
1551
1552 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001553 // Processing a Dex `long-to-double' instruction.
1554 locations->SetInAt(0, Location::RequiresRegister());
1555 locations->SetOut(Location::RequiresFpuRegister());
1556 locations->AddTemp(Location::RequiresRegister());
1557 locations->AddTemp(Location::RequiresRegister());
1558 locations->AddTemp(Location::RequiresFpuRegister());
1559 break;
1560
Roland Levillaincff13742014-11-17 14:32:17 +00001561 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001562 // Processing a Dex `float-to-double' instruction.
1563 locations->SetInAt(0, Location::RequiresFpuRegister());
1564 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001565 break;
1566
1567 default:
1568 LOG(FATAL) << "Unexpected type conversion from " << input_type
1569 << " to " << result_type;
1570 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001571 break;
1572
1573 default:
1574 LOG(FATAL) << "Unexpected type conversion from " << input_type
1575 << " to " << result_type;
1576 }
1577}
1578
1579void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1580 LocationSummary* locations = conversion->GetLocations();
1581 Location out = locations->Out();
1582 Location in = locations->InAt(0);
1583 Primitive::Type result_type = conversion->GetResultType();
1584 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001585 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001586 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001587 case Primitive::kPrimByte:
1588 switch (input_type) {
1589 case Primitive::kPrimShort:
1590 case Primitive::kPrimInt:
1591 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001592 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001593 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001594 break;
1595
1596 default:
1597 LOG(FATAL) << "Unexpected type conversion from " << input_type
1598 << " to " << result_type;
1599 }
1600 break;
1601
Roland Levillain01a8d712014-11-14 16:27:39 +00001602 case Primitive::kPrimShort:
1603 switch (input_type) {
1604 case Primitive::kPrimByte:
1605 case Primitive::kPrimInt:
1606 case Primitive::kPrimChar:
1607 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001608 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001609 break;
1610
1611 default:
1612 LOG(FATAL) << "Unexpected type conversion from " << input_type
1613 << " to " << result_type;
1614 }
1615 break;
1616
Roland Levillain946e1432014-11-11 17:35:19 +00001617 case Primitive::kPrimInt:
1618 switch (input_type) {
1619 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001620 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001621 DCHECK(out.IsRegister());
1622 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001623 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001624 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001625 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001626 } else {
1627 DCHECK(in.IsConstant());
1628 DCHECK(in.GetConstant()->IsLongConstant());
1629 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001630 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001631 }
1632 break;
1633
Roland Levillain3f8f9362014-12-02 17:45:01 +00001634 case Primitive::kPrimFloat: {
1635 // Processing a Dex `float-to-int' instruction.
1636 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1637 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1638 __ vcvtis(temp, temp);
1639 __ vmovrs(out.AsRegister<Register>(), temp);
1640 break;
1641 }
1642
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001643 case Primitive::kPrimDouble: {
1644 // Processing a Dex `double-to-int' instruction.
1645 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1646 DRegister temp_d = FromLowSToD(temp_s);
1647 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1648 __ vcvtid(temp_s, temp_d);
1649 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001650 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001651 }
Roland Levillain946e1432014-11-11 17:35:19 +00001652
1653 default:
1654 LOG(FATAL) << "Unexpected type conversion from " << input_type
1655 << " to " << result_type;
1656 }
1657 break;
1658
Roland Levillaindff1f282014-11-05 14:15:05 +00001659 case Primitive::kPrimLong:
1660 switch (input_type) {
1661 case Primitive::kPrimByte:
1662 case Primitive::kPrimShort:
1663 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001664 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001665 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001666 DCHECK(out.IsRegisterPair());
1667 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001668 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001669 // Sign extension.
1670 __ Asr(out.AsRegisterPairHigh<Register>(),
1671 out.AsRegisterPairLow<Register>(),
1672 31);
1673 break;
1674
1675 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001676 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001677 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1678 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001679 conversion->GetDexPc(),
1680 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001681 break;
1682
Roland Levillaindff1f282014-11-05 14:15:05 +00001683 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001684 // Processing a Dex `double-to-long' instruction.
1685 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1686 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001687 conversion->GetDexPc(),
1688 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001689 break;
1690
1691 default:
1692 LOG(FATAL) << "Unexpected type conversion from " << input_type
1693 << " to " << result_type;
1694 }
1695 break;
1696
Roland Levillain981e4542014-11-14 11:47:14 +00001697 case Primitive::kPrimChar:
1698 switch (input_type) {
1699 case Primitive::kPrimByte:
1700 case Primitive::kPrimShort:
1701 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001702 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001703 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001704 break;
1705
1706 default:
1707 LOG(FATAL) << "Unexpected type conversion from " << input_type
1708 << " to " << result_type;
1709 }
1710 break;
1711
Roland Levillaindff1f282014-11-05 14:15:05 +00001712 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001713 switch (input_type) {
1714 case Primitive::kPrimByte:
1715 case Primitive::kPrimShort:
1716 case Primitive::kPrimInt:
1717 case Primitive::kPrimChar: {
1718 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001719 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1720 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001721 break;
1722 }
1723
Roland Levillain6d0e4832014-11-27 18:31:21 +00001724 case Primitive::kPrimLong: {
1725 // Processing a Dex `long-to-float' instruction.
1726 Register low = in.AsRegisterPairLow<Register>();
1727 Register high = in.AsRegisterPairHigh<Register>();
1728 SRegister output = out.AsFpuRegister<SRegister>();
1729 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1730 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1731 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1732 DRegister temp1_d = FromLowSToD(temp1_s);
1733 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1734 DRegister temp2_d = FromLowSToD(temp2_s);
1735
1736 // Operations use doubles for precision reasons (each 32-bit
1737 // half of a long fits in the 53-bit mantissa of a double,
1738 // but not in the 24-bit mantissa of a float). This is
1739 // especially important for the low bits. The result is
1740 // eventually converted to float.
1741
1742 // temp1_d = int-to-double(high)
1743 __ vmovsr(temp1_s, high);
1744 __ vcvtdi(temp1_d, temp1_s);
1745 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1746 // as an immediate value into `temp2_d` does not work, as
1747 // this instruction only transfers 8 significant bits of its
1748 // immediate operand. Instead, use two 32-bit core
1749 // registers to load `k2Pow32EncodingForDouble` into
1750 // `temp2_d`.
1751 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1752 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1753 __ vmovdrr(temp2_d, constant_low, constant_high);
1754 // temp1_d = temp1_d * 2^32
1755 __ vmuld(temp1_d, temp1_d, temp2_d);
1756 // temp2_d = unsigned-to-double(low)
1757 __ vmovsr(temp2_s, low);
1758 __ vcvtdu(temp2_d, temp2_s);
1759 // temp1_d = temp1_d + temp2_d
1760 __ vaddd(temp1_d, temp1_d, temp2_d);
1761 // output = double-to-float(temp1_d);
1762 __ vcvtsd(output, temp1_d);
1763 break;
1764 }
1765
Roland Levillaincff13742014-11-17 14:32:17 +00001766 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001767 // Processing a Dex `double-to-float' instruction.
1768 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1769 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001770 break;
1771
1772 default:
1773 LOG(FATAL) << "Unexpected type conversion from " << input_type
1774 << " to " << result_type;
1775 };
1776 break;
1777
Roland Levillaindff1f282014-11-05 14:15:05 +00001778 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001779 switch (input_type) {
1780 case Primitive::kPrimByte:
1781 case Primitive::kPrimShort:
1782 case Primitive::kPrimInt:
1783 case Primitive::kPrimChar: {
1784 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001785 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001786 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1787 out.AsFpuRegisterPairLow<SRegister>());
1788 break;
1789 }
1790
Roland Levillain647b9ed2014-11-27 12:06:00 +00001791 case Primitive::kPrimLong: {
1792 // Processing a Dex `long-to-double' instruction.
1793 Register low = in.AsRegisterPairLow<Register>();
1794 Register high = in.AsRegisterPairHigh<Register>();
1795 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1796 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001797 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1798 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001799 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1800 DRegister temp_d = FromLowSToD(temp_s);
1801
Roland Levillain647b9ed2014-11-27 12:06:00 +00001802 // out_d = int-to-double(high)
1803 __ vmovsr(out_s, high);
1804 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001805 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1806 // as an immediate value into `temp_d` does not work, as
1807 // this instruction only transfers 8 significant bits of its
1808 // immediate operand. Instead, use two 32-bit core
1809 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1810 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1811 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001812 __ vmovdrr(temp_d, constant_low, constant_high);
1813 // out_d = out_d * 2^32
1814 __ vmuld(out_d, out_d, temp_d);
1815 // temp_d = unsigned-to-double(low)
1816 __ vmovsr(temp_s, low);
1817 __ vcvtdu(temp_d, temp_s);
1818 // out_d = out_d + temp_d
1819 __ vaddd(out_d, out_d, temp_d);
1820 break;
1821 }
1822
Roland Levillaincff13742014-11-17 14:32:17 +00001823 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001824 // Processing a Dex `float-to-double' instruction.
1825 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1826 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001827 break;
1828
1829 default:
1830 LOG(FATAL) << "Unexpected type conversion from " << input_type
1831 << " to " << result_type;
1832 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001833 break;
1834
1835 default:
1836 LOG(FATAL) << "Unexpected type conversion from " << input_type
1837 << " to " << result_type;
1838 }
1839}
1840
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001841void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001842 LocationSummary* locations =
1843 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001844 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001845 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001846 locations->SetInAt(0, Location::RequiresRegister());
1847 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001848 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1849 break;
1850 }
1851
1852 case Primitive::kPrimLong: {
1853 locations->SetInAt(0, Location::RequiresRegister());
1854 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001855 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001856 break;
1857 }
1858
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001859 case Primitive::kPrimFloat:
1860 case Primitive::kPrimDouble: {
1861 locations->SetInAt(0, Location::RequiresFpuRegister());
1862 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001863 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001864 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001865 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001866
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001867 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001868 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001869 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001870}
1871
1872void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1873 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001874 Location out = locations->Out();
1875 Location first = locations->InAt(0);
1876 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001877 switch (add->GetResultType()) {
1878 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001879 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001880 __ add(out.AsRegister<Register>(),
1881 first.AsRegister<Register>(),
1882 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001883 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001884 __ AddConstant(out.AsRegister<Register>(),
1885 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001886 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001887 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001888 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001889
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001890 case Primitive::kPrimLong: {
1891 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001892 __ adds(out.AsRegisterPairLow<Register>(),
1893 first.AsRegisterPairLow<Register>(),
1894 ShifterOperand(second.AsRegisterPairLow<Register>()));
1895 __ adc(out.AsRegisterPairHigh<Register>(),
1896 first.AsRegisterPairHigh<Register>(),
1897 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001898 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001899 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001900
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001901 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001902 __ vadds(out.AsFpuRegister<SRegister>(),
1903 first.AsFpuRegister<SRegister>(),
1904 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001905 break;
1906
1907 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001908 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1909 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1910 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001911 break;
1912
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001913 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001914 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001915 }
1916}
1917
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001918void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001919 LocationSummary* locations =
1920 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001921 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001922 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001923 locations->SetInAt(0, Location::RequiresRegister());
1924 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001925 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1926 break;
1927 }
1928
1929 case Primitive::kPrimLong: {
1930 locations->SetInAt(0, Location::RequiresRegister());
1931 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001932 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001933 break;
1934 }
Calin Juravle11351682014-10-23 15:38:15 +01001935 case Primitive::kPrimFloat:
1936 case Primitive::kPrimDouble: {
1937 locations->SetInAt(0, Location::RequiresFpuRegister());
1938 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001939 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001940 break;
Calin Juravle11351682014-10-23 15:38:15 +01001941 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001942 default:
Calin Juravle11351682014-10-23 15:38:15 +01001943 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001944 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001945}
1946
1947void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1948 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001949 Location out = locations->Out();
1950 Location first = locations->InAt(0);
1951 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001952 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001953 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001954 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001955 __ sub(out.AsRegister<Register>(),
1956 first.AsRegister<Register>(),
1957 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001958 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001959 __ AddConstant(out.AsRegister<Register>(),
1960 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001961 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001962 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001963 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001964 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001965
Calin Juravle11351682014-10-23 15:38:15 +01001966 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001967 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001968 __ subs(out.AsRegisterPairLow<Register>(),
1969 first.AsRegisterPairLow<Register>(),
1970 ShifterOperand(second.AsRegisterPairLow<Register>()));
1971 __ sbc(out.AsRegisterPairHigh<Register>(),
1972 first.AsRegisterPairHigh<Register>(),
1973 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001974 break;
Calin Juravle11351682014-10-23 15:38:15 +01001975 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001976
Calin Juravle11351682014-10-23 15:38:15 +01001977 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001978 __ vsubs(out.AsFpuRegister<SRegister>(),
1979 first.AsFpuRegister<SRegister>(),
1980 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001981 break;
Calin Juravle11351682014-10-23 15:38:15 +01001982 }
1983
1984 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001985 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1986 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1987 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001988 break;
1989 }
1990
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001991
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001992 default:
Calin Juravle11351682014-10-23 15:38:15 +01001993 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001994 }
1995}
1996
Calin Juravle34bacdf2014-10-07 20:23:36 +01001997void LocationsBuilderARM::VisitMul(HMul* mul) {
1998 LocationSummary* locations =
1999 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2000 switch (mul->GetResultType()) {
2001 case Primitive::kPrimInt:
2002 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002003 locations->SetInAt(0, Location::RequiresRegister());
2004 locations->SetInAt(1, Location::RequiresRegister());
2005 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002006 break;
2007 }
2008
Calin Juravleb5bfa962014-10-21 18:02:24 +01002009 case Primitive::kPrimFloat:
2010 case Primitive::kPrimDouble: {
2011 locations->SetInAt(0, Location::RequiresFpuRegister());
2012 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002013 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002014 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002015 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002016
2017 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002018 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002019 }
2020}
2021
2022void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2023 LocationSummary* locations = mul->GetLocations();
2024 Location out = locations->Out();
2025 Location first = locations->InAt(0);
2026 Location second = locations->InAt(1);
2027 switch (mul->GetResultType()) {
2028 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002029 __ mul(out.AsRegister<Register>(),
2030 first.AsRegister<Register>(),
2031 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002032 break;
2033 }
2034 case Primitive::kPrimLong: {
2035 Register out_hi = out.AsRegisterPairHigh<Register>();
2036 Register out_lo = out.AsRegisterPairLow<Register>();
2037 Register in1_hi = first.AsRegisterPairHigh<Register>();
2038 Register in1_lo = first.AsRegisterPairLow<Register>();
2039 Register in2_hi = second.AsRegisterPairHigh<Register>();
2040 Register in2_lo = second.AsRegisterPairLow<Register>();
2041
2042 // Extra checks to protect caused by the existence of R1_R2.
2043 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2044 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2045 DCHECK_NE(out_hi, in1_lo);
2046 DCHECK_NE(out_hi, in2_lo);
2047
2048 // input: in1 - 64 bits, in2 - 64 bits
2049 // output: out
2050 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2051 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2052 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2053
2054 // IP <- in1.lo * in2.hi
2055 __ mul(IP, in1_lo, in2_hi);
2056 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2057 __ mla(out_hi, in1_hi, in2_lo, IP);
2058 // out.lo <- (in1.lo * in2.lo)[31:0];
2059 __ umull(out_lo, IP, in1_lo, in2_lo);
2060 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2061 __ add(out_hi, out_hi, ShifterOperand(IP));
2062 break;
2063 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002064
2065 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002066 __ vmuls(out.AsFpuRegister<SRegister>(),
2067 first.AsFpuRegister<SRegister>(),
2068 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002069 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002070 }
2071
2072 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002073 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2074 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2075 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002076 break;
2077 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002078
2079 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002080 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002081 }
2082}
2083
Calin Juravle7c4954d2014-10-28 16:57:40 +00002084void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002085 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2086 ? LocationSummary::kCall
2087 : LocationSummary::kNoCall;
2088 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2089
Calin Juravle7c4954d2014-10-28 16:57:40 +00002090 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002091 case Primitive::kPrimInt: {
2092 locations->SetInAt(0, Location::RequiresRegister());
2093 locations->SetInAt(1, Location::RequiresRegister());
2094 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2095 break;
2096 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002097 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002098 InvokeRuntimeCallingConvention calling_convention;
2099 locations->SetInAt(0, Location::RegisterPairLocation(
2100 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2101 locations->SetInAt(1, Location::RegisterPairLocation(
2102 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002103 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002104 break;
2105 }
2106 case Primitive::kPrimFloat:
2107 case Primitive::kPrimDouble: {
2108 locations->SetInAt(0, Location::RequiresFpuRegister());
2109 locations->SetInAt(1, Location::RequiresFpuRegister());
2110 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2111 break;
2112 }
2113
2114 default:
2115 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2116 }
2117}
2118
2119void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2120 LocationSummary* locations = div->GetLocations();
2121 Location out = locations->Out();
2122 Location first = locations->InAt(0);
2123 Location second = locations->InAt(1);
2124
2125 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002126 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002127 __ sdiv(out.AsRegister<Register>(),
2128 first.AsRegister<Register>(),
2129 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002130 break;
2131 }
2132
Calin Juravle7c4954d2014-10-28 16:57:40 +00002133 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002134 InvokeRuntimeCallingConvention calling_convention;
2135 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2136 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2137 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2138 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2139 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002140 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002141
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002142 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002143 break;
2144 }
2145
2146 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002147 __ vdivs(out.AsFpuRegister<SRegister>(),
2148 first.AsFpuRegister<SRegister>(),
2149 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002150 break;
2151 }
2152
2153 case Primitive::kPrimDouble: {
2154 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2155 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2156 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2157 break;
2158 }
2159
2160 default:
2161 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2162 }
2163}
2164
Calin Juravlebacfec32014-11-14 15:54:36 +00002165void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002166 Primitive::Type type = rem->GetResultType();
2167 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2168 ? LocationSummary::kNoCall
2169 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002170 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2171
Calin Juravled2ec87d2014-12-08 14:24:46 +00002172 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002173 case Primitive::kPrimInt: {
2174 locations->SetInAt(0, Location::RequiresRegister());
2175 locations->SetInAt(1, Location::RequiresRegister());
2176 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2177 locations->AddTemp(Location::RequiresRegister());
2178 break;
2179 }
2180 case Primitive::kPrimLong: {
2181 InvokeRuntimeCallingConvention calling_convention;
2182 locations->SetInAt(0, Location::RegisterPairLocation(
2183 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2184 locations->SetInAt(1, Location::RegisterPairLocation(
2185 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2186 // The runtime helper puts the output in R2,R3.
2187 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2188 break;
2189 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002190 case Primitive::kPrimFloat: {
2191 InvokeRuntimeCallingConvention calling_convention;
2192 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2193 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2194 locations->SetOut(Location::FpuRegisterLocation(S0));
2195 break;
2196 }
2197
Calin Juravlebacfec32014-11-14 15:54:36 +00002198 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002199 InvokeRuntimeCallingConvention calling_convention;
2200 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2201 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2202 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2203 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2204 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002205 break;
2206 }
2207
2208 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002209 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002210 }
2211}
2212
2213void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2214 LocationSummary* locations = rem->GetLocations();
2215 Location out = locations->Out();
2216 Location first = locations->InAt(0);
2217 Location second = locations->InAt(1);
2218
Calin Juravled2ec87d2014-12-08 14:24:46 +00002219 Primitive::Type type = rem->GetResultType();
2220 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002221 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002222 Register reg1 = first.AsRegister<Register>();
2223 Register reg2 = second.AsRegister<Register>();
2224 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002225
2226 // temp = reg1 / reg2 (integer division)
2227 // temp = temp * reg2
2228 // dest = reg1 - temp
2229 __ sdiv(temp, reg1, reg2);
2230 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002231 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002232 break;
2233 }
2234
2235 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002236 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002237 break;
2238 }
2239
Calin Juravled2ec87d2014-12-08 14:24:46 +00002240 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002241 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002242 break;
2243 }
2244
Calin Juravlebacfec32014-11-14 15:54:36 +00002245 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002246 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002247 break;
2248 }
2249
2250 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002251 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002252 }
2253}
2254
Calin Juravled0d48522014-11-04 16:40:20 +00002255void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2256 LocationSummary* locations =
2257 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002258 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002259 if (instruction->HasUses()) {
2260 locations->SetOut(Location::SameAsFirstInput());
2261 }
2262}
2263
2264void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2265 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2266 codegen_->AddSlowPath(slow_path);
2267
2268 LocationSummary* locations = instruction->GetLocations();
2269 Location value = locations->InAt(0);
2270
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002271 switch (instruction->GetType()) {
2272 case Primitive::kPrimInt: {
2273 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002274 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002275 __ b(slow_path->GetEntryLabel(), EQ);
2276 } else {
2277 DCHECK(value.IsConstant()) << value;
2278 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2279 __ b(slow_path->GetEntryLabel());
2280 }
2281 }
2282 break;
2283 }
2284 case Primitive::kPrimLong: {
2285 if (value.IsRegisterPair()) {
2286 __ orrs(IP,
2287 value.AsRegisterPairLow<Register>(),
2288 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2289 __ b(slow_path->GetEntryLabel(), EQ);
2290 } else {
2291 DCHECK(value.IsConstant()) << value;
2292 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2293 __ b(slow_path->GetEntryLabel());
2294 }
2295 }
2296 break;
2297 default:
2298 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2299 }
2300 }
Calin Juravled0d48522014-11-04 16:40:20 +00002301}
2302
Calin Juravle9aec02f2014-11-18 23:06:35 +00002303void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2304 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2305
2306 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2307 ? LocationSummary::kCall
2308 : LocationSummary::kNoCall;
2309 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2310
2311 switch (op->GetResultType()) {
2312 case Primitive::kPrimInt: {
2313 locations->SetInAt(0, Location::RequiresRegister());
2314 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002315 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002316 break;
2317 }
2318 case Primitive::kPrimLong: {
2319 InvokeRuntimeCallingConvention calling_convention;
2320 locations->SetInAt(0, Location::RegisterPairLocation(
2321 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2322 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002323 // The runtime helper puts the output in R0,R1.
2324 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002325 break;
2326 }
2327 default:
2328 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2329 }
2330}
2331
2332void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2333 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2334
2335 LocationSummary* locations = op->GetLocations();
2336 Location out = locations->Out();
2337 Location first = locations->InAt(0);
2338 Location second = locations->InAt(1);
2339
2340 Primitive::Type type = op->GetResultType();
2341 switch (type) {
2342 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002343 Register out_reg = out.AsRegister<Register>();
2344 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002345 // Arm doesn't mask the shift count so we need to do it ourselves.
2346 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002347 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002348 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2349 if (op->IsShl()) {
2350 __ Lsl(out_reg, first_reg, second_reg);
2351 } else if (op->IsShr()) {
2352 __ Asr(out_reg, first_reg, second_reg);
2353 } else {
2354 __ Lsr(out_reg, first_reg, second_reg);
2355 }
2356 } else {
2357 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2358 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2359 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2360 __ Mov(out_reg, first_reg);
2361 } else if (op->IsShl()) {
2362 __ Lsl(out_reg, first_reg, shift_value);
2363 } else if (op->IsShr()) {
2364 __ Asr(out_reg, first_reg, shift_value);
2365 } else {
2366 __ Lsr(out_reg, first_reg, shift_value);
2367 }
2368 }
2369 break;
2370 }
2371 case Primitive::kPrimLong: {
2372 // TODO: Inline the assembly instead of calling the runtime.
2373 InvokeRuntimeCallingConvention calling_convention;
2374 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2375 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002376 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002377 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002378 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002379
2380 int32_t entry_point_offset;
2381 if (op->IsShl()) {
2382 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2383 } else if (op->IsShr()) {
2384 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2385 } else {
2386 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2387 }
2388 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2389 __ blx(LR);
2390 break;
2391 }
2392 default:
2393 LOG(FATAL) << "Unexpected operation type " << type;
2394 }
2395}
2396
2397void LocationsBuilderARM::VisitShl(HShl* shl) {
2398 HandleShift(shl);
2399}
2400
2401void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2402 HandleShift(shl);
2403}
2404
2405void LocationsBuilderARM::VisitShr(HShr* shr) {
2406 HandleShift(shr);
2407}
2408
2409void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2410 HandleShift(shr);
2411}
2412
2413void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2414 HandleShift(ushr);
2415}
2416
2417void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2418 HandleShift(ushr);
2419}
2420
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002421void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002422 LocationSummary* locations =
2423 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002424 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002425 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2426 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2427 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002428}
2429
2430void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2431 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002432 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002433 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002434 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2435 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002436 instruction->GetDexPc(),
2437 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002438}
2439
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002440void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2441 LocationSummary* locations =
2442 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2443 InvokeRuntimeCallingConvention calling_convention;
2444 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002445 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002446 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002447 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002448}
2449
2450void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2451 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002452 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002453 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002454 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2455 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002456 instruction->GetDexPc(),
2457 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002458}
2459
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002460void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002461 LocationSummary* locations =
2462 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002463 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2464 if (location.IsStackSlot()) {
2465 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2466 } else if (location.IsDoubleStackSlot()) {
2467 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002468 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002469 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002470}
2471
2472void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002473 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002474 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002475}
2476
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002477void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002478 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002479 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002480 locations->SetInAt(0, Location::RequiresRegister());
2481 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002482}
2483
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002484void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2485 LocationSummary* locations = not_->GetLocations();
2486 Location out = locations->Out();
2487 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002488 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002489 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002490 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002491 break;
2492
2493 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002494 __ mvn(out.AsRegisterPairLow<Register>(),
2495 ShifterOperand(in.AsRegisterPairLow<Register>()));
2496 __ mvn(out.AsRegisterPairHigh<Register>(),
2497 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002498 break;
2499
2500 default:
2501 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2502 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002503}
2504
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002505void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002506 LocationSummary* locations =
2507 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002508 switch (compare->InputAt(0)->GetType()) {
2509 case Primitive::kPrimLong: {
2510 locations->SetInAt(0, Location::RequiresRegister());
2511 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002512 // Output overlaps because it is written before doing the low comparison.
2513 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002514 break;
2515 }
2516 case Primitive::kPrimFloat:
2517 case Primitive::kPrimDouble: {
2518 locations->SetInAt(0, Location::RequiresFpuRegister());
2519 locations->SetInAt(1, Location::RequiresFpuRegister());
2520 locations->SetOut(Location::RequiresRegister());
2521 break;
2522 }
2523 default:
2524 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2525 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002526}
2527
2528void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002529 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002530 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002531 Location left = locations->InAt(0);
2532 Location right = locations->InAt(1);
2533
2534 Label less, greater, done;
2535 Primitive::Type type = compare->InputAt(0)->GetType();
2536 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002537 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002538 __ cmp(left.AsRegisterPairHigh<Register>(),
2539 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002540 __ b(&less, LT);
2541 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002542 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2543 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002544 __ cmp(left.AsRegisterPairLow<Register>(),
2545 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002546 break;
2547 }
2548 case Primitive::kPrimFloat:
2549 case Primitive::kPrimDouble: {
2550 __ LoadImmediate(out, 0);
2551 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002552 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002553 } else {
2554 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2555 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2556 }
2557 __ vmstat(); // transfer FP status register to ARM APSR.
2558 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002559 break;
2560 }
2561 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002562 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002563 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002564 __ b(&done, EQ);
2565 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2566
2567 __ Bind(&greater);
2568 __ LoadImmediate(out, 1);
2569 __ b(&done);
2570
2571 __ Bind(&less);
2572 __ LoadImmediate(out, -1);
2573
2574 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002575}
2576
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002577void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002578 LocationSummary* locations =
2579 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002580 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2581 locations->SetInAt(i, Location::Any());
2582 }
2583 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002584}
2585
2586void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002587 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002588 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002589}
2590
Calin Juravle52c48962014-12-16 17:02:57 +00002591void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2592 // TODO (ported from quick): revisit Arm barrier kinds
2593 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2594 switch (kind) {
2595 case MemBarrierKind::kAnyStore:
2596 case MemBarrierKind::kLoadAny:
2597 case MemBarrierKind::kAnyAny: {
2598 flavour = DmbOptions::ISH;
2599 break;
2600 }
2601 case MemBarrierKind::kStoreStore: {
2602 flavour = DmbOptions::ISHST;
2603 break;
2604 }
2605 default:
2606 LOG(FATAL) << "Unexpected memory barrier " << kind;
2607 }
2608 __ dmb(flavour);
2609}
2610
2611void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2612 uint32_t offset,
2613 Register out_lo,
2614 Register out_hi) {
2615 if (offset != 0) {
2616 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002617 __ add(IP, addr, ShifterOperand(out_lo));
2618 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002619 }
2620 __ ldrexd(out_lo, out_hi, addr);
2621}
2622
2623void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2624 uint32_t offset,
2625 Register value_lo,
2626 Register value_hi,
2627 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002628 Register temp2,
2629 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002630 Label fail;
2631 if (offset != 0) {
2632 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002633 __ add(IP, addr, ShifterOperand(temp1));
2634 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002635 }
2636 __ Bind(&fail);
2637 // We need a load followed by store. (The address used in a STREX instruction must
2638 // be the same as the address in the most recently executed LDREX instruction.)
2639 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002640 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002641 __ strexd(temp1, value_lo, value_hi, addr);
2642 __ cmp(temp1, ShifterOperand(0));
2643 __ b(&fail, NE);
2644}
2645
2646void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2647 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2648
Nicolas Geoffray39468442014-09-02 15:17:15 +01002649 LocationSummary* locations =
2650 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002651 locations->SetInAt(0, Location::RequiresRegister());
2652 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002653
Calin Juravle34166012014-12-19 17:22:29 +00002654
Calin Juravle52c48962014-12-16 17:02:57 +00002655 Primitive::Type field_type = field_info.GetFieldType();
2656 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002657 bool generate_volatile = field_info.IsVolatile()
2658 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002659 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002660 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002661 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2662 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002663 locations->AddTemp(Location::RequiresRegister());
2664 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002665 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002666 // Arm encoding have some additional constraints for ldrexd/strexd:
2667 // - registers need to be consecutive
2668 // - the first register should be even but not R14.
2669 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2670 // enable Arm encoding.
2671 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2672
2673 locations->AddTemp(Location::RequiresRegister());
2674 locations->AddTemp(Location::RequiresRegister());
2675 if (field_type == Primitive::kPrimDouble) {
2676 // For doubles we need two more registers to copy the value.
2677 locations->AddTemp(Location::RegisterLocation(R2));
2678 locations->AddTemp(Location::RegisterLocation(R3));
2679 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002680 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002681}
2682
Calin Juravle52c48962014-12-16 17:02:57 +00002683void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2684 const FieldInfo& field_info) {
2685 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2686
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002687 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002688 Register base = locations->InAt(0).AsRegister<Register>();
2689 Location value = locations->InAt(1);
2690
2691 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002692 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002693 Primitive::Type field_type = field_info.GetFieldType();
2694 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2695
2696 if (is_volatile) {
2697 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2698 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002699
2700 switch (field_type) {
2701 case Primitive::kPrimBoolean:
2702 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002703 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002704 break;
2705 }
2706
2707 case Primitive::kPrimShort:
2708 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002709 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002710 break;
2711 }
2712
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002713 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002714 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002715 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002716 break;
2717 }
2718
2719 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002720 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002721 GenerateWideAtomicStore(base, offset,
2722 value.AsRegisterPairLow<Register>(),
2723 value.AsRegisterPairHigh<Register>(),
2724 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002725 locations->GetTemp(1).AsRegister<Register>(),
2726 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002727 } else {
2728 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002729 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002730 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002731 break;
2732 }
2733
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002734 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002735 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002736 break;
2737 }
2738
2739 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002740 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002741 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002742 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2743 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2744
2745 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2746
2747 GenerateWideAtomicStore(base, offset,
2748 value_reg_lo,
2749 value_reg_hi,
2750 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002751 locations->GetTemp(3).AsRegister<Register>(),
2752 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002753 } else {
2754 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002755 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002756 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002757 break;
2758 }
2759
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002760 case Primitive::kPrimVoid:
2761 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002762 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002763 }
Calin Juravle52c48962014-12-16 17:02:57 +00002764
Calin Juravle77520bc2015-01-12 18:45:46 +00002765 // Longs and doubles are handled in the switch.
2766 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2767 codegen_->MaybeRecordImplicitNullCheck(instruction);
2768 }
2769
2770 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2771 Register temp = locations->GetTemp(0).AsRegister<Register>();
2772 Register card = locations->GetTemp(1).AsRegister<Register>();
2773 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2774 }
2775
Calin Juravle52c48962014-12-16 17:02:57 +00002776 if (is_volatile) {
2777 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2778 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002779}
2780
Calin Juravle52c48962014-12-16 17:02:57 +00002781void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2782 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002783 LocationSummary* locations =
2784 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002785 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002786
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002787 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002788 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002789 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002790 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2791 locations->SetOut(Location::RequiresRegister(),
2792 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2793 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002794 // Arm encoding have some additional constraints for ldrexd/strexd:
2795 // - registers need to be consecutive
2796 // - the first register should be even but not R14.
2797 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2798 // enable Arm encoding.
2799 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2800 locations->AddTemp(Location::RequiresRegister());
2801 locations->AddTemp(Location::RequiresRegister());
2802 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002803}
2804
Calin Juravle52c48962014-12-16 17:02:57 +00002805void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2806 const FieldInfo& field_info) {
2807 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002808
Calin Juravle52c48962014-12-16 17:02:57 +00002809 LocationSummary* locations = instruction->GetLocations();
2810 Register base = locations->InAt(0).AsRegister<Register>();
2811 Location out = locations->Out();
2812 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002813 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002814 Primitive::Type field_type = field_info.GetFieldType();
2815 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2816
2817 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002818 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002819 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002820 break;
2821 }
2822
2823 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002824 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002825 break;
2826 }
2827
2828 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002829 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002830 break;
2831 }
2832
2833 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002834 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002835 break;
2836 }
2837
2838 case Primitive::kPrimInt:
2839 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002840 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002841 break;
2842 }
2843
2844 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002845 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002846 GenerateWideAtomicLoad(base, offset,
2847 out.AsRegisterPairLow<Register>(),
2848 out.AsRegisterPairHigh<Register>());
2849 } else {
2850 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2851 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002852 break;
2853 }
2854
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002855 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002856 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002857 break;
2858 }
2859
2860 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002861 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002862 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002863 Register lo = locations->GetTemp(0).AsRegister<Register>();
2864 Register hi = locations->GetTemp(1).AsRegister<Register>();
2865 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002866 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002867 __ vmovdrr(out_reg, lo, hi);
2868 } else {
2869 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002870 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002871 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002872 break;
2873 }
2874
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002875 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002876 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002877 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002878 }
Calin Juravle52c48962014-12-16 17:02:57 +00002879
Calin Juravle77520bc2015-01-12 18:45:46 +00002880 // Doubles are handled in the switch.
2881 if (field_type != Primitive::kPrimDouble) {
2882 codegen_->MaybeRecordImplicitNullCheck(instruction);
2883 }
2884
Calin Juravle52c48962014-12-16 17:02:57 +00002885 if (is_volatile) {
2886 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2887 }
2888}
2889
2890void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2891 HandleFieldSet(instruction, instruction->GetFieldInfo());
2892}
2893
2894void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2895 HandleFieldSet(instruction, instruction->GetFieldInfo());
2896}
2897
2898void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2899 HandleFieldGet(instruction, instruction->GetFieldInfo());
2900}
2901
2902void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2903 HandleFieldGet(instruction, instruction->GetFieldInfo());
2904}
2905
2906void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2907 HandleFieldGet(instruction, instruction->GetFieldInfo());
2908}
2909
2910void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2911 HandleFieldGet(instruction, instruction->GetFieldInfo());
2912}
2913
2914void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2915 HandleFieldSet(instruction, instruction->GetFieldInfo());
2916}
2917
2918void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2919 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002920}
2921
2922void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002923 LocationSummary* locations =
2924 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002925 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002926 if (instruction->HasUses()) {
2927 locations->SetOut(Location::SameAsFirstInput());
2928 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002929}
2930
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002931void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002932 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2933 return;
2934 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002935 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002936
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002937 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2938 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2939}
2940
2941void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002942 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002943 codegen_->AddSlowPath(slow_path);
2944
2945 LocationSummary* locations = instruction->GetLocations();
2946 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002947
Calin Juravle77520bc2015-01-12 18:45:46 +00002948 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2949 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002950}
2951
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002952void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2953 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2954 GenerateImplicitNullCheck(instruction);
2955 } else {
2956 GenerateExplicitNullCheck(instruction);
2957 }
2958}
2959
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002960void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002961 LocationSummary* locations =
2962 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002963 locations->SetInAt(0, Location::RequiresRegister());
2964 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2965 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002966}
2967
2968void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2969 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002970 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002971 Location index = locations->InAt(1);
2972
2973 switch (instruction->GetType()) {
2974 case Primitive::kPrimBoolean: {
2975 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002976 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002977 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002978 size_t offset =
2979 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002980 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2981 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002982 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002983 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2984 }
2985 break;
2986 }
2987
2988 case Primitive::kPrimByte: {
2989 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002990 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002991 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002992 size_t offset =
2993 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002994 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2995 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002996 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002997 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2998 }
2999 break;
3000 }
3001
3002 case Primitive::kPrimShort: {
3003 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003004 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003005 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003006 size_t offset =
3007 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003008 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3009 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003010 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003011 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3012 }
3013 break;
3014 }
3015
3016 case Primitive::kPrimChar: {
3017 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003018 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003019 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003020 size_t offset =
3021 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003022 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3023 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003024 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003025 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3026 }
3027 break;
3028 }
3029
3030 case Primitive::kPrimInt:
3031 case Primitive::kPrimNot: {
3032 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3033 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003034 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003035 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003036 size_t offset =
3037 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003038 __ LoadFromOffset(kLoadWord, out, obj, offset);
3039 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003040 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003041 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3042 }
3043 break;
3044 }
3045
3046 case Primitive::kPrimLong: {
3047 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003048 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003049 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003050 size_t offset =
3051 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003052 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003053 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003054 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003055 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003056 }
3057 break;
3058 }
3059
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003060 case Primitive::kPrimFloat: {
3061 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3062 Location out = locations->Out();
3063 DCHECK(out.IsFpuRegister());
3064 if (index.IsConstant()) {
3065 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3066 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3067 } else {
3068 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3069 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3070 }
3071 break;
3072 }
3073
3074 case Primitive::kPrimDouble: {
3075 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3076 Location out = locations->Out();
3077 DCHECK(out.IsFpuRegisterPair());
3078 if (index.IsConstant()) {
3079 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3080 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3081 } else {
3082 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3083 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3084 }
3085 break;
3086 }
3087
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003088 case Primitive::kPrimVoid:
3089 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003090 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003091 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003092 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003093}
3094
3095void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003096 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003097
3098 bool needs_write_barrier =
3099 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3100 bool needs_runtime_call = instruction->NeedsTypeCheck();
3101
Nicolas Geoffray39468442014-09-02 15:17:15 +01003102 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003103 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3104 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003105 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003106 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3107 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3108 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003109 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003110 locations->SetInAt(0, Location::RequiresRegister());
3111 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3112 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003113
3114 if (needs_write_barrier) {
3115 // Temporary registers for the write barrier.
3116 locations->AddTemp(Location::RequiresRegister());
3117 locations->AddTemp(Location::RequiresRegister());
3118 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003119 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003120}
3121
3122void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3123 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003124 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003125 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003126 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003127 bool needs_runtime_call = locations->WillCall();
3128 bool needs_write_barrier =
3129 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003130
3131 switch (value_type) {
3132 case Primitive::kPrimBoolean:
3133 case Primitive::kPrimByte: {
3134 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003135 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003136 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003137 size_t offset =
3138 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003139 __ StoreToOffset(kStoreByte, value, obj, offset);
3140 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003141 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003142 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3143 }
3144 break;
3145 }
3146
3147 case Primitive::kPrimShort:
3148 case Primitive::kPrimChar: {
3149 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003150 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003151 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003152 size_t offset =
3153 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003154 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3155 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003156 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003157 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3158 }
3159 break;
3160 }
3161
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003162 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003163 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003164 if (!needs_runtime_call) {
3165 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003166 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003167 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003168 size_t offset =
3169 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003170 __ StoreToOffset(kStoreWord, value, obj, offset);
3171 } else {
3172 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003173 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003174 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3175 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003176 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003177 if (needs_write_barrier) {
3178 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003179 Register temp = locations->GetTemp(0).AsRegister<Register>();
3180 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003181 codegen_->MarkGCCard(temp, card, obj, value);
3182 }
3183 } else {
3184 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003185 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3186 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003187 instruction->GetDexPc(),
3188 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003189 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003190 break;
3191 }
3192
3193 case Primitive::kPrimLong: {
3194 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003195 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003196 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003197 size_t offset =
3198 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003199 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003200 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003201 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003202 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003203 }
3204 break;
3205 }
3206
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003207 case Primitive::kPrimFloat: {
3208 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3209 Location value = locations->InAt(2);
3210 DCHECK(value.IsFpuRegister());
3211 if (index.IsConstant()) {
3212 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3213 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3214 } else {
3215 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3216 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3217 }
3218 break;
3219 }
3220
3221 case Primitive::kPrimDouble: {
3222 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3223 Location value = locations->InAt(2);
3224 DCHECK(value.IsFpuRegisterPair());
3225 if (index.IsConstant()) {
3226 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3227 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3228 } else {
3229 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3230 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3231 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003232
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003233 break;
3234 }
3235
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003236 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003237 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003238 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003239 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003240
3241 // Ints and objects are handled in the switch.
3242 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3243 codegen_->MaybeRecordImplicitNullCheck(instruction);
3244 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003245}
3246
3247void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003248 LocationSummary* locations =
3249 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003250 locations->SetInAt(0, Location::RequiresRegister());
3251 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003252}
3253
3254void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3255 LocationSummary* locations = instruction->GetLocations();
3256 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003257 Register obj = locations->InAt(0).AsRegister<Register>();
3258 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003259 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003260 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003261}
3262
3263void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003264 LocationSummary* locations =
3265 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003266 locations->SetInAt(0, Location::RequiresRegister());
3267 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003268 if (instruction->HasUses()) {
3269 locations->SetOut(Location::SameAsFirstInput());
3270 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003271}
3272
3273void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3274 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003275 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003276 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003277 codegen_->AddSlowPath(slow_path);
3278
Roland Levillain271ab9c2014-11-27 15:23:57 +00003279 Register index = locations->InAt(0).AsRegister<Register>();
3280 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003281
3282 __ cmp(index, ShifterOperand(length));
3283 __ b(slow_path->GetEntryLabel(), CS);
3284}
3285
3286void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3287 Label is_null;
3288 __ CompareAndBranchIfZero(value, &is_null);
3289 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3290 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3291 __ strb(card, Address(card, temp));
3292 __ Bind(&is_null);
3293}
3294
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003295void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3296 temp->SetLocations(nullptr);
3297}
3298
3299void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3300 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003301 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003302}
3303
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003304void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003305 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003306 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003307}
3308
3309void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003310 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3311}
3312
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003313void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3314 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3315}
3316
3317void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003318 HBasicBlock* block = instruction->GetBlock();
3319 if (block->GetLoopInformation() != nullptr) {
3320 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3321 // The back edge will generate the suspend check.
3322 return;
3323 }
3324 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3325 // The goto will generate the suspend check.
3326 return;
3327 }
3328 GenerateSuspendCheck(instruction, nullptr);
3329}
3330
3331void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3332 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003333 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003334 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003335 codegen_->AddSlowPath(slow_path);
3336
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003337 __ LoadFromOffset(
3338 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3339 __ cmp(IP, ShifterOperand(0));
3340 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003341 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003342 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003343 __ Bind(slow_path->GetReturnLabel());
3344 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003345 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003346 __ b(slow_path->GetEntryLabel());
3347 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003348}
3349
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003350ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3351 return codegen_->GetAssembler();
3352}
3353
3354void ParallelMoveResolverARM::EmitMove(size_t index) {
3355 MoveOperands* move = moves_.Get(index);
3356 Location source = move->GetSource();
3357 Location destination = move->GetDestination();
3358
3359 if (source.IsRegister()) {
3360 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003361 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003362 } else {
3363 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003364 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003365 SP, destination.GetStackIndex());
3366 }
3367 } else if (source.IsStackSlot()) {
3368 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003369 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003370 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003371 } else if (destination.IsFpuRegister()) {
3372 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003373 } else {
3374 DCHECK(destination.IsStackSlot());
3375 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3376 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3377 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003378 } else if (source.IsFpuRegister()) {
3379 if (destination.IsFpuRegister()) {
3380 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003381 } else {
3382 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003383 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3384 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003385 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003386 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003387 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3388 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003389 } else if (destination.IsRegisterPair()) {
3390 DCHECK(ExpectedPairLayout(destination));
3391 __ LoadFromOffset(
3392 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3393 } else {
3394 DCHECK(destination.IsFpuRegisterPair()) << destination;
3395 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3396 SP,
3397 source.GetStackIndex());
3398 }
3399 } else if (source.IsRegisterPair()) {
3400 if (destination.IsRegisterPair()) {
3401 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3402 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3403 } else {
3404 DCHECK(destination.IsDoubleStackSlot()) << destination;
3405 DCHECK(ExpectedPairLayout(source));
3406 __ StoreToOffset(
3407 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3408 }
3409 } else if (source.IsFpuRegisterPair()) {
3410 if (destination.IsFpuRegisterPair()) {
3411 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3412 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3413 } else {
3414 DCHECK(destination.IsDoubleStackSlot()) << destination;
3415 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3416 SP,
3417 destination.GetStackIndex());
3418 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003419 } else {
3420 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003421 HConstant* constant = source.GetConstant();
3422 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3423 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003424 if (destination.IsRegister()) {
3425 __ LoadImmediate(destination.AsRegister<Register>(), value);
3426 } else {
3427 DCHECK(destination.IsStackSlot());
3428 __ LoadImmediate(IP, value);
3429 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3430 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003431 } else if (constant->IsLongConstant()) {
3432 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003433 if (destination.IsRegisterPair()) {
3434 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3435 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003436 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003437 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003438 __ LoadImmediate(IP, Low32Bits(value));
3439 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3440 __ LoadImmediate(IP, High32Bits(value));
3441 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3442 }
3443 } else if (constant->IsDoubleConstant()) {
3444 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003445 if (destination.IsFpuRegisterPair()) {
3446 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003447 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003448 DCHECK(destination.IsDoubleStackSlot()) << destination;
3449 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003450 __ LoadImmediate(IP, Low32Bits(int_value));
3451 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3452 __ LoadImmediate(IP, High32Bits(int_value));
3453 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3454 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003455 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003456 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003457 float value = constant->AsFloatConstant()->GetValue();
3458 if (destination.IsFpuRegister()) {
3459 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3460 } else {
3461 DCHECK(destination.IsStackSlot());
3462 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3463 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3464 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003465 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003466 }
3467}
3468
3469void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3470 __ Mov(IP, reg);
3471 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3472 __ StoreToOffset(kStoreWord, IP, SP, mem);
3473}
3474
3475void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3476 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3477 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3478 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3479 SP, mem1 + stack_offset);
3480 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3481 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3482 SP, mem2 + stack_offset);
3483 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3484}
3485
3486void ParallelMoveResolverARM::EmitSwap(size_t index) {
3487 MoveOperands* move = moves_.Get(index);
3488 Location source = move->GetSource();
3489 Location destination = move->GetDestination();
3490
3491 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003492 DCHECK_NE(source.AsRegister<Register>(), IP);
3493 DCHECK_NE(destination.AsRegister<Register>(), IP);
3494 __ Mov(IP, source.AsRegister<Register>());
3495 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3496 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003497 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003498 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003499 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003500 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003501 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3502 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003503 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003504 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003505 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003506 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003507 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003508 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003509 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003510 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003511 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3512 destination.AsRegisterPairHigh<Register>(),
3513 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003514 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003515 Register low_reg = source.IsRegisterPair()
3516 ? source.AsRegisterPairLow<Register>()
3517 : destination.AsRegisterPairLow<Register>();
3518 int mem = source.IsRegisterPair()
3519 ? destination.GetStackIndex()
3520 : source.GetStackIndex();
3521 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003522 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003523 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003524 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003525 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003526 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3527 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003528 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003529 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003530 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003531 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3532 DRegister reg = source.IsFpuRegisterPair()
3533 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3534 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3535 int mem = source.IsFpuRegisterPair()
3536 ? destination.GetStackIndex()
3537 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003538 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003539 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003540 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003541 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3542 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3543 : destination.AsFpuRegister<SRegister>();
3544 int mem = source.IsFpuRegister()
3545 ? destination.GetStackIndex()
3546 : source.GetStackIndex();
3547
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003548 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003549 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003550 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003551 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003552 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3553 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003554 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003555 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003556 }
3557}
3558
3559void ParallelMoveResolverARM::SpillScratch(int reg) {
3560 __ Push(static_cast<Register>(reg));
3561}
3562
3563void ParallelMoveResolverARM::RestoreScratch(int reg) {
3564 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003565}
3566
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003567void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003568 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3569 ? LocationSummary::kCallOnSlowPath
3570 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003571 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003572 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003573 locations->SetOut(Location::RequiresRegister());
3574}
3575
3576void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003577 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003578 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003579 DCHECK(!cls->CanCallRuntime());
3580 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003581 codegen_->LoadCurrentMethod(out);
3582 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3583 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003584 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003585 codegen_->LoadCurrentMethod(out);
3586 __ LoadFromOffset(
3587 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3588 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003589
3590 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3591 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3592 codegen_->AddSlowPath(slow_path);
3593 __ cmp(out, ShifterOperand(0));
3594 __ b(slow_path->GetEntryLabel(), EQ);
3595 if (cls->MustGenerateClinitCheck()) {
3596 GenerateClassInitializationCheck(slow_path, out);
3597 } else {
3598 __ Bind(slow_path->GetExitLabel());
3599 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003600 }
3601}
3602
3603void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3604 LocationSummary* locations =
3605 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3606 locations->SetInAt(0, Location::RequiresRegister());
3607 if (check->HasUses()) {
3608 locations->SetOut(Location::SameAsFirstInput());
3609 }
3610}
3611
3612void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003613 // We assume the class is not null.
3614 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3615 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003616 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003617 GenerateClassInitializationCheck(slow_path,
3618 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003619}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003620
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003621void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3622 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003623 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3624 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3625 __ b(slow_path->GetEntryLabel(), LT);
3626 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3627 // properly. Therefore, we do a memory fence.
3628 __ dmb(ISH);
3629 __ Bind(slow_path->GetExitLabel());
3630}
3631
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003632void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3633 LocationSummary* locations =
3634 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3635 locations->SetOut(Location::RequiresRegister());
3636}
3637
3638void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3639 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3640 codegen_->AddSlowPath(slow_path);
3641
Roland Levillain271ab9c2014-11-27 15:23:57 +00003642 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003643 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003644 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3645 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003646 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3647 __ cmp(out, ShifterOperand(0));
3648 __ b(slow_path->GetEntryLabel(), EQ);
3649 __ Bind(slow_path->GetExitLabel());
3650}
3651
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003652void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3653 LocationSummary* locations =
3654 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3655 locations->SetOut(Location::RequiresRegister());
3656}
3657
3658void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003659 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003660 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3661 __ LoadFromOffset(kLoadWord, out, TR, offset);
3662 __ LoadImmediate(IP, 0);
3663 __ StoreToOffset(kStoreWord, IP, TR, offset);
3664}
3665
3666void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3667 LocationSummary* locations =
3668 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3669 InvokeRuntimeCallingConvention calling_convention;
3670 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3671}
3672
3673void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3674 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003675 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003676}
3677
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003678void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003679 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3680 ? LocationSummary::kNoCall
3681 : LocationSummary::kCallOnSlowPath;
3682 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3683 locations->SetInAt(0, Location::RequiresRegister());
3684 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003685 // The out register is used as a temporary, so it overlaps with the inputs.
3686 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003687}
3688
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003689void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003690 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003691 Register obj = locations->InAt(0).AsRegister<Register>();
3692 Register cls = locations->InAt(1).AsRegister<Register>();
3693 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003694 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3695 Label done, zero;
3696 SlowPathCodeARM* slow_path = nullptr;
3697
3698 // Return 0 if `obj` is null.
3699 // TODO: avoid this check if we know obj is not null.
3700 __ cmp(obj, ShifterOperand(0));
3701 __ b(&zero, EQ);
3702 // Compare the class of `obj` with `cls`.
3703 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3704 __ cmp(out, ShifterOperand(cls));
3705 if (instruction->IsClassFinal()) {
3706 // Classes must be equal for the instanceof to succeed.
3707 __ b(&zero, NE);
3708 __ LoadImmediate(out, 1);
3709 __ b(&done);
3710 } else {
3711 // If the classes are not equal, we go into a slow path.
3712 DCHECK(locations->OnlyCallsOnSlowPath());
3713 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003714 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003715 codegen_->AddSlowPath(slow_path);
3716 __ b(slow_path->GetEntryLabel(), NE);
3717 __ LoadImmediate(out, 1);
3718 __ b(&done);
3719 }
3720 __ Bind(&zero);
3721 __ LoadImmediate(out, 0);
3722 if (slow_path != nullptr) {
3723 __ Bind(slow_path->GetExitLabel());
3724 }
3725 __ Bind(&done);
3726}
3727
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003728void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3729 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3730 instruction, LocationSummary::kCallOnSlowPath);
3731 locations->SetInAt(0, Location::RequiresRegister());
3732 locations->SetInAt(1, Location::RequiresRegister());
3733 locations->AddTemp(Location::RequiresRegister());
3734}
3735
3736void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3737 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003738 Register obj = locations->InAt(0).AsRegister<Register>();
3739 Register cls = locations->InAt(1).AsRegister<Register>();
3740 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003741 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3742
3743 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3744 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3745 codegen_->AddSlowPath(slow_path);
3746
3747 // TODO: avoid this check if we know obj is not null.
3748 __ cmp(obj, ShifterOperand(0));
3749 __ b(slow_path->GetExitLabel(), EQ);
3750 // Compare the class of `obj` with `cls`.
3751 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3752 __ cmp(temp, ShifterOperand(cls));
3753 __ b(slow_path->GetEntryLabel(), NE);
3754 __ Bind(slow_path->GetExitLabel());
3755}
3756
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003757void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3758 LocationSummary* locations =
3759 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3760 InvokeRuntimeCallingConvention calling_convention;
3761 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3762}
3763
3764void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3765 codegen_->InvokeRuntime(instruction->IsEnter()
3766 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3767 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003768 instruction->GetDexPc(),
3769 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003770}
3771
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003772void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3773void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3774void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3775
3776void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3777 LocationSummary* locations =
3778 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3779 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3780 || instruction->GetResultType() == Primitive::kPrimLong);
3781 locations->SetInAt(0, Location::RequiresRegister());
3782 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003783 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003784}
3785
3786void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3787 HandleBitwiseOperation(instruction);
3788}
3789
3790void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3791 HandleBitwiseOperation(instruction);
3792}
3793
3794void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3795 HandleBitwiseOperation(instruction);
3796}
3797
3798void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3799 LocationSummary* locations = instruction->GetLocations();
3800
3801 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003802 Register first = locations->InAt(0).AsRegister<Register>();
3803 Register second = locations->InAt(1).AsRegister<Register>();
3804 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003805 if (instruction->IsAnd()) {
3806 __ and_(out, first, ShifterOperand(second));
3807 } else if (instruction->IsOr()) {
3808 __ orr(out, first, ShifterOperand(second));
3809 } else {
3810 DCHECK(instruction->IsXor());
3811 __ eor(out, first, ShifterOperand(second));
3812 }
3813 } else {
3814 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3815 Location first = locations->InAt(0);
3816 Location second = locations->InAt(1);
3817 Location out = locations->Out();
3818 if (instruction->IsAnd()) {
3819 __ and_(out.AsRegisterPairLow<Register>(),
3820 first.AsRegisterPairLow<Register>(),
3821 ShifterOperand(second.AsRegisterPairLow<Register>()));
3822 __ and_(out.AsRegisterPairHigh<Register>(),
3823 first.AsRegisterPairHigh<Register>(),
3824 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3825 } else if (instruction->IsOr()) {
3826 __ orr(out.AsRegisterPairLow<Register>(),
3827 first.AsRegisterPairLow<Register>(),
3828 ShifterOperand(second.AsRegisterPairLow<Register>()));
3829 __ orr(out.AsRegisterPairHigh<Register>(),
3830 first.AsRegisterPairHigh<Register>(),
3831 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3832 } else {
3833 DCHECK(instruction->IsXor());
3834 __ eor(out.AsRegisterPairLow<Register>(),
3835 first.AsRegisterPairLow<Register>(),
3836 ShifterOperand(second.AsRegisterPairLow<Register>()));
3837 __ eor(out.AsRegisterPairHigh<Register>(),
3838 first.AsRegisterPairHigh<Register>(),
3839 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3840 }
3841 }
3842}
3843
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003844void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
3845 DCHECK_EQ(temp, kArtMethodRegister);
3846
3847 // TODO: Implement all kinds of calls:
3848 // 1) boot -> boot
3849 // 2) app -> boot
3850 // 3) app -> app
3851 //
3852 // Currently we implement the app -> app logic, which looks up in the resolve cache.
3853
3854 // temp = method;
3855 LoadCurrentMethod(temp);
3856 if (!invoke->IsRecursive()) {
3857 // temp = temp->dex_cache_resolved_methods_;
3858 __ LoadFromOffset(
3859 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
3860 // temp = temp[index_in_cache]
3861 __ LoadFromOffset(
3862 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
3863 // LR = temp[offset_of_quick_compiled_code]
3864 __ LoadFromOffset(kLoadWord, LR, temp,
3865 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3866 kArmWordSize).Int32Value());
3867 // LR()
3868 __ blx(LR);
3869 } else {
3870 __ bl(GetFrameEntryLabel());
3871 }
3872
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003873 DCHECK(!IsLeafMethod());
3874}
3875
Calin Juravleb1498f62015-02-16 13:13:29 +00003876void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
3877 // Nothing to do, this should be removed during prepare for register allocator.
3878 UNUSED(instruction);
3879 LOG(FATAL) << "Unreachable";
3880}
3881
3882void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
3883 // Nothing to do, this should be removed during prepare for register allocator.
3884 UNUSED(instruction);
3885 LOG(FATAL) << "Unreachable";
3886}
3887
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003888} // namespace arm
3889} // namespace art