blob: d0a72bb42a027c021105eb2871d550156b946963 [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"
Ian Rogers7e70b002014-10-08 11:47:24 -070022#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000023#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010024#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070025#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010026#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000028#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010029#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000030
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000031namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010032
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033namespace arm {
34
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000035static DRegister FromLowSToD(SRegister reg) {
36 DCHECK_EQ(reg % 2, 0);
37 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010038}
39
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010040static constexpr bool kExplicitStackOverflowCheck = false;
41
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +000042static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010043static constexpr int kCurrentMethodStackOffset = 0;
44
Calin Juravled6fb6cf2014-11-11 19:07:44 +000045static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010046static constexpr size_t kRuntimeParameterCoreRegistersLength =
47 arraysize(kRuntimeParameterCoreRegisters);
Calin Juravled2ec87d2014-12-08 14:24:46 +000048static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000049static constexpr size_t kRuntimeParameterFpuRegistersLength =
50 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000052class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053 public:
54 InvokeRuntimeCallingConvention()
55 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010056 kRuntimeParameterCoreRegistersLength,
57 kRuntimeParameterFpuRegisters,
58 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010059
60 private:
61 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
62};
63
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010065#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010066
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010067class SlowPathCodeARM : public SlowPathCode {
68 public:
69 SlowPathCodeARM() : entry_label_(), exit_label_() {}
70
71 Label* GetEntryLabel() { return &entry_label_; }
72 Label* GetExitLabel() { return &exit_label_; }
73
74 private:
75 Label entry_label_;
76 Label exit_label_;
77
78 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
79};
80
81class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010083 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010084
Alexandre Rames67555f72014-11-18 10:55:16 +000085 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010086 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010087 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010088 arm_codegen->InvokeRuntime(
89 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010090 }
91
92 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010093 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010094 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
95};
96
Calin Juravled0d48522014-11-04 16:40:20 +000097class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
98 public:
99 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
100
Alexandre Rames67555f72014-11-18 10:55:16 +0000101 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000102 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
103 __ Bind(GetEntryLabel());
104 arm_codegen->InvokeRuntime(
105 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
106 }
107
108 private:
109 HDivZeroCheck* const instruction_;
110 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
111};
112
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100113class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100114 public:
115 StackOverflowCheckSlowPathARM() {}
116
Alexandre Rames67555f72014-11-18 10:55:16 +0000117 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100118 __ Bind(GetEntryLabel());
119 __ LoadFromOffset(kLoadWord, PC, TR,
120 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
121 }
122
123 private:
124 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
125};
126
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100127class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000128 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000129 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100130 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000131
Alexandre Rames67555f72014-11-18 10:55:16 +0000132 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100133 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000134 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100135 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100136 arm_codegen->InvokeRuntime(
137 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100138 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100139 if (successor_ == nullptr) {
140 __ b(GetReturnLabel());
141 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100142 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100143 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000144 }
145
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100146 Label* GetReturnLabel() {
147 DCHECK(successor_ == nullptr);
148 return &return_label_;
149 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000150
151 private:
152 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100153 // If not null, the block to branch to after the suspend check.
154 HBasicBlock* const successor_;
155
156 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000157 Label return_label_;
158
159 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
160};
161
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100162class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100164 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
165 Location index_location,
166 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100167 : instruction_(instruction),
168 index_location_(index_location),
169 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100170
Alexandre Rames67555f72014-11-18 10:55:16 +0000171 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100172 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100173 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000174 // We're moving two locations to locations that could overlap, so we need a parallel
175 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100176 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000177 codegen->EmitParallelMoves(
178 index_location_,
179 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
180 length_location_,
181 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100182 arm_codegen->InvokeRuntime(
183 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100184 }
185
186 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100187 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100188 const Location index_location_;
189 const Location length_location_;
190
191 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
192};
193
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100195 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000196 LoadClassSlowPathARM(HLoadClass* cls,
197 HInstruction* at,
198 uint32_t dex_pc,
199 bool do_clinit)
200 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
201 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
202 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100203
Alexandre Rames67555f72014-11-18 10:55:16 +0000204 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000205 LocationSummary* locations = at_->GetLocations();
206
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100207 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
208 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000209 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100211 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100213 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000214 int32_t entry_point_offset = do_clinit_
215 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
216 : QUICK_ENTRY_POINT(pInitializeType);
217 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
218
219 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000220 Location out = locations->Out();
221 if (out.IsValid()) {
222 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000223 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
224 }
225 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100226 __ b(GetExitLabel());
227 }
228
229 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000230 // The class this slow path will load.
231 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100232
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000233 // The instruction where this slow path is happening.
234 // (Might be the load class or an initialization check).
235 HInstruction* const at_;
236
237 // The dex PC of `at_`.
238 const uint32_t dex_pc_;
239
240 // Whether to initialize the class.
241 const bool do_clinit_;
242
243 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100244};
245
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000246class LoadStringSlowPathARM : public SlowPathCodeARM {
247 public:
248 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
249
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000251 LocationSummary* locations = instruction_->GetLocations();
252 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
253
254 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
255 __ Bind(GetEntryLabel());
256 codegen->SaveLiveRegisters(locations);
257
258 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800259 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
260 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000261 arm_codegen->InvokeRuntime(
262 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
263 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
264
265 codegen->RestoreLiveRegisters(locations);
266 __ b(GetExitLabel());
267 }
268
269 private:
270 HLoadString* const instruction_;
271
272 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
273};
274
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000275class TypeCheckSlowPathARM : public SlowPathCodeARM {
276 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000277 TypeCheckSlowPathARM(HInstruction* instruction,
278 Location class_to_check,
279 Location object_class,
280 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000281 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000282 class_to_check_(class_to_check),
283 object_class_(object_class),
284 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
Alexandre Rames67555f72014-11-18 10:55:16 +0000286 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000287 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 DCHECK(instruction_->IsCheckCast()
289 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000290
291 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
292 __ Bind(GetEntryLabel());
293 codegen->SaveLiveRegisters(locations);
294
295 // We're moving two locations to locations that could overlap, so we need a parallel
296 // move resolver.
297 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000298 codegen->EmitParallelMoves(
299 class_to_check_,
300 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
301 object_class_,
302 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000303
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000304 if (instruction_->IsInstanceOf()) {
305 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
306 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
307 } else {
308 DCHECK(instruction_->IsCheckCast());
309 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
310 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000311
312 codegen->RestoreLiveRegisters(locations);
313 __ b(GetExitLabel());
314 }
315
316 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000317 HInstruction* const instruction_;
318 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000319 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000320 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000321
322 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
323};
324
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000325#undef __
326
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100327#undef __
328#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700329
330inline Condition ARMCondition(IfCondition cond) {
331 switch (cond) {
332 case kCondEQ: return EQ;
333 case kCondNE: return NE;
334 case kCondLT: return LT;
335 case kCondLE: return LE;
336 case kCondGT: return GT;
337 case kCondGE: return GE;
338 default:
339 LOG(FATAL) << "Unknown if condition";
340 }
341 return EQ; // Unreachable.
342}
343
344inline Condition ARMOppositeCondition(IfCondition cond) {
345 switch (cond) {
346 case kCondEQ: return NE;
347 case kCondNE: return EQ;
348 case kCondLT: return GE;
349 case kCondLE: return GT;
350 case kCondGT: return LE;
351 case kCondGE: return LT;
352 default:
353 LOG(FATAL) << "Unknown if condition";
354 }
355 return EQ; // Unreachable.
356}
357
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100358void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
359 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
360}
361
362void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000363 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100364}
365
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100366size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
367 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
368 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100369}
370
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100371size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
372 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
373 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100374}
375
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000376size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
377 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
378 return kArmWordSize;
379}
380
381size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
382 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
383 return kArmWordSize;
384}
385
Calin Juravle34166012014-12-19 17:22:29 +0000386CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
387 const ArmInstructionSetFeatures* isa_features)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000388 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100389 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100390 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100391 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100392 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000393 assembler_(true),
394 isa_features_(isa_features) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100395
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100396size_t CodeGeneratorARM::FrameEntrySpillSize() const {
397 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
398}
399
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100400Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100401 switch (type) {
402 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100403 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 ArmManagedRegister pair =
405 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100406 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
407 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
408
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100409 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
410 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100411 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100412 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100413 }
414
415 case Primitive::kPrimByte:
416 case Primitive::kPrimBoolean:
417 case Primitive::kPrimChar:
418 case Primitive::kPrimShort:
419 case Primitive::kPrimInt:
420 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100421 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100422 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100423 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
424 ArmManagedRegister current =
425 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
426 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100427 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100428 }
429 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100430 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100431 }
432
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000433 case Primitive::kPrimFloat: {
434 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100435 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100436 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100437
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000438 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000439 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
440 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000441 return Location::FpuRegisterPairLocation(reg, reg + 1);
442 }
443
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100444 case Primitive::kPrimVoid:
445 LOG(FATAL) << "Unreachable type " << type;
446 }
447
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100448 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100449}
450
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100451void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100453 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100454
455 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456 blocked_core_registers_[SP] = true;
457 blocked_core_registers_[LR] = true;
458 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100459
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100460 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100461 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100462
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100463 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100464 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100465
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000466 // TODO: We currently don't use Quick's callee saved registers.
467 // We always save and restore R6 and R7 to make sure we can use three
468 // register pairs for long operations.
469 blocked_core_registers_[R4] = true;
470 blocked_core_registers_[R5] = true;
471 blocked_core_registers_[R8] = true;
472 blocked_core_registers_[R10] = true;
473 blocked_core_registers_[R11] = true;
474
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000475 blocked_fpu_registers_[S16] = true;
476 blocked_fpu_registers_[S17] = true;
477 blocked_fpu_registers_[S18] = true;
478 blocked_fpu_registers_[S19] = true;
479 blocked_fpu_registers_[S20] = true;
480 blocked_fpu_registers_[S21] = true;
481 blocked_fpu_registers_[S22] = true;
482 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000483 blocked_fpu_registers_[S24] = true;
484 blocked_fpu_registers_[S25] = true;
485 blocked_fpu_registers_[S26] = true;
486 blocked_fpu_registers_[S27] = true;
487 blocked_fpu_registers_[S28] = true;
488 blocked_fpu_registers_[S29] = true;
489 blocked_fpu_registers_[S30] = true;
490 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100491
492 UpdateBlockedPairRegisters();
493}
494
495void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
496 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
497 ArmManagedRegister current =
498 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
499 if (blocked_core_registers_[current.AsRegisterPairLow()]
500 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
501 blocked_register_pairs_[i] = true;
502 }
503 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100504}
505
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100506InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
507 : HGraphVisitor(graph),
508 assembler_(codegen->GetAssembler()),
509 codegen_(codegen) {}
510
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000511void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000512 bool skip_overflow_check =
513 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100514 if (!skip_overflow_check) {
515 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100516 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100517 AddSlowPath(slow_path);
518
519 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
520 __ cmp(SP, ShifterOperand(IP));
521 __ b(slow_path->GetEntryLabel(), CC);
522 } else {
523 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100524 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100525 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100526 }
527 }
528
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000529 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
530 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000531
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100532 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100533 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100534 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000535}
536
537void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100538 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000539 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000540}
541
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100542void CodeGeneratorARM::Bind(HBasicBlock* block) {
543 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000544}
545
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100546Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
547 switch (load->GetType()) {
548 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100549 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100550 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
551 break;
552
553 case Primitive::kPrimInt:
554 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100555 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100556 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100557
558 case Primitive::kPrimBoolean:
559 case Primitive::kPrimByte:
560 case Primitive::kPrimChar:
561 case Primitive::kPrimShort:
562 case Primitive::kPrimVoid:
563 LOG(FATAL) << "Unexpected type " << load->GetType();
564 }
565
566 LOG(FATAL) << "Unreachable";
567 return Location();
568}
569
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100570Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
571 switch (type) {
572 case Primitive::kPrimBoolean:
573 case Primitive::kPrimByte:
574 case Primitive::kPrimChar:
575 case Primitive::kPrimShort:
576 case Primitive::kPrimInt:
577 case Primitive::kPrimNot: {
578 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000579 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100580 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100581 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100582 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000583 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100584 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100585 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100586
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000587 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100588 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000589 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100590 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000591 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100592 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100593 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
594 calling_convention.GetRegisterPairAt(index));
595 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100596 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000597 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100598 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000599 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
600 }
601 }
602
603 case Primitive::kPrimFloat: {
604 uint32_t stack_index = stack_index_++;
605 if (float_index_ % 2 == 0) {
606 float_index_ = std::max(double_index_, float_index_);
607 }
608 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
609 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
610 } else {
611 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
612 }
613 }
614
615 case Primitive::kPrimDouble: {
616 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
617 uint32_t stack_index = stack_index_;
618 stack_index_ += 2;
619 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
620 uint32_t index = double_index_;
621 double_index_ += 2;
622 return Location::FpuRegisterPairLocation(
623 calling_convention.GetFpuRegisterAt(index),
624 calling_convention.GetFpuRegisterAt(index + 1));
625 } else {
626 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100627 }
628 }
629
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100630 case Primitive::kPrimVoid:
631 LOG(FATAL) << "Unexpected parameter type " << type;
632 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100633 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100634 return Location();
635}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100636
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000637Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
638 switch (type) {
639 case Primitive::kPrimBoolean:
640 case Primitive::kPrimByte:
641 case Primitive::kPrimChar:
642 case Primitive::kPrimShort:
643 case Primitive::kPrimInt:
644 case Primitive::kPrimNot: {
645 return Location::RegisterLocation(R0);
646 }
647
648 case Primitive::kPrimFloat: {
649 return Location::FpuRegisterLocation(S0);
650 }
651
652 case Primitive::kPrimLong: {
653 return Location::RegisterPairLocation(R0, R1);
654 }
655
656 case Primitive::kPrimDouble: {
657 return Location::FpuRegisterPairLocation(S0, S1);
658 }
659
660 case Primitive::kPrimVoid:
661 return Location();
662 }
663 UNREACHABLE();
664 return Location();
665}
666
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100667void CodeGeneratorARM::Move32(Location destination, Location source) {
668 if (source.Equals(destination)) {
669 return;
670 }
671 if (destination.IsRegister()) {
672 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000673 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100674 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000675 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100676 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000677 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100678 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100679 } else if (destination.IsFpuRegister()) {
680 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000681 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100682 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000683 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100684 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000685 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100686 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100687 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000688 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000690 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100691 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000692 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100693 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000694 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100695 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
696 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100697 }
698 }
699}
700
701void CodeGeneratorARM::Move64(Location destination, Location source) {
702 if (source.Equals(destination)) {
703 return;
704 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100705 if (destination.IsRegisterPair()) {
706 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000707 EmitParallelMoves(
708 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
709 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
710 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
711 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100712 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000713 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100714 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000715 uint16_t register_index = source.GetQuickParameterRegisterIndex();
716 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100717 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000718 EmitParallelMoves(
719 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
720 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
721 Location::StackSlot(
722 calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()),
723 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100724 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000725 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100726 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100727 if (destination.AsRegisterPairLow<Register>() == R1) {
728 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100729 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
730 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100731 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100732 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100733 SP, source.GetStackIndex());
734 }
735 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000736 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100737 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000738 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
739 SP,
740 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100741 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000742 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100743 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100744 } else if (destination.IsQuickParameter()) {
745 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000746 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
747 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100748 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000749 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100750 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000751 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100752 } else {
753 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000754 EmitParallelMoves(
755 Location::StackSlot(source.GetStackIndex()),
756 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
757 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
758 Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index + 1)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100759 }
760 } else {
761 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100762 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000763 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100764 if (source.AsRegisterPairLow<Register>() == R1) {
765 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100766 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
767 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100769 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100770 SP, destination.GetStackIndex());
771 }
772 } else if (source.IsQuickParameter()) {
773 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000774 uint16_t register_index = source.GetQuickParameterRegisterIndex();
775 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000776 // Just move the low part. The only time a source is a quick parameter is
777 // when moving the parameter to its stack locations. And the (Java) caller
778 // of this method has already done that.
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000779 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000780 SP, destination.GetStackIndex());
781 DCHECK_EQ(calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize(),
782 static_cast<size_t>(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000783 } else if (source.IsFpuRegisterPair()) {
784 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
785 SP,
786 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100787 } else {
788 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000789 EmitParallelMoves(
790 Location::StackSlot(source.GetStackIndex()),
791 Location::StackSlot(destination.GetStackIndex()),
792 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
793 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100794 }
795 }
796}
797
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100798void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100799 LocationSummary* locations = instruction->GetLocations();
800 if (locations != nullptr && locations->Out().Equals(location)) {
801 return;
802 }
803
Calin Juravlea21f5982014-11-13 15:53:04 +0000804 if (locations != nullptr && locations->Out().IsConstant()) {
805 HConstant* const_to_move = locations->Out().GetConstant();
806 if (const_to_move->IsIntConstant()) {
807 int32_t value = const_to_move->AsIntConstant()->GetValue();
808 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000809 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000810 } else {
811 DCHECK(location.IsStackSlot());
812 __ LoadImmediate(IP, value);
813 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
814 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000815 } else {
816 DCHECK(const_to_move->IsLongConstant()) << const_to_move;
Calin Juravlea21f5982014-11-13 15:53:04 +0000817 int64_t value = const_to_move->AsLongConstant()->GetValue();
818 if (location.IsRegisterPair()) {
819 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
820 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
821 } else {
822 DCHECK(location.IsDoubleStackSlot());
823 __ LoadImmediate(IP, Low32Bits(value));
824 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
825 __ LoadImmediate(IP, High32Bits(value));
826 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
827 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100828 }
Roland Levillain476df552014-10-09 17:51:36 +0100829 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
831 switch (instruction->GetType()) {
832 case Primitive::kPrimBoolean:
833 case Primitive::kPrimByte:
834 case Primitive::kPrimChar:
835 case Primitive::kPrimShort:
836 case Primitive::kPrimInt:
837 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100838 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 Move32(location, Location::StackSlot(stack_slot));
840 break;
841
842 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100843 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100844 Move64(location, Location::DoubleStackSlot(stack_slot));
845 break;
846
847 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100848 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000850 } else if (instruction->IsTemporary()) {
851 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000852 if (temp_location.IsStackSlot()) {
853 Move32(location, temp_location);
854 } else {
855 DCHECK(temp_location.IsDoubleStackSlot());
856 Move64(location, temp_location);
857 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000858 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100859 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100860 switch (instruction->GetType()) {
861 case Primitive::kPrimBoolean:
862 case Primitive::kPrimByte:
863 case Primitive::kPrimChar:
864 case Primitive::kPrimShort:
865 case Primitive::kPrimNot:
866 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100867 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100868 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100869 break;
870
871 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100872 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100873 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100874 break;
875
876 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100877 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100878 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000879 }
880}
881
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100882void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
883 HInstruction* instruction,
884 uint32_t dex_pc) {
885 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
886 __ blx(LR);
887 RecordPcInfo(instruction, dex_pc);
888 DCHECK(instruction->IsSuspendCheck()
889 || instruction->IsBoundsCheck()
890 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000891 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000892 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100893 || !IsLeafMethod());
894}
895
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000896void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000897 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000898}
899
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000900void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000901 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100902 DCHECK(!successor->IsExitBlock());
903
904 HBasicBlock* block = got->GetBlock();
905 HInstruction* previous = got->GetPrevious();
906
907 HLoopInformation* info = block->GetLoopInformation();
908 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
909 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
910 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
911 return;
912 }
913
914 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
915 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
916 }
917 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000918 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000919 }
920}
921
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000922void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000923 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000924}
925
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000926void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700927 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000928 if (kIsDebugBuild) {
929 __ Comment("Unreachable");
930 __ bkpt(0);
931 }
932}
933
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000934void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100935 LocationSummary* locations =
936 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100937 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100938 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100939 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100940 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000941}
942
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000943void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700944 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100945 if (cond->IsIntConstant()) {
946 // Constant condition, statically compared against 1.
947 int32_t cond_value = cond->AsIntConstant()->GetValue();
948 if (cond_value == 1) {
949 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
950 if_instr->IfTrueSuccessor())) {
951 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100952 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100953 return;
954 } else {
955 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100956 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100957 } else {
958 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
959 // Condition has been materialized, compare the output to 0
960 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000961 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100962 ShifterOperand(0));
963 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
964 } else {
965 // Condition has not been materialized, use its inputs as the
966 // comparison and its condition as the branch condition.
967 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000968 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100969 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000970 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100971 } else {
972 DCHECK(locations->InAt(1).IsConstant());
973 int32_t value =
974 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
975 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000976 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
977 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100978 } else {
979 Register temp = IP;
980 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000981 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100982 }
983 }
984 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
985 ARMCondition(cond->AsCondition()->GetCondition()));
986 }
Dave Allison20dfc792014-06-16 20:44:29 -0700987 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100988 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
989 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700990 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000991 }
992}
993
Dave Allison20dfc792014-06-16 20:44:29 -0700994
995void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100996 LocationSummary* locations =
997 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100998 locations->SetInAt(0, Location::RequiresRegister());
999 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001000 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001001 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001002 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001003}
1004
Dave Allison20dfc792014-06-16 20:44:29 -07001005void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001006 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001007 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001008 Register left = locations->InAt(0).AsRegister<Register>();
1009
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001010 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001011 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001012 } else {
1013 DCHECK(locations->InAt(1).IsConstant());
1014 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
1015 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001016 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1017 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001018 } else {
1019 Register temp = IP;
1020 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001021 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001022 }
Dave Allison20dfc792014-06-16 20:44:29 -07001023 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001024 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001025 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001026 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001027 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001028 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001029}
1030
1031void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1032 VisitCondition(comp);
1033}
1034
1035void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1036 VisitCondition(comp);
1037}
1038
1039void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1040 VisitCondition(comp);
1041}
1042
1043void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1044 VisitCondition(comp);
1045}
1046
1047void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1048 VisitCondition(comp);
1049}
1050
1051void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1052 VisitCondition(comp);
1053}
1054
1055void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1056 VisitCondition(comp);
1057}
1058
1059void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1060 VisitCondition(comp);
1061}
1062
1063void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1064 VisitCondition(comp);
1065}
1066
1067void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1068 VisitCondition(comp);
1069}
1070
1071void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1072 VisitCondition(comp);
1073}
1074
1075void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1076 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001077}
1078
1079void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001080 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001081}
1082
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001083void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1084 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001085}
1086
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001087void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001088 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001089}
1090
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001091void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001092 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001093 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001094}
1095
1096void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001097 LocationSummary* locations =
1098 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001099 switch (store->InputAt(1)->GetType()) {
1100 case Primitive::kPrimBoolean:
1101 case Primitive::kPrimByte:
1102 case Primitive::kPrimChar:
1103 case Primitive::kPrimShort:
1104 case Primitive::kPrimInt:
1105 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001106 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001107 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1108 break;
1109
1110 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001111 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001112 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1113 break;
1114
1115 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001116 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001117 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001118}
1119
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001120void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001121 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001122}
1123
1124void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001125 LocationSummary* locations =
1126 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001127 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001128}
1129
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001130void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001131 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001132 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001133}
1134
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001135void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001136 LocationSummary* locations =
1137 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001138 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001139}
1140
1141void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1142 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001143 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001144}
1145
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001146void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1147 LocationSummary* locations =
1148 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1149 locations->SetOut(Location::ConstantLocation(constant));
1150}
1151
1152void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1153 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001154 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001155}
1156
1157void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1158 LocationSummary* locations =
1159 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1160 locations->SetOut(Location::ConstantLocation(constant));
1161}
1162
1163void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1164 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001165 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001166}
1167
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001168void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001169 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001170}
1171
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001172void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001173 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001174 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001175}
1176
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001177void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001178 LocationSummary* locations =
1179 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001180 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001181}
1182
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001183void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001184 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001185 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001186}
1187
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001188void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189 HandleInvoke(invoke);
1190}
1191
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001192void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001193 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001194}
1195
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001196void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001197 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001198
1199 // TODO: Implement all kinds of calls:
1200 // 1) boot -> boot
1201 // 2) app -> boot
1202 // 3) app -> app
1203 //
1204 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1205
1206 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001207 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001208 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001209 __ LoadFromOffset(
1210 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001211 // temp = temp[index_in_cache]
1212 __ LoadFromOffset(
1213 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
1214 // LR = temp[offset_of_quick_compiled_code]
1215 __ LoadFromOffset(kLoadWord, LR, temp,
1216 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1217 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001218 // LR()
1219 __ blx(LR);
1220
1221 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1222 DCHECK(!codegen_->IsLeafMethod());
1223}
1224
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001225void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001226 LocationSummary* locations =
1227 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001228 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001229
1230 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001231 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001232 HInstruction* input = invoke->InputAt(i);
1233 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1234 }
1235
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001236 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001237}
1238
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001239void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1240 HandleInvoke(invoke);
1241}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001242
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001243void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001244 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001245 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1246 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1247 LocationSummary* locations = invoke->GetLocations();
1248 Location receiver = locations->InAt(0);
1249 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1250 // temp = object->GetClass();
1251 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001252 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1253 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001254 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001255 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001256 }
1257 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001258 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001259 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001260 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001261 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001262 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001263 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001264 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001265 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001266 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001267}
1268
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001269void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1270 HandleInvoke(invoke);
1271 // Add the hidden argument.
1272 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1273}
1274
1275void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1276 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001277 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001278 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1279 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1280 LocationSummary* locations = invoke->GetLocations();
1281 Location receiver = locations->InAt(0);
1282 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1283
1284 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001285 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1286 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001287
1288 // temp = object->GetClass();
1289 if (receiver.IsStackSlot()) {
1290 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1291 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1292 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001293 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001294 }
1295 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001296 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001297 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001298 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1299 // LR = temp->GetEntryPoint();
1300 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1301 // LR();
1302 __ blx(LR);
1303 DCHECK(!codegen_->IsLeafMethod());
1304 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1305}
1306
Roland Levillain88cb1752014-10-20 16:36:47 +01001307void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1308 LocationSummary* locations =
1309 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1310 switch (neg->GetResultType()) {
1311 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001312 case Primitive::kPrimLong: {
1313 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001314 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001315 locations->SetOut(Location::RequiresRegister(), output_overlaps);
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 Geoffraya7aca372014-04-28 17:47:12 +01001840 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001841 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001842 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1843 locations->SetInAt(0, Location::RequiresRegister());
1844 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1845 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001846 break;
1847 }
1848
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001849 case Primitive::kPrimFloat:
1850 case Primitive::kPrimDouble: {
1851 locations->SetInAt(0, Location::RequiresFpuRegister());
1852 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001853 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001854 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001855 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001856
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001857 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001858 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001859 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001860}
1861
1862void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1863 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001864 Location out = locations->Out();
1865 Location first = locations->InAt(0);
1866 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001867 switch (add->GetResultType()) {
1868 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001869 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001870 __ add(out.AsRegister<Register>(),
1871 first.AsRegister<Register>(),
1872 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001873 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001874 __ AddConstant(out.AsRegister<Register>(),
1875 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001876 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001877 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001878 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001879
1880 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001881 __ adds(out.AsRegisterPairLow<Register>(),
1882 first.AsRegisterPairLow<Register>(),
1883 ShifterOperand(second.AsRegisterPairLow<Register>()));
1884 __ adc(out.AsRegisterPairHigh<Register>(),
1885 first.AsRegisterPairHigh<Register>(),
1886 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001887 break;
1888
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001889 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001890 __ vadds(out.AsFpuRegister<SRegister>(),
1891 first.AsFpuRegister<SRegister>(),
1892 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001893 break;
1894
1895 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001896 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1897 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1898 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001899 break;
1900
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001901 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001902 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001903 }
1904}
1905
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001906void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001907 LocationSummary* locations =
1908 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001909 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001910 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001911 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001912 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1913 locations->SetInAt(0, Location::RequiresRegister());
1914 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1915 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001916 break;
1917 }
Calin Juravle11351682014-10-23 15:38:15 +01001918 case Primitive::kPrimFloat:
1919 case Primitive::kPrimDouble: {
1920 locations->SetInAt(0, Location::RequiresFpuRegister());
1921 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001922 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001923 break;
Calin Juravle11351682014-10-23 15:38:15 +01001924 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001925 default:
Calin Juravle11351682014-10-23 15:38:15 +01001926 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001927 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001928}
1929
1930void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1931 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001932 Location out = locations->Out();
1933 Location first = locations->InAt(0);
1934 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001935 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001936 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001937 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001938 __ sub(out.AsRegister<Register>(),
1939 first.AsRegister<Register>(),
1940 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001941 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001942 __ AddConstant(out.AsRegister<Register>(),
1943 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001944 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001945 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001946 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001947 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001948
Calin Juravle11351682014-10-23 15:38:15 +01001949 case Primitive::kPrimLong: {
1950 __ subs(out.AsRegisterPairLow<Register>(),
1951 first.AsRegisterPairLow<Register>(),
1952 ShifterOperand(second.AsRegisterPairLow<Register>()));
1953 __ sbc(out.AsRegisterPairHigh<Register>(),
1954 first.AsRegisterPairHigh<Register>(),
1955 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001956 break;
Calin Juravle11351682014-10-23 15:38:15 +01001957 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001958
Calin Juravle11351682014-10-23 15:38:15 +01001959 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001960 __ vsubs(out.AsFpuRegister<SRegister>(),
1961 first.AsFpuRegister<SRegister>(),
1962 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001963 break;
Calin Juravle11351682014-10-23 15:38:15 +01001964 }
1965
1966 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001967 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1968 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1969 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001970 break;
1971 }
1972
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001973
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001974 default:
Calin Juravle11351682014-10-23 15:38:15 +01001975 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001976 }
1977}
1978
Calin Juravle34bacdf2014-10-07 20:23:36 +01001979void LocationsBuilderARM::VisitMul(HMul* mul) {
1980 LocationSummary* locations =
1981 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1982 switch (mul->GetResultType()) {
1983 case Primitive::kPrimInt:
1984 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001985 locations->SetInAt(0, Location::RequiresRegister());
1986 locations->SetInAt(1, Location::RequiresRegister());
1987 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001988 break;
1989 }
1990
Calin Juravleb5bfa962014-10-21 18:02:24 +01001991 case Primitive::kPrimFloat:
1992 case Primitive::kPrimDouble: {
1993 locations->SetInAt(0, Location::RequiresFpuRegister());
1994 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001995 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001996 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001997 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001998
1999 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002000 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002001 }
2002}
2003
2004void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2005 LocationSummary* locations = mul->GetLocations();
2006 Location out = locations->Out();
2007 Location first = locations->InAt(0);
2008 Location second = locations->InAt(1);
2009 switch (mul->GetResultType()) {
2010 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002011 __ mul(out.AsRegister<Register>(),
2012 first.AsRegister<Register>(),
2013 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002014 break;
2015 }
2016 case Primitive::kPrimLong: {
2017 Register out_hi = out.AsRegisterPairHigh<Register>();
2018 Register out_lo = out.AsRegisterPairLow<Register>();
2019 Register in1_hi = first.AsRegisterPairHigh<Register>();
2020 Register in1_lo = first.AsRegisterPairLow<Register>();
2021 Register in2_hi = second.AsRegisterPairHigh<Register>();
2022 Register in2_lo = second.AsRegisterPairLow<Register>();
2023
2024 // Extra checks to protect caused by the existence of R1_R2.
2025 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2026 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2027 DCHECK_NE(out_hi, in1_lo);
2028 DCHECK_NE(out_hi, in2_lo);
2029
2030 // input: in1 - 64 bits, in2 - 64 bits
2031 // output: out
2032 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2033 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2034 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2035
2036 // IP <- in1.lo * in2.hi
2037 __ mul(IP, in1_lo, in2_hi);
2038 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2039 __ mla(out_hi, in1_hi, in2_lo, IP);
2040 // out.lo <- (in1.lo * in2.lo)[31:0];
2041 __ umull(out_lo, IP, in1_lo, in2_lo);
2042 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2043 __ add(out_hi, out_hi, ShifterOperand(IP));
2044 break;
2045 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002046
2047 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002048 __ vmuls(out.AsFpuRegister<SRegister>(),
2049 first.AsFpuRegister<SRegister>(),
2050 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002051 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002052 }
2053
2054 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002055 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2056 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2057 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002058 break;
2059 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002060
2061 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002062 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002063 }
2064}
2065
Calin Juravle7c4954d2014-10-28 16:57:40 +00002066void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002067 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2068 ? LocationSummary::kCall
2069 : LocationSummary::kNoCall;
2070 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2071
Calin Juravle7c4954d2014-10-28 16:57:40 +00002072 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002073 case Primitive::kPrimInt: {
2074 locations->SetInAt(0, Location::RequiresRegister());
2075 locations->SetInAt(1, Location::RequiresRegister());
2076 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2077 break;
2078 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002079 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002080 InvokeRuntimeCallingConvention calling_convention;
2081 locations->SetInAt(0, Location::RegisterPairLocation(
2082 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2083 locations->SetInAt(1, Location::RegisterPairLocation(
2084 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2085 // The runtime helper puts the output in R0,R2.
2086 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002087 break;
2088 }
2089 case Primitive::kPrimFloat:
2090 case Primitive::kPrimDouble: {
2091 locations->SetInAt(0, Location::RequiresFpuRegister());
2092 locations->SetInAt(1, Location::RequiresFpuRegister());
2093 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2094 break;
2095 }
2096
2097 default:
2098 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2099 }
2100}
2101
2102void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2103 LocationSummary* locations = div->GetLocations();
2104 Location out = locations->Out();
2105 Location first = locations->InAt(0);
2106 Location second = locations->InAt(1);
2107
2108 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002109 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002110 __ sdiv(out.AsRegister<Register>(),
2111 first.AsRegister<Register>(),
2112 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002113 break;
2114 }
2115
Calin Juravle7c4954d2014-10-28 16:57:40 +00002116 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002117 InvokeRuntimeCallingConvention calling_convention;
2118 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2119 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2120 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2121 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2122 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2123 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2124
2125 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002126 break;
2127 }
2128
2129 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002130 __ vdivs(out.AsFpuRegister<SRegister>(),
2131 first.AsFpuRegister<SRegister>(),
2132 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002133 break;
2134 }
2135
2136 case Primitive::kPrimDouble: {
2137 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2138 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2139 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2140 break;
2141 }
2142
2143 default:
2144 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2145 }
2146}
2147
Calin Juravlebacfec32014-11-14 15:54:36 +00002148void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002149 Primitive::Type type = rem->GetResultType();
2150 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2151 ? LocationSummary::kNoCall
2152 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002153 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2154
Calin Juravled2ec87d2014-12-08 14:24:46 +00002155 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002156 case Primitive::kPrimInt: {
2157 locations->SetInAt(0, Location::RequiresRegister());
2158 locations->SetInAt(1, Location::RequiresRegister());
2159 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2160 locations->AddTemp(Location::RequiresRegister());
2161 break;
2162 }
2163 case Primitive::kPrimLong: {
2164 InvokeRuntimeCallingConvention calling_convention;
2165 locations->SetInAt(0, Location::RegisterPairLocation(
2166 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2167 locations->SetInAt(1, Location::RegisterPairLocation(
2168 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2169 // The runtime helper puts the output in R2,R3.
2170 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2171 break;
2172 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002173 case Primitive::kPrimFloat: {
2174 InvokeRuntimeCallingConvention calling_convention;
2175 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2176 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2177 locations->SetOut(Location::FpuRegisterLocation(S0));
2178 break;
2179 }
2180
Calin Juravlebacfec32014-11-14 15:54:36 +00002181 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002182 InvokeRuntimeCallingConvention calling_convention;
2183 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2184 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2185 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2186 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2187 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002188 break;
2189 }
2190
2191 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002192 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002193 }
2194}
2195
2196void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2197 LocationSummary* locations = rem->GetLocations();
2198 Location out = locations->Out();
2199 Location first = locations->InAt(0);
2200 Location second = locations->InAt(1);
2201
Calin Juravled2ec87d2014-12-08 14:24:46 +00002202 Primitive::Type type = rem->GetResultType();
2203 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002204 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002205 Register reg1 = first.AsRegister<Register>();
2206 Register reg2 = second.AsRegister<Register>();
2207 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002208
2209 // temp = reg1 / reg2 (integer division)
2210 // temp = temp * reg2
2211 // dest = reg1 - temp
2212 __ sdiv(temp, reg1, reg2);
2213 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002214 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002215 break;
2216 }
2217
2218 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002219 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2220 break;
2221 }
2222
Calin Juravled2ec87d2014-12-08 14:24:46 +00002223 case Primitive::kPrimFloat: {
2224 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2225 break;
2226 }
2227
Calin Juravlebacfec32014-11-14 15:54:36 +00002228 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002229 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002230 break;
2231 }
2232
2233 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002234 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002235 }
2236}
2237
Calin Juravled0d48522014-11-04 16:40:20 +00002238void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2239 LocationSummary* locations =
2240 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002241 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002242 if (instruction->HasUses()) {
2243 locations->SetOut(Location::SameAsFirstInput());
2244 }
2245}
2246
2247void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2248 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2249 codegen_->AddSlowPath(slow_path);
2250
2251 LocationSummary* locations = instruction->GetLocations();
2252 Location value = locations->InAt(0);
2253
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002254 switch (instruction->GetType()) {
2255 case Primitive::kPrimInt: {
2256 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002257 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002258 __ b(slow_path->GetEntryLabel(), EQ);
2259 } else {
2260 DCHECK(value.IsConstant()) << value;
2261 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2262 __ b(slow_path->GetEntryLabel());
2263 }
2264 }
2265 break;
2266 }
2267 case Primitive::kPrimLong: {
2268 if (value.IsRegisterPair()) {
2269 __ orrs(IP,
2270 value.AsRegisterPairLow<Register>(),
2271 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2272 __ b(slow_path->GetEntryLabel(), EQ);
2273 } else {
2274 DCHECK(value.IsConstant()) << value;
2275 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2276 __ b(slow_path->GetEntryLabel());
2277 }
2278 }
2279 break;
2280 default:
2281 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2282 }
2283 }
Calin Juravled0d48522014-11-04 16:40:20 +00002284}
2285
Calin Juravle9aec02f2014-11-18 23:06:35 +00002286void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2287 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2288
2289 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2290 ? LocationSummary::kCall
2291 : LocationSummary::kNoCall;
2292 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2293
2294 switch (op->GetResultType()) {
2295 case Primitive::kPrimInt: {
2296 locations->SetInAt(0, Location::RequiresRegister());
2297 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2298 locations->SetOut(Location::RequiresRegister());
2299 break;
2300 }
2301 case Primitive::kPrimLong: {
2302 InvokeRuntimeCallingConvention calling_convention;
2303 locations->SetInAt(0, Location::RegisterPairLocation(
2304 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2305 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2306 // The runtime helper puts the output in R0,R2.
2307 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2308 break;
2309 }
2310 default:
2311 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2312 }
2313}
2314
2315void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2316 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2317
2318 LocationSummary* locations = op->GetLocations();
2319 Location out = locations->Out();
2320 Location first = locations->InAt(0);
2321 Location second = locations->InAt(1);
2322
2323 Primitive::Type type = op->GetResultType();
2324 switch (type) {
2325 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002326 Register out_reg = out.AsRegister<Register>();
2327 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002328 // Arm doesn't mask the shift count so we need to do it ourselves.
2329 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002330 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002331 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2332 if (op->IsShl()) {
2333 __ Lsl(out_reg, first_reg, second_reg);
2334 } else if (op->IsShr()) {
2335 __ Asr(out_reg, first_reg, second_reg);
2336 } else {
2337 __ Lsr(out_reg, first_reg, second_reg);
2338 }
2339 } else {
2340 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2341 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2342 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2343 __ Mov(out_reg, first_reg);
2344 } else if (op->IsShl()) {
2345 __ Lsl(out_reg, first_reg, shift_value);
2346 } else if (op->IsShr()) {
2347 __ Asr(out_reg, first_reg, shift_value);
2348 } else {
2349 __ Lsr(out_reg, first_reg, shift_value);
2350 }
2351 }
2352 break;
2353 }
2354 case Primitive::kPrimLong: {
2355 // TODO: Inline the assembly instead of calling the runtime.
2356 InvokeRuntimeCallingConvention calling_convention;
2357 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2358 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002359 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002360 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2361 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2362
2363 int32_t entry_point_offset;
2364 if (op->IsShl()) {
2365 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2366 } else if (op->IsShr()) {
2367 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2368 } else {
2369 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2370 }
2371 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2372 __ blx(LR);
2373 break;
2374 }
2375 default:
2376 LOG(FATAL) << "Unexpected operation type " << type;
2377 }
2378}
2379
2380void LocationsBuilderARM::VisitShl(HShl* shl) {
2381 HandleShift(shl);
2382}
2383
2384void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2385 HandleShift(shl);
2386}
2387
2388void LocationsBuilderARM::VisitShr(HShr* shr) {
2389 HandleShift(shr);
2390}
2391
2392void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2393 HandleShift(shr);
2394}
2395
2396void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2397 HandleShift(ushr);
2398}
2399
2400void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2401 HandleShift(ushr);
2402}
2403
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002404void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002405 LocationSummary* locations =
2406 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002407 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002408 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2409 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2410 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002411}
2412
2413void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2414 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002415 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002416 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002417 codegen_->InvokeRuntime(
2418 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002419}
2420
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002421void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2422 LocationSummary* locations =
2423 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2424 InvokeRuntimeCallingConvention calling_convention;
2425 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002426 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002427 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002428 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002429}
2430
2431void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2432 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002433 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002434 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002435 codegen_->InvokeRuntime(
2436 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002437}
2438
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002439void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002440 LocationSummary* locations =
2441 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002442 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2443 if (location.IsStackSlot()) {
2444 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2445 } else if (location.IsDoubleStackSlot()) {
2446 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002447 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002448 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002449}
2450
2451void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002452 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002453 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002454}
2455
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002456void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002457 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002458 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002459 locations->SetInAt(0, Location::RequiresRegister());
2460 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002461}
2462
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002463void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2464 LocationSummary* locations = not_->GetLocations();
2465 Location out = locations->Out();
2466 Location in = locations->InAt(0);
2467 switch (not_->InputAt(0)->GetType()) {
2468 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002469 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002470 break;
2471
2472 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002473 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002474 break;
2475
2476 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002477 __ mvn(out.AsRegisterPairLow<Register>(),
2478 ShifterOperand(in.AsRegisterPairLow<Register>()));
2479 __ mvn(out.AsRegisterPairHigh<Register>(),
2480 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002481 break;
2482
2483 default:
2484 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2485 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002486}
2487
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002488void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002489 LocationSummary* locations =
2490 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002491 switch (compare->InputAt(0)->GetType()) {
2492 case Primitive::kPrimLong: {
2493 locations->SetInAt(0, Location::RequiresRegister());
2494 locations->SetInAt(1, Location::RequiresRegister());
2495 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2496 break;
2497 }
2498 case Primitive::kPrimFloat:
2499 case Primitive::kPrimDouble: {
2500 locations->SetInAt(0, Location::RequiresFpuRegister());
2501 locations->SetInAt(1, Location::RequiresFpuRegister());
2502 locations->SetOut(Location::RequiresRegister());
2503 break;
2504 }
2505 default:
2506 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2507 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002508}
2509
2510void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002511 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002512 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002513 Location left = locations->InAt(0);
2514 Location right = locations->InAt(1);
2515
2516 Label less, greater, done;
2517 Primitive::Type type = compare->InputAt(0)->GetType();
2518 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002519 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002520 __ cmp(left.AsRegisterPairHigh<Register>(),
2521 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002522 __ b(&less, LT);
2523 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002524 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2525 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002526 __ cmp(left.AsRegisterPairLow<Register>(),
2527 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002528 break;
2529 }
2530 case Primitive::kPrimFloat:
2531 case Primitive::kPrimDouble: {
2532 __ LoadImmediate(out, 0);
2533 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002534 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002535 } else {
2536 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2537 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2538 }
2539 __ vmstat(); // transfer FP status register to ARM APSR.
2540 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002541 break;
2542 }
2543 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002544 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002545 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002546 __ b(&done, EQ);
2547 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2548
2549 __ Bind(&greater);
2550 __ LoadImmediate(out, 1);
2551 __ b(&done);
2552
2553 __ Bind(&less);
2554 __ LoadImmediate(out, -1);
2555
2556 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002557}
2558
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002559void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002560 LocationSummary* locations =
2561 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002562 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2563 locations->SetInAt(i, Location::Any());
2564 }
2565 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002566}
2567
2568void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002569 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002570 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002571}
2572
Calin Juravle52c48962014-12-16 17:02:57 +00002573void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2574 // TODO (ported from quick): revisit Arm barrier kinds
2575 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2576 switch (kind) {
2577 case MemBarrierKind::kAnyStore:
2578 case MemBarrierKind::kLoadAny:
2579 case MemBarrierKind::kAnyAny: {
2580 flavour = DmbOptions::ISH;
2581 break;
2582 }
2583 case MemBarrierKind::kStoreStore: {
2584 flavour = DmbOptions::ISHST;
2585 break;
2586 }
2587 default:
2588 LOG(FATAL) << "Unexpected memory barrier " << kind;
2589 }
2590 __ dmb(flavour);
2591}
2592
2593void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2594 uint32_t offset,
2595 Register out_lo,
2596 Register out_hi) {
2597 if (offset != 0) {
2598 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002599 __ add(IP, addr, ShifterOperand(out_lo));
2600 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002601 }
2602 __ ldrexd(out_lo, out_hi, addr);
2603}
2604
2605void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2606 uint32_t offset,
2607 Register value_lo,
2608 Register value_hi,
2609 Register temp1,
2610 Register temp2) {
2611 Label fail;
2612 if (offset != 0) {
2613 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002614 __ add(IP, addr, ShifterOperand(temp1));
2615 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002616 }
2617 __ Bind(&fail);
2618 // We need a load followed by store. (The address used in a STREX instruction must
2619 // be the same as the address in the most recently executed LDREX instruction.)
2620 __ ldrexd(temp1, temp2, addr);
2621 __ strexd(temp1, value_lo, value_hi, addr);
2622 __ cmp(temp1, ShifterOperand(0));
2623 __ b(&fail, NE);
2624}
2625
2626void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2627 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2628
Nicolas Geoffray39468442014-09-02 15:17:15 +01002629 LocationSummary* locations =
2630 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002631 locations->SetInAt(0, Location::RequiresRegister());
2632 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002633
Calin Juravle34166012014-12-19 17:22:29 +00002634
Calin Juravle52c48962014-12-16 17:02:57 +00002635 Primitive::Type field_type = field_info.GetFieldType();
2636 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002637 bool generate_volatile = field_info.IsVolatile()
2638 && is_wide
2639 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002640 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002641 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2642 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002643 locations->AddTemp(Location::RequiresRegister());
2644 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002645 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002646 // Arm encoding have some additional constraints for ldrexd/strexd:
2647 // - registers need to be consecutive
2648 // - the first register should be even but not R14.
2649 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2650 // enable Arm encoding.
2651 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2652
2653 locations->AddTemp(Location::RequiresRegister());
2654 locations->AddTemp(Location::RequiresRegister());
2655 if (field_type == Primitive::kPrimDouble) {
2656 // For doubles we need two more registers to copy the value.
2657 locations->AddTemp(Location::RegisterLocation(R2));
2658 locations->AddTemp(Location::RegisterLocation(R3));
2659 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002660 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002661}
2662
Calin Juravle52c48962014-12-16 17:02:57 +00002663void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2664 const FieldInfo& field_info) {
2665 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2666
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002667 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002668 Register base = locations->InAt(0).AsRegister<Register>();
2669 Location value = locations->InAt(1);
2670
2671 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002672 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002673 Primitive::Type field_type = field_info.GetFieldType();
2674 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2675
2676 if (is_volatile) {
2677 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2678 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002679
2680 switch (field_type) {
2681 case Primitive::kPrimBoolean:
2682 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002683 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002684 break;
2685 }
2686
2687 case Primitive::kPrimShort:
2688 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002689 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002690 break;
2691 }
2692
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002693 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002694 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002695 Register value_reg = value.AsRegister<Register>();
2696 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2697 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002698 Register temp = locations->GetTemp(0).AsRegister<Register>();
2699 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002700 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002701 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002702 break;
2703 }
2704
2705 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002706 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002707 GenerateWideAtomicStore(base, offset,
2708 value.AsRegisterPairLow<Register>(),
2709 value.AsRegisterPairHigh<Register>(),
2710 locations->GetTemp(0).AsRegister<Register>(),
2711 locations->GetTemp(1).AsRegister<Register>());
2712 } else {
2713 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2714 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002715 break;
2716 }
2717
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002718 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002719 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002720 break;
2721 }
2722
2723 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002724 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002725 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002726 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2727 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2728
2729 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2730
2731 GenerateWideAtomicStore(base, offset,
2732 value_reg_lo,
2733 value_reg_hi,
2734 locations->GetTemp(2).AsRegister<Register>(),
2735 locations->GetTemp(3).AsRegister<Register>());
2736 } else {
2737 __ StoreDToOffset(value_reg, base, offset);
2738 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002739 break;
2740 }
2741
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002742 case Primitive::kPrimVoid:
2743 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002744 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002745 }
Calin Juravle52c48962014-12-16 17:02:57 +00002746
2747 if (is_volatile) {
2748 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2749 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002750}
2751
Calin Juravle52c48962014-12-16 17:02:57 +00002752void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2753 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002754 LocationSummary* locations =
2755 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002756 locations->SetInAt(0, Location::RequiresRegister());
2757 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002758
Calin Juravle34166012014-12-19 17:22:29 +00002759 bool generate_volatile = field_info.IsVolatile()
2760 && (field_info.GetFieldType() == Primitive::kPrimDouble)
2761 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
2762 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002763 // Arm encoding have some additional constraints for ldrexd/strexd:
2764 // - registers need to be consecutive
2765 // - the first register should be even but not R14.
2766 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2767 // enable Arm encoding.
2768 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2769 locations->AddTemp(Location::RequiresRegister());
2770 locations->AddTemp(Location::RequiresRegister());
2771 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002772}
2773
Calin Juravle52c48962014-12-16 17:02:57 +00002774void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2775 const FieldInfo& field_info) {
2776 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002777
Calin Juravle52c48962014-12-16 17:02:57 +00002778 LocationSummary* locations = instruction->GetLocations();
2779 Register base = locations->InAt(0).AsRegister<Register>();
2780 Location out = locations->Out();
2781 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002782 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002783 Primitive::Type field_type = field_info.GetFieldType();
2784 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2785
2786 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002787 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002788 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002789 break;
2790 }
2791
2792 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002793 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002794 break;
2795 }
2796
2797 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002798 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002799 break;
2800 }
2801
2802 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002803 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002804 break;
2805 }
2806
2807 case Primitive::kPrimInt:
2808 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002809 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002810 break;
2811 }
2812
2813 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002814 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002815 GenerateWideAtomicLoad(base, offset,
2816 out.AsRegisterPairLow<Register>(),
2817 out.AsRegisterPairHigh<Register>());
2818 } else {
2819 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2820 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002821 break;
2822 }
2823
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002824 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002825 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002826 break;
2827 }
2828
2829 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002830 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002831 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002832 Register lo = locations->GetTemp(0).AsRegister<Register>();
2833 Register hi = locations->GetTemp(1).AsRegister<Register>();
2834 GenerateWideAtomicLoad(base, offset, lo, hi);
2835 __ vmovdrr(out_reg, lo, hi);
2836 } else {
2837 __ LoadDFromOffset(out_reg, base, offset);
2838 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002839 break;
2840 }
2841
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002842 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002843 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002844 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002845 }
Calin Juravle52c48962014-12-16 17:02:57 +00002846
2847 if (is_volatile) {
2848 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2849 }
2850}
2851
2852void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2853 HandleFieldSet(instruction, instruction->GetFieldInfo());
2854}
2855
2856void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2857 HandleFieldSet(instruction, instruction->GetFieldInfo());
2858}
2859
2860void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2861 HandleFieldGet(instruction, instruction->GetFieldInfo());
2862}
2863
2864void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2865 HandleFieldGet(instruction, instruction->GetFieldInfo());
2866}
2867
2868void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2869 HandleFieldGet(instruction, instruction->GetFieldInfo());
2870}
2871
2872void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2873 HandleFieldGet(instruction, instruction->GetFieldInfo());
2874}
2875
2876void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2877 HandleFieldSet(instruction, instruction->GetFieldInfo());
2878}
2879
2880void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2881 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002882}
2883
2884void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002885 LocationSummary* locations =
2886 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002887 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002888 if (instruction->HasUses()) {
2889 locations->SetOut(Location::SameAsFirstInput());
2890 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002891}
2892
2893void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002894 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002895 codegen_->AddSlowPath(slow_path);
2896
2897 LocationSummary* locations = instruction->GetLocations();
2898 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002899
2900 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002901 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002902 __ b(slow_path->GetEntryLabel(), EQ);
2903 } else {
2904 DCHECK(obj.IsConstant()) << obj;
2905 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2906 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002907 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002908}
2909
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002910void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002911 LocationSummary* locations =
2912 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002913 locations->SetInAt(0, Location::RequiresRegister());
2914 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2915 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002916}
2917
2918void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2919 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002920 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002921 Location index = locations->InAt(1);
2922
2923 switch (instruction->GetType()) {
2924 case Primitive::kPrimBoolean: {
2925 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002926 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002927 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002928 size_t offset =
2929 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002930 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2931 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002932 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002933 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2934 }
2935 break;
2936 }
2937
2938 case Primitive::kPrimByte: {
2939 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002940 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002941 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002942 size_t offset =
2943 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002944 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2945 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002946 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002947 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2948 }
2949 break;
2950 }
2951
2952 case Primitive::kPrimShort: {
2953 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002954 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002955 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002956 size_t offset =
2957 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002958 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2959 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002960 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002961 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2962 }
2963 break;
2964 }
2965
2966 case Primitive::kPrimChar: {
2967 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002968 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002969 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002970 size_t offset =
2971 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002972 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2973 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002974 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002975 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2976 }
2977 break;
2978 }
2979
2980 case Primitive::kPrimInt:
2981 case Primitive::kPrimNot: {
2982 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2983 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002984 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002985 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002986 size_t offset =
2987 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002988 __ LoadFromOffset(kLoadWord, out, obj, offset);
2989 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002990 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002991 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2992 }
2993 break;
2994 }
2995
2996 case Primitive::kPrimLong: {
2997 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002998 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002999 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003000 size_t offset =
3001 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003002 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003003 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003004 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003005 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003006 }
3007 break;
3008 }
3009
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003010 case Primitive::kPrimFloat: {
3011 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3012 Location out = locations->Out();
3013 DCHECK(out.IsFpuRegister());
3014 if (index.IsConstant()) {
3015 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3016 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3017 } else {
3018 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3019 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3020 }
3021 break;
3022 }
3023
3024 case Primitive::kPrimDouble: {
3025 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3026 Location out = locations->Out();
3027 DCHECK(out.IsFpuRegisterPair());
3028 if (index.IsConstant()) {
3029 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3030 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3031 } else {
3032 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3033 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3034 }
3035 break;
3036 }
3037
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003038 case Primitive::kPrimVoid:
3039 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003040 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003041 }
3042}
3043
3044void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003045 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003046
3047 bool needs_write_barrier =
3048 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3049 bool needs_runtime_call = instruction->NeedsTypeCheck();
3050
Nicolas Geoffray39468442014-09-02 15:17:15 +01003051 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003052 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3053 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003054 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003055 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3056 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3057 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003058 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003059 locations->SetInAt(0, Location::RequiresRegister());
3060 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3061 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003062
3063 if (needs_write_barrier) {
3064 // Temporary registers for the write barrier.
3065 locations->AddTemp(Location::RequiresRegister());
3066 locations->AddTemp(Location::RequiresRegister());
3067 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003068 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003069}
3070
3071void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3072 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003073 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003074 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003075 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003076 bool needs_runtime_call = locations->WillCall();
3077 bool needs_write_barrier =
3078 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003079
3080 switch (value_type) {
3081 case Primitive::kPrimBoolean:
3082 case Primitive::kPrimByte: {
3083 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003084 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003085 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003086 size_t offset =
3087 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003088 __ StoreToOffset(kStoreByte, value, obj, offset);
3089 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003090 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003091 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3092 }
3093 break;
3094 }
3095
3096 case Primitive::kPrimShort:
3097 case Primitive::kPrimChar: {
3098 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003099 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003100 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003101 size_t offset =
3102 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003103 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3104 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003105 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003106 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3107 }
3108 break;
3109 }
3110
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003111 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003112 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003113 if (!needs_runtime_call) {
3114 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003115 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003116 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003117 size_t offset =
3118 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003119 __ StoreToOffset(kStoreWord, value, obj, offset);
3120 } else {
3121 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003122 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003123 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3124 }
3125 if (needs_write_barrier) {
3126 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003127 Register temp = locations->GetTemp(0).AsRegister<Register>();
3128 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003129 codegen_->MarkGCCard(temp, card, obj, value);
3130 }
3131 } else {
3132 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003133 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3134 instruction,
3135 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003136 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003137 break;
3138 }
3139
3140 case Primitive::kPrimLong: {
3141 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003142 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003143 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003144 size_t offset =
3145 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003146 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003147 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003148 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003149 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003150 }
3151 break;
3152 }
3153
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003154 case Primitive::kPrimFloat: {
3155 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3156 Location value = locations->InAt(2);
3157 DCHECK(value.IsFpuRegister());
3158 if (index.IsConstant()) {
3159 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3160 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3161 } else {
3162 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3163 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3164 }
3165 break;
3166 }
3167
3168 case Primitive::kPrimDouble: {
3169 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3170 Location value = locations->InAt(2);
3171 DCHECK(value.IsFpuRegisterPair());
3172 if (index.IsConstant()) {
3173 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3174 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3175 } else {
3176 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3177 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3178 }
3179 break;
3180 }
3181
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003182 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003183 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003184 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003185 }
3186}
3187
3188void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003189 LocationSummary* locations =
3190 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003191 locations->SetInAt(0, Location::RequiresRegister());
3192 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003193}
3194
3195void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3196 LocationSummary* locations = instruction->GetLocations();
3197 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003198 Register obj = locations->InAt(0).AsRegister<Register>();
3199 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003200 __ LoadFromOffset(kLoadWord, out, obj, offset);
3201}
3202
3203void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003204 LocationSummary* locations =
3205 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003206 locations->SetInAt(0, Location::RequiresRegister());
3207 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003208 if (instruction->HasUses()) {
3209 locations->SetOut(Location::SameAsFirstInput());
3210 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003211}
3212
3213void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3214 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003215 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003216 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003217 codegen_->AddSlowPath(slow_path);
3218
Roland Levillain271ab9c2014-11-27 15:23:57 +00003219 Register index = locations->InAt(0).AsRegister<Register>();
3220 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003221
3222 __ cmp(index, ShifterOperand(length));
3223 __ b(slow_path->GetEntryLabel(), CS);
3224}
3225
3226void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3227 Label is_null;
3228 __ CompareAndBranchIfZero(value, &is_null);
3229 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3230 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3231 __ strb(card, Address(card, temp));
3232 __ Bind(&is_null);
3233}
3234
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003235void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3236 temp->SetLocations(nullptr);
3237}
3238
3239void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3240 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003241 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003242}
3243
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003244void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003245 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003246 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003247}
3248
3249void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003250 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3251}
3252
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003253void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3254 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3255}
3256
3257void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003258 HBasicBlock* block = instruction->GetBlock();
3259 if (block->GetLoopInformation() != nullptr) {
3260 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3261 // The back edge will generate the suspend check.
3262 return;
3263 }
3264 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3265 // The goto will generate the suspend check.
3266 return;
3267 }
3268 GenerateSuspendCheck(instruction, nullptr);
3269}
3270
3271void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3272 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003273 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003274 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003275 codegen_->AddSlowPath(slow_path);
3276
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003277 __ LoadFromOffset(
3278 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3279 __ cmp(IP, ShifterOperand(0));
3280 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003281 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003282 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003283 __ Bind(slow_path->GetReturnLabel());
3284 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003285 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003286 __ b(slow_path->GetEntryLabel());
3287 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003288}
3289
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003290ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3291 return codegen_->GetAssembler();
3292}
3293
3294void ParallelMoveResolverARM::EmitMove(size_t index) {
3295 MoveOperands* move = moves_.Get(index);
3296 Location source = move->GetSource();
3297 Location destination = move->GetDestination();
3298
3299 if (source.IsRegister()) {
3300 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003301 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003302 } else {
3303 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003304 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003305 SP, destination.GetStackIndex());
3306 }
3307 } else if (source.IsStackSlot()) {
3308 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003309 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003310 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003311 } else if (destination.IsFpuRegister()) {
3312 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003313 } else {
3314 DCHECK(destination.IsStackSlot());
3315 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3316 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3317 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003318 } else if (source.IsFpuRegister()) {
3319 if (destination.IsFpuRegister()) {
3320 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003321 } else {
3322 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003323 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3324 }
3325 } else if (source.IsFpuRegisterPair()) {
3326 if (destination.IsFpuRegisterPair()) {
3327 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3328 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3329 } else {
3330 DCHECK(destination.IsDoubleStackSlot()) << destination;
3331 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3332 SP, destination.GetStackIndex());
3333 }
3334 } else if (source.IsDoubleStackSlot()) {
3335 if (destination.IsFpuRegisterPair()) {
3336 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3337 SP, source.GetStackIndex());
3338 } else {
3339 DCHECK(destination.IsDoubleStackSlot()) << destination;
3340 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003341 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003342 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3343 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3344 }
3345 } else {
3346 DCHECK(source.IsConstant()) << source;
3347 HInstruction* constant = source.GetConstant();
3348 if (constant->IsIntConstant()) {
3349 int32_t value = constant->AsIntConstant()->GetValue();
3350 if (destination.IsRegister()) {
3351 __ LoadImmediate(destination.AsRegister<Register>(), value);
3352 } else {
3353 DCHECK(destination.IsStackSlot());
3354 __ LoadImmediate(IP, value);
3355 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3356 }
3357 } else {
3358 DCHECK(constant->IsFloatConstant());
3359 float value = constant->AsFloatConstant()->GetValue();
3360 if (destination.IsFpuRegister()) {
3361 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3362 } else {
3363 DCHECK(destination.IsStackSlot());
3364 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3365 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3366 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003367 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003368 }
3369}
3370
3371void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3372 __ Mov(IP, reg);
3373 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3374 __ StoreToOffset(kStoreWord, IP, SP, mem);
3375}
3376
3377void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3378 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3379 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3380 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3381 SP, mem1 + stack_offset);
3382 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3383 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3384 SP, mem2 + stack_offset);
3385 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3386}
3387
3388void ParallelMoveResolverARM::EmitSwap(size_t index) {
3389 MoveOperands* move = moves_.Get(index);
3390 Location source = move->GetSource();
3391 Location destination = move->GetDestination();
3392
3393 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003394 DCHECK_NE(source.AsRegister<Register>(), IP);
3395 DCHECK_NE(destination.AsRegister<Register>(), IP);
3396 __ Mov(IP, source.AsRegister<Register>());
3397 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3398 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003399 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003400 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003401 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003402 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003403 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3404 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003405 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
3406 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
3407 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
3408 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
3409 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3410 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3411 : destination.AsFpuRegister<SRegister>();
3412 int mem = source.IsFpuRegister()
3413 ? destination.GetStackIndex()
3414 : source.GetStackIndex();
3415
3416 __ vmovrs(IP, reg);
3417 __ LoadSFromOffset(reg, SP, mem);
3418 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003419 } else {
3420 LOG(FATAL) << "Unimplemented";
3421 }
3422}
3423
3424void ParallelMoveResolverARM::SpillScratch(int reg) {
3425 __ Push(static_cast<Register>(reg));
3426}
3427
3428void ParallelMoveResolverARM::RestoreScratch(int reg) {
3429 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003430}
3431
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003432void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003433 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3434 ? LocationSummary::kCallOnSlowPath
3435 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003436 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003437 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003438 locations->SetOut(Location::RequiresRegister());
3439}
3440
3441void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003442 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003443 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003444 DCHECK(!cls->CanCallRuntime());
3445 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003446 codegen_->LoadCurrentMethod(out);
3447 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3448 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003449 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003450 codegen_->LoadCurrentMethod(out);
3451 __ LoadFromOffset(
3452 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3453 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003454
3455 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3456 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3457 codegen_->AddSlowPath(slow_path);
3458 __ cmp(out, ShifterOperand(0));
3459 __ b(slow_path->GetEntryLabel(), EQ);
3460 if (cls->MustGenerateClinitCheck()) {
3461 GenerateClassInitializationCheck(slow_path, out);
3462 } else {
3463 __ Bind(slow_path->GetExitLabel());
3464 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003465 }
3466}
3467
3468void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3469 LocationSummary* locations =
3470 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3471 locations->SetInAt(0, Location::RequiresRegister());
3472 if (check->HasUses()) {
3473 locations->SetOut(Location::SameAsFirstInput());
3474 }
3475}
3476
3477void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003478 // We assume the class is not null.
3479 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3480 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003481 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003482 GenerateClassInitializationCheck(slow_path,
3483 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003484}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003485
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003486void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3487 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003488 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3489 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3490 __ b(slow_path->GetEntryLabel(), LT);
3491 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3492 // properly. Therefore, we do a memory fence.
3493 __ dmb(ISH);
3494 __ Bind(slow_path->GetExitLabel());
3495}
3496
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003497void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3498 LocationSummary* locations =
3499 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3500 locations->SetOut(Location::RequiresRegister());
3501}
3502
3503void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3504 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3505 codegen_->AddSlowPath(slow_path);
3506
Roland Levillain271ab9c2014-11-27 15:23:57 +00003507 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003508 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003509 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3510 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003511 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3512 __ cmp(out, ShifterOperand(0));
3513 __ b(slow_path->GetEntryLabel(), EQ);
3514 __ Bind(slow_path->GetExitLabel());
3515}
3516
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003517void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3518 LocationSummary* locations =
3519 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3520 locations->SetOut(Location::RequiresRegister());
3521}
3522
3523void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003524 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003525 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3526 __ LoadFromOffset(kLoadWord, out, TR, offset);
3527 __ LoadImmediate(IP, 0);
3528 __ StoreToOffset(kStoreWord, IP, TR, offset);
3529}
3530
3531void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3532 LocationSummary* locations =
3533 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3534 InvokeRuntimeCallingConvention calling_convention;
3535 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3536}
3537
3538void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3539 codegen_->InvokeRuntime(
3540 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3541}
3542
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003543void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003544 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3545 ? LocationSummary::kNoCall
3546 : LocationSummary::kCallOnSlowPath;
3547 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3548 locations->SetInAt(0, Location::RequiresRegister());
3549 locations->SetInAt(1, Location::RequiresRegister());
3550 locations->SetOut(Location::RequiresRegister());
3551}
3552
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003553void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003554 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003555 Register obj = locations->InAt(0).AsRegister<Register>();
3556 Register cls = locations->InAt(1).AsRegister<Register>();
3557 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003558 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3559 Label done, zero;
3560 SlowPathCodeARM* slow_path = nullptr;
3561
3562 // Return 0 if `obj` is null.
3563 // TODO: avoid this check if we know obj is not null.
3564 __ cmp(obj, ShifterOperand(0));
3565 __ b(&zero, EQ);
3566 // Compare the class of `obj` with `cls`.
3567 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3568 __ cmp(out, ShifterOperand(cls));
3569 if (instruction->IsClassFinal()) {
3570 // Classes must be equal for the instanceof to succeed.
3571 __ b(&zero, NE);
3572 __ LoadImmediate(out, 1);
3573 __ b(&done);
3574 } else {
3575 // If the classes are not equal, we go into a slow path.
3576 DCHECK(locations->OnlyCallsOnSlowPath());
3577 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003578 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003579 codegen_->AddSlowPath(slow_path);
3580 __ b(slow_path->GetEntryLabel(), NE);
3581 __ LoadImmediate(out, 1);
3582 __ b(&done);
3583 }
3584 __ Bind(&zero);
3585 __ LoadImmediate(out, 0);
3586 if (slow_path != nullptr) {
3587 __ Bind(slow_path->GetExitLabel());
3588 }
3589 __ Bind(&done);
3590}
3591
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003592void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3593 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3594 instruction, LocationSummary::kCallOnSlowPath);
3595 locations->SetInAt(0, Location::RequiresRegister());
3596 locations->SetInAt(1, Location::RequiresRegister());
3597 locations->AddTemp(Location::RequiresRegister());
3598}
3599
3600void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3601 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003602 Register obj = locations->InAt(0).AsRegister<Register>();
3603 Register cls = locations->InAt(1).AsRegister<Register>();
3604 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003605 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3606
3607 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3608 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3609 codegen_->AddSlowPath(slow_path);
3610
3611 // TODO: avoid this check if we know obj is not null.
3612 __ cmp(obj, ShifterOperand(0));
3613 __ b(slow_path->GetExitLabel(), EQ);
3614 // Compare the class of `obj` with `cls`.
3615 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3616 __ cmp(temp, ShifterOperand(cls));
3617 __ b(slow_path->GetEntryLabel(), NE);
3618 __ Bind(slow_path->GetExitLabel());
3619}
3620
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003621void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3622 LocationSummary* locations =
3623 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3624 InvokeRuntimeCallingConvention calling_convention;
3625 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3626}
3627
3628void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3629 codegen_->InvokeRuntime(instruction->IsEnter()
3630 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3631 instruction,
3632 instruction->GetDexPc());
3633}
3634
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003635void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3636void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3637void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3638
3639void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3640 LocationSummary* locations =
3641 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3642 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3643 || instruction->GetResultType() == Primitive::kPrimLong);
3644 locations->SetInAt(0, Location::RequiresRegister());
3645 locations->SetInAt(1, Location::RequiresRegister());
3646 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3647 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3648}
3649
3650void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3651 HandleBitwiseOperation(instruction);
3652}
3653
3654void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3655 HandleBitwiseOperation(instruction);
3656}
3657
3658void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3659 HandleBitwiseOperation(instruction);
3660}
3661
3662void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3663 LocationSummary* locations = instruction->GetLocations();
3664
3665 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003666 Register first = locations->InAt(0).AsRegister<Register>();
3667 Register second = locations->InAt(1).AsRegister<Register>();
3668 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003669 if (instruction->IsAnd()) {
3670 __ and_(out, first, ShifterOperand(second));
3671 } else if (instruction->IsOr()) {
3672 __ orr(out, first, ShifterOperand(second));
3673 } else {
3674 DCHECK(instruction->IsXor());
3675 __ eor(out, first, ShifterOperand(second));
3676 }
3677 } else {
3678 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3679 Location first = locations->InAt(0);
3680 Location second = locations->InAt(1);
3681 Location out = locations->Out();
3682 if (instruction->IsAnd()) {
3683 __ and_(out.AsRegisterPairLow<Register>(),
3684 first.AsRegisterPairLow<Register>(),
3685 ShifterOperand(second.AsRegisterPairLow<Register>()));
3686 __ and_(out.AsRegisterPairHigh<Register>(),
3687 first.AsRegisterPairHigh<Register>(),
3688 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3689 } else if (instruction->IsOr()) {
3690 __ orr(out.AsRegisterPairLow<Register>(),
3691 first.AsRegisterPairLow<Register>(),
3692 ShifterOperand(second.AsRegisterPairLow<Register>()));
3693 __ orr(out.AsRegisterPairHigh<Register>(),
3694 first.AsRegisterPairHigh<Register>(),
3695 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3696 } else {
3697 DCHECK(instruction->IsXor());
3698 __ eor(out.AsRegisterPairLow<Register>(),
3699 first.AsRegisterPairLow<Register>(),
3700 ShifterOperand(second.AsRegisterPairLow<Register>()));
3701 __ eor(out.AsRegisterPairHigh<Register>(),
3702 first.AsRegisterPairHigh<Register>(),
3703 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3704 }
3705 }
3706}
3707
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003708} // namespace arm
3709} // namespace art