blob: 63f5f94e7e17bcf71c8384f4795debec015b2407 [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);
2599 __ add(addr, addr, ShifterOperand(out_lo));
2600 }
2601 __ ldrexd(out_lo, out_hi, addr);
2602}
2603
2604void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2605 uint32_t offset,
2606 Register value_lo,
2607 Register value_hi,
2608 Register temp1,
2609 Register temp2) {
2610 Label fail;
2611 if (offset != 0) {
2612 __ LoadImmediate(temp1, offset);
2613 __ add(addr, addr, ShifterOperand(temp1));
2614 }
2615 __ Bind(&fail);
2616 // We need a load followed by store. (The address used in a STREX instruction must
2617 // be the same as the address in the most recently executed LDREX instruction.)
2618 __ ldrexd(temp1, temp2, addr);
2619 __ strexd(temp1, value_lo, value_hi, addr);
2620 __ cmp(temp1, ShifterOperand(0));
2621 __ b(&fail, NE);
2622}
2623
2624void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2625 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2626
Nicolas Geoffray39468442014-09-02 15:17:15 +01002627 LocationSummary* locations =
2628 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002629 locations->SetInAt(0, Location::RequiresRegister());
2630 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002631
Calin Juravle34166012014-12-19 17:22:29 +00002632
Calin Juravle52c48962014-12-16 17:02:57 +00002633 Primitive::Type field_type = field_info.GetFieldType();
2634 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002635 bool generate_volatile = field_info.IsVolatile()
2636 && is_wide
2637 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002638 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002639 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2640 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002641 locations->AddTemp(Location::RequiresRegister());
2642 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002643 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002644 // Arm encoding have some additional constraints for ldrexd/strexd:
2645 // - registers need to be consecutive
2646 // - the first register should be even but not R14.
2647 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2648 // enable Arm encoding.
2649 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2650
2651 locations->AddTemp(Location::RequiresRegister());
2652 locations->AddTemp(Location::RequiresRegister());
2653 if (field_type == Primitive::kPrimDouble) {
2654 // For doubles we need two more registers to copy the value.
2655 locations->AddTemp(Location::RegisterLocation(R2));
2656 locations->AddTemp(Location::RegisterLocation(R3));
2657 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002658 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002659}
2660
Calin Juravle52c48962014-12-16 17:02:57 +00002661void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2662 const FieldInfo& field_info) {
2663 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2664
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002665 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002666 Register base = locations->InAt(0).AsRegister<Register>();
2667 Location value = locations->InAt(1);
2668
2669 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002670 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002671 Primitive::Type field_type = field_info.GetFieldType();
2672 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2673
2674 if (is_volatile) {
2675 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2676 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002677
2678 switch (field_type) {
2679 case Primitive::kPrimBoolean:
2680 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002681 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002682 break;
2683 }
2684
2685 case Primitive::kPrimShort:
2686 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002687 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002688 break;
2689 }
2690
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002691 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002692 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002693 Register value_reg = value.AsRegister<Register>();
2694 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2695 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002696 Register temp = locations->GetTemp(0).AsRegister<Register>();
2697 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002698 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002699 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002700 break;
2701 }
2702
2703 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002704 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002705 GenerateWideAtomicStore(base, offset,
2706 value.AsRegisterPairLow<Register>(),
2707 value.AsRegisterPairHigh<Register>(),
2708 locations->GetTemp(0).AsRegister<Register>(),
2709 locations->GetTemp(1).AsRegister<Register>());
2710 } else {
2711 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2712 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002713 break;
2714 }
2715
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002716 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002717 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002718 break;
2719 }
2720
2721 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002722 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002723 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002724 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2725 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2726
2727 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2728
2729 GenerateWideAtomicStore(base, offset,
2730 value_reg_lo,
2731 value_reg_hi,
2732 locations->GetTemp(2).AsRegister<Register>(),
2733 locations->GetTemp(3).AsRegister<Register>());
2734 } else {
2735 __ StoreDToOffset(value_reg, base, offset);
2736 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002737 break;
2738 }
2739
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002740 case Primitive::kPrimVoid:
2741 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002742 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002743 }
Calin Juravle52c48962014-12-16 17:02:57 +00002744
2745 if (is_volatile) {
2746 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2747 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002748}
2749
Calin Juravle52c48962014-12-16 17:02:57 +00002750void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2751 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002752 LocationSummary* locations =
2753 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002754 locations->SetInAt(0, Location::RequiresRegister());
2755 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002756
Calin Juravle34166012014-12-19 17:22:29 +00002757 bool generate_volatile = field_info.IsVolatile()
2758 && (field_info.GetFieldType() == Primitive::kPrimDouble)
2759 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
2760 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002761 // Arm encoding have some additional constraints for ldrexd/strexd:
2762 // - registers need to be consecutive
2763 // - the first register should be even but not R14.
2764 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2765 // enable Arm encoding.
2766 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2767 locations->AddTemp(Location::RequiresRegister());
2768 locations->AddTemp(Location::RequiresRegister());
2769 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002770}
2771
Calin Juravle52c48962014-12-16 17:02:57 +00002772void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2773 const FieldInfo& field_info) {
2774 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002775
Calin Juravle52c48962014-12-16 17:02:57 +00002776 LocationSummary* locations = instruction->GetLocations();
2777 Register base = locations->InAt(0).AsRegister<Register>();
2778 Location out = locations->Out();
2779 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002780 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002781 Primitive::Type field_type = field_info.GetFieldType();
2782 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2783
2784 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002785 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002786 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002787 break;
2788 }
2789
2790 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002791 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002792 break;
2793 }
2794
2795 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002796 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002797 break;
2798 }
2799
2800 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002801 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002802 break;
2803 }
2804
2805 case Primitive::kPrimInt:
2806 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002807 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002808 break;
2809 }
2810
2811 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002812 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002813 GenerateWideAtomicLoad(base, offset,
2814 out.AsRegisterPairLow<Register>(),
2815 out.AsRegisterPairHigh<Register>());
2816 } else {
2817 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2818 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002819 break;
2820 }
2821
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002822 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002823 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002824 break;
2825 }
2826
2827 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002828 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002829 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002830 Register lo = locations->GetTemp(0).AsRegister<Register>();
2831 Register hi = locations->GetTemp(1).AsRegister<Register>();
2832 GenerateWideAtomicLoad(base, offset, lo, hi);
2833 __ vmovdrr(out_reg, lo, hi);
2834 } else {
2835 __ LoadDFromOffset(out_reg, base, offset);
2836 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002837 break;
2838 }
2839
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002840 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002841 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002842 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002843 }
Calin Juravle52c48962014-12-16 17:02:57 +00002844
2845 if (is_volatile) {
2846 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2847 }
2848}
2849
2850void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2851 HandleFieldSet(instruction, instruction->GetFieldInfo());
2852}
2853
2854void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2855 HandleFieldSet(instruction, instruction->GetFieldInfo());
2856}
2857
2858void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2859 HandleFieldGet(instruction, instruction->GetFieldInfo());
2860}
2861
2862void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2863 HandleFieldGet(instruction, instruction->GetFieldInfo());
2864}
2865
2866void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2867 HandleFieldGet(instruction, instruction->GetFieldInfo());
2868}
2869
2870void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2871 HandleFieldGet(instruction, instruction->GetFieldInfo());
2872}
2873
2874void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2875 HandleFieldSet(instruction, instruction->GetFieldInfo());
2876}
2877
2878void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2879 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002880}
2881
2882void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002883 LocationSummary* locations =
2884 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002885 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002886 if (instruction->HasUses()) {
2887 locations->SetOut(Location::SameAsFirstInput());
2888 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002889}
2890
2891void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002892 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002893 codegen_->AddSlowPath(slow_path);
2894
2895 LocationSummary* locations = instruction->GetLocations();
2896 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002897
2898 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002899 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002900 __ b(slow_path->GetEntryLabel(), EQ);
2901 } else {
2902 DCHECK(obj.IsConstant()) << obj;
2903 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2904 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002905 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002906}
2907
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002908void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002909 LocationSummary* locations =
2910 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002911 locations->SetInAt(0, Location::RequiresRegister());
2912 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2913 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002914}
2915
2916void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2917 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002918 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002919 Location index = locations->InAt(1);
2920
2921 switch (instruction->GetType()) {
2922 case Primitive::kPrimBoolean: {
2923 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002924 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002925 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002926 size_t offset =
2927 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002928 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2929 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002930 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002931 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2932 }
2933 break;
2934 }
2935
2936 case Primitive::kPrimByte: {
2937 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002938 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002939 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002940 size_t offset =
2941 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002942 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2943 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002944 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002945 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2946 }
2947 break;
2948 }
2949
2950 case Primitive::kPrimShort: {
2951 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002952 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002953 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002954 size_t offset =
2955 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002956 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2957 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002958 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002959 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2960 }
2961 break;
2962 }
2963
2964 case Primitive::kPrimChar: {
2965 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002966 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002967 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002968 size_t offset =
2969 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002970 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2971 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002972 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002973 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2974 }
2975 break;
2976 }
2977
2978 case Primitive::kPrimInt:
2979 case Primitive::kPrimNot: {
2980 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2981 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002982 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002983 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002984 size_t offset =
2985 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002986 __ LoadFromOffset(kLoadWord, out, obj, offset);
2987 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002988 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002989 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2990 }
2991 break;
2992 }
2993
2994 case Primitive::kPrimLong: {
2995 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002996 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002997 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002998 size_t offset =
2999 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003000 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003001 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003002 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003003 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003004 }
3005 break;
3006 }
3007
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003008 case Primitive::kPrimFloat: {
3009 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3010 Location out = locations->Out();
3011 DCHECK(out.IsFpuRegister());
3012 if (index.IsConstant()) {
3013 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3014 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3015 } else {
3016 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3017 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3018 }
3019 break;
3020 }
3021
3022 case Primitive::kPrimDouble: {
3023 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3024 Location out = locations->Out();
3025 DCHECK(out.IsFpuRegisterPair());
3026 if (index.IsConstant()) {
3027 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3028 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3029 } else {
3030 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3031 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3032 }
3033 break;
3034 }
3035
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003036 case Primitive::kPrimVoid:
3037 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003038 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003039 }
3040}
3041
3042void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003043 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003044
3045 bool needs_write_barrier =
3046 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3047 bool needs_runtime_call = instruction->NeedsTypeCheck();
3048
Nicolas Geoffray39468442014-09-02 15:17:15 +01003049 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003050 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3051 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003052 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003053 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3054 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3055 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003056 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003057 locations->SetInAt(0, Location::RequiresRegister());
3058 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3059 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003060
3061 if (needs_write_barrier) {
3062 // Temporary registers for the write barrier.
3063 locations->AddTemp(Location::RequiresRegister());
3064 locations->AddTemp(Location::RequiresRegister());
3065 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003066 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003067}
3068
3069void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3070 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003071 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003072 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003073 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003074 bool needs_runtime_call = locations->WillCall();
3075 bool needs_write_barrier =
3076 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003077
3078 switch (value_type) {
3079 case Primitive::kPrimBoolean:
3080 case Primitive::kPrimByte: {
3081 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003082 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003083 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003084 size_t offset =
3085 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003086 __ StoreToOffset(kStoreByte, value, obj, offset);
3087 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003088 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003089 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3090 }
3091 break;
3092 }
3093
3094 case Primitive::kPrimShort:
3095 case Primitive::kPrimChar: {
3096 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003097 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003098 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003099 size_t offset =
3100 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003101 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3102 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003103 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003104 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3105 }
3106 break;
3107 }
3108
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003109 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003110 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003111 if (!needs_runtime_call) {
3112 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003113 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003114 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003115 size_t offset =
3116 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003117 __ StoreToOffset(kStoreWord, value, obj, offset);
3118 } else {
3119 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003120 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003121 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3122 }
3123 if (needs_write_barrier) {
3124 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003125 Register temp = locations->GetTemp(0).AsRegister<Register>();
3126 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003127 codegen_->MarkGCCard(temp, card, obj, value);
3128 }
3129 } else {
3130 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003131 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3132 instruction,
3133 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003134 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003135 break;
3136 }
3137
3138 case Primitive::kPrimLong: {
3139 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003140 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003141 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003142 size_t offset =
3143 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003144 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003145 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003146 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003147 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003148 }
3149 break;
3150 }
3151
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003152 case Primitive::kPrimFloat: {
3153 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3154 Location value = locations->InAt(2);
3155 DCHECK(value.IsFpuRegister());
3156 if (index.IsConstant()) {
3157 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3158 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3159 } else {
3160 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3161 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3162 }
3163 break;
3164 }
3165
3166 case Primitive::kPrimDouble: {
3167 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3168 Location value = locations->InAt(2);
3169 DCHECK(value.IsFpuRegisterPair());
3170 if (index.IsConstant()) {
3171 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3172 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3173 } else {
3174 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3175 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3176 }
3177 break;
3178 }
3179
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003180 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003181 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003182 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003183 }
3184}
3185
3186void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003187 LocationSummary* locations =
3188 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003189 locations->SetInAt(0, Location::RequiresRegister());
3190 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003191}
3192
3193void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3194 LocationSummary* locations = instruction->GetLocations();
3195 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003196 Register obj = locations->InAt(0).AsRegister<Register>();
3197 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003198 __ LoadFromOffset(kLoadWord, out, obj, offset);
3199}
3200
3201void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003202 LocationSummary* locations =
3203 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003204 locations->SetInAt(0, Location::RequiresRegister());
3205 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003206 if (instruction->HasUses()) {
3207 locations->SetOut(Location::SameAsFirstInput());
3208 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003209}
3210
3211void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3212 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003213 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003214 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003215 codegen_->AddSlowPath(slow_path);
3216
Roland Levillain271ab9c2014-11-27 15:23:57 +00003217 Register index = locations->InAt(0).AsRegister<Register>();
3218 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003219
3220 __ cmp(index, ShifterOperand(length));
3221 __ b(slow_path->GetEntryLabel(), CS);
3222}
3223
3224void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3225 Label is_null;
3226 __ CompareAndBranchIfZero(value, &is_null);
3227 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3228 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3229 __ strb(card, Address(card, temp));
3230 __ Bind(&is_null);
3231}
3232
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003233void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3234 temp->SetLocations(nullptr);
3235}
3236
3237void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3238 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003239 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003240}
3241
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003242void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003243 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003244 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003245}
3246
3247void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003248 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3249}
3250
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003251void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3252 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3253}
3254
3255void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003256 HBasicBlock* block = instruction->GetBlock();
3257 if (block->GetLoopInformation() != nullptr) {
3258 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3259 // The back edge will generate the suspend check.
3260 return;
3261 }
3262 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3263 // The goto will generate the suspend check.
3264 return;
3265 }
3266 GenerateSuspendCheck(instruction, nullptr);
3267}
3268
3269void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3270 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003271 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003272 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003273 codegen_->AddSlowPath(slow_path);
3274
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003275 __ LoadFromOffset(
3276 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3277 __ cmp(IP, ShifterOperand(0));
3278 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003279 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003280 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003281 __ Bind(slow_path->GetReturnLabel());
3282 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003283 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003284 __ b(slow_path->GetEntryLabel());
3285 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003286}
3287
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003288ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3289 return codegen_->GetAssembler();
3290}
3291
3292void ParallelMoveResolverARM::EmitMove(size_t index) {
3293 MoveOperands* move = moves_.Get(index);
3294 Location source = move->GetSource();
3295 Location destination = move->GetDestination();
3296
3297 if (source.IsRegister()) {
3298 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003299 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003300 } else {
3301 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003302 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003303 SP, destination.GetStackIndex());
3304 }
3305 } else if (source.IsStackSlot()) {
3306 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003307 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003308 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003309 } else if (destination.IsFpuRegister()) {
3310 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003311 } else {
3312 DCHECK(destination.IsStackSlot());
3313 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3314 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3315 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003316 } else if (source.IsFpuRegister()) {
3317 if (destination.IsFpuRegister()) {
3318 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003319 } else {
3320 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003321 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3322 }
3323 } else if (source.IsFpuRegisterPair()) {
3324 if (destination.IsFpuRegisterPair()) {
3325 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3326 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3327 } else {
3328 DCHECK(destination.IsDoubleStackSlot()) << destination;
3329 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3330 SP, destination.GetStackIndex());
3331 }
3332 } else if (source.IsDoubleStackSlot()) {
3333 if (destination.IsFpuRegisterPair()) {
3334 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3335 SP, source.GetStackIndex());
3336 } else {
3337 DCHECK(destination.IsDoubleStackSlot()) << destination;
3338 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003339 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003340 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3341 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3342 }
3343 } else {
3344 DCHECK(source.IsConstant()) << source;
3345 HInstruction* constant = source.GetConstant();
3346 if (constant->IsIntConstant()) {
3347 int32_t value = constant->AsIntConstant()->GetValue();
3348 if (destination.IsRegister()) {
3349 __ LoadImmediate(destination.AsRegister<Register>(), value);
3350 } else {
3351 DCHECK(destination.IsStackSlot());
3352 __ LoadImmediate(IP, value);
3353 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3354 }
3355 } else {
3356 DCHECK(constant->IsFloatConstant());
3357 float value = constant->AsFloatConstant()->GetValue();
3358 if (destination.IsFpuRegister()) {
3359 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3360 } else {
3361 DCHECK(destination.IsStackSlot());
3362 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3363 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3364 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003365 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003366 }
3367}
3368
3369void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3370 __ Mov(IP, reg);
3371 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3372 __ StoreToOffset(kStoreWord, IP, SP, mem);
3373}
3374
3375void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3376 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3377 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3378 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3379 SP, mem1 + stack_offset);
3380 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3381 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3382 SP, mem2 + stack_offset);
3383 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3384}
3385
3386void ParallelMoveResolverARM::EmitSwap(size_t index) {
3387 MoveOperands* move = moves_.Get(index);
3388 Location source = move->GetSource();
3389 Location destination = move->GetDestination();
3390
3391 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003392 DCHECK_NE(source.AsRegister<Register>(), IP);
3393 DCHECK_NE(destination.AsRegister<Register>(), IP);
3394 __ Mov(IP, source.AsRegister<Register>());
3395 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3396 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003397 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003398 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003399 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003400 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003401 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3402 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003403 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
3404 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
3405 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
3406 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
3407 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3408 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3409 : destination.AsFpuRegister<SRegister>();
3410 int mem = source.IsFpuRegister()
3411 ? destination.GetStackIndex()
3412 : source.GetStackIndex();
3413
3414 __ vmovrs(IP, reg);
3415 __ LoadSFromOffset(reg, SP, mem);
3416 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003417 } else {
3418 LOG(FATAL) << "Unimplemented";
3419 }
3420}
3421
3422void ParallelMoveResolverARM::SpillScratch(int reg) {
3423 __ Push(static_cast<Register>(reg));
3424}
3425
3426void ParallelMoveResolverARM::RestoreScratch(int reg) {
3427 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003428}
3429
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003430void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003431 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3432 ? LocationSummary::kCallOnSlowPath
3433 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003434 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003435 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003436 locations->SetOut(Location::RequiresRegister());
3437}
3438
3439void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003440 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003441 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003442 DCHECK(!cls->CanCallRuntime());
3443 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003444 codegen_->LoadCurrentMethod(out);
3445 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3446 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003447 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003448 codegen_->LoadCurrentMethod(out);
3449 __ LoadFromOffset(
3450 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3451 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003452
3453 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3454 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3455 codegen_->AddSlowPath(slow_path);
3456 __ cmp(out, ShifterOperand(0));
3457 __ b(slow_path->GetEntryLabel(), EQ);
3458 if (cls->MustGenerateClinitCheck()) {
3459 GenerateClassInitializationCheck(slow_path, out);
3460 } else {
3461 __ Bind(slow_path->GetExitLabel());
3462 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003463 }
3464}
3465
3466void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3467 LocationSummary* locations =
3468 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3469 locations->SetInAt(0, Location::RequiresRegister());
3470 if (check->HasUses()) {
3471 locations->SetOut(Location::SameAsFirstInput());
3472 }
3473}
3474
3475void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003476 // We assume the class is not null.
3477 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3478 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003479 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003480 GenerateClassInitializationCheck(slow_path,
3481 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003482}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003483
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003484void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3485 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003486 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3487 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3488 __ b(slow_path->GetEntryLabel(), LT);
3489 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3490 // properly. Therefore, we do a memory fence.
3491 __ dmb(ISH);
3492 __ Bind(slow_path->GetExitLabel());
3493}
3494
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003495void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3496 LocationSummary* locations =
3497 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3498 locations->SetOut(Location::RequiresRegister());
3499}
3500
3501void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3502 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3503 codegen_->AddSlowPath(slow_path);
3504
Roland Levillain271ab9c2014-11-27 15:23:57 +00003505 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003506 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003507 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3508 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003509 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3510 __ cmp(out, ShifterOperand(0));
3511 __ b(slow_path->GetEntryLabel(), EQ);
3512 __ Bind(slow_path->GetExitLabel());
3513}
3514
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003515void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3516 LocationSummary* locations =
3517 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3518 locations->SetOut(Location::RequiresRegister());
3519}
3520
3521void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003522 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003523 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3524 __ LoadFromOffset(kLoadWord, out, TR, offset);
3525 __ LoadImmediate(IP, 0);
3526 __ StoreToOffset(kStoreWord, IP, TR, offset);
3527}
3528
3529void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3530 LocationSummary* locations =
3531 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3532 InvokeRuntimeCallingConvention calling_convention;
3533 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3534}
3535
3536void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3537 codegen_->InvokeRuntime(
3538 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3539}
3540
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003541void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003542 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3543 ? LocationSummary::kNoCall
3544 : LocationSummary::kCallOnSlowPath;
3545 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3546 locations->SetInAt(0, Location::RequiresRegister());
3547 locations->SetInAt(1, Location::RequiresRegister());
3548 locations->SetOut(Location::RequiresRegister());
3549}
3550
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003551void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003552 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003553 Register obj = locations->InAt(0).AsRegister<Register>();
3554 Register cls = locations->InAt(1).AsRegister<Register>();
3555 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003556 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3557 Label done, zero;
3558 SlowPathCodeARM* slow_path = nullptr;
3559
3560 // Return 0 if `obj` is null.
3561 // TODO: avoid this check if we know obj is not null.
3562 __ cmp(obj, ShifterOperand(0));
3563 __ b(&zero, EQ);
3564 // Compare the class of `obj` with `cls`.
3565 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3566 __ cmp(out, ShifterOperand(cls));
3567 if (instruction->IsClassFinal()) {
3568 // Classes must be equal for the instanceof to succeed.
3569 __ b(&zero, NE);
3570 __ LoadImmediate(out, 1);
3571 __ b(&done);
3572 } else {
3573 // If the classes are not equal, we go into a slow path.
3574 DCHECK(locations->OnlyCallsOnSlowPath());
3575 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003576 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003577 codegen_->AddSlowPath(slow_path);
3578 __ b(slow_path->GetEntryLabel(), NE);
3579 __ LoadImmediate(out, 1);
3580 __ b(&done);
3581 }
3582 __ Bind(&zero);
3583 __ LoadImmediate(out, 0);
3584 if (slow_path != nullptr) {
3585 __ Bind(slow_path->GetExitLabel());
3586 }
3587 __ Bind(&done);
3588}
3589
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003590void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3591 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3592 instruction, LocationSummary::kCallOnSlowPath);
3593 locations->SetInAt(0, Location::RequiresRegister());
3594 locations->SetInAt(1, Location::RequiresRegister());
3595 locations->AddTemp(Location::RequiresRegister());
3596}
3597
3598void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3599 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003600 Register obj = locations->InAt(0).AsRegister<Register>();
3601 Register cls = locations->InAt(1).AsRegister<Register>();
3602 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003603 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3604
3605 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3606 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3607 codegen_->AddSlowPath(slow_path);
3608
3609 // TODO: avoid this check if we know obj is not null.
3610 __ cmp(obj, ShifterOperand(0));
3611 __ b(slow_path->GetExitLabel(), EQ);
3612 // Compare the class of `obj` with `cls`.
3613 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3614 __ cmp(temp, ShifterOperand(cls));
3615 __ b(slow_path->GetEntryLabel(), NE);
3616 __ Bind(slow_path->GetExitLabel());
3617}
3618
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003619void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3620 LocationSummary* locations =
3621 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3622 InvokeRuntimeCallingConvention calling_convention;
3623 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3624}
3625
3626void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3627 codegen_->InvokeRuntime(instruction->IsEnter()
3628 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3629 instruction,
3630 instruction->GetDexPc());
3631}
3632
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003633void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3634void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3635void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3636
3637void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3638 LocationSummary* locations =
3639 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3640 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3641 || instruction->GetResultType() == Primitive::kPrimLong);
3642 locations->SetInAt(0, Location::RequiresRegister());
3643 locations->SetInAt(1, Location::RequiresRegister());
3644 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3645 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3646}
3647
3648void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3649 HandleBitwiseOperation(instruction);
3650}
3651
3652void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3653 HandleBitwiseOperation(instruction);
3654}
3655
3656void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3657 HandleBitwiseOperation(instruction);
3658}
3659
3660void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3661 LocationSummary* locations = instruction->GetLocations();
3662
3663 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003664 Register first = locations->InAt(0).AsRegister<Register>();
3665 Register second = locations->InAt(1).AsRegister<Register>();
3666 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003667 if (instruction->IsAnd()) {
3668 __ and_(out, first, ShifterOperand(second));
3669 } else if (instruction->IsOr()) {
3670 __ orr(out, first, ShifterOperand(second));
3671 } else {
3672 DCHECK(instruction->IsXor());
3673 __ eor(out, first, ShifterOperand(second));
3674 }
3675 } else {
3676 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3677 Location first = locations->InAt(0);
3678 Location second = locations->InAt(1);
3679 Location out = locations->Out();
3680 if (instruction->IsAnd()) {
3681 __ and_(out.AsRegisterPairLow<Register>(),
3682 first.AsRegisterPairLow<Register>(),
3683 ShifterOperand(second.AsRegisterPairLow<Register>()));
3684 __ and_(out.AsRegisterPairHigh<Register>(),
3685 first.AsRegisterPairHigh<Register>(),
3686 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3687 } else if (instruction->IsOr()) {
3688 __ orr(out.AsRegisterPairLow<Register>(),
3689 first.AsRegisterPairLow<Register>(),
3690 ShifterOperand(second.AsRegisterPairLow<Register>()));
3691 __ orr(out.AsRegisterPairHigh<Register>(),
3692 first.AsRegisterPairHigh<Register>(),
3693 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3694 } else {
3695 DCHECK(instruction->IsXor());
3696 __ eor(out.AsRegisterPairLow<Register>(),
3697 first.AsRegisterPairLow<Register>(),
3698 ShifterOperand(second.AsRegisterPairLow<Register>()));
3699 __ eor(out.AsRegisterPairHigh<Register>(),
3700 first.AsRegisterPairHigh<Register>(),
3701 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3702 }
3703 }
3704}
3705
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003706} // namespace arm
3707} // namespace art