blob: d7839033495d4a875c81023e6380218f1cd9bba3 [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();
David Brazdil46e2a392015-03-16 17:31:52 +0000886 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100887 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}
907
Andreas Gampe0ba62732015-03-24 02:39:46 +0000908void LocationsBuilderARM::VisitIf(HIf* if_instr) {
909 LocationSummary* locations =
910 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
911 HInstruction* cond = if_instr->InputAt(0);
912 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
913 locations->SetInAt(0, Location::RequiresRegister());
914 }
915}
916
917void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
918 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100919 if (cond->IsIntConstant()) {
920 // Constant condition, statically compared against 1.
921 int32_t cond_value = cond->AsIntConstant()->GetValue();
922 if (cond_value == 1) {
Andreas Gampe0ba62732015-03-24 02:39:46 +0000923 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
924 if_instr->IfTrueSuccessor())) {
925 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100926 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100927 return;
928 } else {
929 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100930 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100931 } else {
932 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
933 // Condition has been materialized, compare the output to 0
Andreas Gampe0ba62732015-03-24 02:39:46 +0000934 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
935 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100936 ShifterOperand(0));
Andreas Gampe0ba62732015-03-24 02:39:46 +0000937 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100938 } else {
939 // Condition has not been materialized, use its inputs as the
940 // comparison and its condition as the branch condition.
941 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000942 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000943 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100944 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000945 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100946 } else {
947 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000948 HConstant* constant = locations->InAt(1).GetConstant();
949 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100950 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000951 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
952 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100953 } else {
954 Register temp = IP;
955 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000956 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100957 }
958 }
Andreas Gampe0ba62732015-03-24 02:39:46 +0000959 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
960 ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100961 }
Dave Allison20dfc792014-06-16 20:44:29 -0700962 }
Andreas Gampe0ba62732015-03-24 02:39:46 +0000963 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
964 if_instr->IfFalseSuccessor())) {
965 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000966 }
967}
968
Dave Allison20dfc792014-06-16 20:44:29 -0700969
970void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100971 LocationSummary* locations =
972 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100973 locations->SetInAt(0, Location::RequiresRegister());
974 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100975 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100976 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100977 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000978}
979
Dave Allison20dfc792014-06-16 20:44:29 -0700980void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100982 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000983 Register left = locations->InAt(0).AsRegister<Register>();
984
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100985 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000986 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100987 } else {
988 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -0800989 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100990 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000991 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
992 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100993 } else {
994 Register temp = IP;
995 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000996 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 }
Dave Allison20dfc792014-06-16 20:44:29 -0700998 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100999 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001000 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001001 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001002 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001003 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001004}
1005
1006void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1007 VisitCondition(comp);
1008}
1009
1010void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1011 VisitCondition(comp);
1012}
1013
1014void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1015 VisitCondition(comp);
1016}
1017
1018void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1019 VisitCondition(comp);
1020}
1021
1022void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1023 VisitCondition(comp);
1024}
1025
1026void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1027 VisitCondition(comp);
1028}
1029
1030void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1031 VisitCondition(comp);
1032}
1033
1034void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1035 VisitCondition(comp);
1036}
1037
1038void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1039 VisitCondition(comp);
1040}
1041
1042void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1043 VisitCondition(comp);
1044}
1045
1046void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1047 VisitCondition(comp);
1048}
1049
1050void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1051 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001052}
1053
1054void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001055 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001056}
1057
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001058void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1059 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001060}
1061
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001062void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001063 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001064}
1065
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001066void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001067 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001068 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001069}
1070
1071void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001072 LocationSummary* locations =
1073 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001074 switch (store->InputAt(1)->GetType()) {
1075 case Primitive::kPrimBoolean:
1076 case Primitive::kPrimByte:
1077 case Primitive::kPrimChar:
1078 case Primitive::kPrimShort:
1079 case Primitive::kPrimInt:
1080 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001081 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001082 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1083 break;
1084
1085 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001086 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001087 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1088 break;
1089
1090 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001091 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001092 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001093}
1094
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001095void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001096 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001097}
1098
1099void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001100 LocationSummary* locations =
1101 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001102 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001103}
1104
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001105void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001106 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001107 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001108}
1109
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001110void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1111 LocationSummary* locations =
1112 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1113 locations->SetOut(Location::ConstantLocation(constant));
1114}
1115
1116void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1117 // Will be generated at use site.
1118 UNUSED(constant);
1119}
1120
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001121void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001122 LocationSummary* locations =
1123 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001124 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001125}
1126
1127void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1128 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001129 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001130}
1131
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001132void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1133 LocationSummary* locations =
1134 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1135 locations->SetOut(Location::ConstantLocation(constant));
1136}
1137
1138void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1139 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001140 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001141}
1142
1143void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1144 LocationSummary* locations =
1145 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1146 locations->SetOut(Location::ConstantLocation(constant));
1147}
1148
1149void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1150 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001151 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001152}
1153
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001154void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001155 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001156}
1157
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001158void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001159 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001160 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001161}
1162
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001163void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001164 LocationSummary* locations =
1165 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001166 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001167}
1168
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001169void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001170 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001171 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001172}
1173
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001174void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001175 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1176 codegen_->GetInstructionSetFeatures());
1177 if (intrinsic.TryDispatch(invoke)) {
1178 return;
1179 }
1180
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001181 HandleInvoke(invoke);
1182}
1183
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001184void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001185 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001186 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001187}
1188
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001189static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1190 if (invoke->GetLocations()->Intrinsified()) {
1191 IntrinsicCodeGeneratorARM intrinsic(codegen);
1192 intrinsic.Dispatch(invoke);
1193 return true;
1194 }
1195 return false;
1196}
1197
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001198void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001199 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1200 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001201 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001202
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001203 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1204
1205 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001206 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001207}
1208
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001209void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001210 LocationSummary* locations =
1211 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001212 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001213
1214 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001215 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001216 HInstruction* input = invoke->InputAt(i);
1217 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1218 }
1219
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001220 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001221}
1222
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001223void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001224 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1225 codegen_->GetInstructionSetFeatures());
1226 if (intrinsic.TryDispatch(invoke)) {
1227 return;
1228 }
1229
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001230 HandleInvoke(invoke);
1231}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001232
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001233void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001234 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1235 return;
1236 }
1237
Roland Levillain271ab9c2014-11-27 15:23:57 +00001238 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001239 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1240 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1241 LocationSummary* locations = invoke->GetLocations();
1242 Location receiver = locations->InAt(0);
1243 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1244 // temp = object->GetClass();
1245 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001246 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1247 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001248 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001249 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001250 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001251 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001252 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001253 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001254 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001255 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001256 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001257 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001258 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001259 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001260 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001261 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001262}
1263
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001264void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1265 HandleInvoke(invoke);
1266 // Add the hidden argument.
1267 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1268}
1269
1270void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1271 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001272 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001273 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1274 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1275 LocationSummary* locations = invoke->GetLocations();
1276 Location receiver = locations->InAt(0);
1277 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1278
1279 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001280 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1281 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001282
1283 // temp = object->GetClass();
1284 if (receiver.IsStackSlot()) {
1285 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1286 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1287 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001288 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001289 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001290 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001291 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001292 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001293 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001294 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1295 // LR = temp->GetEntryPoint();
1296 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1297 // LR();
1298 __ blx(LR);
1299 DCHECK(!codegen_->IsLeafMethod());
1300 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1301}
1302
Roland Levillain88cb1752014-10-20 16:36:47 +01001303void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1304 LocationSummary* locations =
1305 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1306 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001307 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001308 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001309 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1310 break;
1311 }
1312 case Primitive::kPrimLong: {
1313 locations->SetInAt(0, Location::RequiresRegister());
1314 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001315 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001316 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001317
Roland Levillain88cb1752014-10-20 16:36:47 +01001318 case Primitive::kPrimFloat:
1319 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001320 locations->SetInAt(0, Location::RequiresFpuRegister());
1321 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001322 break;
1323
1324 default:
1325 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1326 }
1327}
1328
1329void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1330 LocationSummary* locations = neg->GetLocations();
1331 Location out = locations->Out();
1332 Location in = locations->InAt(0);
1333 switch (neg->GetResultType()) {
1334 case Primitive::kPrimInt:
1335 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001336 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001337 break;
1338
1339 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001340 DCHECK(in.IsRegisterPair());
1341 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1342 __ rsbs(out.AsRegisterPairLow<Register>(),
1343 in.AsRegisterPairLow<Register>(),
1344 ShifterOperand(0));
1345 // We cannot emit an RSC (Reverse Subtract with Carry)
1346 // instruction here, as it does not exist in the Thumb-2
1347 // instruction set. We use the following approach
1348 // using SBC and SUB instead.
1349 //
1350 // out.hi = -C
1351 __ sbc(out.AsRegisterPairHigh<Register>(),
1352 out.AsRegisterPairHigh<Register>(),
1353 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1354 // out.hi = out.hi - in.hi
1355 __ sub(out.AsRegisterPairHigh<Register>(),
1356 out.AsRegisterPairHigh<Register>(),
1357 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1358 break;
1359
Roland Levillain88cb1752014-10-20 16:36:47 +01001360 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001361 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001362 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001363 break;
1364
Roland Levillain88cb1752014-10-20 16:36:47 +01001365 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001366 DCHECK(in.IsFpuRegisterPair());
1367 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1368 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001369 break;
1370
1371 default:
1372 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1373 }
1374}
1375
Roland Levillaindff1f282014-11-05 14:15:05 +00001376void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001377 Primitive::Type result_type = conversion->GetResultType();
1378 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001379 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001380
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001381 // The float-to-long and double-to-long type conversions rely on a
1382 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001383 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001384 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1385 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001386 ? LocationSummary::kCall
1387 : LocationSummary::kNoCall;
1388 LocationSummary* locations =
1389 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1390
David Brazdil46e2a392015-03-16 17:31:52 +00001391 // Java language does not allow treating boolean as an integral type but our
1392 // bit representation makes it safe.
1393
Roland Levillaindff1f282014-11-05 14:15:05 +00001394 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001395 case Primitive::kPrimByte:
1396 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001397 case Primitive::kPrimBoolean:
1398 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001399 case Primitive::kPrimShort:
1400 case Primitive::kPrimInt:
1401 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001402 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001403 locations->SetInAt(0, Location::RequiresRegister());
1404 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1405 break;
1406
1407 default:
1408 LOG(FATAL) << "Unexpected type conversion from " << input_type
1409 << " to " << result_type;
1410 }
1411 break;
1412
Roland Levillain01a8d712014-11-14 16:27:39 +00001413 case Primitive::kPrimShort:
1414 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001415 case Primitive::kPrimBoolean:
1416 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001417 case Primitive::kPrimByte:
1418 case Primitive::kPrimInt:
1419 case Primitive::kPrimChar:
1420 // Processing a Dex `int-to-short' instruction.
1421 locations->SetInAt(0, Location::RequiresRegister());
1422 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1423 break;
1424
1425 default:
1426 LOG(FATAL) << "Unexpected type conversion from " << input_type
1427 << " to " << result_type;
1428 }
1429 break;
1430
Roland Levillain946e1432014-11-11 17:35:19 +00001431 case Primitive::kPrimInt:
1432 switch (input_type) {
1433 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001434 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001435 locations->SetInAt(0, Location::Any());
1436 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1437 break;
1438
1439 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001440 // Processing a Dex `float-to-int' instruction.
1441 locations->SetInAt(0, Location::RequiresFpuRegister());
1442 locations->SetOut(Location::RequiresRegister());
1443 locations->AddTemp(Location::RequiresFpuRegister());
1444 break;
1445
Roland Levillain946e1432014-11-11 17:35:19 +00001446 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001447 // Processing a Dex `double-to-int' instruction.
1448 locations->SetInAt(0, Location::RequiresFpuRegister());
1449 locations->SetOut(Location::RequiresRegister());
1450 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001451 break;
1452
1453 default:
1454 LOG(FATAL) << "Unexpected type conversion from " << input_type
1455 << " to " << result_type;
1456 }
1457 break;
1458
Roland Levillaindff1f282014-11-05 14:15:05 +00001459 case Primitive::kPrimLong:
1460 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001461 case Primitive::kPrimBoolean:
1462 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001463 case Primitive::kPrimByte:
1464 case Primitive::kPrimShort:
1465 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001466 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001467 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001468 locations->SetInAt(0, Location::RequiresRegister());
1469 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1470 break;
1471
Roland Levillain624279f2014-12-04 11:54:28 +00001472 case Primitive::kPrimFloat: {
1473 // Processing a Dex `float-to-long' instruction.
1474 InvokeRuntimeCallingConvention calling_convention;
1475 locations->SetInAt(0, Location::FpuRegisterLocation(
1476 calling_convention.GetFpuRegisterAt(0)));
1477 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1478 break;
1479 }
1480
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001481 case Primitive::kPrimDouble: {
1482 // Processing a Dex `double-to-long' instruction.
1483 InvokeRuntimeCallingConvention calling_convention;
1484 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1485 calling_convention.GetFpuRegisterAt(0),
1486 calling_convention.GetFpuRegisterAt(1)));
1487 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001488 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001489 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001490
1491 default:
1492 LOG(FATAL) << "Unexpected type conversion from " << input_type
1493 << " to " << result_type;
1494 }
1495 break;
1496
Roland Levillain981e4542014-11-14 11:47:14 +00001497 case Primitive::kPrimChar:
1498 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001499 case Primitive::kPrimBoolean:
1500 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001501 case Primitive::kPrimByte:
1502 case Primitive::kPrimShort:
1503 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001504 // Processing a Dex `int-to-char' instruction.
1505 locations->SetInAt(0, Location::RequiresRegister());
1506 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1507 break;
1508
1509 default:
1510 LOG(FATAL) << "Unexpected type conversion from " << input_type
1511 << " to " << result_type;
1512 }
1513 break;
1514
Roland Levillaindff1f282014-11-05 14:15:05 +00001515 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001516 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001517 case Primitive::kPrimBoolean:
1518 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001519 case Primitive::kPrimByte:
1520 case Primitive::kPrimShort:
1521 case Primitive::kPrimInt:
1522 case Primitive::kPrimChar:
1523 // Processing a Dex `int-to-float' instruction.
1524 locations->SetInAt(0, Location::RequiresRegister());
1525 locations->SetOut(Location::RequiresFpuRegister());
1526 break;
1527
1528 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001529 // Processing a Dex `long-to-float' instruction.
1530 locations->SetInAt(0, Location::RequiresRegister());
1531 locations->SetOut(Location::RequiresFpuRegister());
1532 locations->AddTemp(Location::RequiresRegister());
1533 locations->AddTemp(Location::RequiresRegister());
1534 locations->AddTemp(Location::RequiresFpuRegister());
1535 locations->AddTemp(Location::RequiresFpuRegister());
1536 break;
1537
Roland Levillaincff13742014-11-17 14:32:17 +00001538 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001539 // Processing a Dex `double-to-float' instruction.
1540 locations->SetInAt(0, Location::RequiresFpuRegister());
1541 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001542 break;
1543
1544 default:
1545 LOG(FATAL) << "Unexpected type conversion from " << input_type
1546 << " to " << result_type;
1547 };
1548 break;
1549
Roland Levillaindff1f282014-11-05 14:15:05 +00001550 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001551 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001552 case Primitive::kPrimBoolean:
1553 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001554 case Primitive::kPrimByte:
1555 case Primitive::kPrimShort:
1556 case Primitive::kPrimInt:
1557 case Primitive::kPrimChar:
1558 // Processing a Dex `int-to-double' instruction.
1559 locations->SetInAt(0, Location::RequiresRegister());
1560 locations->SetOut(Location::RequiresFpuRegister());
1561 break;
1562
1563 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001564 // Processing a Dex `long-to-double' instruction.
1565 locations->SetInAt(0, Location::RequiresRegister());
1566 locations->SetOut(Location::RequiresFpuRegister());
1567 locations->AddTemp(Location::RequiresRegister());
1568 locations->AddTemp(Location::RequiresRegister());
1569 locations->AddTemp(Location::RequiresFpuRegister());
1570 break;
1571
Roland Levillaincff13742014-11-17 14:32:17 +00001572 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001573 // Processing a Dex `float-to-double' instruction.
1574 locations->SetInAt(0, Location::RequiresFpuRegister());
1575 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001576 break;
1577
1578 default:
1579 LOG(FATAL) << "Unexpected type conversion from " << input_type
1580 << " to " << result_type;
1581 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001582 break;
1583
1584 default:
1585 LOG(FATAL) << "Unexpected type conversion from " << input_type
1586 << " to " << result_type;
1587 }
1588}
1589
1590void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1591 LocationSummary* locations = conversion->GetLocations();
1592 Location out = locations->Out();
1593 Location in = locations->InAt(0);
1594 Primitive::Type result_type = conversion->GetResultType();
1595 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001596 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001597 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001598 case Primitive::kPrimByte:
1599 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001600 case Primitive::kPrimBoolean:
1601 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001602 case Primitive::kPrimShort:
1603 case Primitive::kPrimInt:
1604 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001605 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001606 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001607 break;
1608
1609 default:
1610 LOG(FATAL) << "Unexpected type conversion from " << input_type
1611 << " to " << result_type;
1612 }
1613 break;
1614
Roland Levillain01a8d712014-11-14 16:27:39 +00001615 case Primitive::kPrimShort:
1616 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001617 case Primitive::kPrimBoolean:
1618 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001619 case Primitive::kPrimByte:
1620 case Primitive::kPrimInt:
1621 case Primitive::kPrimChar:
1622 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001623 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001624 break;
1625
1626 default:
1627 LOG(FATAL) << "Unexpected type conversion from " << input_type
1628 << " to " << result_type;
1629 }
1630 break;
1631
Roland Levillain946e1432014-11-11 17:35:19 +00001632 case Primitive::kPrimInt:
1633 switch (input_type) {
1634 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001635 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001636 DCHECK(out.IsRegister());
1637 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001638 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001639 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001640 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001641 } else {
1642 DCHECK(in.IsConstant());
1643 DCHECK(in.GetConstant()->IsLongConstant());
1644 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001645 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001646 }
1647 break;
1648
Roland Levillain3f8f9362014-12-02 17:45:01 +00001649 case Primitive::kPrimFloat: {
1650 // Processing a Dex `float-to-int' instruction.
1651 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1652 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1653 __ vcvtis(temp, temp);
1654 __ vmovrs(out.AsRegister<Register>(), temp);
1655 break;
1656 }
1657
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001658 case Primitive::kPrimDouble: {
1659 // Processing a Dex `double-to-int' instruction.
1660 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1661 DRegister temp_d = FromLowSToD(temp_s);
1662 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1663 __ vcvtid(temp_s, temp_d);
1664 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001665 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001666 }
Roland Levillain946e1432014-11-11 17:35:19 +00001667
1668 default:
1669 LOG(FATAL) << "Unexpected type conversion from " << input_type
1670 << " to " << result_type;
1671 }
1672 break;
1673
Roland Levillaindff1f282014-11-05 14:15:05 +00001674 case Primitive::kPrimLong:
1675 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001676 case Primitive::kPrimBoolean:
1677 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001678 case Primitive::kPrimByte:
1679 case Primitive::kPrimShort:
1680 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001681 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001682 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001683 DCHECK(out.IsRegisterPair());
1684 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001685 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001686 // Sign extension.
1687 __ Asr(out.AsRegisterPairHigh<Register>(),
1688 out.AsRegisterPairLow<Register>(),
1689 31);
1690 break;
1691
1692 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001693 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001694 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1695 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001696 conversion->GetDexPc(),
1697 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001698 break;
1699
Roland Levillaindff1f282014-11-05 14:15:05 +00001700 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001701 // Processing a Dex `double-to-long' instruction.
1702 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1703 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001704 conversion->GetDexPc(),
1705 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001706 break;
1707
1708 default:
1709 LOG(FATAL) << "Unexpected type conversion from " << input_type
1710 << " to " << result_type;
1711 }
1712 break;
1713
Roland Levillain981e4542014-11-14 11:47:14 +00001714 case Primitive::kPrimChar:
1715 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001716 case Primitive::kPrimBoolean:
1717 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001718 case Primitive::kPrimByte:
1719 case Primitive::kPrimShort:
1720 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001721 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001722 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001723 break;
1724
1725 default:
1726 LOG(FATAL) << "Unexpected type conversion from " << input_type
1727 << " to " << result_type;
1728 }
1729 break;
1730
Roland Levillaindff1f282014-11-05 14:15:05 +00001731 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001732 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001733 case Primitive::kPrimBoolean:
1734 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001735 case Primitive::kPrimByte:
1736 case Primitive::kPrimShort:
1737 case Primitive::kPrimInt:
1738 case Primitive::kPrimChar: {
1739 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001740 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1741 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001742 break;
1743 }
1744
Roland Levillain6d0e4832014-11-27 18:31:21 +00001745 case Primitive::kPrimLong: {
1746 // Processing a Dex `long-to-float' instruction.
1747 Register low = in.AsRegisterPairLow<Register>();
1748 Register high = in.AsRegisterPairHigh<Register>();
1749 SRegister output = out.AsFpuRegister<SRegister>();
1750 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1751 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1752 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1753 DRegister temp1_d = FromLowSToD(temp1_s);
1754 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1755 DRegister temp2_d = FromLowSToD(temp2_s);
1756
1757 // Operations use doubles for precision reasons (each 32-bit
1758 // half of a long fits in the 53-bit mantissa of a double,
1759 // but not in the 24-bit mantissa of a float). This is
1760 // especially important for the low bits. The result is
1761 // eventually converted to float.
1762
1763 // temp1_d = int-to-double(high)
1764 __ vmovsr(temp1_s, high);
1765 __ vcvtdi(temp1_d, temp1_s);
1766 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1767 // as an immediate value into `temp2_d` does not work, as
1768 // this instruction only transfers 8 significant bits of its
1769 // immediate operand. Instead, use two 32-bit core
1770 // registers to load `k2Pow32EncodingForDouble` into
1771 // `temp2_d`.
1772 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1773 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1774 __ vmovdrr(temp2_d, constant_low, constant_high);
1775 // temp1_d = temp1_d * 2^32
1776 __ vmuld(temp1_d, temp1_d, temp2_d);
1777 // temp2_d = unsigned-to-double(low)
1778 __ vmovsr(temp2_s, low);
1779 __ vcvtdu(temp2_d, temp2_s);
1780 // temp1_d = temp1_d + temp2_d
1781 __ vaddd(temp1_d, temp1_d, temp2_d);
1782 // output = double-to-float(temp1_d);
1783 __ vcvtsd(output, temp1_d);
1784 break;
1785 }
1786
Roland Levillaincff13742014-11-17 14:32:17 +00001787 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001788 // Processing a Dex `double-to-float' instruction.
1789 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1790 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001791 break;
1792
1793 default:
1794 LOG(FATAL) << "Unexpected type conversion from " << input_type
1795 << " to " << result_type;
1796 };
1797 break;
1798
Roland Levillaindff1f282014-11-05 14:15:05 +00001799 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001800 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001801 case Primitive::kPrimBoolean:
1802 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001803 case Primitive::kPrimByte:
1804 case Primitive::kPrimShort:
1805 case Primitive::kPrimInt:
1806 case Primitive::kPrimChar: {
1807 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001808 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001809 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1810 out.AsFpuRegisterPairLow<SRegister>());
1811 break;
1812 }
1813
Roland Levillain647b9ed2014-11-27 12:06:00 +00001814 case Primitive::kPrimLong: {
1815 // Processing a Dex `long-to-double' instruction.
1816 Register low = in.AsRegisterPairLow<Register>();
1817 Register high = in.AsRegisterPairHigh<Register>();
1818 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1819 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001820 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1821 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001822 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1823 DRegister temp_d = FromLowSToD(temp_s);
1824
Roland Levillain647b9ed2014-11-27 12:06:00 +00001825 // out_d = int-to-double(high)
1826 __ vmovsr(out_s, high);
1827 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001828 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1829 // as an immediate value into `temp_d` does not work, as
1830 // this instruction only transfers 8 significant bits of its
1831 // immediate operand. Instead, use two 32-bit core
1832 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1833 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1834 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001835 __ vmovdrr(temp_d, constant_low, constant_high);
1836 // out_d = out_d * 2^32
1837 __ vmuld(out_d, out_d, temp_d);
1838 // temp_d = unsigned-to-double(low)
1839 __ vmovsr(temp_s, low);
1840 __ vcvtdu(temp_d, temp_s);
1841 // out_d = out_d + temp_d
1842 __ vaddd(out_d, out_d, temp_d);
1843 break;
1844 }
1845
Roland Levillaincff13742014-11-17 14:32:17 +00001846 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001847 // Processing a Dex `float-to-double' instruction.
1848 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1849 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001850 break;
1851
1852 default:
1853 LOG(FATAL) << "Unexpected type conversion from " << input_type
1854 << " to " << result_type;
1855 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001856 break;
1857
1858 default:
1859 LOG(FATAL) << "Unexpected type conversion from " << input_type
1860 << " to " << result_type;
1861 }
1862}
1863
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001864void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001865 LocationSummary* locations =
1866 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001867 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001868 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001869 locations->SetInAt(0, Location::RequiresRegister());
1870 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001871 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1872 break;
1873 }
1874
1875 case Primitive::kPrimLong: {
1876 locations->SetInAt(0, Location::RequiresRegister());
1877 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001878 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001879 break;
1880 }
1881
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001882 case Primitive::kPrimFloat:
1883 case Primitive::kPrimDouble: {
1884 locations->SetInAt(0, Location::RequiresFpuRegister());
1885 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001886 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001887 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001888 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001889
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001890 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001891 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001892 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001893}
1894
1895void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1896 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001897 Location out = locations->Out();
1898 Location first = locations->InAt(0);
1899 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001900 switch (add->GetResultType()) {
1901 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001902 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001903 __ add(out.AsRegister<Register>(),
1904 first.AsRegister<Register>(),
1905 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001906 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001907 __ AddConstant(out.AsRegister<Register>(),
1908 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001909 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001910 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001911 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001912
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001913 case Primitive::kPrimLong: {
1914 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001915 __ adds(out.AsRegisterPairLow<Register>(),
1916 first.AsRegisterPairLow<Register>(),
1917 ShifterOperand(second.AsRegisterPairLow<Register>()));
1918 __ adc(out.AsRegisterPairHigh<Register>(),
1919 first.AsRegisterPairHigh<Register>(),
1920 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001921 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001922 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001923
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001924 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001925 __ vadds(out.AsFpuRegister<SRegister>(),
1926 first.AsFpuRegister<SRegister>(),
1927 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001928 break;
1929
1930 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001931 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1932 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1933 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001934 break;
1935
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001936 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001937 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001938 }
1939}
1940
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001941void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001942 LocationSummary* locations =
1943 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001944 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001945 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001946 locations->SetInAt(0, Location::RequiresRegister());
1947 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001948 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1949 break;
1950 }
1951
1952 case Primitive::kPrimLong: {
1953 locations->SetInAt(0, Location::RequiresRegister());
1954 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001955 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001956 break;
1957 }
Calin Juravle11351682014-10-23 15:38:15 +01001958 case Primitive::kPrimFloat:
1959 case Primitive::kPrimDouble: {
1960 locations->SetInAt(0, Location::RequiresFpuRegister());
1961 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001962 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001963 break;
Calin Juravle11351682014-10-23 15:38:15 +01001964 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001965 default:
Calin Juravle11351682014-10-23 15:38:15 +01001966 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001967 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001968}
1969
1970void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1971 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001972 Location out = locations->Out();
1973 Location first = locations->InAt(0);
1974 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001975 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001976 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001977 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001978 __ sub(out.AsRegister<Register>(),
1979 first.AsRegister<Register>(),
1980 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001981 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001982 __ AddConstant(out.AsRegister<Register>(),
1983 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001984 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001985 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001986 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001987 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001988
Calin Juravle11351682014-10-23 15:38:15 +01001989 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001990 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001991 __ subs(out.AsRegisterPairLow<Register>(),
1992 first.AsRegisterPairLow<Register>(),
1993 ShifterOperand(second.AsRegisterPairLow<Register>()));
1994 __ sbc(out.AsRegisterPairHigh<Register>(),
1995 first.AsRegisterPairHigh<Register>(),
1996 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001997 break;
Calin Juravle11351682014-10-23 15:38:15 +01001998 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001999
Calin Juravle11351682014-10-23 15:38:15 +01002000 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002001 __ vsubs(out.AsFpuRegister<SRegister>(),
2002 first.AsFpuRegister<SRegister>(),
2003 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002004 break;
Calin Juravle11351682014-10-23 15:38:15 +01002005 }
2006
2007 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002008 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2009 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2010 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002011 break;
2012 }
2013
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002014
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002015 default:
Calin Juravle11351682014-10-23 15:38:15 +01002016 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002017 }
2018}
2019
Calin Juravle34bacdf2014-10-07 20:23:36 +01002020void LocationsBuilderARM::VisitMul(HMul* mul) {
2021 LocationSummary* locations =
2022 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2023 switch (mul->GetResultType()) {
2024 case Primitive::kPrimInt:
2025 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002026 locations->SetInAt(0, Location::RequiresRegister());
2027 locations->SetInAt(1, Location::RequiresRegister());
2028 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002029 break;
2030 }
2031
Calin Juravleb5bfa962014-10-21 18:02:24 +01002032 case Primitive::kPrimFloat:
2033 case Primitive::kPrimDouble: {
2034 locations->SetInAt(0, Location::RequiresFpuRegister());
2035 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002036 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002037 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002038 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002039
2040 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002041 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002042 }
2043}
2044
2045void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2046 LocationSummary* locations = mul->GetLocations();
2047 Location out = locations->Out();
2048 Location first = locations->InAt(0);
2049 Location second = locations->InAt(1);
2050 switch (mul->GetResultType()) {
2051 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002052 __ mul(out.AsRegister<Register>(),
2053 first.AsRegister<Register>(),
2054 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002055 break;
2056 }
2057 case Primitive::kPrimLong: {
2058 Register out_hi = out.AsRegisterPairHigh<Register>();
2059 Register out_lo = out.AsRegisterPairLow<Register>();
2060 Register in1_hi = first.AsRegisterPairHigh<Register>();
2061 Register in1_lo = first.AsRegisterPairLow<Register>();
2062 Register in2_hi = second.AsRegisterPairHigh<Register>();
2063 Register in2_lo = second.AsRegisterPairLow<Register>();
2064
2065 // Extra checks to protect caused by the existence of R1_R2.
2066 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2067 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2068 DCHECK_NE(out_hi, in1_lo);
2069 DCHECK_NE(out_hi, in2_lo);
2070
2071 // input: in1 - 64 bits, in2 - 64 bits
2072 // output: out
2073 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2074 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2075 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2076
2077 // IP <- in1.lo * in2.hi
2078 __ mul(IP, in1_lo, in2_hi);
2079 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2080 __ mla(out_hi, in1_hi, in2_lo, IP);
2081 // out.lo <- (in1.lo * in2.lo)[31:0];
2082 __ umull(out_lo, IP, in1_lo, in2_lo);
2083 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2084 __ add(out_hi, out_hi, ShifterOperand(IP));
2085 break;
2086 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002087
2088 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002089 __ vmuls(out.AsFpuRegister<SRegister>(),
2090 first.AsFpuRegister<SRegister>(),
2091 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002092 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002093 }
2094
2095 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002096 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2097 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2098 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002099 break;
2100 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002101
2102 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002103 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002104 }
2105}
2106
Calin Juravle7c4954d2014-10-28 16:57:40 +00002107void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002108 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2109 ? LocationSummary::kCall
2110 : LocationSummary::kNoCall;
2111 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2112
Calin Juravle7c4954d2014-10-28 16:57:40 +00002113 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002114 case Primitive::kPrimInt: {
2115 locations->SetInAt(0, Location::RequiresRegister());
2116 locations->SetInAt(1, Location::RequiresRegister());
2117 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2118 break;
2119 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002120 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002121 InvokeRuntimeCallingConvention calling_convention;
2122 locations->SetInAt(0, Location::RegisterPairLocation(
2123 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2124 locations->SetInAt(1, Location::RegisterPairLocation(
2125 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002126 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002127 break;
2128 }
2129 case Primitive::kPrimFloat:
2130 case Primitive::kPrimDouble: {
2131 locations->SetInAt(0, Location::RequiresFpuRegister());
2132 locations->SetInAt(1, Location::RequiresFpuRegister());
2133 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2134 break;
2135 }
2136
2137 default:
2138 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2139 }
2140}
2141
2142void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2143 LocationSummary* locations = div->GetLocations();
2144 Location out = locations->Out();
2145 Location first = locations->InAt(0);
2146 Location second = locations->InAt(1);
2147
2148 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002149 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002150 __ sdiv(out.AsRegister<Register>(),
2151 first.AsRegister<Register>(),
2152 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002153 break;
2154 }
2155
Calin Juravle7c4954d2014-10-28 16:57:40 +00002156 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002157 InvokeRuntimeCallingConvention calling_convention;
2158 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2159 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2160 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2161 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2162 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002163 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002164
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002165 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002166 break;
2167 }
2168
2169 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002170 __ vdivs(out.AsFpuRegister<SRegister>(),
2171 first.AsFpuRegister<SRegister>(),
2172 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002173 break;
2174 }
2175
2176 case Primitive::kPrimDouble: {
2177 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2178 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2179 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2180 break;
2181 }
2182
2183 default:
2184 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2185 }
2186}
2187
Calin Juravlebacfec32014-11-14 15:54:36 +00002188void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002189 Primitive::Type type = rem->GetResultType();
2190 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2191 ? LocationSummary::kNoCall
2192 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002193 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2194
Calin Juravled2ec87d2014-12-08 14:24:46 +00002195 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002196 case Primitive::kPrimInt: {
2197 locations->SetInAt(0, Location::RequiresRegister());
2198 locations->SetInAt(1, Location::RequiresRegister());
2199 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2200 locations->AddTemp(Location::RequiresRegister());
2201 break;
2202 }
2203 case Primitive::kPrimLong: {
2204 InvokeRuntimeCallingConvention calling_convention;
2205 locations->SetInAt(0, Location::RegisterPairLocation(
2206 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2207 locations->SetInAt(1, Location::RegisterPairLocation(
2208 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2209 // The runtime helper puts the output in R2,R3.
2210 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2211 break;
2212 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002213 case Primitive::kPrimFloat: {
2214 InvokeRuntimeCallingConvention calling_convention;
2215 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2216 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2217 locations->SetOut(Location::FpuRegisterLocation(S0));
2218 break;
2219 }
2220
Calin Juravlebacfec32014-11-14 15:54:36 +00002221 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002222 InvokeRuntimeCallingConvention calling_convention;
2223 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2224 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2225 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2226 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2227 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002228 break;
2229 }
2230
2231 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002232 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002233 }
2234}
2235
2236void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2237 LocationSummary* locations = rem->GetLocations();
2238 Location out = locations->Out();
2239 Location first = locations->InAt(0);
2240 Location second = locations->InAt(1);
2241
Calin Juravled2ec87d2014-12-08 14:24:46 +00002242 Primitive::Type type = rem->GetResultType();
2243 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002244 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002245 Register reg1 = first.AsRegister<Register>();
2246 Register reg2 = second.AsRegister<Register>();
2247 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002248
2249 // temp = reg1 / reg2 (integer division)
2250 // temp = temp * reg2
2251 // dest = reg1 - temp
2252 __ sdiv(temp, reg1, reg2);
2253 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002254 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002255 break;
2256 }
2257
2258 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002259 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002260 break;
2261 }
2262
Calin Juravled2ec87d2014-12-08 14:24:46 +00002263 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002264 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002265 break;
2266 }
2267
Calin Juravlebacfec32014-11-14 15:54:36 +00002268 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002269 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002270 break;
2271 }
2272
2273 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002274 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002275 }
2276}
2277
Calin Juravled0d48522014-11-04 16:40:20 +00002278void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2279 LocationSummary* locations =
2280 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002281 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002282 if (instruction->HasUses()) {
2283 locations->SetOut(Location::SameAsFirstInput());
2284 }
2285}
2286
2287void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2288 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2289 codegen_->AddSlowPath(slow_path);
2290
2291 LocationSummary* locations = instruction->GetLocations();
2292 Location value = locations->InAt(0);
2293
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002294 switch (instruction->GetType()) {
2295 case Primitive::kPrimInt: {
2296 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002297 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002298 __ b(slow_path->GetEntryLabel(), EQ);
2299 } else {
2300 DCHECK(value.IsConstant()) << value;
2301 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2302 __ b(slow_path->GetEntryLabel());
2303 }
2304 }
2305 break;
2306 }
2307 case Primitive::kPrimLong: {
2308 if (value.IsRegisterPair()) {
2309 __ orrs(IP,
2310 value.AsRegisterPairLow<Register>(),
2311 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2312 __ b(slow_path->GetEntryLabel(), EQ);
2313 } else {
2314 DCHECK(value.IsConstant()) << value;
2315 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2316 __ b(slow_path->GetEntryLabel());
2317 }
2318 }
2319 break;
2320 default:
2321 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2322 }
2323 }
Calin Juravled0d48522014-11-04 16:40:20 +00002324}
2325
Calin Juravle9aec02f2014-11-18 23:06:35 +00002326void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2327 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2328
2329 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2330 ? LocationSummary::kCall
2331 : LocationSummary::kNoCall;
2332 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2333
2334 switch (op->GetResultType()) {
2335 case Primitive::kPrimInt: {
2336 locations->SetInAt(0, Location::RequiresRegister());
2337 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002338 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002339 break;
2340 }
2341 case Primitive::kPrimLong: {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002342 InvokeRuntimeCallingConvention calling_convention;
2343 locations->SetInAt(0, Location::RegisterPairLocation(
2344 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2345 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2346 // The runtime helper puts the output in R0,R1.
2347 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002348 break;
2349 }
2350 default:
2351 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2352 }
2353}
2354
2355void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2356 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2357
2358 LocationSummary* locations = op->GetLocations();
2359 Location out = locations->Out();
2360 Location first = locations->InAt(0);
2361 Location second = locations->InAt(1);
2362
2363 Primitive::Type type = op->GetResultType();
2364 switch (type) {
2365 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002366 Register out_reg = out.AsRegister<Register>();
2367 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002368 // Arm doesn't mask the shift count so we need to do it ourselves.
2369 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002370 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002371 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2372 if (op->IsShl()) {
2373 __ Lsl(out_reg, first_reg, second_reg);
2374 } else if (op->IsShr()) {
2375 __ Asr(out_reg, first_reg, second_reg);
2376 } else {
2377 __ Lsr(out_reg, first_reg, second_reg);
2378 }
2379 } else {
2380 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2381 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2382 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2383 __ Mov(out_reg, first_reg);
2384 } else if (op->IsShl()) {
2385 __ Lsl(out_reg, first_reg, shift_value);
2386 } else if (op->IsShr()) {
2387 __ Asr(out_reg, first_reg, shift_value);
2388 } else {
2389 __ Lsr(out_reg, first_reg, shift_value);
2390 }
2391 }
2392 break;
2393 }
2394 case Primitive::kPrimLong: {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002395 // TODO: Inline the assembly instead of calling the runtime.
2396 InvokeRuntimeCallingConvention calling_convention;
2397 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2398 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2399 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
2400 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2401 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002402
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002403 int32_t entry_point_offset;
Calin Juravle9aec02f2014-11-18 23:06:35 +00002404 if (op->IsShl()) {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002405 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002406 } else if (op->IsShr()) {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002407 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002408 } else {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002409 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002410 }
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002411 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2412 __ blx(LR);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002413 break;
2414 }
2415 default:
2416 LOG(FATAL) << "Unexpected operation type " << type;
2417 }
2418}
2419
2420void LocationsBuilderARM::VisitShl(HShl* shl) {
2421 HandleShift(shl);
2422}
2423
2424void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2425 HandleShift(shl);
2426}
2427
2428void LocationsBuilderARM::VisitShr(HShr* shr) {
2429 HandleShift(shr);
2430}
2431
2432void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2433 HandleShift(shr);
2434}
2435
2436void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2437 HandleShift(ushr);
2438}
2439
2440void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2441 HandleShift(ushr);
2442}
2443
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002444void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002445 LocationSummary* locations =
2446 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002447 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002448 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2449 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2450 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002451}
2452
2453void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2454 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002455 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002456 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002457 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2458 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002459 instruction->GetDexPc(),
2460 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002461}
2462
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002463void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2464 LocationSummary* locations =
2465 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2466 InvokeRuntimeCallingConvention calling_convention;
2467 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002468 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002469 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002470 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002471}
2472
2473void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2474 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002475 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002476 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002477 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2478 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002479 instruction->GetDexPc(),
2480 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002481}
2482
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002483void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002484 LocationSummary* locations =
2485 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002486 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2487 if (location.IsStackSlot()) {
2488 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2489 } else if (location.IsDoubleStackSlot()) {
2490 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002491 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002492 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002493}
2494
2495void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002496 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002497 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002498}
2499
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002500void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002501 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002502 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002503 locations->SetInAt(0, Location::RequiresRegister());
2504 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002505}
2506
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002507void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2508 LocationSummary* locations = not_->GetLocations();
2509 Location out = locations->Out();
2510 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002511 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002512 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002513 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002514 break;
2515
2516 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002517 __ mvn(out.AsRegisterPairLow<Register>(),
2518 ShifterOperand(in.AsRegisterPairLow<Register>()));
2519 __ mvn(out.AsRegisterPairHigh<Register>(),
2520 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002521 break;
2522
2523 default:
2524 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2525 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002526}
2527
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002528void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002529 LocationSummary* locations =
2530 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002531 switch (compare->InputAt(0)->GetType()) {
2532 case Primitive::kPrimLong: {
2533 locations->SetInAt(0, Location::RequiresRegister());
2534 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002535 // Output overlaps because it is written before doing the low comparison.
2536 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002537 break;
2538 }
2539 case Primitive::kPrimFloat:
2540 case Primitive::kPrimDouble: {
2541 locations->SetInAt(0, Location::RequiresFpuRegister());
2542 locations->SetInAt(1, Location::RequiresFpuRegister());
2543 locations->SetOut(Location::RequiresRegister());
2544 break;
2545 }
2546 default:
2547 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2548 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002549}
2550
2551void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002552 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002553 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002554 Location left = locations->InAt(0);
2555 Location right = locations->InAt(1);
2556
2557 Label less, greater, done;
2558 Primitive::Type type = compare->InputAt(0)->GetType();
2559 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002560 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002561 __ cmp(left.AsRegisterPairHigh<Register>(),
2562 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002563 __ b(&less, LT);
2564 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002565 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2566 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002567 __ cmp(left.AsRegisterPairLow<Register>(),
2568 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002569 break;
2570 }
2571 case Primitive::kPrimFloat:
2572 case Primitive::kPrimDouble: {
2573 __ LoadImmediate(out, 0);
2574 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002575 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002576 } else {
2577 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2578 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2579 }
2580 __ vmstat(); // transfer FP status register to ARM APSR.
2581 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002582 break;
2583 }
2584 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002585 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002586 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002587 __ b(&done, EQ);
2588 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2589
2590 __ Bind(&greater);
2591 __ LoadImmediate(out, 1);
2592 __ b(&done);
2593
2594 __ Bind(&less);
2595 __ LoadImmediate(out, -1);
2596
2597 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002598}
2599
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002600void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002601 LocationSummary* locations =
2602 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002603 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2604 locations->SetInAt(i, Location::Any());
2605 }
2606 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002607}
2608
2609void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002610 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002611 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002612}
2613
Calin Juravle52c48962014-12-16 17:02:57 +00002614void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2615 // TODO (ported from quick): revisit Arm barrier kinds
2616 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2617 switch (kind) {
2618 case MemBarrierKind::kAnyStore:
2619 case MemBarrierKind::kLoadAny:
2620 case MemBarrierKind::kAnyAny: {
2621 flavour = DmbOptions::ISH;
2622 break;
2623 }
2624 case MemBarrierKind::kStoreStore: {
2625 flavour = DmbOptions::ISHST;
2626 break;
2627 }
2628 default:
2629 LOG(FATAL) << "Unexpected memory barrier " << kind;
2630 }
2631 __ dmb(flavour);
2632}
2633
2634void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2635 uint32_t offset,
2636 Register out_lo,
2637 Register out_hi) {
2638 if (offset != 0) {
2639 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002640 __ add(IP, addr, ShifterOperand(out_lo));
2641 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002642 }
2643 __ ldrexd(out_lo, out_hi, addr);
2644}
2645
2646void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2647 uint32_t offset,
2648 Register value_lo,
2649 Register value_hi,
2650 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002651 Register temp2,
2652 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002653 Label fail;
2654 if (offset != 0) {
2655 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002656 __ add(IP, addr, ShifterOperand(temp1));
2657 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002658 }
2659 __ Bind(&fail);
2660 // We need a load followed by store. (The address used in a STREX instruction must
2661 // be the same as the address in the most recently executed LDREX instruction.)
2662 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002663 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002664 __ strexd(temp1, value_lo, value_hi, addr);
2665 __ cmp(temp1, ShifterOperand(0));
2666 __ b(&fail, NE);
2667}
2668
2669void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2670 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2671
Nicolas Geoffray39468442014-09-02 15:17:15 +01002672 LocationSummary* locations =
2673 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002674 locations->SetInAt(0, Location::RequiresRegister());
2675 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002676
Calin Juravle34166012014-12-19 17:22:29 +00002677
Calin Juravle52c48962014-12-16 17:02:57 +00002678 Primitive::Type field_type = field_info.GetFieldType();
2679 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002680 bool generate_volatile = field_info.IsVolatile()
2681 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002682 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002683 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002684 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2685 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002686 locations->AddTemp(Location::RequiresRegister());
2687 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002688 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002689 // Arm encoding have some additional constraints for ldrexd/strexd:
2690 // - registers need to be consecutive
2691 // - the first register should be even but not R14.
2692 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2693 // enable Arm encoding.
2694 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2695
2696 locations->AddTemp(Location::RequiresRegister());
2697 locations->AddTemp(Location::RequiresRegister());
2698 if (field_type == Primitive::kPrimDouble) {
2699 // For doubles we need two more registers to copy the value.
2700 locations->AddTemp(Location::RegisterLocation(R2));
2701 locations->AddTemp(Location::RegisterLocation(R3));
2702 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002703 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002704}
2705
Calin Juravle52c48962014-12-16 17:02:57 +00002706void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2707 const FieldInfo& field_info) {
2708 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2709
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002710 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002711 Register base = locations->InAt(0).AsRegister<Register>();
2712 Location value = locations->InAt(1);
2713
2714 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002715 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002716 Primitive::Type field_type = field_info.GetFieldType();
2717 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2718
2719 if (is_volatile) {
2720 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2721 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002722
2723 switch (field_type) {
2724 case Primitive::kPrimBoolean:
2725 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002726 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002727 break;
2728 }
2729
2730 case Primitive::kPrimShort:
2731 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002732 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002733 break;
2734 }
2735
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002736 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002737 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002738 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002739 break;
2740 }
2741
2742 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002743 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002744 GenerateWideAtomicStore(base, offset,
2745 value.AsRegisterPairLow<Register>(),
2746 value.AsRegisterPairHigh<Register>(),
2747 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002748 locations->GetTemp(1).AsRegister<Register>(),
2749 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002750 } else {
2751 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002752 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002753 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002754 break;
2755 }
2756
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002757 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002758 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002759 break;
2760 }
2761
2762 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002763 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002764 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002765 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2766 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2767
2768 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2769
2770 GenerateWideAtomicStore(base, offset,
2771 value_reg_lo,
2772 value_reg_hi,
2773 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002774 locations->GetTemp(3).AsRegister<Register>(),
2775 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002776 } else {
2777 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002778 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002779 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002780 break;
2781 }
2782
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002783 case Primitive::kPrimVoid:
2784 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002785 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002786 }
Calin Juravle52c48962014-12-16 17:02:57 +00002787
Calin Juravle77520bc2015-01-12 18:45:46 +00002788 // Longs and doubles are handled in the switch.
2789 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2790 codegen_->MaybeRecordImplicitNullCheck(instruction);
2791 }
2792
2793 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2794 Register temp = locations->GetTemp(0).AsRegister<Register>();
2795 Register card = locations->GetTemp(1).AsRegister<Register>();
2796 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2797 }
2798
Calin Juravle52c48962014-12-16 17:02:57 +00002799 if (is_volatile) {
2800 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2801 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002802}
2803
Calin Juravle52c48962014-12-16 17:02:57 +00002804void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2805 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002806 LocationSummary* locations =
2807 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002808 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002809
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002810 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002811 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002812 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002813 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2814 locations->SetOut(Location::RequiresRegister(),
2815 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2816 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002817 // Arm encoding have some additional constraints for ldrexd/strexd:
2818 // - registers need to be consecutive
2819 // - the first register should be even but not R14.
2820 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2821 // enable Arm encoding.
2822 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2823 locations->AddTemp(Location::RequiresRegister());
2824 locations->AddTemp(Location::RequiresRegister());
2825 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002826}
2827
Calin Juravle52c48962014-12-16 17:02:57 +00002828void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2829 const FieldInfo& field_info) {
2830 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002831
Calin Juravle52c48962014-12-16 17:02:57 +00002832 LocationSummary* locations = instruction->GetLocations();
2833 Register base = locations->InAt(0).AsRegister<Register>();
2834 Location out = locations->Out();
2835 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002836 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002837 Primitive::Type field_type = field_info.GetFieldType();
2838 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2839
2840 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002841 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002842 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002843 break;
2844 }
2845
2846 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002847 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002848 break;
2849 }
2850
2851 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002852 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002853 break;
2854 }
2855
2856 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002857 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002858 break;
2859 }
2860
2861 case Primitive::kPrimInt:
2862 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002863 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002864 break;
2865 }
2866
2867 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002868 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002869 GenerateWideAtomicLoad(base, offset,
2870 out.AsRegisterPairLow<Register>(),
2871 out.AsRegisterPairHigh<Register>());
2872 } else {
2873 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2874 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002875 break;
2876 }
2877
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002878 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002879 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002880 break;
2881 }
2882
2883 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002884 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002885 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002886 Register lo = locations->GetTemp(0).AsRegister<Register>();
2887 Register hi = locations->GetTemp(1).AsRegister<Register>();
2888 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002889 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002890 __ vmovdrr(out_reg, lo, hi);
2891 } else {
2892 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002893 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002894 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002895 break;
2896 }
2897
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002898 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002899 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002900 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002901 }
Calin Juravle52c48962014-12-16 17:02:57 +00002902
Calin Juravle77520bc2015-01-12 18:45:46 +00002903 // Doubles are handled in the switch.
2904 if (field_type != Primitive::kPrimDouble) {
2905 codegen_->MaybeRecordImplicitNullCheck(instruction);
2906 }
2907
Calin Juravle52c48962014-12-16 17:02:57 +00002908 if (is_volatile) {
2909 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2910 }
2911}
2912
2913void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2914 HandleFieldSet(instruction, instruction->GetFieldInfo());
2915}
2916
2917void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2918 HandleFieldSet(instruction, instruction->GetFieldInfo());
2919}
2920
2921void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2922 HandleFieldGet(instruction, instruction->GetFieldInfo());
2923}
2924
2925void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2926 HandleFieldGet(instruction, instruction->GetFieldInfo());
2927}
2928
2929void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2930 HandleFieldGet(instruction, instruction->GetFieldInfo());
2931}
2932
2933void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2934 HandleFieldGet(instruction, instruction->GetFieldInfo());
2935}
2936
2937void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2938 HandleFieldSet(instruction, instruction->GetFieldInfo());
2939}
2940
2941void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2942 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002943}
2944
2945void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002946 LocationSummary* locations =
2947 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002948 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002949 if (instruction->HasUses()) {
2950 locations->SetOut(Location::SameAsFirstInput());
2951 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002952}
2953
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002954void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002955 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2956 return;
2957 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002958 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002959
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002960 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2961 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2962}
2963
2964void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002965 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002966 codegen_->AddSlowPath(slow_path);
2967
2968 LocationSummary* locations = instruction->GetLocations();
2969 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002970
Calin Juravle77520bc2015-01-12 18:45:46 +00002971 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2972 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002973}
2974
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002975void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2976 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2977 GenerateImplicitNullCheck(instruction);
2978 } else {
2979 GenerateExplicitNullCheck(instruction);
2980 }
2981}
2982
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002983void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002984 LocationSummary* locations =
2985 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002986 locations->SetInAt(0, Location::RequiresRegister());
2987 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2988 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002989}
2990
2991void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2992 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002993 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002994 Location index = locations->InAt(1);
2995
2996 switch (instruction->GetType()) {
2997 case Primitive::kPrimBoolean: {
2998 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002999 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003000 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003001 size_t offset =
3002 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003003 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3004 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003005 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003006 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3007 }
3008 break;
3009 }
3010
3011 case Primitive::kPrimByte: {
3012 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003013 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003014 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003015 size_t offset =
3016 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003017 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3018 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003019 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003020 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3021 }
3022 break;
3023 }
3024
3025 case Primitive::kPrimShort: {
3026 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003027 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003028 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003029 size_t offset =
3030 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003031 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3032 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003033 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003034 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3035 }
3036 break;
3037 }
3038
3039 case Primitive::kPrimChar: {
3040 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003041 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003042 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003043 size_t offset =
3044 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003045 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3046 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003047 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003048 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3049 }
3050 break;
3051 }
3052
3053 case Primitive::kPrimInt:
3054 case Primitive::kPrimNot: {
3055 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3056 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003057 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003058 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003059 size_t offset =
3060 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003061 __ LoadFromOffset(kLoadWord, out, obj, offset);
3062 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003063 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003064 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3065 }
3066 break;
3067 }
3068
3069 case Primitive::kPrimLong: {
3070 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003071 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003072 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003073 size_t offset =
3074 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003075 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003076 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003077 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003078 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003079 }
3080 break;
3081 }
3082
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003083 case Primitive::kPrimFloat: {
3084 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3085 Location out = locations->Out();
3086 DCHECK(out.IsFpuRegister());
3087 if (index.IsConstant()) {
3088 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3089 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3090 } else {
3091 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3092 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3093 }
3094 break;
3095 }
3096
3097 case Primitive::kPrimDouble: {
3098 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3099 Location out = locations->Out();
3100 DCHECK(out.IsFpuRegisterPair());
3101 if (index.IsConstant()) {
3102 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3103 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3104 } else {
3105 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3106 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3107 }
3108 break;
3109 }
3110
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003111 case Primitive::kPrimVoid:
3112 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003113 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003114 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003115 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003116}
3117
3118void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003119 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003120
3121 bool needs_write_barrier =
3122 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3123 bool needs_runtime_call = instruction->NeedsTypeCheck();
3124
Nicolas Geoffray39468442014-09-02 15:17:15 +01003125 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003126 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3127 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003128 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003129 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3130 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3131 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003132 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003133 locations->SetInAt(0, Location::RequiresRegister());
3134 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3135 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003136
3137 if (needs_write_barrier) {
3138 // Temporary registers for the write barrier.
3139 locations->AddTemp(Location::RequiresRegister());
3140 locations->AddTemp(Location::RequiresRegister());
3141 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003142 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003143}
3144
3145void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3146 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003147 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003148 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003149 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003150 bool needs_runtime_call = locations->WillCall();
3151 bool needs_write_barrier =
3152 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003153
3154 switch (value_type) {
3155 case Primitive::kPrimBoolean:
3156 case Primitive::kPrimByte: {
3157 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003158 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003159 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003160 size_t offset =
3161 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003162 __ StoreToOffset(kStoreByte, value, obj, offset);
3163 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003164 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003165 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3166 }
3167 break;
3168 }
3169
3170 case Primitive::kPrimShort:
3171 case Primitive::kPrimChar: {
3172 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003173 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003174 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003175 size_t offset =
3176 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003177 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3178 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003179 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003180 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3181 }
3182 break;
3183 }
3184
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003185 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003186 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003187 if (!needs_runtime_call) {
3188 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003190 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003191 size_t offset =
3192 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003193 __ StoreToOffset(kStoreWord, value, obj, offset);
3194 } else {
3195 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003196 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003197 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3198 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003199 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003200 if (needs_write_barrier) {
3201 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003202 Register temp = locations->GetTemp(0).AsRegister<Register>();
3203 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003204 codegen_->MarkGCCard(temp, card, obj, value);
3205 }
3206 } else {
3207 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003208 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3209 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003210 instruction->GetDexPc(),
3211 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003212 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003213 break;
3214 }
3215
3216 case Primitive::kPrimLong: {
3217 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003218 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003219 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003220 size_t offset =
3221 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003222 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003223 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003224 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003225 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003226 }
3227 break;
3228 }
3229
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003230 case Primitive::kPrimFloat: {
3231 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3232 Location value = locations->InAt(2);
3233 DCHECK(value.IsFpuRegister());
3234 if (index.IsConstant()) {
3235 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3236 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3237 } else {
3238 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3239 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3240 }
3241 break;
3242 }
3243
3244 case Primitive::kPrimDouble: {
3245 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3246 Location value = locations->InAt(2);
3247 DCHECK(value.IsFpuRegisterPair());
3248 if (index.IsConstant()) {
3249 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3250 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3251 } else {
3252 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3253 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3254 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003255
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003256 break;
3257 }
3258
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003259 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003260 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003261 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003262 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003263
3264 // Ints and objects are handled in the switch.
3265 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3266 codegen_->MaybeRecordImplicitNullCheck(instruction);
3267 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003268}
3269
3270void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003271 LocationSummary* locations =
3272 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003273 locations->SetInAt(0, Location::RequiresRegister());
3274 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003275}
3276
3277void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3278 LocationSummary* locations = instruction->GetLocations();
3279 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003280 Register obj = locations->InAt(0).AsRegister<Register>();
3281 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003282 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003283 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003284}
3285
3286void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003287 LocationSummary* locations =
3288 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003289 locations->SetInAt(0, Location::RequiresRegister());
3290 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003291 if (instruction->HasUses()) {
3292 locations->SetOut(Location::SameAsFirstInput());
3293 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003294}
3295
3296void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3297 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003298 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003299 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003300 codegen_->AddSlowPath(slow_path);
3301
Roland Levillain271ab9c2014-11-27 15:23:57 +00003302 Register index = locations->InAt(0).AsRegister<Register>();
3303 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003304
3305 __ cmp(index, ShifterOperand(length));
3306 __ b(slow_path->GetEntryLabel(), CS);
3307}
3308
3309void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3310 Label is_null;
3311 __ CompareAndBranchIfZero(value, &is_null);
3312 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3313 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3314 __ strb(card, Address(card, temp));
3315 __ Bind(&is_null);
3316}
3317
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003318void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3319 temp->SetLocations(nullptr);
3320}
3321
3322void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3323 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003324 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003325}
3326
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003327void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003328 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003329 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003330}
3331
3332void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003333 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3334}
3335
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003336void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3337 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3338}
3339
3340void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003341 HBasicBlock* block = instruction->GetBlock();
3342 if (block->GetLoopInformation() != nullptr) {
3343 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3344 // The back edge will generate the suspend check.
3345 return;
3346 }
3347 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3348 // The goto will generate the suspend check.
3349 return;
3350 }
3351 GenerateSuspendCheck(instruction, nullptr);
3352}
3353
3354void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3355 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003356 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003357 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003358 codegen_->AddSlowPath(slow_path);
3359
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003360 __ LoadFromOffset(
3361 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3362 __ cmp(IP, ShifterOperand(0));
3363 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003364 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003365 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003366 __ Bind(slow_path->GetReturnLabel());
3367 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003368 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003369 __ b(slow_path->GetEntryLabel());
3370 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003371}
3372
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003373ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3374 return codegen_->GetAssembler();
3375}
3376
3377void ParallelMoveResolverARM::EmitMove(size_t index) {
3378 MoveOperands* move = moves_.Get(index);
3379 Location source = move->GetSource();
3380 Location destination = move->GetDestination();
3381
3382 if (source.IsRegister()) {
3383 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003384 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003385 } else {
3386 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003387 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003388 SP, destination.GetStackIndex());
3389 }
3390 } else if (source.IsStackSlot()) {
3391 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003392 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003393 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003394 } else if (destination.IsFpuRegister()) {
3395 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003396 } else {
3397 DCHECK(destination.IsStackSlot());
3398 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3399 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3400 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003401 } else if (source.IsFpuRegister()) {
3402 if (destination.IsFpuRegister()) {
3403 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003404 } else {
3405 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003406 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3407 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003408 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003409 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003410 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3411 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003412 } else if (destination.IsRegisterPair()) {
3413 DCHECK(ExpectedPairLayout(destination));
3414 __ LoadFromOffset(
3415 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3416 } else {
3417 DCHECK(destination.IsFpuRegisterPair()) << destination;
3418 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3419 SP,
3420 source.GetStackIndex());
3421 }
3422 } else if (source.IsRegisterPair()) {
3423 if (destination.IsRegisterPair()) {
3424 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3425 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3426 } else {
3427 DCHECK(destination.IsDoubleStackSlot()) << destination;
3428 DCHECK(ExpectedPairLayout(source));
3429 __ StoreToOffset(
3430 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3431 }
3432 } else if (source.IsFpuRegisterPair()) {
3433 if (destination.IsFpuRegisterPair()) {
3434 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3435 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3436 } else {
3437 DCHECK(destination.IsDoubleStackSlot()) << destination;
3438 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3439 SP,
3440 destination.GetStackIndex());
3441 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003442 } else {
3443 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003444 HConstant* constant = source.GetConstant();
3445 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3446 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003447 if (destination.IsRegister()) {
3448 __ LoadImmediate(destination.AsRegister<Register>(), value);
3449 } else {
3450 DCHECK(destination.IsStackSlot());
3451 __ LoadImmediate(IP, value);
3452 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3453 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003454 } else if (constant->IsLongConstant()) {
3455 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003456 if (destination.IsRegisterPair()) {
3457 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3458 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003459 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003460 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003461 __ LoadImmediate(IP, Low32Bits(value));
3462 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3463 __ LoadImmediate(IP, High32Bits(value));
3464 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3465 }
3466 } else if (constant->IsDoubleConstant()) {
3467 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003468 if (destination.IsFpuRegisterPair()) {
3469 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003470 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003471 DCHECK(destination.IsDoubleStackSlot()) << destination;
3472 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003473 __ LoadImmediate(IP, Low32Bits(int_value));
3474 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3475 __ LoadImmediate(IP, High32Bits(int_value));
3476 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3477 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003478 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003479 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003480 float value = constant->AsFloatConstant()->GetValue();
3481 if (destination.IsFpuRegister()) {
3482 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3483 } else {
3484 DCHECK(destination.IsStackSlot());
3485 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3486 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3487 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003488 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003489 }
3490}
3491
3492void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3493 __ Mov(IP, reg);
3494 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3495 __ StoreToOffset(kStoreWord, IP, SP, mem);
3496}
3497
3498void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3499 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3500 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3501 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3502 SP, mem1 + stack_offset);
3503 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3504 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3505 SP, mem2 + stack_offset);
3506 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3507}
3508
3509void ParallelMoveResolverARM::EmitSwap(size_t index) {
3510 MoveOperands* move = moves_.Get(index);
3511 Location source = move->GetSource();
3512 Location destination = move->GetDestination();
3513
3514 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003515 DCHECK_NE(source.AsRegister<Register>(), IP);
3516 DCHECK_NE(destination.AsRegister<Register>(), IP);
3517 __ Mov(IP, source.AsRegister<Register>());
3518 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3519 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003520 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003521 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003522 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003523 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003524 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3525 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003526 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003527 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003528 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003529 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003530 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003531 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003532 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003533 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003534 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3535 destination.AsRegisterPairHigh<Register>(),
3536 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003537 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003538 Register low_reg = source.IsRegisterPair()
3539 ? source.AsRegisterPairLow<Register>()
3540 : destination.AsRegisterPairLow<Register>();
3541 int mem = source.IsRegisterPair()
3542 ? destination.GetStackIndex()
3543 : source.GetStackIndex();
3544 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003545 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003546 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003547 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003548 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003549 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3550 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003551 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003552 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003553 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003554 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3555 DRegister reg = source.IsFpuRegisterPair()
3556 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3557 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3558 int mem = source.IsFpuRegisterPair()
3559 ? destination.GetStackIndex()
3560 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003561 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003562 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003563 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003564 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3565 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3566 : destination.AsFpuRegister<SRegister>();
3567 int mem = source.IsFpuRegister()
3568 ? destination.GetStackIndex()
3569 : source.GetStackIndex();
3570
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003571 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003572 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003573 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003574 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003575 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3576 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003577 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003578 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003579 }
3580}
3581
3582void ParallelMoveResolverARM::SpillScratch(int reg) {
3583 __ Push(static_cast<Register>(reg));
3584}
3585
3586void ParallelMoveResolverARM::RestoreScratch(int reg) {
3587 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003588}
3589
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003590void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003591 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3592 ? LocationSummary::kCallOnSlowPath
3593 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003594 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003595 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003596 locations->SetOut(Location::RequiresRegister());
3597}
3598
3599void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003600 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003601 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003602 DCHECK(!cls->CanCallRuntime());
3603 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003604 codegen_->LoadCurrentMethod(out);
3605 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3606 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003607 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003608 codegen_->LoadCurrentMethod(out);
3609 __ LoadFromOffset(
3610 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3611 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003612
3613 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3614 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3615 codegen_->AddSlowPath(slow_path);
3616 __ cmp(out, ShifterOperand(0));
3617 __ b(slow_path->GetEntryLabel(), EQ);
3618 if (cls->MustGenerateClinitCheck()) {
3619 GenerateClassInitializationCheck(slow_path, out);
3620 } else {
3621 __ Bind(slow_path->GetExitLabel());
3622 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003623 }
3624}
3625
3626void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3627 LocationSummary* locations =
3628 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3629 locations->SetInAt(0, Location::RequiresRegister());
3630 if (check->HasUses()) {
3631 locations->SetOut(Location::SameAsFirstInput());
3632 }
3633}
3634
3635void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003636 // We assume the class is not null.
3637 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3638 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003639 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003640 GenerateClassInitializationCheck(slow_path,
3641 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003642}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003643
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003644void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3645 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003646 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3647 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3648 __ b(slow_path->GetEntryLabel(), LT);
3649 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3650 // properly. Therefore, we do a memory fence.
3651 __ dmb(ISH);
3652 __ Bind(slow_path->GetExitLabel());
3653}
3654
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003655void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3656 LocationSummary* locations =
3657 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3658 locations->SetOut(Location::RequiresRegister());
3659}
3660
3661void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3662 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3663 codegen_->AddSlowPath(slow_path);
3664
Roland Levillain271ab9c2014-11-27 15:23:57 +00003665 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003666 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003667 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3668 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003669 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3670 __ cmp(out, ShifterOperand(0));
3671 __ b(slow_path->GetEntryLabel(), EQ);
3672 __ Bind(slow_path->GetExitLabel());
3673}
3674
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003675void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3676 LocationSummary* locations =
3677 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3678 locations->SetOut(Location::RequiresRegister());
3679}
3680
3681void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003682 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003683 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3684 __ LoadFromOffset(kLoadWord, out, TR, offset);
3685 __ LoadImmediate(IP, 0);
3686 __ StoreToOffset(kStoreWord, IP, TR, offset);
3687}
3688
3689void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3690 LocationSummary* locations =
3691 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3692 InvokeRuntimeCallingConvention calling_convention;
3693 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3694}
3695
3696void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3697 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003698 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003699}
3700
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003701void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003702 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3703 ? LocationSummary::kNoCall
3704 : LocationSummary::kCallOnSlowPath;
3705 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3706 locations->SetInAt(0, Location::RequiresRegister());
3707 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003708 // The out register is used as a temporary, so it overlaps with the inputs.
3709 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003710}
3711
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003712void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003713 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003714 Register obj = locations->InAt(0).AsRegister<Register>();
3715 Register cls = locations->InAt(1).AsRegister<Register>();
3716 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003717 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3718 Label done, zero;
3719 SlowPathCodeARM* slow_path = nullptr;
3720
3721 // Return 0 if `obj` is null.
3722 // TODO: avoid this check if we know obj is not null.
3723 __ cmp(obj, ShifterOperand(0));
3724 __ b(&zero, EQ);
3725 // Compare the class of `obj` with `cls`.
3726 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3727 __ cmp(out, ShifterOperand(cls));
3728 if (instruction->IsClassFinal()) {
3729 // Classes must be equal for the instanceof to succeed.
3730 __ b(&zero, NE);
3731 __ LoadImmediate(out, 1);
3732 __ b(&done);
3733 } else {
3734 // If the classes are not equal, we go into a slow path.
3735 DCHECK(locations->OnlyCallsOnSlowPath());
3736 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003737 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003738 codegen_->AddSlowPath(slow_path);
3739 __ b(slow_path->GetEntryLabel(), NE);
3740 __ LoadImmediate(out, 1);
3741 __ b(&done);
3742 }
3743 __ Bind(&zero);
3744 __ LoadImmediate(out, 0);
3745 if (slow_path != nullptr) {
3746 __ Bind(slow_path->GetExitLabel());
3747 }
3748 __ Bind(&done);
3749}
3750
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003751void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3752 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3753 instruction, LocationSummary::kCallOnSlowPath);
3754 locations->SetInAt(0, Location::RequiresRegister());
3755 locations->SetInAt(1, Location::RequiresRegister());
3756 locations->AddTemp(Location::RequiresRegister());
3757}
3758
3759void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3760 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003761 Register obj = locations->InAt(0).AsRegister<Register>();
3762 Register cls = locations->InAt(1).AsRegister<Register>();
3763 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003764 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3765
3766 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3767 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3768 codegen_->AddSlowPath(slow_path);
3769
3770 // TODO: avoid this check if we know obj is not null.
3771 __ cmp(obj, ShifterOperand(0));
3772 __ b(slow_path->GetExitLabel(), EQ);
3773 // Compare the class of `obj` with `cls`.
3774 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3775 __ cmp(temp, ShifterOperand(cls));
3776 __ b(slow_path->GetEntryLabel(), NE);
3777 __ Bind(slow_path->GetExitLabel());
3778}
3779
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003780void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3781 LocationSummary* locations =
3782 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3783 InvokeRuntimeCallingConvention calling_convention;
3784 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3785}
3786
3787void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3788 codegen_->InvokeRuntime(instruction->IsEnter()
3789 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3790 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003791 instruction->GetDexPc(),
3792 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003793}
3794
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003795void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3796void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3797void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3798
3799void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3800 LocationSummary* locations =
3801 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3802 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3803 || instruction->GetResultType() == Primitive::kPrimLong);
3804 locations->SetInAt(0, Location::RequiresRegister());
3805 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003806 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003807}
3808
3809void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3810 HandleBitwiseOperation(instruction);
3811}
3812
3813void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3814 HandleBitwiseOperation(instruction);
3815}
3816
3817void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3818 HandleBitwiseOperation(instruction);
3819}
3820
3821void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3822 LocationSummary* locations = instruction->GetLocations();
3823
3824 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003825 Register first = locations->InAt(0).AsRegister<Register>();
3826 Register second = locations->InAt(1).AsRegister<Register>();
3827 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003828 if (instruction->IsAnd()) {
3829 __ and_(out, first, ShifterOperand(second));
3830 } else if (instruction->IsOr()) {
3831 __ orr(out, first, ShifterOperand(second));
3832 } else {
3833 DCHECK(instruction->IsXor());
3834 __ eor(out, first, ShifterOperand(second));
3835 }
3836 } else {
3837 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3838 Location first = locations->InAt(0);
3839 Location second = locations->InAt(1);
3840 Location out = locations->Out();
3841 if (instruction->IsAnd()) {
3842 __ and_(out.AsRegisterPairLow<Register>(),
3843 first.AsRegisterPairLow<Register>(),
3844 ShifterOperand(second.AsRegisterPairLow<Register>()));
3845 __ and_(out.AsRegisterPairHigh<Register>(),
3846 first.AsRegisterPairHigh<Register>(),
3847 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3848 } else if (instruction->IsOr()) {
3849 __ orr(out.AsRegisterPairLow<Register>(),
3850 first.AsRegisterPairLow<Register>(),
3851 ShifterOperand(second.AsRegisterPairLow<Register>()));
3852 __ orr(out.AsRegisterPairHigh<Register>(),
3853 first.AsRegisterPairHigh<Register>(),
3854 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3855 } else {
3856 DCHECK(instruction->IsXor());
3857 __ eor(out.AsRegisterPairLow<Register>(),
3858 first.AsRegisterPairLow<Register>(),
3859 ShifterOperand(second.AsRegisterPairLow<Register>()));
3860 __ eor(out.AsRegisterPairHigh<Register>(),
3861 first.AsRegisterPairHigh<Register>(),
3862 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3863 }
3864 }
3865}
3866
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003867void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
3868 DCHECK_EQ(temp, kArtMethodRegister);
3869
3870 // TODO: Implement all kinds of calls:
3871 // 1) boot -> boot
3872 // 2) app -> boot
3873 // 3) app -> app
3874 //
3875 // Currently we implement the app -> app logic, which looks up in the resolve cache.
3876
3877 // temp = method;
3878 LoadCurrentMethod(temp);
3879 if (!invoke->IsRecursive()) {
3880 // temp = temp->dex_cache_resolved_methods_;
3881 __ LoadFromOffset(
3882 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
3883 // temp = temp[index_in_cache]
3884 __ LoadFromOffset(
3885 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
3886 // LR = temp[offset_of_quick_compiled_code]
3887 __ LoadFromOffset(kLoadWord, LR, temp,
3888 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3889 kArmWordSize).Int32Value());
3890 // LR()
3891 __ blx(LR);
3892 } else {
3893 __ bl(GetFrameEntryLabel());
3894 }
3895
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003896 DCHECK(!IsLeafMethod());
3897}
3898
Calin Juravleb1498f62015-02-16 13:13:29 +00003899void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
3900 // Nothing to do, this should be removed during prepare for register allocator.
3901 UNUSED(instruction);
3902 LOG(FATAL) << "Unreachable";
3903}
3904
3905void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
3906 // Nothing to do, this should be removed during prepare for register allocator.
3907 UNUSED(instruction);
3908 LOG(FATAL) << "Unreachable";
3909}
3910
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003911} // namespace arm
3912} // namespace art