blob: 0403af1eaf70f97c9c451a50869566a0b32f578d [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(
85 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
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(
101 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
102 }
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 Geoffray3bca0df2014-09-19 11:01:00 +0100117 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100118 arm_codegen->InvokeRuntime(
119 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100120 codegen->RestoreLiveRegisters(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(
165 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
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 Geoffray424f6762014-11-03 14:51:25 +0000191 codegen->SaveLiveRegisters(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);
199 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
200
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 }
207 codegen->RestoreLiveRegisters(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());
238 codegen->SaveLiveRegisters(locations);
239
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(
244 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
245 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
246
247 codegen->RestoreLiveRegisters(locations);
248 __ 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());
275 codegen->SaveLiveRegisters(locations);
276
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()) {
287 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
288 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
289 } else {
290 DCHECK(instruction_->IsCheckCast());
291 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
292 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000293
294 codegen->RestoreLiveRegisters(locations);
295 __ b(GetExitLabel());
296 }
297
298 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000299 HInstruction* const instruction_;
300 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000301 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000302 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000303
304 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
305};
306
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000307#undef __
308
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100309#undef __
310#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700311
312inline Condition ARMCondition(IfCondition cond) {
313 switch (cond) {
314 case kCondEQ: return EQ;
315 case kCondNE: return NE;
316 case kCondLT: return LT;
317 case kCondLE: return LE;
318 case kCondGT: return GT;
319 case kCondGE: return GE;
320 default:
321 LOG(FATAL) << "Unknown if condition";
322 }
323 return EQ; // Unreachable.
324}
325
326inline Condition ARMOppositeCondition(IfCondition cond) {
327 switch (cond) {
328 case kCondEQ: return NE;
329 case kCondNE: return EQ;
330 case kCondLT: return GE;
331 case kCondLE: return GT;
332 case kCondGT: return LE;
333 case kCondGE: return LT;
334 default:
335 LOG(FATAL) << "Unknown if condition";
336 }
337 return EQ; // Unreachable.
338}
339
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100340void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
341 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
342}
343
344void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000345 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100346}
347
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100348size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
349 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
350 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100351}
352
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100353size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
354 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
355 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100356}
357
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000358size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
359 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
360 return kArmWordSize;
361}
362
363size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
364 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
365 return kArmWordSize;
366}
367
Calin Juravle34166012014-12-19 17:22:29 +0000368CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000369 const ArmInstructionSetFeatures& isa_features,
370 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000371 : CodeGenerator(graph,
372 kNumberOfCoreRegisters,
373 kNumberOfSRegisters,
374 kNumberOfRegisterPairs,
375 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
376 arraysize(kCoreCalleeSaves)),
377 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
378 arraysize(kFpuCalleeSaves)),
379 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100380 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100381 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100382 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100383 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000384 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000385 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000386 // Save the PC register to mimic Quick.
387 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100388}
389
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100390Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100391 switch (type) {
392 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100393 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100394 ArmManagedRegister pair =
395 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100396 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
397 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
398
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100399 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
400 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100401 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100402 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100403 }
404
405 case Primitive::kPrimByte:
406 case Primitive::kPrimBoolean:
407 case Primitive::kPrimChar:
408 case Primitive::kPrimShort:
409 case Primitive::kPrimInt:
410 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100411 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100412 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100413 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
414 ArmManagedRegister current =
415 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
416 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100417 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100418 }
419 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100420 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100421 }
422
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000423 case Primitive::kPrimFloat: {
424 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100425 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100426 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100427
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000428 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000429 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
430 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000431 return Location::FpuRegisterPairLocation(reg, reg + 1);
432 }
433
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100434 case Primitive::kPrimVoid:
435 LOG(FATAL) << "Unreachable type " << type;
436 }
437
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100438 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100439}
440
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000441void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100443 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100444
445 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100446 blocked_core_registers_[SP] = true;
447 blocked_core_registers_[LR] = true;
448 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100449
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100450 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100451 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100453 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100455
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000456 if (is_baseline) {
457 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
458 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
459 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000460
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000461 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
462
463 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
464 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
465 }
466 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100467
468 UpdateBlockedPairRegisters();
469}
470
471void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
472 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
473 ArmManagedRegister current =
474 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
475 if (blocked_core_registers_[current.AsRegisterPairLow()]
476 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
477 blocked_register_pairs_[i] = true;
478 }
479 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100480}
481
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100482InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
483 : HGraphVisitor(graph),
484 assembler_(codegen->GetAssembler()),
485 codegen_(codegen) {}
486
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000487static uint32_t LeastSignificantBit(uint32_t mask) {
488 // ffs starts at 1.
489 return ffs(mask) - 1;
490}
491
492void CodeGeneratorARM::ComputeSpillMask() {
493 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000494 // Save one extra register for baseline. Note that on thumb2, there is no easy
495 // instruction to restore just the PC, so this actually helps both baseline
496 // and non-baseline to save and restore at least two registers at entry and exit.
497 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000498 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
499 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
500 // We use vpush and vpop for saving and restoring floating point registers, which take
501 // a SRegister and the number of registers to save/restore after that SRegister. We
502 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
503 // but in the range.
504 if (fpu_spill_mask_ != 0) {
505 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
506 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
507 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
508 fpu_spill_mask_ |= (1 << i);
509 }
510 }
511}
512
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000513void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000514 bool skip_overflow_check =
515 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000516 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000517 __ Bind(&frame_entry_label_);
518
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000519 if (HasEmptyFrame()) {
520 return;
521 }
522
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100523 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000524 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
525 __ LoadFromOffset(kLoadWord, IP, IP, 0);
526 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100527 }
528
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000529 // PC is in the list of callee-save to mimic Quick, but we need to push
530 // LR at entry instead.
531 __ PushList((core_spill_mask_ & (~(1 << PC))) | 1 << LR);
532 if (fpu_spill_mask_ != 0) {
533 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
534 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
535 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000536 __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize()));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100537 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000538}
539
540void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000541 if (HasEmptyFrame()) {
542 __ bx(LR);
543 return;
544 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000545 __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000546 if (fpu_spill_mask_ != 0) {
547 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
548 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
549 }
550 __ PopList(core_spill_mask_);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000551}
552
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100553void CodeGeneratorARM::Bind(HBasicBlock* block) {
554 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000555}
556
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100557Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
558 switch (load->GetType()) {
559 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100560 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100561 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
562 break;
563
564 case Primitive::kPrimInt:
565 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100566 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100567 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100568
569 case Primitive::kPrimBoolean:
570 case Primitive::kPrimByte:
571 case Primitive::kPrimChar:
572 case Primitive::kPrimShort:
573 case Primitive::kPrimVoid:
574 LOG(FATAL) << "Unexpected type " << load->GetType();
575 }
576
577 LOG(FATAL) << "Unreachable";
578 return Location();
579}
580
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100581Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
582 switch (type) {
583 case Primitive::kPrimBoolean:
584 case Primitive::kPrimByte:
585 case Primitive::kPrimChar:
586 case Primitive::kPrimShort:
587 case Primitive::kPrimInt:
588 case Primitive::kPrimNot: {
589 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000590 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100591 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100592 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100593 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000594 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100595 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100596 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100597
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000598 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100599 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000600 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100601 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000602 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100603 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000604 if (calling_convention.GetRegisterAt(index) == R1) {
605 // Skip R1, and use R2_R3 instead.
606 gp_index_++;
607 index++;
608 }
609 }
610 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
611 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000612 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000613 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000614 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100615 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000616 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
617 }
618 }
619
620 case Primitive::kPrimFloat: {
621 uint32_t stack_index = stack_index_++;
622 if (float_index_ % 2 == 0) {
623 float_index_ = std::max(double_index_, float_index_);
624 }
625 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
626 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
627 } else {
628 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
629 }
630 }
631
632 case Primitive::kPrimDouble: {
633 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
634 uint32_t stack_index = stack_index_;
635 stack_index_ += 2;
636 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
637 uint32_t index = double_index_;
638 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000639 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000640 calling_convention.GetFpuRegisterAt(index),
641 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000642 DCHECK(ExpectedPairLayout(result));
643 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000644 } else {
645 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100646 }
647 }
648
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100649 case Primitive::kPrimVoid:
650 LOG(FATAL) << "Unexpected parameter type " << type;
651 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100652 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100653 return Location();
654}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100655
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000656Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
657 switch (type) {
658 case Primitive::kPrimBoolean:
659 case Primitive::kPrimByte:
660 case Primitive::kPrimChar:
661 case Primitive::kPrimShort:
662 case Primitive::kPrimInt:
663 case Primitive::kPrimNot: {
664 return Location::RegisterLocation(R0);
665 }
666
667 case Primitive::kPrimFloat: {
668 return Location::FpuRegisterLocation(S0);
669 }
670
671 case Primitive::kPrimLong: {
672 return Location::RegisterPairLocation(R0, R1);
673 }
674
675 case Primitive::kPrimDouble: {
676 return Location::FpuRegisterPairLocation(S0, S1);
677 }
678
679 case Primitive::kPrimVoid:
680 return Location();
681 }
682 UNREACHABLE();
683 return Location();
684}
685
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100686void CodeGeneratorARM::Move32(Location destination, Location source) {
687 if (source.Equals(destination)) {
688 return;
689 }
690 if (destination.IsRegister()) {
691 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000692 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100693 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000694 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100695 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000696 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100697 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100698 } else if (destination.IsFpuRegister()) {
699 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000700 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100701 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000702 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100703 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000704 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100705 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000707 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100708 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000709 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100710 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000711 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000713 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100714 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
715 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100716 }
717 }
718}
719
720void CodeGeneratorARM::Move64(Location destination, Location source) {
721 if (source.Equals(destination)) {
722 return;
723 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100724 if (destination.IsRegisterPair()) {
725 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000726 EmitParallelMoves(
727 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
728 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
729 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
730 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100731 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000732 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100733 } else {
734 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000735 DCHECK(ExpectedPairLayout(destination));
736 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
737 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100738 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000739 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100740 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000741 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
742 SP,
743 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100744 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000745 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100746 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100747 } else {
748 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100749 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000750 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100751 if (source.AsRegisterPairLow<Register>() == R1) {
752 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100753 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
754 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100755 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100756 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100757 SP, destination.GetStackIndex());
758 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000759 } else if (source.IsFpuRegisterPair()) {
760 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
761 SP,
762 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100763 } else {
764 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000765 EmitParallelMoves(
766 Location::StackSlot(source.GetStackIndex()),
767 Location::StackSlot(destination.GetStackIndex()),
768 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
769 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100770 }
771 }
772}
773
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100774void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100775 LocationSummary* locations = instruction->GetLocations();
776 if (locations != nullptr && locations->Out().Equals(location)) {
777 return;
778 }
779
Calin Juravlea21f5982014-11-13 15:53:04 +0000780 if (locations != nullptr && locations->Out().IsConstant()) {
781 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000782 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
783 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000784 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000785 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000786 } else {
787 DCHECK(location.IsStackSlot());
788 __ LoadImmediate(IP, value);
789 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
790 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000791 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000792 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000793 int64_t value = const_to_move->AsLongConstant()->GetValue();
794 if (location.IsRegisterPair()) {
795 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
796 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
797 } else {
798 DCHECK(location.IsDoubleStackSlot());
799 __ LoadImmediate(IP, Low32Bits(value));
800 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
801 __ LoadImmediate(IP, High32Bits(value));
802 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
803 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100804 }
Roland Levillain476df552014-10-09 17:51:36 +0100805 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100806 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
807 switch (instruction->GetType()) {
808 case Primitive::kPrimBoolean:
809 case Primitive::kPrimByte:
810 case Primitive::kPrimChar:
811 case Primitive::kPrimShort:
812 case Primitive::kPrimInt:
813 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100814 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100815 Move32(location, Location::StackSlot(stack_slot));
816 break;
817
818 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100819 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100820 Move64(location, Location::DoubleStackSlot(stack_slot));
821 break;
822
823 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000826 } else if (instruction->IsTemporary()) {
827 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000828 if (temp_location.IsStackSlot()) {
829 Move32(location, temp_location);
830 } else {
831 DCHECK(temp_location.IsDoubleStackSlot());
832 Move64(location, temp_location);
833 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000834 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100835 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100836 switch (instruction->GetType()) {
837 case Primitive::kPrimBoolean:
838 case Primitive::kPrimByte:
839 case Primitive::kPrimChar:
840 case Primitive::kPrimShort:
841 case Primitive::kPrimNot:
842 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100843 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100844 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100845 break;
846
847 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100848 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100849 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100850 break;
851
852 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100853 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100854 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000855 }
856}
857
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100858void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
859 HInstruction* instruction,
860 uint32_t dex_pc) {
861 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
862 __ blx(LR);
863 RecordPcInfo(instruction, dex_pc);
864 DCHECK(instruction->IsSuspendCheck()
865 || instruction->IsBoundsCheck()
866 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000867 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000868 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100869 || !IsLeafMethod());
870}
871
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000872void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000873 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000874}
875
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000876void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000877 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100878 DCHECK(!successor->IsExitBlock());
879
880 HBasicBlock* block = got->GetBlock();
881 HInstruction* previous = got->GetPrevious();
882
883 HLoopInformation* info = block->GetLoopInformation();
884 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
885 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
886 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
887 return;
888 }
889
890 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
891 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
892 }
893 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000894 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000895 }
896}
897
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000898void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000899 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000900}
901
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000902void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700903 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000904 if (kIsDebugBuild) {
905 __ Comment("Unreachable");
906 __ bkpt(0);
907 }
908}
909
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000910void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100911 LocationSummary* locations =
912 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100913 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100914 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100915 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100916 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000917}
918
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000919void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700920 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100921 if (cond->IsIntConstant()) {
922 // Constant condition, statically compared against 1.
923 int32_t cond_value = cond->AsIntConstant()->GetValue();
924 if (cond_value == 1) {
925 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
926 if_instr->IfTrueSuccessor())) {
927 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100928 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100929 return;
930 } else {
931 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100932 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100933 } else {
934 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
935 // Condition has been materialized, compare the output to 0
936 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000937 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100938 ShifterOperand(0));
939 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
940 } else {
941 // Condition has not been materialized, use its inputs as the
942 // comparison and its condition as the branch condition.
943 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000944 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000945 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100946 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000947 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100948 } else {
949 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000950 HConstant* constant = locations->InAt(1).GetConstant();
951 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100952 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000953 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
954 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100955 } else {
956 Register temp = IP;
957 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000958 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 }
960 }
961 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
962 ARMCondition(cond->AsCondition()->GetCondition()));
963 }
Dave Allison20dfc792014-06-16 20:44:29 -0700964 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100965 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
966 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700967 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000968 }
969}
970
Dave Allison20dfc792014-06-16 20:44:29 -0700971
972void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100973 LocationSummary* locations =
974 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100975 locations->SetInAt(0, Location::RequiresRegister());
976 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100977 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100978 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100979 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000980}
981
Dave Allison20dfc792014-06-16 20:44:29 -0700982void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100983 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100984 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000985 Register left = locations->InAt(0).AsRegister<Register>();
986
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100987 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000988 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100989 } else {
990 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -0800991 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100992 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000993 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
994 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100995 } else {
996 Register temp = IP;
997 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000998 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100999 }
Dave Allison20dfc792014-06-16 20:44:29 -07001000 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001001 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001002 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001003 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001004 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001005 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001006}
1007
1008void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1009 VisitCondition(comp);
1010}
1011
1012void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1013 VisitCondition(comp);
1014}
1015
1016void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1017 VisitCondition(comp);
1018}
1019
1020void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1021 VisitCondition(comp);
1022}
1023
1024void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1025 VisitCondition(comp);
1026}
1027
1028void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1029 VisitCondition(comp);
1030}
1031
1032void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1033 VisitCondition(comp);
1034}
1035
1036void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1037 VisitCondition(comp);
1038}
1039
1040void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1041 VisitCondition(comp);
1042}
1043
1044void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1045 VisitCondition(comp);
1046}
1047
1048void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1049 VisitCondition(comp);
1050}
1051
1052void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1053 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001054}
1055
1056void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001057 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001058}
1059
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001060void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1061 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001062}
1063
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001064void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001065 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001066}
1067
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001068void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001069 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001070 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001071}
1072
1073void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001074 LocationSummary* locations =
1075 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001076 switch (store->InputAt(1)->GetType()) {
1077 case Primitive::kPrimBoolean:
1078 case Primitive::kPrimByte:
1079 case Primitive::kPrimChar:
1080 case Primitive::kPrimShort:
1081 case Primitive::kPrimInt:
1082 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001083 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001084 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1085 break;
1086
1087 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001088 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001089 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1090 break;
1091
1092 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001093 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001094 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001095}
1096
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001097void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001098 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001099}
1100
1101void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001102 LocationSummary* locations =
1103 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001104 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001105}
1106
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001107void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001108 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001109 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001110}
1111
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001112void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1113 LocationSummary* locations =
1114 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1115 locations->SetOut(Location::ConstantLocation(constant));
1116}
1117
1118void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1119 // Will be generated at use site.
1120 UNUSED(constant);
1121}
1122
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001123void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001124 LocationSummary* locations =
1125 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001126 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001127}
1128
1129void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1130 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001131 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001132}
1133
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001134void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1135 LocationSummary* locations =
1136 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1137 locations->SetOut(Location::ConstantLocation(constant));
1138}
1139
1140void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1141 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001142 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001143}
1144
1145void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1146 LocationSummary* locations =
1147 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1148 locations->SetOut(Location::ConstantLocation(constant));
1149}
1150
1151void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1152 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001153 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001154}
1155
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001156void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001158}
1159
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001160void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001161 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001162 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001163}
1164
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001165void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001166 LocationSummary* locations =
1167 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001168 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001169}
1170
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001171void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001172 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001173 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001174}
1175
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001176void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001177 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1178 codegen_->GetInstructionSetFeatures());
1179 if (intrinsic.TryDispatch(invoke)) {
1180 return;
1181 }
1182
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001183 HandleInvoke(invoke);
1184}
1185
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001186void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001187 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001188 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189}
1190
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001191static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1192 if (invoke->GetLocations()->Intrinsified()) {
1193 IntrinsicCodeGeneratorARM intrinsic(codegen);
1194 intrinsic.Dispatch(invoke);
1195 return true;
1196 }
1197 return false;
1198}
1199
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001200void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001201 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1202 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001203 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001204
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001205 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1206
1207 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001208}
1209
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001210void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001211 LocationSummary* locations =
1212 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001213 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001214
1215 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001216 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001217 HInstruction* input = invoke->InputAt(i);
1218 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1219 }
1220
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001221 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001222}
1223
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001224void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001225 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1226 codegen_->GetInstructionSetFeatures());
1227 if (intrinsic.TryDispatch(invoke)) {
1228 return;
1229 }
1230
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001231 HandleInvoke(invoke);
1232}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001233
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001234void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001235 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1236 return;
1237 }
1238
Roland Levillain271ab9c2014-11-27 15:23:57 +00001239 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001240 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1241 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1242 LocationSummary* locations = invoke->GetLocations();
1243 Location receiver = locations->InAt(0);
1244 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1245 // temp = object->GetClass();
1246 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001247 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1248 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001249 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001250 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001251 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001252 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001253 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001254 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001255 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001256 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001257 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001258 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001259 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001260 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001261 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001262 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001263}
1264
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001265void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1266 HandleInvoke(invoke);
1267 // Add the hidden argument.
1268 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1269}
1270
1271void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1272 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001273 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001274 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1275 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1276 LocationSummary* locations = invoke->GetLocations();
1277 Location receiver = locations->InAt(0);
1278 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1279
1280 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001281 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1282 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001283
1284 // temp = object->GetClass();
1285 if (receiver.IsStackSlot()) {
1286 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1287 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1288 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001289 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001290 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001291 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001292 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001293 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001294 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001295 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1296 // LR = temp->GetEntryPoint();
1297 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1298 // LR();
1299 __ blx(LR);
1300 DCHECK(!codegen_->IsLeafMethod());
1301 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1302}
1303
Roland Levillain88cb1752014-10-20 16:36:47 +01001304void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1305 LocationSummary* locations =
1306 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1307 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001308 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001309 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001310 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1311 break;
1312 }
1313 case Primitive::kPrimLong: {
1314 locations->SetInAt(0, Location::RequiresRegister());
1315 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001316 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001317 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001318
Roland Levillain88cb1752014-10-20 16:36:47 +01001319 case Primitive::kPrimFloat:
1320 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001321 locations->SetInAt(0, Location::RequiresFpuRegister());
1322 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001323 break;
1324
1325 default:
1326 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1327 }
1328}
1329
1330void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1331 LocationSummary* locations = neg->GetLocations();
1332 Location out = locations->Out();
1333 Location in = locations->InAt(0);
1334 switch (neg->GetResultType()) {
1335 case Primitive::kPrimInt:
1336 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001337 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001338 break;
1339
1340 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001341 DCHECK(in.IsRegisterPair());
1342 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1343 __ rsbs(out.AsRegisterPairLow<Register>(),
1344 in.AsRegisterPairLow<Register>(),
1345 ShifterOperand(0));
1346 // We cannot emit an RSC (Reverse Subtract with Carry)
1347 // instruction here, as it does not exist in the Thumb-2
1348 // instruction set. We use the following approach
1349 // using SBC and SUB instead.
1350 //
1351 // out.hi = -C
1352 __ sbc(out.AsRegisterPairHigh<Register>(),
1353 out.AsRegisterPairHigh<Register>(),
1354 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1355 // out.hi = out.hi - in.hi
1356 __ sub(out.AsRegisterPairHigh<Register>(),
1357 out.AsRegisterPairHigh<Register>(),
1358 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1359 break;
1360
Roland Levillain88cb1752014-10-20 16:36:47 +01001361 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001362 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001363 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001364 break;
1365
Roland Levillain88cb1752014-10-20 16:36:47 +01001366 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001367 DCHECK(in.IsFpuRegisterPair());
1368 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1369 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001370 break;
1371
1372 default:
1373 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1374 }
1375}
1376
Roland Levillaindff1f282014-11-05 14:15:05 +00001377void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001378 Primitive::Type result_type = conversion->GetResultType();
1379 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001380 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001381
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001382 // The float-to-long and double-to-long type conversions rely on a
1383 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001384 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001385 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1386 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001387 ? LocationSummary::kCall
1388 : LocationSummary::kNoCall;
1389 LocationSummary* locations =
1390 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1391
Roland Levillaindff1f282014-11-05 14:15:05 +00001392 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001393 case Primitive::kPrimByte:
1394 switch (input_type) {
1395 case Primitive::kPrimShort:
1396 case Primitive::kPrimInt:
1397 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001398 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001399 locations->SetInAt(0, Location::RequiresRegister());
1400 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1401 break;
1402
1403 default:
1404 LOG(FATAL) << "Unexpected type conversion from " << input_type
1405 << " to " << result_type;
1406 }
1407 break;
1408
Roland Levillain01a8d712014-11-14 16:27:39 +00001409 case Primitive::kPrimShort:
1410 switch (input_type) {
1411 case Primitive::kPrimByte:
1412 case Primitive::kPrimInt:
1413 case Primitive::kPrimChar:
1414 // Processing a Dex `int-to-short' instruction.
1415 locations->SetInAt(0, Location::RequiresRegister());
1416 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1417 break;
1418
1419 default:
1420 LOG(FATAL) << "Unexpected type conversion from " << input_type
1421 << " to " << result_type;
1422 }
1423 break;
1424
Roland Levillain946e1432014-11-11 17:35:19 +00001425 case Primitive::kPrimInt:
1426 switch (input_type) {
1427 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001428 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001429 locations->SetInAt(0, Location::Any());
1430 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1431 break;
1432
1433 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001434 // Processing a Dex `float-to-int' instruction.
1435 locations->SetInAt(0, Location::RequiresFpuRegister());
1436 locations->SetOut(Location::RequiresRegister());
1437 locations->AddTemp(Location::RequiresFpuRegister());
1438 break;
1439
Roland Levillain946e1432014-11-11 17:35:19 +00001440 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001441 // Processing a Dex `double-to-int' instruction.
1442 locations->SetInAt(0, Location::RequiresFpuRegister());
1443 locations->SetOut(Location::RequiresRegister());
1444 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001445 break;
1446
1447 default:
1448 LOG(FATAL) << "Unexpected type conversion from " << input_type
1449 << " to " << result_type;
1450 }
1451 break;
1452
Roland Levillaindff1f282014-11-05 14:15:05 +00001453 case Primitive::kPrimLong:
1454 switch (input_type) {
1455 case Primitive::kPrimByte:
1456 case Primitive::kPrimShort:
1457 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001458 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001459 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001460 locations->SetInAt(0, Location::RequiresRegister());
1461 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1462 break;
1463
Roland Levillain624279f2014-12-04 11:54:28 +00001464 case Primitive::kPrimFloat: {
1465 // Processing a Dex `float-to-long' instruction.
1466 InvokeRuntimeCallingConvention calling_convention;
1467 locations->SetInAt(0, Location::FpuRegisterLocation(
1468 calling_convention.GetFpuRegisterAt(0)));
1469 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1470 break;
1471 }
1472
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001473 case Primitive::kPrimDouble: {
1474 // Processing a Dex `double-to-long' instruction.
1475 InvokeRuntimeCallingConvention calling_convention;
1476 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1477 calling_convention.GetFpuRegisterAt(0),
1478 calling_convention.GetFpuRegisterAt(1)));
1479 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001480 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001481 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001482
1483 default:
1484 LOG(FATAL) << "Unexpected type conversion from " << input_type
1485 << " to " << result_type;
1486 }
1487 break;
1488
Roland Levillain981e4542014-11-14 11:47:14 +00001489 case Primitive::kPrimChar:
1490 switch (input_type) {
1491 case Primitive::kPrimByte:
1492 case Primitive::kPrimShort:
1493 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001494 // Processing a Dex `int-to-char' instruction.
1495 locations->SetInAt(0, Location::RequiresRegister());
1496 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1497 break;
1498
1499 default:
1500 LOG(FATAL) << "Unexpected type conversion from " << input_type
1501 << " to " << result_type;
1502 }
1503 break;
1504
Roland Levillaindff1f282014-11-05 14:15:05 +00001505 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001506 switch (input_type) {
1507 case Primitive::kPrimByte:
1508 case Primitive::kPrimShort:
1509 case Primitive::kPrimInt:
1510 case Primitive::kPrimChar:
1511 // Processing a Dex `int-to-float' instruction.
1512 locations->SetInAt(0, Location::RequiresRegister());
1513 locations->SetOut(Location::RequiresFpuRegister());
1514 break;
1515
1516 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001517 // Processing a Dex `long-to-float' instruction.
1518 locations->SetInAt(0, Location::RequiresRegister());
1519 locations->SetOut(Location::RequiresFpuRegister());
1520 locations->AddTemp(Location::RequiresRegister());
1521 locations->AddTemp(Location::RequiresRegister());
1522 locations->AddTemp(Location::RequiresFpuRegister());
1523 locations->AddTemp(Location::RequiresFpuRegister());
1524 break;
1525
Roland Levillaincff13742014-11-17 14:32:17 +00001526 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001527 // Processing a Dex `double-to-float' instruction.
1528 locations->SetInAt(0, Location::RequiresFpuRegister());
1529 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001530 break;
1531
1532 default:
1533 LOG(FATAL) << "Unexpected type conversion from " << input_type
1534 << " to " << result_type;
1535 };
1536 break;
1537
Roland Levillaindff1f282014-11-05 14:15:05 +00001538 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001539 switch (input_type) {
1540 case Primitive::kPrimByte:
1541 case Primitive::kPrimShort:
1542 case Primitive::kPrimInt:
1543 case Primitive::kPrimChar:
1544 // Processing a Dex `int-to-double' instruction.
1545 locations->SetInAt(0, Location::RequiresRegister());
1546 locations->SetOut(Location::RequiresFpuRegister());
1547 break;
1548
1549 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001550 // Processing a Dex `long-to-double' instruction.
1551 locations->SetInAt(0, Location::RequiresRegister());
1552 locations->SetOut(Location::RequiresFpuRegister());
1553 locations->AddTemp(Location::RequiresRegister());
1554 locations->AddTemp(Location::RequiresRegister());
1555 locations->AddTemp(Location::RequiresFpuRegister());
1556 break;
1557
Roland Levillaincff13742014-11-17 14:32:17 +00001558 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001559 // Processing a Dex `float-to-double' instruction.
1560 locations->SetInAt(0, Location::RequiresFpuRegister());
1561 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001562 break;
1563
1564 default:
1565 LOG(FATAL) << "Unexpected type conversion from " << input_type
1566 << " to " << result_type;
1567 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001568 break;
1569
1570 default:
1571 LOG(FATAL) << "Unexpected type conversion from " << input_type
1572 << " to " << result_type;
1573 }
1574}
1575
1576void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1577 LocationSummary* locations = conversion->GetLocations();
1578 Location out = locations->Out();
1579 Location in = locations->InAt(0);
1580 Primitive::Type result_type = conversion->GetResultType();
1581 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001582 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001583 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001584 case Primitive::kPrimByte:
1585 switch (input_type) {
1586 case Primitive::kPrimShort:
1587 case Primitive::kPrimInt:
1588 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001589 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001590 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001591 break;
1592
1593 default:
1594 LOG(FATAL) << "Unexpected type conversion from " << input_type
1595 << " to " << result_type;
1596 }
1597 break;
1598
Roland Levillain01a8d712014-11-14 16:27:39 +00001599 case Primitive::kPrimShort:
1600 switch (input_type) {
1601 case Primitive::kPrimByte:
1602 case Primitive::kPrimInt:
1603 case Primitive::kPrimChar:
1604 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001605 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001606 break;
1607
1608 default:
1609 LOG(FATAL) << "Unexpected type conversion from " << input_type
1610 << " to " << result_type;
1611 }
1612 break;
1613
Roland Levillain946e1432014-11-11 17:35:19 +00001614 case Primitive::kPrimInt:
1615 switch (input_type) {
1616 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001617 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001618 DCHECK(out.IsRegister());
1619 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001620 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001621 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001622 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001623 } else {
1624 DCHECK(in.IsConstant());
1625 DCHECK(in.GetConstant()->IsLongConstant());
1626 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001627 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001628 }
1629 break;
1630
Roland Levillain3f8f9362014-12-02 17:45:01 +00001631 case Primitive::kPrimFloat: {
1632 // Processing a Dex `float-to-int' instruction.
1633 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1634 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1635 __ vcvtis(temp, temp);
1636 __ vmovrs(out.AsRegister<Register>(), temp);
1637 break;
1638 }
1639
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001640 case Primitive::kPrimDouble: {
1641 // Processing a Dex `double-to-int' instruction.
1642 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1643 DRegister temp_d = FromLowSToD(temp_s);
1644 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1645 __ vcvtid(temp_s, temp_d);
1646 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001647 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001648 }
Roland Levillain946e1432014-11-11 17:35:19 +00001649
1650 default:
1651 LOG(FATAL) << "Unexpected type conversion from " << input_type
1652 << " to " << result_type;
1653 }
1654 break;
1655
Roland Levillaindff1f282014-11-05 14:15:05 +00001656 case Primitive::kPrimLong:
1657 switch (input_type) {
1658 case Primitive::kPrimByte:
1659 case Primitive::kPrimShort:
1660 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001661 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001662 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001663 DCHECK(out.IsRegisterPair());
1664 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001665 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001666 // Sign extension.
1667 __ Asr(out.AsRegisterPairHigh<Register>(),
1668 out.AsRegisterPairLow<Register>(),
1669 31);
1670 break;
1671
1672 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001673 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001674 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1675 conversion,
1676 conversion->GetDexPc());
1677 break;
1678
Roland Levillaindff1f282014-11-05 14:15:05 +00001679 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001680 // Processing a Dex `double-to-long' instruction.
1681 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1682 conversion,
1683 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001684 break;
1685
1686 default:
1687 LOG(FATAL) << "Unexpected type conversion from " << input_type
1688 << " to " << result_type;
1689 }
1690 break;
1691
Roland Levillain981e4542014-11-14 11:47:14 +00001692 case Primitive::kPrimChar:
1693 switch (input_type) {
1694 case Primitive::kPrimByte:
1695 case Primitive::kPrimShort:
1696 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001697 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001698 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001699 break;
1700
1701 default:
1702 LOG(FATAL) << "Unexpected type conversion from " << input_type
1703 << " to " << result_type;
1704 }
1705 break;
1706
Roland Levillaindff1f282014-11-05 14:15:05 +00001707 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001708 switch (input_type) {
1709 case Primitive::kPrimByte:
1710 case Primitive::kPrimShort:
1711 case Primitive::kPrimInt:
1712 case Primitive::kPrimChar: {
1713 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001714 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1715 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001716 break;
1717 }
1718
Roland Levillain6d0e4832014-11-27 18:31:21 +00001719 case Primitive::kPrimLong: {
1720 // Processing a Dex `long-to-float' instruction.
1721 Register low = in.AsRegisterPairLow<Register>();
1722 Register high = in.AsRegisterPairHigh<Register>();
1723 SRegister output = out.AsFpuRegister<SRegister>();
1724 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1725 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1726 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1727 DRegister temp1_d = FromLowSToD(temp1_s);
1728 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1729 DRegister temp2_d = FromLowSToD(temp2_s);
1730
1731 // Operations use doubles for precision reasons (each 32-bit
1732 // half of a long fits in the 53-bit mantissa of a double,
1733 // but not in the 24-bit mantissa of a float). This is
1734 // especially important for the low bits. The result is
1735 // eventually converted to float.
1736
1737 // temp1_d = int-to-double(high)
1738 __ vmovsr(temp1_s, high);
1739 __ vcvtdi(temp1_d, temp1_s);
1740 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1741 // as an immediate value into `temp2_d` does not work, as
1742 // this instruction only transfers 8 significant bits of its
1743 // immediate operand. Instead, use two 32-bit core
1744 // registers to load `k2Pow32EncodingForDouble` into
1745 // `temp2_d`.
1746 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1747 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1748 __ vmovdrr(temp2_d, constant_low, constant_high);
1749 // temp1_d = temp1_d * 2^32
1750 __ vmuld(temp1_d, temp1_d, temp2_d);
1751 // temp2_d = unsigned-to-double(low)
1752 __ vmovsr(temp2_s, low);
1753 __ vcvtdu(temp2_d, temp2_s);
1754 // temp1_d = temp1_d + temp2_d
1755 __ vaddd(temp1_d, temp1_d, temp2_d);
1756 // output = double-to-float(temp1_d);
1757 __ vcvtsd(output, temp1_d);
1758 break;
1759 }
1760
Roland Levillaincff13742014-11-17 14:32:17 +00001761 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001762 // Processing a Dex `double-to-float' instruction.
1763 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1764 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001765 break;
1766
1767 default:
1768 LOG(FATAL) << "Unexpected type conversion from " << input_type
1769 << " to " << result_type;
1770 };
1771 break;
1772
Roland Levillaindff1f282014-11-05 14:15:05 +00001773 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001774 switch (input_type) {
1775 case Primitive::kPrimByte:
1776 case Primitive::kPrimShort:
1777 case Primitive::kPrimInt:
1778 case Primitive::kPrimChar: {
1779 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001780 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001781 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1782 out.AsFpuRegisterPairLow<SRegister>());
1783 break;
1784 }
1785
Roland Levillain647b9ed2014-11-27 12:06:00 +00001786 case Primitive::kPrimLong: {
1787 // Processing a Dex `long-to-double' instruction.
1788 Register low = in.AsRegisterPairLow<Register>();
1789 Register high = in.AsRegisterPairHigh<Register>();
1790 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1791 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001792 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1793 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001794 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1795 DRegister temp_d = FromLowSToD(temp_s);
1796
Roland Levillain647b9ed2014-11-27 12:06:00 +00001797 // out_d = int-to-double(high)
1798 __ vmovsr(out_s, high);
1799 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001800 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1801 // as an immediate value into `temp_d` does not work, as
1802 // this instruction only transfers 8 significant bits of its
1803 // immediate operand. Instead, use two 32-bit core
1804 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1805 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1806 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001807 __ vmovdrr(temp_d, constant_low, constant_high);
1808 // out_d = out_d * 2^32
1809 __ vmuld(out_d, out_d, temp_d);
1810 // temp_d = unsigned-to-double(low)
1811 __ vmovsr(temp_s, low);
1812 __ vcvtdu(temp_d, temp_s);
1813 // out_d = out_d + temp_d
1814 __ vaddd(out_d, out_d, temp_d);
1815 break;
1816 }
1817
Roland Levillaincff13742014-11-17 14:32:17 +00001818 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001819 // Processing a Dex `float-to-double' instruction.
1820 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1821 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001822 break;
1823
1824 default:
1825 LOG(FATAL) << "Unexpected type conversion from " << input_type
1826 << " to " << result_type;
1827 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001828 break;
1829
1830 default:
1831 LOG(FATAL) << "Unexpected type conversion from " << input_type
1832 << " to " << result_type;
1833 }
1834}
1835
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001836void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001837 LocationSummary* locations =
1838 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001839 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001840 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001841 locations->SetInAt(0, Location::RequiresRegister());
1842 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001843 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1844 break;
1845 }
1846
1847 case Primitive::kPrimLong: {
1848 locations->SetInAt(0, Location::RequiresRegister());
1849 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001850 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001851 break;
1852 }
1853
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001854 case Primitive::kPrimFloat:
1855 case Primitive::kPrimDouble: {
1856 locations->SetInAt(0, Location::RequiresFpuRegister());
1857 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001858 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001859 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001860 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001861
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001862 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001863 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001864 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001865}
1866
1867void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1868 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001869 Location out = locations->Out();
1870 Location first = locations->InAt(0);
1871 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001872 switch (add->GetResultType()) {
1873 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001874 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001875 __ add(out.AsRegister<Register>(),
1876 first.AsRegister<Register>(),
1877 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001878 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001879 __ AddConstant(out.AsRegister<Register>(),
1880 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001881 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001882 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001883 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001884
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001885 case Primitive::kPrimLong: {
1886 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001887 __ adds(out.AsRegisterPairLow<Register>(),
1888 first.AsRegisterPairLow<Register>(),
1889 ShifterOperand(second.AsRegisterPairLow<Register>()));
1890 __ adc(out.AsRegisterPairHigh<Register>(),
1891 first.AsRegisterPairHigh<Register>(),
1892 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001893 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001894 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001895
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001896 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001897 __ vadds(out.AsFpuRegister<SRegister>(),
1898 first.AsFpuRegister<SRegister>(),
1899 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001900 break;
1901
1902 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001903 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1904 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1905 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001906 break;
1907
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001908 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001909 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001910 }
1911}
1912
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001913void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001914 LocationSummary* locations =
1915 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001916 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001917 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001918 locations->SetInAt(0, Location::RequiresRegister());
1919 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001920 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1921 break;
1922 }
1923
1924 case Primitive::kPrimLong: {
1925 locations->SetInAt(0, Location::RequiresRegister());
1926 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001927 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001928 break;
1929 }
Calin Juravle11351682014-10-23 15:38:15 +01001930 case Primitive::kPrimFloat:
1931 case Primitive::kPrimDouble: {
1932 locations->SetInAt(0, Location::RequiresFpuRegister());
1933 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001934 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001935 break;
Calin Juravle11351682014-10-23 15:38:15 +01001936 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001937 default:
Calin Juravle11351682014-10-23 15:38:15 +01001938 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001939 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001940}
1941
1942void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1943 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001944 Location out = locations->Out();
1945 Location first = locations->InAt(0);
1946 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001947 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001948 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001949 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001950 __ sub(out.AsRegister<Register>(),
1951 first.AsRegister<Register>(),
1952 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001953 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001954 __ AddConstant(out.AsRegister<Register>(),
1955 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001956 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001957 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001958 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001959 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001960
Calin Juravle11351682014-10-23 15:38:15 +01001961 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001962 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001963 __ subs(out.AsRegisterPairLow<Register>(),
1964 first.AsRegisterPairLow<Register>(),
1965 ShifterOperand(second.AsRegisterPairLow<Register>()));
1966 __ sbc(out.AsRegisterPairHigh<Register>(),
1967 first.AsRegisterPairHigh<Register>(),
1968 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001969 break;
Calin Juravle11351682014-10-23 15:38:15 +01001970 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001971
Calin Juravle11351682014-10-23 15:38:15 +01001972 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001973 __ vsubs(out.AsFpuRegister<SRegister>(),
1974 first.AsFpuRegister<SRegister>(),
1975 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001976 break;
Calin Juravle11351682014-10-23 15:38:15 +01001977 }
1978
1979 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001980 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1981 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1982 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001983 break;
1984 }
1985
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001986
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001987 default:
Calin Juravle11351682014-10-23 15:38:15 +01001988 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001989 }
1990}
1991
Calin Juravle34bacdf2014-10-07 20:23:36 +01001992void LocationsBuilderARM::VisitMul(HMul* mul) {
1993 LocationSummary* locations =
1994 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1995 switch (mul->GetResultType()) {
1996 case Primitive::kPrimInt:
1997 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001998 locations->SetInAt(0, Location::RequiresRegister());
1999 locations->SetInAt(1, Location::RequiresRegister());
2000 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002001 break;
2002 }
2003
Calin Juravleb5bfa962014-10-21 18:02:24 +01002004 case Primitive::kPrimFloat:
2005 case Primitive::kPrimDouble: {
2006 locations->SetInAt(0, Location::RequiresFpuRegister());
2007 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002008 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002009 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002010 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002011
2012 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002013 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002014 }
2015}
2016
2017void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2018 LocationSummary* locations = mul->GetLocations();
2019 Location out = locations->Out();
2020 Location first = locations->InAt(0);
2021 Location second = locations->InAt(1);
2022 switch (mul->GetResultType()) {
2023 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002024 __ mul(out.AsRegister<Register>(),
2025 first.AsRegister<Register>(),
2026 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002027 break;
2028 }
2029 case Primitive::kPrimLong: {
2030 Register out_hi = out.AsRegisterPairHigh<Register>();
2031 Register out_lo = out.AsRegisterPairLow<Register>();
2032 Register in1_hi = first.AsRegisterPairHigh<Register>();
2033 Register in1_lo = first.AsRegisterPairLow<Register>();
2034 Register in2_hi = second.AsRegisterPairHigh<Register>();
2035 Register in2_lo = second.AsRegisterPairLow<Register>();
2036
2037 // Extra checks to protect caused by the existence of R1_R2.
2038 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2039 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2040 DCHECK_NE(out_hi, in1_lo);
2041 DCHECK_NE(out_hi, in2_lo);
2042
2043 // input: in1 - 64 bits, in2 - 64 bits
2044 // output: out
2045 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2046 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2047 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2048
2049 // IP <- in1.lo * in2.hi
2050 __ mul(IP, in1_lo, in2_hi);
2051 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2052 __ mla(out_hi, in1_hi, in2_lo, IP);
2053 // out.lo <- (in1.lo * in2.lo)[31:0];
2054 __ umull(out_lo, IP, in1_lo, in2_lo);
2055 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2056 __ add(out_hi, out_hi, ShifterOperand(IP));
2057 break;
2058 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002059
2060 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002061 __ vmuls(out.AsFpuRegister<SRegister>(),
2062 first.AsFpuRegister<SRegister>(),
2063 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002064 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002065 }
2066
2067 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002068 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2069 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2070 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002071 break;
2072 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002073
2074 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002075 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002076 }
2077}
2078
Calin Juravle7c4954d2014-10-28 16:57:40 +00002079void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002080 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2081 ? LocationSummary::kCall
2082 : LocationSummary::kNoCall;
2083 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2084
Calin Juravle7c4954d2014-10-28 16:57:40 +00002085 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002086 case Primitive::kPrimInt: {
2087 locations->SetInAt(0, Location::RequiresRegister());
2088 locations->SetInAt(1, Location::RequiresRegister());
2089 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2090 break;
2091 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002092 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002093 InvokeRuntimeCallingConvention calling_convention;
2094 locations->SetInAt(0, Location::RegisterPairLocation(
2095 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2096 locations->SetInAt(1, Location::RegisterPairLocation(
2097 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002098 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002099 break;
2100 }
2101 case Primitive::kPrimFloat:
2102 case Primitive::kPrimDouble: {
2103 locations->SetInAt(0, Location::RequiresFpuRegister());
2104 locations->SetInAt(1, Location::RequiresFpuRegister());
2105 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2106 break;
2107 }
2108
2109 default:
2110 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2111 }
2112}
2113
2114void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2115 LocationSummary* locations = div->GetLocations();
2116 Location out = locations->Out();
2117 Location first = locations->InAt(0);
2118 Location second = locations->InAt(1);
2119
2120 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002121 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002122 __ sdiv(out.AsRegister<Register>(),
2123 first.AsRegister<Register>(),
2124 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002125 break;
2126 }
2127
Calin Juravle7c4954d2014-10-28 16:57:40 +00002128 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002129 InvokeRuntimeCallingConvention calling_convention;
2130 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2131 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2132 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2133 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2134 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002135 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002136
2137 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002138 break;
2139 }
2140
2141 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002142 __ vdivs(out.AsFpuRegister<SRegister>(),
2143 first.AsFpuRegister<SRegister>(),
2144 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002145 break;
2146 }
2147
2148 case Primitive::kPrimDouble: {
2149 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2150 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2151 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2152 break;
2153 }
2154
2155 default:
2156 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2157 }
2158}
2159
Calin Juravlebacfec32014-11-14 15:54:36 +00002160void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002161 Primitive::Type type = rem->GetResultType();
2162 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2163 ? LocationSummary::kNoCall
2164 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002165 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2166
Calin Juravled2ec87d2014-12-08 14:24:46 +00002167 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002168 case Primitive::kPrimInt: {
2169 locations->SetInAt(0, Location::RequiresRegister());
2170 locations->SetInAt(1, Location::RequiresRegister());
2171 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2172 locations->AddTemp(Location::RequiresRegister());
2173 break;
2174 }
2175 case Primitive::kPrimLong: {
2176 InvokeRuntimeCallingConvention calling_convention;
2177 locations->SetInAt(0, Location::RegisterPairLocation(
2178 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2179 locations->SetInAt(1, Location::RegisterPairLocation(
2180 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2181 // The runtime helper puts the output in R2,R3.
2182 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2183 break;
2184 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002185 case Primitive::kPrimFloat: {
2186 InvokeRuntimeCallingConvention calling_convention;
2187 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2188 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2189 locations->SetOut(Location::FpuRegisterLocation(S0));
2190 break;
2191 }
2192
Calin Juravlebacfec32014-11-14 15:54:36 +00002193 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002194 InvokeRuntimeCallingConvention calling_convention;
2195 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2196 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2197 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2198 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2199 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002200 break;
2201 }
2202
2203 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002204 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002205 }
2206}
2207
2208void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2209 LocationSummary* locations = rem->GetLocations();
2210 Location out = locations->Out();
2211 Location first = locations->InAt(0);
2212 Location second = locations->InAt(1);
2213
Calin Juravled2ec87d2014-12-08 14:24:46 +00002214 Primitive::Type type = rem->GetResultType();
2215 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002216 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002217 Register reg1 = first.AsRegister<Register>();
2218 Register reg2 = second.AsRegister<Register>();
2219 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002220
2221 // temp = reg1 / reg2 (integer division)
2222 // temp = temp * reg2
2223 // dest = reg1 - temp
2224 __ sdiv(temp, reg1, reg2);
2225 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002226 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002227 break;
2228 }
2229
2230 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002231 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2232 break;
2233 }
2234
Calin Juravled2ec87d2014-12-08 14:24:46 +00002235 case Primitive::kPrimFloat: {
2236 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2237 break;
2238 }
2239
Calin Juravlebacfec32014-11-14 15:54:36 +00002240 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002241 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002242 break;
2243 }
2244
2245 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002246 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002247 }
2248}
2249
Calin Juravled0d48522014-11-04 16:40:20 +00002250void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2251 LocationSummary* locations =
2252 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002253 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002254 if (instruction->HasUses()) {
2255 locations->SetOut(Location::SameAsFirstInput());
2256 }
2257}
2258
2259void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2260 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2261 codegen_->AddSlowPath(slow_path);
2262
2263 LocationSummary* locations = instruction->GetLocations();
2264 Location value = locations->InAt(0);
2265
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002266 switch (instruction->GetType()) {
2267 case Primitive::kPrimInt: {
2268 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002269 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002270 __ b(slow_path->GetEntryLabel(), EQ);
2271 } else {
2272 DCHECK(value.IsConstant()) << value;
2273 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2274 __ b(slow_path->GetEntryLabel());
2275 }
2276 }
2277 break;
2278 }
2279 case Primitive::kPrimLong: {
2280 if (value.IsRegisterPair()) {
2281 __ orrs(IP,
2282 value.AsRegisterPairLow<Register>(),
2283 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2284 __ b(slow_path->GetEntryLabel(), EQ);
2285 } else {
2286 DCHECK(value.IsConstant()) << value;
2287 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2288 __ b(slow_path->GetEntryLabel());
2289 }
2290 }
2291 break;
2292 default:
2293 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2294 }
2295 }
Calin Juravled0d48522014-11-04 16:40:20 +00002296}
2297
Calin Juravle9aec02f2014-11-18 23:06:35 +00002298void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2299 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2300
2301 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2302 ? LocationSummary::kCall
2303 : LocationSummary::kNoCall;
2304 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2305
2306 switch (op->GetResultType()) {
2307 case Primitive::kPrimInt: {
2308 locations->SetInAt(0, Location::RequiresRegister());
2309 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002310 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002311 break;
2312 }
2313 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchez09895eb2015-03-11 14:57:40 +00002314 locations->SetInAt(0, Location::RequiresRegister());
2315 locations->SetInAt(1, Location::RequiresRegister());
2316 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002317 break;
2318 }
2319 default:
2320 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2321 }
2322}
2323
2324void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2325 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2326
2327 LocationSummary* locations = op->GetLocations();
2328 Location out = locations->Out();
2329 Location first = locations->InAt(0);
2330 Location second = locations->InAt(1);
2331
2332 Primitive::Type type = op->GetResultType();
2333 switch (type) {
2334 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002335 Register out_reg = out.AsRegister<Register>();
2336 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002337 // Arm doesn't mask the shift count so we need to do it ourselves.
2338 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002339 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002340 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2341 if (op->IsShl()) {
2342 __ Lsl(out_reg, first_reg, second_reg);
2343 } else if (op->IsShr()) {
2344 __ Asr(out_reg, first_reg, second_reg);
2345 } else {
2346 __ Lsr(out_reg, first_reg, second_reg);
2347 }
2348 } else {
2349 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2350 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2351 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2352 __ Mov(out_reg, first_reg);
2353 } else if (op->IsShl()) {
2354 __ Lsl(out_reg, first_reg, shift_value);
2355 } else if (op->IsShr()) {
2356 __ Asr(out_reg, first_reg, shift_value);
2357 } else {
2358 __ Lsr(out_reg, first_reg, shift_value);
2359 }
2360 }
2361 break;
2362 }
2363 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchez09895eb2015-03-11 14:57:40 +00002364 Register o_h = out.AsRegisterPairHigh<Register>();
2365 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002366
Guillaume "Vermeille" Sanchez09895eb2015-03-11 14:57:40 +00002367 Register high = first.AsRegisterPairHigh<Register>();
2368 Register low = first.AsRegisterPairLow<Register>();
2369
2370 Register second_reg = second.AsRegister<Register>();
2371
Calin Juravle9aec02f2014-11-18 23:06:35 +00002372 if (op->IsShl()) {
Guillaume "Vermeille" Sanchez09895eb2015-03-11 14:57:40 +00002373 // Shift the high part
2374 __ and_(second_reg, second_reg, ShifterOperand(63));
2375 __ Lsl(high, high, second_reg);
2376 // Shift the low part and `or` what overflowed on the high part
2377 __ rsb(IP, second_reg, ShifterOperand(32));
2378 __ Lsr(IP, low, IP);
2379 __ orr(o_h, high, ShifterOperand(IP));
2380 // If the shift is > 32 bits, override the high part
2381 __ subs(IP, second_reg, ShifterOperand(32));
2382 __ it(PL);
2383 __ Lsl(o_h, low, IP, false, PL);
2384 // Shift the low part
2385 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002386 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchez09895eb2015-03-11 14:57:40 +00002387 // Shift the low part
2388 __ and_(second_reg, second_reg, ShifterOperand(63));
2389 __ Lsr(low, low, second_reg);
2390 // Shift the high part and `or` what underflowed on the low part
2391 __ rsb(IP, second_reg, ShifterOperand(32));
2392 __ Lsl(IP, high, IP);
2393 __ orr(o_l, low, ShifterOperand(IP));
2394 // If the shift is > 32 bits, override the low part
2395 __ subs(IP, second_reg, ShifterOperand(32));
2396 __ it(PL);
2397 __ Asr(o_l, high, IP, false, PL);
2398 // Shift the high part
2399 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002400 } else {
Guillaume "Vermeille" Sanchez09895eb2015-03-11 14:57:40 +00002401 // same as Shr except we use `Lsr`s and not `Asr`s
2402 __ and_(second_reg, second_reg, ShifterOperand(63));
2403 __ Lsr(low, low, second_reg);
2404 __ rsb(IP, second_reg, ShifterOperand(32));
2405 __ Lsl(IP, high, IP);
2406 __ orr(o_l, low, ShifterOperand(IP));
2407 __ subs(IP, second_reg, ShifterOperand(32));
2408 __ it(PL);
2409 __ Lsr(o_l, high, IP, false, PL);
2410 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002411 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002412 break;
2413 }
2414 default:
2415 LOG(FATAL) << "Unexpected operation type " << type;
2416 }
2417}
2418
2419void LocationsBuilderARM::VisitShl(HShl* shl) {
2420 HandleShift(shl);
2421}
2422
2423void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2424 HandleShift(shl);
2425}
2426
2427void LocationsBuilderARM::VisitShr(HShr* shr) {
2428 HandleShift(shr);
2429}
2430
2431void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2432 HandleShift(shr);
2433}
2434
2435void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2436 HandleShift(ushr);
2437}
2438
2439void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2440 HandleShift(ushr);
2441}
2442
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002443void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002444 LocationSummary* locations =
2445 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002446 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002447 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2448 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2449 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002450}
2451
2452void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2453 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002454 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002455 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002456 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2457 instruction,
2458 instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002459}
2460
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002461void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2462 LocationSummary* locations =
2463 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2464 InvokeRuntimeCallingConvention calling_convention;
2465 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002466 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002467 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002468 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002469}
2470
2471void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2472 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002473 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002474 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002475 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2476 instruction,
2477 instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002478}
2479
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002480void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002481 LocationSummary* locations =
2482 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002483 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2484 if (location.IsStackSlot()) {
2485 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2486 } else if (location.IsDoubleStackSlot()) {
2487 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002488 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002489 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002490}
2491
2492void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002493 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002494 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002495}
2496
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002497void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002498 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002499 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002500 locations->SetInAt(0, Location::RequiresRegister());
2501 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002502}
2503
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002504void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2505 LocationSummary* locations = not_->GetLocations();
2506 Location out = locations->Out();
2507 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002508 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002509 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002510 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002511 break;
2512
2513 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002514 __ mvn(out.AsRegisterPairLow<Register>(),
2515 ShifterOperand(in.AsRegisterPairLow<Register>()));
2516 __ mvn(out.AsRegisterPairHigh<Register>(),
2517 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002518 break;
2519
2520 default:
2521 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2522 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002523}
2524
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002525void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002526 LocationSummary* locations =
2527 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002528 switch (compare->InputAt(0)->GetType()) {
2529 case Primitive::kPrimLong: {
2530 locations->SetInAt(0, Location::RequiresRegister());
2531 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002532 // Output overlaps because it is written before doing the low comparison.
2533 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002534 break;
2535 }
2536 case Primitive::kPrimFloat:
2537 case Primitive::kPrimDouble: {
2538 locations->SetInAt(0, Location::RequiresFpuRegister());
2539 locations->SetInAt(1, Location::RequiresFpuRegister());
2540 locations->SetOut(Location::RequiresRegister());
2541 break;
2542 }
2543 default:
2544 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2545 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002546}
2547
2548void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002549 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002550 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002551 Location left = locations->InAt(0);
2552 Location right = locations->InAt(1);
2553
2554 Label less, greater, done;
2555 Primitive::Type type = compare->InputAt(0)->GetType();
2556 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002557 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002558 __ cmp(left.AsRegisterPairHigh<Register>(),
2559 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002560 __ b(&less, LT);
2561 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002562 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2563 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002564 __ cmp(left.AsRegisterPairLow<Register>(),
2565 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002566 break;
2567 }
2568 case Primitive::kPrimFloat:
2569 case Primitive::kPrimDouble: {
2570 __ LoadImmediate(out, 0);
2571 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002572 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002573 } else {
2574 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2575 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2576 }
2577 __ vmstat(); // transfer FP status register to ARM APSR.
2578 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002579 break;
2580 }
2581 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002582 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002583 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002584 __ b(&done, EQ);
2585 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2586
2587 __ Bind(&greater);
2588 __ LoadImmediate(out, 1);
2589 __ b(&done);
2590
2591 __ Bind(&less);
2592 __ LoadImmediate(out, -1);
2593
2594 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002595}
2596
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002597void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002598 LocationSummary* locations =
2599 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002600 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2601 locations->SetInAt(i, Location::Any());
2602 }
2603 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002604}
2605
2606void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002607 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002608 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002609}
2610
Calin Juravle52c48962014-12-16 17:02:57 +00002611void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2612 // TODO (ported from quick): revisit Arm barrier kinds
2613 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2614 switch (kind) {
2615 case MemBarrierKind::kAnyStore:
2616 case MemBarrierKind::kLoadAny:
2617 case MemBarrierKind::kAnyAny: {
2618 flavour = DmbOptions::ISH;
2619 break;
2620 }
2621 case MemBarrierKind::kStoreStore: {
2622 flavour = DmbOptions::ISHST;
2623 break;
2624 }
2625 default:
2626 LOG(FATAL) << "Unexpected memory barrier " << kind;
2627 }
2628 __ dmb(flavour);
2629}
2630
2631void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2632 uint32_t offset,
2633 Register out_lo,
2634 Register out_hi) {
2635 if (offset != 0) {
2636 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002637 __ add(IP, addr, ShifterOperand(out_lo));
2638 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002639 }
2640 __ ldrexd(out_lo, out_hi, addr);
2641}
2642
2643void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2644 uint32_t offset,
2645 Register value_lo,
2646 Register value_hi,
2647 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002648 Register temp2,
2649 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002650 Label fail;
2651 if (offset != 0) {
2652 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002653 __ add(IP, addr, ShifterOperand(temp1));
2654 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002655 }
2656 __ Bind(&fail);
2657 // We need a load followed by store. (The address used in a STREX instruction must
2658 // be the same as the address in the most recently executed LDREX instruction.)
2659 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002660 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002661 __ strexd(temp1, value_lo, value_hi, addr);
2662 __ cmp(temp1, ShifterOperand(0));
2663 __ b(&fail, NE);
2664}
2665
2666void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2667 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2668
Nicolas Geoffray39468442014-09-02 15:17:15 +01002669 LocationSummary* locations =
2670 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002671 locations->SetInAt(0, Location::RequiresRegister());
2672 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002673
Calin Juravle34166012014-12-19 17:22:29 +00002674
Calin Juravle52c48962014-12-16 17:02:57 +00002675 Primitive::Type field_type = field_info.GetFieldType();
2676 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002677 bool generate_volatile = field_info.IsVolatile()
2678 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002679 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002680 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002681 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2682 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002683 locations->AddTemp(Location::RequiresRegister());
2684 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002685 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002686 // Arm encoding have some additional constraints for ldrexd/strexd:
2687 // - registers need to be consecutive
2688 // - the first register should be even but not R14.
2689 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2690 // enable Arm encoding.
2691 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2692
2693 locations->AddTemp(Location::RequiresRegister());
2694 locations->AddTemp(Location::RequiresRegister());
2695 if (field_type == Primitive::kPrimDouble) {
2696 // For doubles we need two more registers to copy the value.
2697 locations->AddTemp(Location::RegisterLocation(R2));
2698 locations->AddTemp(Location::RegisterLocation(R3));
2699 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002700 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002701}
2702
Calin Juravle52c48962014-12-16 17:02:57 +00002703void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2704 const FieldInfo& field_info) {
2705 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2706
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002707 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002708 Register base = locations->InAt(0).AsRegister<Register>();
2709 Location value = locations->InAt(1);
2710
2711 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002712 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002713 Primitive::Type field_type = field_info.GetFieldType();
2714 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2715
2716 if (is_volatile) {
2717 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2718 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002719
2720 switch (field_type) {
2721 case Primitive::kPrimBoolean:
2722 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002723 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002724 break;
2725 }
2726
2727 case Primitive::kPrimShort:
2728 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002729 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002730 break;
2731 }
2732
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002733 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002734 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002735 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002736 break;
2737 }
2738
2739 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002740 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002741 GenerateWideAtomicStore(base, offset,
2742 value.AsRegisterPairLow<Register>(),
2743 value.AsRegisterPairHigh<Register>(),
2744 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002745 locations->GetTemp(1).AsRegister<Register>(),
2746 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002747 } else {
2748 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002749 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002750 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002751 break;
2752 }
2753
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002754 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002755 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002756 break;
2757 }
2758
2759 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002760 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002761 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002762 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2763 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2764
2765 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2766
2767 GenerateWideAtomicStore(base, offset,
2768 value_reg_lo,
2769 value_reg_hi,
2770 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002771 locations->GetTemp(3).AsRegister<Register>(),
2772 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002773 } else {
2774 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002775 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002776 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002777 break;
2778 }
2779
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002780 case Primitive::kPrimVoid:
2781 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002782 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002783 }
Calin Juravle52c48962014-12-16 17:02:57 +00002784
Calin Juravle77520bc2015-01-12 18:45:46 +00002785 // Longs and doubles are handled in the switch.
2786 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2787 codegen_->MaybeRecordImplicitNullCheck(instruction);
2788 }
2789
2790 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2791 Register temp = locations->GetTemp(0).AsRegister<Register>();
2792 Register card = locations->GetTemp(1).AsRegister<Register>();
2793 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2794 }
2795
Calin Juravle52c48962014-12-16 17:02:57 +00002796 if (is_volatile) {
2797 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2798 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002799}
2800
Calin Juravle52c48962014-12-16 17:02:57 +00002801void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2802 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002803 LocationSummary* locations =
2804 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002805 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002806
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002807 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002808 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002809 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002810 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2811 locations->SetOut(Location::RequiresRegister(),
2812 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2813 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002814 // Arm encoding have some additional constraints for ldrexd/strexd:
2815 // - registers need to be consecutive
2816 // - the first register should be even but not R14.
2817 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2818 // enable Arm encoding.
2819 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2820 locations->AddTemp(Location::RequiresRegister());
2821 locations->AddTemp(Location::RequiresRegister());
2822 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002823}
2824
Calin Juravle52c48962014-12-16 17:02:57 +00002825void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2826 const FieldInfo& field_info) {
2827 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002828
Calin Juravle52c48962014-12-16 17:02:57 +00002829 LocationSummary* locations = instruction->GetLocations();
2830 Register base = locations->InAt(0).AsRegister<Register>();
2831 Location out = locations->Out();
2832 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002833 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002834 Primitive::Type field_type = field_info.GetFieldType();
2835 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2836
2837 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002838 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002839 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002840 break;
2841 }
2842
2843 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002844 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002845 break;
2846 }
2847
2848 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002849 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002850 break;
2851 }
2852
2853 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002854 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002855 break;
2856 }
2857
2858 case Primitive::kPrimInt:
2859 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002860 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002861 break;
2862 }
2863
2864 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002865 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002866 GenerateWideAtomicLoad(base, offset,
2867 out.AsRegisterPairLow<Register>(),
2868 out.AsRegisterPairHigh<Register>());
2869 } else {
2870 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2871 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002872 break;
2873 }
2874
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002875 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002876 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002877 break;
2878 }
2879
2880 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002881 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002882 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002883 Register lo = locations->GetTemp(0).AsRegister<Register>();
2884 Register hi = locations->GetTemp(1).AsRegister<Register>();
2885 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002886 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002887 __ vmovdrr(out_reg, lo, hi);
2888 } else {
2889 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002890 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002891 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002892 break;
2893 }
2894
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002895 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002896 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002897 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002898 }
Calin Juravle52c48962014-12-16 17:02:57 +00002899
Calin Juravle77520bc2015-01-12 18:45:46 +00002900 // Doubles are handled in the switch.
2901 if (field_type != Primitive::kPrimDouble) {
2902 codegen_->MaybeRecordImplicitNullCheck(instruction);
2903 }
2904
Calin Juravle52c48962014-12-16 17:02:57 +00002905 if (is_volatile) {
2906 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2907 }
2908}
2909
2910void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2911 HandleFieldSet(instruction, instruction->GetFieldInfo());
2912}
2913
2914void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2915 HandleFieldSet(instruction, instruction->GetFieldInfo());
2916}
2917
2918void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2919 HandleFieldGet(instruction, instruction->GetFieldInfo());
2920}
2921
2922void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2923 HandleFieldGet(instruction, instruction->GetFieldInfo());
2924}
2925
2926void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2927 HandleFieldGet(instruction, instruction->GetFieldInfo());
2928}
2929
2930void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2931 HandleFieldGet(instruction, instruction->GetFieldInfo());
2932}
2933
2934void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2935 HandleFieldSet(instruction, instruction->GetFieldInfo());
2936}
2937
2938void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2939 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002940}
2941
2942void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002943 LocationSummary* locations =
2944 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002945 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002946 if (instruction->HasUses()) {
2947 locations->SetOut(Location::SameAsFirstInput());
2948 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002949}
2950
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002951void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002952 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2953 return;
2954 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002955 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002956
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002957 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2958 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2959}
2960
2961void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002962 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002963 codegen_->AddSlowPath(slow_path);
2964
2965 LocationSummary* locations = instruction->GetLocations();
2966 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002967
Calin Juravle77520bc2015-01-12 18:45:46 +00002968 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2969 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002970}
2971
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002972void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2973 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2974 GenerateImplicitNullCheck(instruction);
2975 } else {
2976 GenerateExplicitNullCheck(instruction);
2977 }
2978}
2979
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002980void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002981 LocationSummary* locations =
2982 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002983 locations->SetInAt(0, Location::RequiresRegister());
2984 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2985 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002986}
2987
2988void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2989 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002990 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002991 Location index = locations->InAt(1);
2992
2993 switch (instruction->GetType()) {
2994 case Primitive::kPrimBoolean: {
2995 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002996 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002997 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002998 size_t offset =
2999 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003000 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3001 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003002 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003003 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3004 }
3005 break;
3006 }
3007
3008 case Primitive::kPrimByte: {
3009 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003010 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003011 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003012 size_t offset =
3013 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003014 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3015 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003016 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003017 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3018 }
3019 break;
3020 }
3021
3022 case Primitive::kPrimShort: {
3023 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003024 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003025 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003026 size_t offset =
3027 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003028 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3029 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003030 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003031 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3032 }
3033 break;
3034 }
3035
3036 case Primitive::kPrimChar: {
3037 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003038 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003039 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003040 size_t offset =
3041 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003042 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3043 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003044 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003045 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3046 }
3047 break;
3048 }
3049
3050 case Primitive::kPrimInt:
3051 case Primitive::kPrimNot: {
3052 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3053 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003054 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003055 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003056 size_t offset =
3057 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003058 __ LoadFromOffset(kLoadWord, out, obj, offset);
3059 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003060 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003061 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3062 }
3063 break;
3064 }
3065
3066 case Primitive::kPrimLong: {
3067 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003068 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003069 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003070 size_t offset =
3071 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003072 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003073 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003074 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003075 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003076 }
3077 break;
3078 }
3079
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003080 case Primitive::kPrimFloat: {
3081 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3082 Location out = locations->Out();
3083 DCHECK(out.IsFpuRegister());
3084 if (index.IsConstant()) {
3085 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3086 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3087 } else {
3088 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3089 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3090 }
3091 break;
3092 }
3093
3094 case Primitive::kPrimDouble: {
3095 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3096 Location out = locations->Out();
3097 DCHECK(out.IsFpuRegisterPair());
3098 if (index.IsConstant()) {
3099 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3100 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3101 } else {
3102 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3103 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3104 }
3105 break;
3106 }
3107
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003108 case Primitive::kPrimVoid:
3109 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003110 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003111 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003112 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003113}
3114
3115void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003116 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003117
3118 bool needs_write_barrier =
3119 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3120 bool needs_runtime_call = instruction->NeedsTypeCheck();
3121
Nicolas Geoffray39468442014-09-02 15:17:15 +01003122 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003123 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3124 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003125 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003126 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3127 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3128 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003129 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003130 locations->SetInAt(0, Location::RequiresRegister());
3131 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3132 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003133
3134 if (needs_write_barrier) {
3135 // Temporary registers for the write barrier.
3136 locations->AddTemp(Location::RequiresRegister());
3137 locations->AddTemp(Location::RequiresRegister());
3138 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003139 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003140}
3141
3142void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3143 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003144 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003145 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003146 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003147 bool needs_runtime_call = locations->WillCall();
3148 bool needs_write_barrier =
3149 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003150
3151 switch (value_type) {
3152 case Primitive::kPrimBoolean:
3153 case Primitive::kPrimByte: {
3154 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003155 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003156 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003157 size_t offset =
3158 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003159 __ StoreToOffset(kStoreByte, value, obj, offset);
3160 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003161 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003162 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3163 }
3164 break;
3165 }
3166
3167 case Primitive::kPrimShort:
3168 case Primitive::kPrimChar: {
3169 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003170 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003171 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003172 size_t offset =
3173 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003174 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3175 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003176 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003177 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3178 }
3179 break;
3180 }
3181
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003182 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003183 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003184 if (!needs_runtime_call) {
3185 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003186 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003187 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003188 size_t offset =
3189 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003190 __ StoreToOffset(kStoreWord, value, obj, offset);
3191 } else {
3192 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003193 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003194 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3195 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003196 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003197 if (needs_write_barrier) {
3198 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003199 Register temp = locations->GetTemp(0).AsRegister<Register>();
3200 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003201 codegen_->MarkGCCard(temp, card, obj, value);
3202 }
3203 } else {
3204 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003205 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3206 instruction,
3207 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003208 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003209 break;
3210 }
3211
3212 case Primitive::kPrimLong: {
3213 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003214 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003215 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003216 size_t offset =
3217 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003218 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003219 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003220 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003221 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003222 }
3223 break;
3224 }
3225
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003226 case Primitive::kPrimFloat: {
3227 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3228 Location value = locations->InAt(2);
3229 DCHECK(value.IsFpuRegister());
3230 if (index.IsConstant()) {
3231 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3232 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3233 } else {
3234 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3235 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3236 }
3237 break;
3238 }
3239
3240 case Primitive::kPrimDouble: {
3241 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3242 Location value = locations->InAt(2);
3243 DCHECK(value.IsFpuRegisterPair());
3244 if (index.IsConstant()) {
3245 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3246 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3247 } else {
3248 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3249 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3250 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003251
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003252 break;
3253 }
3254
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003255 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003256 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003257 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003258 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003259
3260 // Ints and objects are handled in the switch.
3261 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3262 codegen_->MaybeRecordImplicitNullCheck(instruction);
3263 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003264}
3265
3266void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003267 LocationSummary* locations =
3268 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003269 locations->SetInAt(0, Location::RequiresRegister());
3270 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003271}
3272
3273void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3274 LocationSummary* locations = instruction->GetLocations();
3275 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003276 Register obj = locations->InAt(0).AsRegister<Register>();
3277 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003278 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003279 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003280}
3281
3282void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003283 LocationSummary* locations =
3284 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003285 locations->SetInAt(0, Location::RequiresRegister());
3286 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003287 if (instruction->HasUses()) {
3288 locations->SetOut(Location::SameAsFirstInput());
3289 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003290}
3291
3292void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3293 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003294 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003295 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003296 codegen_->AddSlowPath(slow_path);
3297
Roland Levillain271ab9c2014-11-27 15:23:57 +00003298 Register index = locations->InAt(0).AsRegister<Register>();
3299 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003300
3301 __ cmp(index, ShifterOperand(length));
3302 __ b(slow_path->GetEntryLabel(), CS);
3303}
3304
3305void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3306 Label is_null;
3307 __ CompareAndBranchIfZero(value, &is_null);
3308 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3309 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3310 __ strb(card, Address(card, temp));
3311 __ Bind(&is_null);
3312}
3313
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003314void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3315 temp->SetLocations(nullptr);
3316}
3317
3318void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3319 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003320 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003321}
3322
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003323void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003324 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003325 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003326}
3327
3328void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003329 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3330}
3331
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003332void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3333 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3334}
3335
3336void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003337 HBasicBlock* block = instruction->GetBlock();
3338 if (block->GetLoopInformation() != nullptr) {
3339 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3340 // The back edge will generate the suspend check.
3341 return;
3342 }
3343 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3344 // The goto will generate the suspend check.
3345 return;
3346 }
3347 GenerateSuspendCheck(instruction, nullptr);
3348}
3349
3350void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3351 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003352 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003353 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003354 codegen_->AddSlowPath(slow_path);
3355
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003356 __ LoadFromOffset(
3357 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3358 __ cmp(IP, ShifterOperand(0));
3359 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003360 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003361 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003362 __ Bind(slow_path->GetReturnLabel());
3363 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003364 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003365 __ b(slow_path->GetEntryLabel());
3366 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003367}
3368
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003369ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3370 return codegen_->GetAssembler();
3371}
3372
3373void ParallelMoveResolverARM::EmitMove(size_t index) {
3374 MoveOperands* move = moves_.Get(index);
3375 Location source = move->GetSource();
3376 Location destination = move->GetDestination();
3377
3378 if (source.IsRegister()) {
3379 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003380 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003381 } else {
3382 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003383 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003384 SP, destination.GetStackIndex());
3385 }
3386 } else if (source.IsStackSlot()) {
3387 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003388 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003389 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003390 } else if (destination.IsFpuRegister()) {
3391 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003392 } else {
3393 DCHECK(destination.IsStackSlot());
3394 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3395 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3396 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003397 } else if (source.IsFpuRegister()) {
3398 if (destination.IsFpuRegister()) {
3399 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003400 } else {
3401 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003402 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3403 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003404 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003405 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003406 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3407 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003408 } else if (destination.IsRegisterPair()) {
3409 DCHECK(ExpectedPairLayout(destination));
3410 __ LoadFromOffset(
3411 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3412 } else {
3413 DCHECK(destination.IsFpuRegisterPair()) << destination;
3414 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3415 SP,
3416 source.GetStackIndex());
3417 }
3418 } else if (source.IsRegisterPair()) {
3419 if (destination.IsRegisterPair()) {
3420 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3421 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3422 } else {
3423 DCHECK(destination.IsDoubleStackSlot()) << destination;
3424 DCHECK(ExpectedPairLayout(source));
3425 __ StoreToOffset(
3426 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3427 }
3428 } else if (source.IsFpuRegisterPair()) {
3429 if (destination.IsFpuRegisterPair()) {
3430 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3431 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3432 } else {
3433 DCHECK(destination.IsDoubleStackSlot()) << destination;
3434 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3435 SP,
3436 destination.GetStackIndex());
3437 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003438 } else {
3439 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003440 HConstant* constant = source.GetConstant();
3441 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3442 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003443 if (destination.IsRegister()) {
3444 __ LoadImmediate(destination.AsRegister<Register>(), value);
3445 } else {
3446 DCHECK(destination.IsStackSlot());
3447 __ LoadImmediate(IP, value);
3448 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3449 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003450 } else if (constant->IsLongConstant()) {
3451 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003452 if (destination.IsRegisterPair()) {
3453 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3454 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003455 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003456 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003457 __ LoadImmediate(IP, Low32Bits(value));
3458 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3459 __ LoadImmediate(IP, High32Bits(value));
3460 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3461 }
3462 } else if (constant->IsDoubleConstant()) {
3463 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003464 if (destination.IsFpuRegisterPair()) {
3465 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003466 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003467 DCHECK(destination.IsDoubleStackSlot()) << destination;
3468 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003469 __ LoadImmediate(IP, Low32Bits(int_value));
3470 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3471 __ LoadImmediate(IP, High32Bits(int_value));
3472 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3473 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003474 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003475 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003476 float value = constant->AsFloatConstant()->GetValue();
3477 if (destination.IsFpuRegister()) {
3478 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3479 } else {
3480 DCHECK(destination.IsStackSlot());
3481 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3482 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3483 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003484 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003485 }
3486}
3487
3488void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3489 __ Mov(IP, reg);
3490 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3491 __ StoreToOffset(kStoreWord, IP, SP, mem);
3492}
3493
3494void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3495 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3496 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3497 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3498 SP, mem1 + stack_offset);
3499 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3500 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3501 SP, mem2 + stack_offset);
3502 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3503}
3504
3505void ParallelMoveResolverARM::EmitSwap(size_t index) {
3506 MoveOperands* move = moves_.Get(index);
3507 Location source = move->GetSource();
3508 Location destination = move->GetDestination();
3509
3510 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003511 DCHECK_NE(source.AsRegister<Register>(), IP);
3512 DCHECK_NE(destination.AsRegister<Register>(), IP);
3513 __ Mov(IP, source.AsRegister<Register>());
3514 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3515 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003516 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003517 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003518 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003519 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003520 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3521 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003522 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003523 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003524 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003525 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003526 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003527 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003528 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003529 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003530 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3531 destination.AsRegisterPairHigh<Register>(),
3532 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003533 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003534 Register low_reg = source.IsRegisterPair()
3535 ? source.AsRegisterPairLow<Register>()
3536 : destination.AsRegisterPairLow<Register>();
3537 int mem = source.IsRegisterPair()
3538 ? destination.GetStackIndex()
3539 : source.GetStackIndex();
3540 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003541 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003542 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003543 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003544 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003545 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3546 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003547 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003548 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003549 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003550 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3551 DRegister reg = source.IsFpuRegisterPair()
3552 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3553 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3554 int mem = source.IsFpuRegisterPair()
3555 ? destination.GetStackIndex()
3556 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003557 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003558 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003559 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003560 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3561 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3562 : destination.AsFpuRegister<SRegister>();
3563 int mem = source.IsFpuRegister()
3564 ? destination.GetStackIndex()
3565 : source.GetStackIndex();
3566
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003567 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003568 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003569 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003570 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003571 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3572 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003573 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003574 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003575 }
3576}
3577
3578void ParallelMoveResolverARM::SpillScratch(int reg) {
3579 __ Push(static_cast<Register>(reg));
3580}
3581
3582void ParallelMoveResolverARM::RestoreScratch(int reg) {
3583 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003584}
3585
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003586void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003587 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3588 ? LocationSummary::kCallOnSlowPath
3589 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003590 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003591 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003592 locations->SetOut(Location::RequiresRegister());
3593}
3594
3595void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003596 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003597 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003598 DCHECK(!cls->CanCallRuntime());
3599 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003600 codegen_->LoadCurrentMethod(out);
3601 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3602 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003603 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003604 codegen_->LoadCurrentMethod(out);
3605 __ LoadFromOffset(
3606 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3607 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003608
3609 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3610 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3611 codegen_->AddSlowPath(slow_path);
3612 __ cmp(out, ShifterOperand(0));
3613 __ b(slow_path->GetEntryLabel(), EQ);
3614 if (cls->MustGenerateClinitCheck()) {
3615 GenerateClassInitializationCheck(slow_path, out);
3616 } else {
3617 __ Bind(slow_path->GetExitLabel());
3618 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003619 }
3620}
3621
3622void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3623 LocationSummary* locations =
3624 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3625 locations->SetInAt(0, Location::RequiresRegister());
3626 if (check->HasUses()) {
3627 locations->SetOut(Location::SameAsFirstInput());
3628 }
3629}
3630
3631void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003632 // We assume the class is not null.
3633 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3634 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003635 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003636 GenerateClassInitializationCheck(slow_path,
3637 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003638}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003639
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003640void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3641 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003642 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3643 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3644 __ b(slow_path->GetEntryLabel(), LT);
3645 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3646 // properly. Therefore, we do a memory fence.
3647 __ dmb(ISH);
3648 __ Bind(slow_path->GetExitLabel());
3649}
3650
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003651void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3652 LocationSummary* locations =
3653 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3654 locations->SetOut(Location::RequiresRegister());
3655}
3656
3657void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3658 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3659 codegen_->AddSlowPath(slow_path);
3660
Roland Levillain271ab9c2014-11-27 15:23:57 +00003661 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003662 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003663 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3664 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003665 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3666 __ cmp(out, ShifterOperand(0));
3667 __ b(slow_path->GetEntryLabel(), EQ);
3668 __ Bind(slow_path->GetExitLabel());
3669}
3670
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003671void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3672 LocationSummary* locations =
3673 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3674 locations->SetOut(Location::RequiresRegister());
3675}
3676
3677void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003678 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003679 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3680 __ LoadFromOffset(kLoadWord, out, TR, offset);
3681 __ LoadImmediate(IP, 0);
3682 __ StoreToOffset(kStoreWord, IP, TR, offset);
3683}
3684
3685void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3686 LocationSummary* locations =
3687 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3688 InvokeRuntimeCallingConvention calling_convention;
3689 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3690}
3691
3692void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3693 codegen_->InvokeRuntime(
3694 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3695}
3696
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003697void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003698 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3699 ? LocationSummary::kNoCall
3700 : LocationSummary::kCallOnSlowPath;
3701 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3702 locations->SetInAt(0, Location::RequiresRegister());
3703 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003704 // The out register is used as a temporary, so it overlaps with the inputs.
3705 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003706}
3707
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003708void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003709 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003710 Register obj = locations->InAt(0).AsRegister<Register>();
3711 Register cls = locations->InAt(1).AsRegister<Register>();
3712 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003713 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3714 Label done, zero;
3715 SlowPathCodeARM* slow_path = nullptr;
3716
3717 // Return 0 if `obj` is null.
3718 // TODO: avoid this check if we know obj is not null.
3719 __ cmp(obj, ShifterOperand(0));
3720 __ b(&zero, EQ);
3721 // Compare the class of `obj` with `cls`.
3722 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3723 __ cmp(out, ShifterOperand(cls));
3724 if (instruction->IsClassFinal()) {
3725 // Classes must be equal for the instanceof to succeed.
3726 __ b(&zero, NE);
3727 __ LoadImmediate(out, 1);
3728 __ b(&done);
3729 } else {
3730 // If the classes are not equal, we go into a slow path.
3731 DCHECK(locations->OnlyCallsOnSlowPath());
3732 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003733 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003734 codegen_->AddSlowPath(slow_path);
3735 __ b(slow_path->GetEntryLabel(), NE);
3736 __ LoadImmediate(out, 1);
3737 __ b(&done);
3738 }
3739 __ Bind(&zero);
3740 __ LoadImmediate(out, 0);
3741 if (slow_path != nullptr) {
3742 __ Bind(slow_path->GetExitLabel());
3743 }
3744 __ Bind(&done);
3745}
3746
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003747void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3748 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3749 instruction, LocationSummary::kCallOnSlowPath);
3750 locations->SetInAt(0, Location::RequiresRegister());
3751 locations->SetInAt(1, Location::RequiresRegister());
3752 locations->AddTemp(Location::RequiresRegister());
3753}
3754
3755void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3756 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003757 Register obj = locations->InAt(0).AsRegister<Register>();
3758 Register cls = locations->InAt(1).AsRegister<Register>();
3759 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003760 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3761
3762 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3763 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3764 codegen_->AddSlowPath(slow_path);
3765
3766 // TODO: avoid this check if we know obj is not null.
3767 __ cmp(obj, ShifterOperand(0));
3768 __ b(slow_path->GetExitLabel(), EQ);
3769 // Compare the class of `obj` with `cls`.
3770 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3771 __ cmp(temp, ShifterOperand(cls));
3772 __ b(slow_path->GetEntryLabel(), NE);
3773 __ Bind(slow_path->GetExitLabel());
3774}
3775
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003776void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3777 LocationSummary* locations =
3778 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3779 InvokeRuntimeCallingConvention calling_convention;
3780 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3781}
3782
3783void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3784 codegen_->InvokeRuntime(instruction->IsEnter()
3785 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3786 instruction,
3787 instruction->GetDexPc());
3788}
3789
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003790void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3791void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3792void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3793
3794void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3795 LocationSummary* locations =
3796 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3797 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3798 || instruction->GetResultType() == Primitive::kPrimLong);
3799 locations->SetInAt(0, Location::RequiresRegister());
3800 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003801 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003802}
3803
3804void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3805 HandleBitwiseOperation(instruction);
3806}
3807
3808void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3809 HandleBitwiseOperation(instruction);
3810}
3811
3812void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3813 HandleBitwiseOperation(instruction);
3814}
3815
3816void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3817 LocationSummary* locations = instruction->GetLocations();
3818
3819 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003820 Register first = locations->InAt(0).AsRegister<Register>();
3821 Register second = locations->InAt(1).AsRegister<Register>();
3822 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003823 if (instruction->IsAnd()) {
3824 __ and_(out, first, ShifterOperand(second));
3825 } else if (instruction->IsOr()) {
3826 __ orr(out, first, ShifterOperand(second));
3827 } else {
3828 DCHECK(instruction->IsXor());
3829 __ eor(out, first, ShifterOperand(second));
3830 }
3831 } else {
3832 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3833 Location first = locations->InAt(0);
3834 Location second = locations->InAt(1);
3835 Location out = locations->Out();
3836 if (instruction->IsAnd()) {
3837 __ and_(out.AsRegisterPairLow<Register>(),
3838 first.AsRegisterPairLow<Register>(),
3839 ShifterOperand(second.AsRegisterPairLow<Register>()));
3840 __ and_(out.AsRegisterPairHigh<Register>(),
3841 first.AsRegisterPairHigh<Register>(),
3842 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3843 } else if (instruction->IsOr()) {
3844 __ orr(out.AsRegisterPairLow<Register>(),
3845 first.AsRegisterPairLow<Register>(),
3846 ShifterOperand(second.AsRegisterPairLow<Register>()));
3847 __ orr(out.AsRegisterPairHigh<Register>(),
3848 first.AsRegisterPairHigh<Register>(),
3849 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3850 } else {
3851 DCHECK(instruction->IsXor());
3852 __ eor(out.AsRegisterPairLow<Register>(),
3853 first.AsRegisterPairLow<Register>(),
3854 ShifterOperand(second.AsRegisterPairLow<Register>()));
3855 __ eor(out.AsRegisterPairHigh<Register>(),
3856 first.AsRegisterPairHigh<Register>(),
3857 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3858 }
3859 }
3860}
3861
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003862void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
3863 DCHECK_EQ(temp, kArtMethodRegister);
3864
3865 // TODO: Implement all kinds of calls:
3866 // 1) boot -> boot
3867 // 2) app -> boot
3868 // 3) app -> app
3869 //
3870 // Currently we implement the app -> app logic, which looks up in the resolve cache.
3871
3872 // temp = method;
3873 LoadCurrentMethod(temp);
3874 if (!invoke->IsRecursive()) {
3875 // temp = temp->dex_cache_resolved_methods_;
3876 __ LoadFromOffset(
3877 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
3878 // temp = temp[index_in_cache]
3879 __ LoadFromOffset(
3880 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
3881 // LR = temp[offset_of_quick_compiled_code]
3882 __ LoadFromOffset(kLoadWord, LR, temp,
3883 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3884 kArmWordSize).Int32Value());
3885 // LR()
3886 __ blx(LR);
3887 } else {
3888 __ bl(GetFrameEntryLabel());
3889 }
3890
3891 RecordPcInfo(invoke, invoke->GetDexPc());
3892 DCHECK(!IsLeafMethod());
3893}
3894
Calin Juravleb1498f62015-02-16 13:13:29 +00003895void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
3896 // Nothing to do, this should be removed during prepare for register allocator.
3897 UNUSED(instruction);
3898 LOG(FATAL) << "Unreachable";
3899}
3900
3901void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
3902 // Nothing to do, this should be removed during prepare for register allocator.
3903 UNUSED(instruction);
3904 LOG(FATAL) << "Unreachable";
3905}
3906
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003907} // namespace arm
3908} // namespace art