blob: 1ca1cee275e2813611f4b5d4ca883e95246284bc [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,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000387 const ArmInstructionSetFeatures& isa_features,
388 const CompilerOptions& compiler_options)
389 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters,
390 kNumberOfRegisterPairs, compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100391 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100393 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100394 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000395 assembler_(true),
396 isa_features_(isa_features) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100397
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100398size_t CodeGeneratorARM::FrameEntrySpillSize() const {
399 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
400}
401
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100402Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100403 switch (type) {
404 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100405 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100406 ArmManagedRegister pair =
407 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100408 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
409 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
410
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100411 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
412 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100413 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100414 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100415 }
416
417 case Primitive::kPrimByte:
418 case Primitive::kPrimBoolean:
419 case Primitive::kPrimChar:
420 case Primitive::kPrimShort:
421 case Primitive::kPrimInt:
422 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100423 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100424 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100425 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
426 ArmManagedRegister current =
427 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
428 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100429 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100430 }
431 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100432 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100433 }
434
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000435 case Primitive::kPrimFloat: {
436 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100437 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100438 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100439
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000440 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000441 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
442 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000443 return Location::FpuRegisterPairLocation(reg, reg + 1);
444 }
445
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100446 case Primitive::kPrimVoid:
447 LOG(FATAL) << "Unreachable type " << type;
448 }
449
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100450 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100451}
452
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100453void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100454 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100455 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100456
457 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100458 blocked_core_registers_[SP] = true;
459 blocked_core_registers_[LR] = true;
460 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100461
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100462 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100463 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100464
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100465 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100466 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100467
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000468 // TODO: We currently don't use Quick's callee saved registers.
469 // We always save and restore R6 and R7 to make sure we can use three
470 // register pairs for long operations.
471 blocked_core_registers_[R4] = true;
472 blocked_core_registers_[R5] = true;
473 blocked_core_registers_[R8] = true;
474 blocked_core_registers_[R10] = true;
475 blocked_core_registers_[R11] = true;
476
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000477 blocked_fpu_registers_[S16] = true;
478 blocked_fpu_registers_[S17] = true;
479 blocked_fpu_registers_[S18] = true;
480 blocked_fpu_registers_[S19] = true;
481 blocked_fpu_registers_[S20] = true;
482 blocked_fpu_registers_[S21] = true;
483 blocked_fpu_registers_[S22] = true;
484 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000485 blocked_fpu_registers_[S24] = true;
486 blocked_fpu_registers_[S25] = true;
487 blocked_fpu_registers_[S26] = true;
488 blocked_fpu_registers_[S27] = true;
489 blocked_fpu_registers_[S28] = true;
490 blocked_fpu_registers_[S29] = true;
491 blocked_fpu_registers_[S30] = true;
492 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100493
494 UpdateBlockedPairRegisters();
495}
496
497void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
498 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
499 ArmManagedRegister current =
500 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
501 if (blocked_core_registers_[current.AsRegisterPairLow()]
502 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
503 blocked_register_pairs_[i] = true;
504 }
505 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100506}
507
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100508InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
509 : HGraphVisitor(graph),
510 assembler_(codegen->GetAssembler()),
511 codegen_(codegen) {}
512
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000513void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000514 bool skip_overflow_check =
515 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100516 if (!skip_overflow_check) {
517 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100518 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100519 AddSlowPath(slow_path);
520
521 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
522 __ cmp(SP, ShifterOperand(IP));
523 __ b(slow_path->GetEntryLabel(), CC);
524 } else {
525 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100526 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100527 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100528 }
529 }
530
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000531 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
532 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000533
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100534 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100535 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100536 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000537}
538
539void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100540 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000541 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000542}
543
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100544void CodeGeneratorARM::Bind(HBasicBlock* block) {
545 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000546}
547
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100548Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
549 switch (load->GetType()) {
550 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100551 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100552 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
553 break;
554
555 case Primitive::kPrimInt:
556 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100557 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100558 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100559
560 case Primitive::kPrimBoolean:
561 case Primitive::kPrimByte:
562 case Primitive::kPrimChar:
563 case Primitive::kPrimShort:
564 case Primitive::kPrimVoid:
565 LOG(FATAL) << "Unexpected type " << load->GetType();
566 }
567
568 LOG(FATAL) << "Unreachable";
569 return Location();
570}
571
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100572Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
573 switch (type) {
574 case Primitive::kPrimBoolean:
575 case Primitive::kPrimByte:
576 case Primitive::kPrimChar:
577 case Primitive::kPrimShort:
578 case Primitive::kPrimInt:
579 case Primitive::kPrimNot: {
580 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000581 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100582 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100583 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100584 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000585 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100586 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100587 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100588
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000589 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100590 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000591 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100592 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000593 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100594 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000595 if (calling_convention.GetRegisterAt(index) == R1) {
596 // Skip R1, and use R2_R3 instead.
597 gp_index_++;
598 index++;
599 }
600 }
601 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
602 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000603 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000604 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000605 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100606 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000607 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
608 }
609 }
610
611 case Primitive::kPrimFloat: {
612 uint32_t stack_index = stack_index_++;
613 if (float_index_ % 2 == 0) {
614 float_index_ = std::max(double_index_, float_index_);
615 }
616 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
617 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
618 } else {
619 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
620 }
621 }
622
623 case Primitive::kPrimDouble: {
624 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
625 uint32_t stack_index = stack_index_;
626 stack_index_ += 2;
627 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
628 uint32_t index = double_index_;
629 double_index_ += 2;
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000630 DCHECK_EQ(calling_convention.GetFpuRegisterAt(index) + 1,
631 calling_convention.GetFpuRegisterAt(index + 1));
632 DCHECK_EQ(calling_convention.GetFpuRegisterAt(index) & 1, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000633 return Location::FpuRegisterPairLocation(
634 calling_convention.GetFpuRegisterAt(index),
635 calling_convention.GetFpuRegisterAt(index + 1));
636 } else {
637 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100638 }
639 }
640
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100641 case Primitive::kPrimVoid:
642 LOG(FATAL) << "Unexpected parameter type " << type;
643 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100644 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100645 return Location();
646}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100647
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000648Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
649 switch (type) {
650 case Primitive::kPrimBoolean:
651 case Primitive::kPrimByte:
652 case Primitive::kPrimChar:
653 case Primitive::kPrimShort:
654 case Primitive::kPrimInt:
655 case Primitive::kPrimNot: {
656 return Location::RegisterLocation(R0);
657 }
658
659 case Primitive::kPrimFloat: {
660 return Location::FpuRegisterLocation(S0);
661 }
662
663 case Primitive::kPrimLong: {
664 return Location::RegisterPairLocation(R0, R1);
665 }
666
667 case Primitive::kPrimDouble: {
668 return Location::FpuRegisterPairLocation(S0, S1);
669 }
670
671 case Primitive::kPrimVoid:
672 return Location();
673 }
674 UNREACHABLE();
675 return Location();
676}
677
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100678void CodeGeneratorARM::Move32(Location destination, Location source) {
679 if (source.Equals(destination)) {
680 return;
681 }
682 if (destination.IsRegister()) {
683 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000684 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100685 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000686 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100687 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000688 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100690 } else if (destination.IsFpuRegister()) {
691 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000692 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100693 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000694 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100695 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000696 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100697 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100698 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000699 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100700 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000701 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100702 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000703 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100704 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000705 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100706 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
707 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100708 }
709 }
710}
711
712void CodeGeneratorARM::Move64(Location destination, Location source) {
713 if (source.Equals(destination)) {
714 return;
715 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100716 if (destination.IsRegisterPair()) {
717 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000718 EmitParallelMoves(
719 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
720 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
721 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
722 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100723 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000724 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100725 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000726 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100727 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100728 if (destination.AsRegisterPairLow<Register>() == R1) {
729 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100730 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
731 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100732 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100733 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100734 SP, source.GetStackIndex());
735 }
736 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000737 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100738 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000739 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
740 SP,
741 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100742 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000743 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100744 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100745 } else {
746 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100747 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000748 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100749 if (source.AsRegisterPairLow<Register>() == R1) {
750 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100751 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
752 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100753 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100754 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100755 SP, destination.GetStackIndex());
756 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000757 } else if (source.IsFpuRegisterPair()) {
758 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
759 SP,
760 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100761 } else {
762 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000763 EmitParallelMoves(
764 Location::StackSlot(source.GetStackIndex()),
765 Location::StackSlot(destination.GetStackIndex()),
766 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
767 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 }
769 }
770}
771
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100772void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100773 LocationSummary* locations = instruction->GetLocations();
774 if (locations != nullptr && locations->Out().Equals(location)) {
775 return;
776 }
777
Calin Juravlea21f5982014-11-13 15:53:04 +0000778 if (locations != nullptr && locations->Out().IsConstant()) {
779 HConstant* const_to_move = locations->Out().GetConstant();
780 if (const_to_move->IsIntConstant()) {
781 int32_t value = const_to_move->AsIntConstant()->GetValue();
782 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000783 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000784 } else {
785 DCHECK(location.IsStackSlot());
786 __ LoadImmediate(IP, value);
787 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
788 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000789 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000790 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000791 int64_t value = const_to_move->AsLongConstant()->GetValue();
792 if (location.IsRegisterPair()) {
793 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
794 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
795 } else {
796 DCHECK(location.IsDoubleStackSlot());
797 __ LoadImmediate(IP, Low32Bits(value));
798 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
799 __ LoadImmediate(IP, High32Bits(value));
800 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
801 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100802 }
Roland Levillain476df552014-10-09 17:51:36 +0100803 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100804 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
805 switch (instruction->GetType()) {
806 case Primitive::kPrimBoolean:
807 case Primitive::kPrimByte:
808 case Primitive::kPrimChar:
809 case Primitive::kPrimShort:
810 case Primitive::kPrimInt:
811 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100812 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100813 Move32(location, Location::StackSlot(stack_slot));
814 break;
815
816 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100817 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100818 Move64(location, Location::DoubleStackSlot(stack_slot));
819 break;
820
821 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100822 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100823 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000824 } else if (instruction->IsTemporary()) {
825 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000826 if (temp_location.IsStackSlot()) {
827 Move32(location, temp_location);
828 } else {
829 DCHECK(temp_location.IsDoubleStackSlot());
830 Move64(location, temp_location);
831 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000832 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100833 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100834 switch (instruction->GetType()) {
835 case Primitive::kPrimBoolean:
836 case Primitive::kPrimByte:
837 case Primitive::kPrimChar:
838 case Primitive::kPrimShort:
839 case Primitive::kPrimNot:
840 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100841 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100842 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100843 break;
844
845 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100846 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100847 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100848 break;
849
850 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100851 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100852 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000853 }
854}
855
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100856void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
857 HInstruction* instruction,
858 uint32_t dex_pc) {
859 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
860 __ blx(LR);
861 RecordPcInfo(instruction, dex_pc);
862 DCHECK(instruction->IsSuspendCheck()
863 || instruction->IsBoundsCheck()
864 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000865 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000866 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100867 || !IsLeafMethod());
868}
869
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000870void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000871 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000872}
873
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000874void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000875 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100876 DCHECK(!successor->IsExitBlock());
877
878 HBasicBlock* block = got->GetBlock();
879 HInstruction* previous = got->GetPrevious();
880
881 HLoopInformation* info = block->GetLoopInformation();
882 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
883 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
884 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
885 return;
886 }
887
888 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
889 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
890 }
891 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000892 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000893 }
894}
895
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000896void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000897 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000898}
899
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000900void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700901 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000902 if (kIsDebugBuild) {
903 __ Comment("Unreachable");
904 __ bkpt(0);
905 }
906}
907
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000908void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100909 LocationSummary* locations =
910 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100911 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100912 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100913 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100914 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000915}
916
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000917void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700918 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100919 if (cond->IsIntConstant()) {
920 // Constant condition, statically compared against 1.
921 int32_t cond_value = cond->AsIntConstant()->GetValue();
922 if (cond_value == 1) {
923 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
924 if_instr->IfTrueSuccessor())) {
925 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100926 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100927 return;
928 } else {
929 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100930 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100931 } else {
932 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
933 // Condition has been materialized, compare the output to 0
934 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000935 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100936 ShifterOperand(0));
937 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
938 } else {
939 // Condition has not been materialized, use its inputs as the
940 // comparison and its condition as the branch condition.
941 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000942 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000944 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100945 } else {
946 DCHECK(locations->InAt(1).IsConstant());
947 int32_t value =
948 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
949 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000950 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
951 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100952 } else {
953 Register temp = IP;
954 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000955 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100956 }
957 }
958 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
959 ARMCondition(cond->AsCondition()->GetCondition()));
960 }
Dave Allison20dfc792014-06-16 20:44:29 -0700961 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100962 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
963 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700964 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000965 }
966}
967
Dave Allison20dfc792014-06-16 20:44:29 -0700968
969void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100970 LocationSummary* locations =
971 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100972 locations->SetInAt(0, Location::RequiresRegister());
973 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100974 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100975 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100976 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000977}
978
Dave Allison20dfc792014-06-16 20:44:29 -0700979void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100980 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000982 Register left = locations->InAt(0).AsRegister<Register>();
983
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100984 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000985 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100986 } else {
987 DCHECK(locations->InAt(1).IsConstant());
988 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
989 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000990 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
991 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100992 } else {
993 Register temp = IP;
994 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000995 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 }
Dave Allison20dfc792014-06-16 20:44:29 -0700997 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100998 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000999 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001001 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001002 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001003}
1004
1005void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1006 VisitCondition(comp);
1007}
1008
1009void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1010 VisitCondition(comp);
1011}
1012
1013void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1014 VisitCondition(comp);
1015}
1016
1017void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1018 VisitCondition(comp);
1019}
1020
1021void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1022 VisitCondition(comp);
1023}
1024
1025void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1026 VisitCondition(comp);
1027}
1028
1029void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1030 VisitCondition(comp);
1031}
1032
1033void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1034 VisitCondition(comp);
1035}
1036
1037void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1038 VisitCondition(comp);
1039}
1040
1041void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1042 VisitCondition(comp);
1043}
1044
1045void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1046 VisitCondition(comp);
1047}
1048
1049void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1050 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001051}
1052
1053void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001054 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001055}
1056
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001057void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1058 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001059}
1060
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001061void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001062 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001063}
1064
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001065void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001066 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001067 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001068}
1069
1070void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001071 LocationSummary* locations =
1072 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001073 switch (store->InputAt(1)->GetType()) {
1074 case Primitive::kPrimBoolean:
1075 case Primitive::kPrimByte:
1076 case Primitive::kPrimChar:
1077 case Primitive::kPrimShort:
1078 case Primitive::kPrimInt:
1079 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001080 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001081 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1082 break;
1083
1084 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001085 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001086 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1087 break;
1088
1089 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001090 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001091 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001092}
1093
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001094void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001095 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001096}
1097
1098void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001099 LocationSummary* locations =
1100 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001101 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001102}
1103
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001104void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001105 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001106 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001107}
1108
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001109void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001110 LocationSummary* locations =
1111 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001112 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001113}
1114
1115void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1116 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001117 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001118}
1119
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001120void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1121 LocationSummary* locations =
1122 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1123 locations->SetOut(Location::ConstantLocation(constant));
1124}
1125
1126void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1127 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001128 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001129}
1130
1131void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1132 LocationSummary* locations =
1133 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1134 locations->SetOut(Location::ConstantLocation(constant));
1135}
1136
1137void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1138 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001139 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001140}
1141
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001142void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001143 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001144}
1145
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001146void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001147 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001148 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001149}
1150
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001151void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001152 LocationSummary* locations =
1153 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001154 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155}
1156
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001158 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001159 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001160}
1161
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001162void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001163 HandleInvoke(invoke);
1164}
1165
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001166void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001167 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001168}
1169
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001170void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001171 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001172
1173 // TODO: Implement all kinds of calls:
1174 // 1) boot -> boot
1175 // 2) app -> boot
1176 // 3) app -> app
1177 //
1178 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1179
1180 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001181 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001182 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001183 __ LoadFromOffset(
1184 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001185 // temp = temp[index_in_cache]
1186 __ LoadFromOffset(
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001187 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001188 // LR = temp[offset_of_quick_compiled_code]
1189 __ LoadFromOffset(kLoadWord, LR, temp,
1190 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1191 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001192 // LR()
1193 __ blx(LR);
1194
1195 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1196 DCHECK(!codegen_->IsLeafMethod());
1197}
1198
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001199void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001200 LocationSummary* locations =
1201 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001202 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001203
1204 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001205 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001206 HInstruction* input = invoke->InputAt(i);
1207 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1208 }
1209
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001210 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001211}
1212
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001213void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1214 HandleInvoke(invoke);
1215}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001216
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001217void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001218 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001219 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1220 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1221 LocationSummary* locations = invoke->GetLocations();
1222 Location receiver = locations->InAt(0);
1223 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1224 // temp = object->GetClass();
1225 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001226 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1227 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001228 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001229 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001230 }
1231 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001232 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001233 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001234 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001235 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001236 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001237 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001238 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001239 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001240 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001241}
1242
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001243void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1244 HandleInvoke(invoke);
1245 // Add the hidden argument.
1246 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1247}
1248
1249void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1250 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001251 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001252 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1253 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1254 LocationSummary* locations = invoke->GetLocations();
1255 Location receiver = locations->InAt(0);
1256 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1257
1258 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001259 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1260 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001261
1262 // temp = object->GetClass();
1263 if (receiver.IsStackSlot()) {
1264 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1265 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1266 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001267 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001268 }
1269 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001270 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001271 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001272 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1273 // LR = temp->GetEntryPoint();
1274 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1275 // LR();
1276 __ blx(LR);
1277 DCHECK(!codegen_->IsLeafMethod());
1278 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1279}
1280
Roland Levillain88cb1752014-10-20 16:36:47 +01001281void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1282 LocationSummary* locations =
1283 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1284 switch (neg->GetResultType()) {
1285 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001286 case Primitive::kPrimLong: {
1287 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001288 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001289 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001290 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001291 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001292
Roland Levillain88cb1752014-10-20 16:36:47 +01001293 case Primitive::kPrimFloat:
1294 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001295 locations->SetInAt(0, Location::RequiresFpuRegister());
1296 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001297 break;
1298
1299 default:
1300 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1301 }
1302}
1303
1304void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1305 LocationSummary* locations = neg->GetLocations();
1306 Location out = locations->Out();
1307 Location in = locations->InAt(0);
1308 switch (neg->GetResultType()) {
1309 case Primitive::kPrimInt:
1310 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001311 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001312 break;
1313
1314 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001315 DCHECK(in.IsRegisterPair());
1316 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1317 __ rsbs(out.AsRegisterPairLow<Register>(),
1318 in.AsRegisterPairLow<Register>(),
1319 ShifterOperand(0));
1320 // We cannot emit an RSC (Reverse Subtract with Carry)
1321 // instruction here, as it does not exist in the Thumb-2
1322 // instruction set. We use the following approach
1323 // using SBC and SUB instead.
1324 //
1325 // out.hi = -C
1326 __ sbc(out.AsRegisterPairHigh<Register>(),
1327 out.AsRegisterPairHigh<Register>(),
1328 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1329 // out.hi = out.hi - in.hi
1330 __ sub(out.AsRegisterPairHigh<Register>(),
1331 out.AsRegisterPairHigh<Register>(),
1332 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1333 break;
1334
Roland Levillain88cb1752014-10-20 16:36:47 +01001335 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001336 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001337 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001338 break;
1339
Roland Levillain88cb1752014-10-20 16:36:47 +01001340 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001341 DCHECK(in.IsFpuRegisterPair());
1342 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1343 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001344 break;
1345
1346 default:
1347 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1348 }
1349}
1350
Roland Levillaindff1f282014-11-05 14:15:05 +00001351void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001352 Primitive::Type result_type = conversion->GetResultType();
1353 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001354 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001355
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001356 // The float-to-long and double-to-long type conversions rely on a
1357 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001358 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001359 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1360 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001361 ? LocationSummary::kCall
1362 : LocationSummary::kNoCall;
1363 LocationSummary* locations =
1364 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1365
Roland Levillaindff1f282014-11-05 14:15:05 +00001366 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001367 case Primitive::kPrimByte:
1368 switch (input_type) {
1369 case Primitive::kPrimShort:
1370 case Primitive::kPrimInt:
1371 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001372 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001373 locations->SetInAt(0, Location::RequiresRegister());
1374 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1375 break;
1376
1377 default:
1378 LOG(FATAL) << "Unexpected type conversion from " << input_type
1379 << " to " << result_type;
1380 }
1381 break;
1382
Roland Levillain01a8d712014-11-14 16:27:39 +00001383 case Primitive::kPrimShort:
1384 switch (input_type) {
1385 case Primitive::kPrimByte:
1386 case Primitive::kPrimInt:
1387 case Primitive::kPrimChar:
1388 // Processing a Dex `int-to-short' instruction.
1389 locations->SetInAt(0, Location::RequiresRegister());
1390 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1391 break;
1392
1393 default:
1394 LOG(FATAL) << "Unexpected type conversion from " << input_type
1395 << " to " << result_type;
1396 }
1397 break;
1398
Roland Levillain946e1432014-11-11 17:35:19 +00001399 case Primitive::kPrimInt:
1400 switch (input_type) {
1401 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001402 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001403 locations->SetInAt(0, Location::Any());
1404 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1405 break;
1406
1407 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001408 // Processing a Dex `float-to-int' instruction.
1409 locations->SetInAt(0, Location::RequiresFpuRegister());
1410 locations->SetOut(Location::RequiresRegister());
1411 locations->AddTemp(Location::RequiresFpuRegister());
1412 break;
1413
Roland Levillain946e1432014-11-11 17:35:19 +00001414 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001415 // Processing a Dex `double-to-int' instruction.
1416 locations->SetInAt(0, Location::RequiresFpuRegister());
1417 locations->SetOut(Location::RequiresRegister());
1418 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001419 break;
1420
1421 default:
1422 LOG(FATAL) << "Unexpected type conversion from " << input_type
1423 << " to " << result_type;
1424 }
1425 break;
1426
Roland Levillaindff1f282014-11-05 14:15:05 +00001427 case Primitive::kPrimLong:
1428 switch (input_type) {
1429 case Primitive::kPrimByte:
1430 case Primitive::kPrimShort:
1431 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001432 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001433 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001434 locations->SetInAt(0, Location::RequiresRegister());
1435 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1436 break;
1437
Roland Levillain624279f2014-12-04 11:54:28 +00001438 case Primitive::kPrimFloat: {
1439 // Processing a Dex `float-to-long' instruction.
1440 InvokeRuntimeCallingConvention calling_convention;
1441 locations->SetInAt(0, Location::FpuRegisterLocation(
1442 calling_convention.GetFpuRegisterAt(0)));
1443 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1444 break;
1445 }
1446
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001447 case Primitive::kPrimDouble: {
1448 // Processing a Dex `double-to-long' instruction.
1449 InvokeRuntimeCallingConvention calling_convention;
1450 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1451 calling_convention.GetFpuRegisterAt(0),
1452 calling_convention.GetFpuRegisterAt(1)));
1453 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001454 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001455 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001456
1457 default:
1458 LOG(FATAL) << "Unexpected type conversion from " << input_type
1459 << " to " << result_type;
1460 }
1461 break;
1462
Roland Levillain981e4542014-11-14 11:47:14 +00001463 case Primitive::kPrimChar:
1464 switch (input_type) {
1465 case Primitive::kPrimByte:
1466 case Primitive::kPrimShort:
1467 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001468 // Processing a Dex `int-to-char' instruction.
1469 locations->SetInAt(0, Location::RequiresRegister());
1470 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1471 break;
1472
1473 default:
1474 LOG(FATAL) << "Unexpected type conversion from " << input_type
1475 << " to " << result_type;
1476 }
1477 break;
1478
Roland Levillaindff1f282014-11-05 14:15:05 +00001479 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001480 switch (input_type) {
1481 case Primitive::kPrimByte:
1482 case Primitive::kPrimShort:
1483 case Primitive::kPrimInt:
1484 case Primitive::kPrimChar:
1485 // Processing a Dex `int-to-float' instruction.
1486 locations->SetInAt(0, Location::RequiresRegister());
1487 locations->SetOut(Location::RequiresFpuRegister());
1488 break;
1489
1490 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001491 // Processing a Dex `long-to-float' instruction.
1492 locations->SetInAt(0, Location::RequiresRegister());
1493 locations->SetOut(Location::RequiresFpuRegister());
1494 locations->AddTemp(Location::RequiresRegister());
1495 locations->AddTemp(Location::RequiresRegister());
1496 locations->AddTemp(Location::RequiresFpuRegister());
1497 locations->AddTemp(Location::RequiresFpuRegister());
1498 break;
1499
Roland Levillaincff13742014-11-17 14:32:17 +00001500 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001501 // Processing a Dex `double-to-float' instruction.
1502 locations->SetInAt(0, Location::RequiresFpuRegister());
1503 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001504 break;
1505
1506 default:
1507 LOG(FATAL) << "Unexpected type conversion from " << input_type
1508 << " to " << result_type;
1509 };
1510 break;
1511
Roland Levillaindff1f282014-11-05 14:15:05 +00001512 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001513 switch (input_type) {
1514 case Primitive::kPrimByte:
1515 case Primitive::kPrimShort:
1516 case Primitive::kPrimInt:
1517 case Primitive::kPrimChar:
1518 // Processing a Dex `int-to-double' instruction.
1519 locations->SetInAt(0, Location::RequiresRegister());
1520 locations->SetOut(Location::RequiresFpuRegister());
1521 break;
1522
1523 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001524 // Processing a Dex `long-to-double' instruction.
1525 locations->SetInAt(0, Location::RequiresRegister());
1526 locations->SetOut(Location::RequiresFpuRegister());
1527 locations->AddTemp(Location::RequiresRegister());
1528 locations->AddTemp(Location::RequiresRegister());
1529 locations->AddTemp(Location::RequiresFpuRegister());
1530 break;
1531
Roland Levillaincff13742014-11-17 14:32:17 +00001532 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001533 // Processing a Dex `float-to-double' instruction.
1534 locations->SetInAt(0, Location::RequiresFpuRegister());
1535 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001536 break;
1537
1538 default:
1539 LOG(FATAL) << "Unexpected type conversion from " << input_type
1540 << " to " << result_type;
1541 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001542 break;
1543
1544 default:
1545 LOG(FATAL) << "Unexpected type conversion from " << input_type
1546 << " to " << result_type;
1547 }
1548}
1549
1550void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1551 LocationSummary* locations = conversion->GetLocations();
1552 Location out = locations->Out();
1553 Location in = locations->InAt(0);
1554 Primitive::Type result_type = conversion->GetResultType();
1555 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001556 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001557 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001558 case Primitive::kPrimByte:
1559 switch (input_type) {
1560 case Primitive::kPrimShort:
1561 case Primitive::kPrimInt:
1562 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001563 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001564 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001565 break;
1566
1567 default:
1568 LOG(FATAL) << "Unexpected type conversion from " << input_type
1569 << " to " << result_type;
1570 }
1571 break;
1572
Roland Levillain01a8d712014-11-14 16:27:39 +00001573 case Primitive::kPrimShort:
1574 switch (input_type) {
1575 case Primitive::kPrimByte:
1576 case Primitive::kPrimInt:
1577 case Primitive::kPrimChar:
1578 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001579 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001580 break;
1581
1582 default:
1583 LOG(FATAL) << "Unexpected type conversion from " << input_type
1584 << " to " << result_type;
1585 }
1586 break;
1587
Roland Levillain946e1432014-11-11 17:35:19 +00001588 case Primitive::kPrimInt:
1589 switch (input_type) {
1590 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001591 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001592 DCHECK(out.IsRegister());
1593 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001594 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001595 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001596 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001597 } else {
1598 DCHECK(in.IsConstant());
1599 DCHECK(in.GetConstant()->IsLongConstant());
1600 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001601 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001602 }
1603 break;
1604
Roland Levillain3f8f9362014-12-02 17:45:01 +00001605 case Primitive::kPrimFloat: {
1606 // Processing a Dex `float-to-int' instruction.
1607 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1608 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1609 __ vcvtis(temp, temp);
1610 __ vmovrs(out.AsRegister<Register>(), temp);
1611 break;
1612 }
1613
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001614 case Primitive::kPrimDouble: {
1615 // Processing a Dex `double-to-int' instruction.
1616 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1617 DRegister temp_d = FromLowSToD(temp_s);
1618 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1619 __ vcvtid(temp_s, temp_d);
1620 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001621 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001622 }
Roland Levillain946e1432014-11-11 17:35:19 +00001623
1624 default:
1625 LOG(FATAL) << "Unexpected type conversion from " << input_type
1626 << " to " << result_type;
1627 }
1628 break;
1629
Roland Levillaindff1f282014-11-05 14:15:05 +00001630 case Primitive::kPrimLong:
1631 switch (input_type) {
1632 case Primitive::kPrimByte:
1633 case Primitive::kPrimShort:
1634 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001635 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001636 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001637 DCHECK(out.IsRegisterPair());
1638 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001639 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001640 // Sign extension.
1641 __ Asr(out.AsRegisterPairHigh<Register>(),
1642 out.AsRegisterPairLow<Register>(),
1643 31);
1644 break;
1645
1646 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001647 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001648 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1649 conversion,
1650 conversion->GetDexPc());
1651 break;
1652
Roland Levillaindff1f282014-11-05 14:15:05 +00001653 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001654 // Processing a Dex `double-to-long' instruction.
1655 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1656 conversion,
1657 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001658 break;
1659
1660 default:
1661 LOG(FATAL) << "Unexpected type conversion from " << input_type
1662 << " to " << result_type;
1663 }
1664 break;
1665
Roland Levillain981e4542014-11-14 11:47:14 +00001666 case Primitive::kPrimChar:
1667 switch (input_type) {
1668 case Primitive::kPrimByte:
1669 case Primitive::kPrimShort:
1670 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001671 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001672 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001673 break;
1674
1675 default:
1676 LOG(FATAL) << "Unexpected type conversion from " << input_type
1677 << " to " << result_type;
1678 }
1679 break;
1680
Roland Levillaindff1f282014-11-05 14:15:05 +00001681 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001682 switch (input_type) {
1683 case Primitive::kPrimByte:
1684 case Primitive::kPrimShort:
1685 case Primitive::kPrimInt:
1686 case Primitive::kPrimChar: {
1687 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001688 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1689 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001690 break;
1691 }
1692
Roland Levillain6d0e4832014-11-27 18:31:21 +00001693 case Primitive::kPrimLong: {
1694 // Processing a Dex `long-to-float' instruction.
1695 Register low = in.AsRegisterPairLow<Register>();
1696 Register high = in.AsRegisterPairHigh<Register>();
1697 SRegister output = out.AsFpuRegister<SRegister>();
1698 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1699 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1700 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1701 DRegister temp1_d = FromLowSToD(temp1_s);
1702 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1703 DRegister temp2_d = FromLowSToD(temp2_s);
1704
1705 // Operations use doubles for precision reasons (each 32-bit
1706 // half of a long fits in the 53-bit mantissa of a double,
1707 // but not in the 24-bit mantissa of a float). This is
1708 // especially important for the low bits. The result is
1709 // eventually converted to float.
1710
1711 // temp1_d = int-to-double(high)
1712 __ vmovsr(temp1_s, high);
1713 __ vcvtdi(temp1_d, temp1_s);
1714 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1715 // as an immediate value into `temp2_d` does not work, as
1716 // this instruction only transfers 8 significant bits of its
1717 // immediate operand. Instead, use two 32-bit core
1718 // registers to load `k2Pow32EncodingForDouble` into
1719 // `temp2_d`.
1720 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1721 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1722 __ vmovdrr(temp2_d, constant_low, constant_high);
1723 // temp1_d = temp1_d * 2^32
1724 __ vmuld(temp1_d, temp1_d, temp2_d);
1725 // temp2_d = unsigned-to-double(low)
1726 __ vmovsr(temp2_s, low);
1727 __ vcvtdu(temp2_d, temp2_s);
1728 // temp1_d = temp1_d + temp2_d
1729 __ vaddd(temp1_d, temp1_d, temp2_d);
1730 // output = double-to-float(temp1_d);
1731 __ vcvtsd(output, temp1_d);
1732 break;
1733 }
1734
Roland Levillaincff13742014-11-17 14:32:17 +00001735 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001736 // Processing a Dex `double-to-float' instruction.
1737 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1738 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001739 break;
1740
1741 default:
1742 LOG(FATAL) << "Unexpected type conversion from " << input_type
1743 << " to " << result_type;
1744 };
1745 break;
1746
Roland Levillaindff1f282014-11-05 14:15:05 +00001747 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001748 switch (input_type) {
1749 case Primitive::kPrimByte:
1750 case Primitive::kPrimShort:
1751 case Primitive::kPrimInt:
1752 case Primitive::kPrimChar: {
1753 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001754 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001755 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1756 out.AsFpuRegisterPairLow<SRegister>());
1757 break;
1758 }
1759
Roland Levillain647b9ed2014-11-27 12:06:00 +00001760 case Primitive::kPrimLong: {
1761 // Processing a Dex `long-to-double' instruction.
1762 Register low = in.AsRegisterPairLow<Register>();
1763 Register high = in.AsRegisterPairHigh<Register>();
1764 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1765 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001766 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1767 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001768 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1769 DRegister temp_d = FromLowSToD(temp_s);
1770
Roland Levillain647b9ed2014-11-27 12:06:00 +00001771 // out_d = int-to-double(high)
1772 __ vmovsr(out_s, high);
1773 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001774 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1775 // as an immediate value into `temp_d` does not work, as
1776 // this instruction only transfers 8 significant bits of its
1777 // immediate operand. Instead, use two 32-bit core
1778 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1779 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1780 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001781 __ vmovdrr(temp_d, constant_low, constant_high);
1782 // out_d = out_d * 2^32
1783 __ vmuld(out_d, out_d, temp_d);
1784 // temp_d = unsigned-to-double(low)
1785 __ vmovsr(temp_s, low);
1786 __ vcvtdu(temp_d, temp_s);
1787 // out_d = out_d + temp_d
1788 __ vaddd(out_d, out_d, temp_d);
1789 break;
1790 }
1791
Roland Levillaincff13742014-11-17 14:32:17 +00001792 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001793 // Processing a Dex `float-to-double' instruction.
1794 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1795 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001796 break;
1797
1798 default:
1799 LOG(FATAL) << "Unexpected type conversion from " << input_type
1800 << " to " << result_type;
1801 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001802 break;
1803
1804 default:
1805 LOG(FATAL) << "Unexpected type conversion from " << input_type
1806 << " to " << result_type;
1807 }
1808}
1809
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001810void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001811 LocationSummary* locations =
1812 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001813 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001814 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001815 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001816 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1817 locations->SetInAt(0, Location::RequiresRegister());
1818 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1819 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001820 break;
1821 }
1822
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001823 case Primitive::kPrimFloat:
1824 case Primitive::kPrimDouble: {
1825 locations->SetInAt(0, Location::RequiresFpuRegister());
1826 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001827 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001828 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001829 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001830
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001831 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001832 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001833 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001834}
1835
1836void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1837 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001838 Location out = locations->Out();
1839 Location first = locations->InAt(0);
1840 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001841 switch (add->GetResultType()) {
1842 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001843 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001844 __ add(out.AsRegister<Register>(),
1845 first.AsRegister<Register>(),
1846 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001847 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001848 __ AddConstant(out.AsRegister<Register>(),
1849 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001850 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001851 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001852 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001853
1854 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001855 __ adds(out.AsRegisterPairLow<Register>(),
1856 first.AsRegisterPairLow<Register>(),
1857 ShifterOperand(second.AsRegisterPairLow<Register>()));
1858 __ adc(out.AsRegisterPairHigh<Register>(),
1859 first.AsRegisterPairHigh<Register>(),
1860 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001861 break;
1862
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001863 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001864 __ vadds(out.AsFpuRegister<SRegister>(),
1865 first.AsFpuRegister<SRegister>(),
1866 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001867 break;
1868
1869 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001870 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1871 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1872 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001873 break;
1874
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001875 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001876 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001877 }
1878}
1879
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001880void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001881 LocationSummary* locations =
1882 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001883 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001884 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001885 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001886 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1887 locations->SetInAt(0, Location::RequiresRegister());
1888 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1889 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001890 break;
1891 }
Calin Juravle11351682014-10-23 15:38:15 +01001892 case Primitive::kPrimFloat:
1893 case Primitive::kPrimDouble: {
1894 locations->SetInAt(0, Location::RequiresFpuRegister());
1895 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001896 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001897 break;
Calin Juravle11351682014-10-23 15:38:15 +01001898 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001899 default:
Calin Juravle11351682014-10-23 15:38:15 +01001900 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001901 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001902}
1903
1904void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1905 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001906 Location out = locations->Out();
1907 Location first = locations->InAt(0);
1908 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001909 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001910 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001911 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001912 __ sub(out.AsRegister<Register>(),
1913 first.AsRegister<Register>(),
1914 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001915 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001916 __ AddConstant(out.AsRegister<Register>(),
1917 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001918 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001919 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001920 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001921 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001922
Calin Juravle11351682014-10-23 15:38:15 +01001923 case Primitive::kPrimLong: {
1924 __ subs(out.AsRegisterPairLow<Register>(),
1925 first.AsRegisterPairLow<Register>(),
1926 ShifterOperand(second.AsRegisterPairLow<Register>()));
1927 __ sbc(out.AsRegisterPairHigh<Register>(),
1928 first.AsRegisterPairHigh<Register>(),
1929 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001930 break;
Calin Juravle11351682014-10-23 15:38:15 +01001931 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001932
Calin Juravle11351682014-10-23 15:38:15 +01001933 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001934 __ vsubs(out.AsFpuRegister<SRegister>(),
1935 first.AsFpuRegister<SRegister>(),
1936 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001937 break;
Calin Juravle11351682014-10-23 15:38:15 +01001938 }
1939
1940 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001941 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1942 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1943 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001944 break;
1945 }
1946
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001947
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001948 default:
Calin Juravle11351682014-10-23 15:38:15 +01001949 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001950 }
1951}
1952
Calin Juravle34bacdf2014-10-07 20:23:36 +01001953void LocationsBuilderARM::VisitMul(HMul* mul) {
1954 LocationSummary* locations =
1955 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1956 switch (mul->GetResultType()) {
1957 case Primitive::kPrimInt:
1958 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001959 locations->SetInAt(0, Location::RequiresRegister());
1960 locations->SetInAt(1, Location::RequiresRegister());
1961 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001962 break;
1963 }
1964
Calin Juravleb5bfa962014-10-21 18:02:24 +01001965 case Primitive::kPrimFloat:
1966 case Primitive::kPrimDouble: {
1967 locations->SetInAt(0, Location::RequiresFpuRegister());
1968 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001969 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001970 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001971 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001972
1973 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001974 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001975 }
1976}
1977
1978void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1979 LocationSummary* locations = mul->GetLocations();
1980 Location out = locations->Out();
1981 Location first = locations->InAt(0);
1982 Location second = locations->InAt(1);
1983 switch (mul->GetResultType()) {
1984 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001985 __ mul(out.AsRegister<Register>(),
1986 first.AsRegister<Register>(),
1987 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001988 break;
1989 }
1990 case Primitive::kPrimLong: {
1991 Register out_hi = out.AsRegisterPairHigh<Register>();
1992 Register out_lo = out.AsRegisterPairLow<Register>();
1993 Register in1_hi = first.AsRegisterPairHigh<Register>();
1994 Register in1_lo = first.AsRegisterPairLow<Register>();
1995 Register in2_hi = second.AsRegisterPairHigh<Register>();
1996 Register in2_lo = second.AsRegisterPairLow<Register>();
1997
1998 // Extra checks to protect caused by the existence of R1_R2.
1999 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2000 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2001 DCHECK_NE(out_hi, in1_lo);
2002 DCHECK_NE(out_hi, in2_lo);
2003
2004 // input: in1 - 64 bits, in2 - 64 bits
2005 // output: out
2006 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2007 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2008 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2009
2010 // IP <- in1.lo * in2.hi
2011 __ mul(IP, in1_lo, in2_hi);
2012 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2013 __ mla(out_hi, in1_hi, in2_lo, IP);
2014 // out.lo <- (in1.lo * in2.lo)[31:0];
2015 __ umull(out_lo, IP, in1_lo, in2_lo);
2016 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2017 __ add(out_hi, out_hi, ShifterOperand(IP));
2018 break;
2019 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002020
2021 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002022 __ vmuls(out.AsFpuRegister<SRegister>(),
2023 first.AsFpuRegister<SRegister>(),
2024 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002025 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002026 }
2027
2028 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002029 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2030 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2031 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002032 break;
2033 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002034
2035 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002036 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002037 }
2038}
2039
Calin Juravle7c4954d2014-10-28 16:57:40 +00002040void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002041 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2042 ? LocationSummary::kCall
2043 : LocationSummary::kNoCall;
2044 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2045
Calin Juravle7c4954d2014-10-28 16:57:40 +00002046 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002047 case Primitive::kPrimInt: {
2048 locations->SetInAt(0, Location::RequiresRegister());
2049 locations->SetInAt(1, Location::RequiresRegister());
2050 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2051 break;
2052 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002053 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002054 InvokeRuntimeCallingConvention calling_convention;
2055 locations->SetInAt(0, Location::RegisterPairLocation(
2056 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2057 locations->SetInAt(1, Location::RegisterPairLocation(
2058 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2059 // The runtime helper puts the output in R0,R2.
2060 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002061 break;
2062 }
2063 case Primitive::kPrimFloat:
2064 case Primitive::kPrimDouble: {
2065 locations->SetInAt(0, Location::RequiresFpuRegister());
2066 locations->SetInAt(1, Location::RequiresFpuRegister());
2067 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2068 break;
2069 }
2070
2071 default:
2072 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2073 }
2074}
2075
2076void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2077 LocationSummary* locations = div->GetLocations();
2078 Location out = locations->Out();
2079 Location first = locations->InAt(0);
2080 Location second = locations->InAt(1);
2081
2082 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002083 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002084 __ sdiv(out.AsRegister<Register>(),
2085 first.AsRegister<Register>(),
2086 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002087 break;
2088 }
2089
Calin Juravle7c4954d2014-10-28 16:57:40 +00002090 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002091 InvokeRuntimeCallingConvention calling_convention;
2092 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2093 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2094 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2095 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2096 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2097 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2098
2099 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002100 break;
2101 }
2102
2103 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002104 __ vdivs(out.AsFpuRegister<SRegister>(),
2105 first.AsFpuRegister<SRegister>(),
2106 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002107 break;
2108 }
2109
2110 case Primitive::kPrimDouble: {
2111 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2112 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2113 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2114 break;
2115 }
2116
2117 default:
2118 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2119 }
2120}
2121
Calin Juravlebacfec32014-11-14 15:54:36 +00002122void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002123 Primitive::Type type = rem->GetResultType();
2124 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2125 ? LocationSummary::kNoCall
2126 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002127 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2128
Calin Juravled2ec87d2014-12-08 14:24:46 +00002129 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002130 case Primitive::kPrimInt: {
2131 locations->SetInAt(0, Location::RequiresRegister());
2132 locations->SetInAt(1, Location::RequiresRegister());
2133 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2134 locations->AddTemp(Location::RequiresRegister());
2135 break;
2136 }
2137 case Primitive::kPrimLong: {
2138 InvokeRuntimeCallingConvention calling_convention;
2139 locations->SetInAt(0, Location::RegisterPairLocation(
2140 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2141 locations->SetInAt(1, Location::RegisterPairLocation(
2142 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2143 // The runtime helper puts the output in R2,R3.
2144 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2145 break;
2146 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002147 case Primitive::kPrimFloat: {
2148 InvokeRuntimeCallingConvention calling_convention;
2149 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2150 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2151 locations->SetOut(Location::FpuRegisterLocation(S0));
2152 break;
2153 }
2154
Calin Juravlebacfec32014-11-14 15:54:36 +00002155 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002156 InvokeRuntimeCallingConvention calling_convention;
2157 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2158 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2159 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2160 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2161 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002162 break;
2163 }
2164
2165 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002166 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002167 }
2168}
2169
2170void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2171 LocationSummary* locations = rem->GetLocations();
2172 Location out = locations->Out();
2173 Location first = locations->InAt(0);
2174 Location second = locations->InAt(1);
2175
Calin Juravled2ec87d2014-12-08 14:24:46 +00002176 Primitive::Type type = rem->GetResultType();
2177 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002178 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002179 Register reg1 = first.AsRegister<Register>();
2180 Register reg2 = second.AsRegister<Register>();
2181 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002182
2183 // temp = reg1 / reg2 (integer division)
2184 // temp = temp * reg2
2185 // dest = reg1 - temp
2186 __ sdiv(temp, reg1, reg2);
2187 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002188 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002189 break;
2190 }
2191
2192 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002193 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2194 break;
2195 }
2196
Calin Juravled2ec87d2014-12-08 14:24:46 +00002197 case Primitive::kPrimFloat: {
2198 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2199 break;
2200 }
2201
Calin Juravlebacfec32014-11-14 15:54:36 +00002202 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002203 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002204 break;
2205 }
2206
2207 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002208 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002209 }
2210}
2211
Calin Juravled0d48522014-11-04 16:40:20 +00002212void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2213 LocationSummary* locations =
2214 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002215 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002216 if (instruction->HasUses()) {
2217 locations->SetOut(Location::SameAsFirstInput());
2218 }
2219}
2220
2221void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2222 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2223 codegen_->AddSlowPath(slow_path);
2224
2225 LocationSummary* locations = instruction->GetLocations();
2226 Location value = locations->InAt(0);
2227
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002228 switch (instruction->GetType()) {
2229 case Primitive::kPrimInt: {
2230 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002231 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002232 __ b(slow_path->GetEntryLabel(), EQ);
2233 } else {
2234 DCHECK(value.IsConstant()) << value;
2235 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2236 __ b(slow_path->GetEntryLabel());
2237 }
2238 }
2239 break;
2240 }
2241 case Primitive::kPrimLong: {
2242 if (value.IsRegisterPair()) {
2243 __ orrs(IP,
2244 value.AsRegisterPairLow<Register>(),
2245 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2246 __ b(slow_path->GetEntryLabel(), EQ);
2247 } else {
2248 DCHECK(value.IsConstant()) << value;
2249 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2250 __ b(slow_path->GetEntryLabel());
2251 }
2252 }
2253 break;
2254 default:
2255 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2256 }
2257 }
Calin Juravled0d48522014-11-04 16:40:20 +00002258}
2259
Calin Juravle9aec02f2014-11-18 23:06:35 +00002260void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2261 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2262
2263 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2264 ? LocationSummary::kCall
2265 : LocationSummary::kNoCall;
2266 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2267
2268 switch (op->GetResultType()) {
2269 case Primitive::kPrimInt: {
2270 locations->SetInAt(0, Location::RequiresRegister());
2271 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2272 locations->SetOut(Location::RequiresRegister());
2273 break;
2274 }
2275 case Primitive::kPrimLong: {
2276 InvokeRuntimeCallingConvention calling_convention;
2277 locations->SetInAt(0, Location::RegisterPairLocation(
2278 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2279 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2280 // The runtime helper puts the output in R0,R2.
2281 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2282 break;
2283 }
2284 default:
2285 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2286 }
2287}
2288
2289void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2290 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2291
2292 LocationSummary* locations = op->GetLocations();
2293 Location out = locations->Out();
2294 Location first = locations->InAt(0);
2295 Location second = locations->InAt(1);
2296
2297 Primitive::Type type = op->GetResultType();
2298 switch (type) {
2299 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002300 Register out_reg = out.AsRegister<Register>();
2301 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002302 // Arm doesn't mask the shift count so we need to do it ourselves.
2303 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002304 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002305 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2306 if (op->IsShl()) {
2307 __ Lsl(out_reg, first_reg, second_reg);
2308 } else if (op->IsShr()) {
2309 __ Asr(out_reg, first_reg, second_reg);
2310 } else {
2311 __ Lsr(out_reg, first_reg, second_reg);
2312 }
2313 } else {
2314 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2315 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2316 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2317 __ Mov(out_reg, first_reg);
2318 } else if (op->IsShl()) {
2319 __ Lsl(out_reg, first_reg, shift_value);
2320 } else if (op->IsShr()) {
2321 __ Asr(out_reg, first_reg, shift_value);
2322 } else {
2323 __ Lsr(out_reg, first_reg, shift_value);
2324 }
2325 }
2326 break;
2327 }
2328 case Primitive::kPrimLong: {
2329 // TODO: Inline the assembly instead of calling the runtime.
2330 InvokeRuntimeCallingConvention calling_convention;
2331 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2332 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002333 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002334 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2335 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2336
2337 int32_t entry_point_offset;
2338 if (op->IsShl()) {
2339 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2340 } else if (op->IsShr()) {
2341 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2342 } else {
2343 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2344 }
2345 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2346 __ blx(LR);
2347 break;
2348 }
2349 default:
2350 LOG(FATAL) << "Unexpected operation type " << type;
2351 }
2352}
2353
2354void LocationsBuilderARM::VisitShl(HShl* shl) {
2355 HandleShift(shl);
2356}
2357
2358void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2359 HandleShift(shl);
2360}
2361
2362void LocationsBuilderARM::VisitShr(HShr* shr) {
2363 HandleShift(shr);
2364}
2365
2366void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2367 HandleShift(shr);
2368}
2369
2370void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2371 HandleShift(ushr);
2372}
2373
2374void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2375 HandleShift(ushr);
2376}
2377
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002378void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002379 LocationSummary* locations =
2380 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002381 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002382 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2383 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2384 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002385}
2386
2387void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2388 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002389 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002390 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002391 codegen_->InvokeRuntime(
2392 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002393}
2394
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002395void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2396 LocationSummary* locations =
2397 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2398 InvokeRuntimeCallingConvention calling_convention;
2399 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002400 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002401 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002402 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002403}
2404
2405void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2406 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002407 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002408 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002409 codegen_->InvokeRuntime(
2410 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002411}
2412
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002413void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002414 LocationSummary* locations =
2415 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002416 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2417 if (location.IsStackSlot()) {
2418 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2419 } else if (location.IsDoubleStackSlot()) {
2420 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002421 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002422 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002423}
2424
2425void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002426 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002427 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002428}
2429
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002430void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002431 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002432 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002433 locations->SetInAt(0, Location::RequiresRegister());
2434 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002435}
2436
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002437void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2438 LocationSummary* locations = not_->GetLocations();
2439 Location out = locations->Out();
2440 Location in = locations->InAt(0);
2441 switch (not_->InputAt(0)->GetType()) {
2442 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002443 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002444 break;
2445
2446 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002447 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002448 break;
2449
2450 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002451 __ mvn(out.AsRegisterPairLow<Register>(),
2452 ShifterOperand(in.AsRegisterPairLow<Register>()));
2453 __ mvn(out.AsRegisterPairHigh<Register>(),
2454 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002455 break;
2456
2457 default:
2458 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2459 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002460}
2461
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002462void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002463 LocationSummary* locations =
2464 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002465 switch (compare->InputAt(0)->GetType()) {
2466 case Primitive::kPrimLong: {
2467 locations->SetInAt(0, Location::RequiresRegister());
2468 locations->SetInAt(1, Location::RequiresRegister());
2469 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2470 break;
2471 }
2472 case Primitive::kPrimFloat:
2473 case Primitive::kPrimDouble: {
2474 locations->SetInAt(0, Location::RequiresFpuRegister());
2475 locations->SetInAt(1, Location::RequiresFpuRegister());
2476 locations->SetOut(Location::RequiresRegister());
2477 break;
2478 }
2479 default:
2480 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2481 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002482}
2483
2484void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002485 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002486 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002487 Location left = locations->InAt(0);
2488 Location right = locations->InAt(1);
2489
2490 Label less, greater, done;
2491 Primitive::Type type = compare->InputAt(0)->GetType();
2492 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002493 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002494 __ cmp(left.AsRegisterPairHigh<Register>(),
2495 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002496 __ b(&less, LT);
2497 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002498 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2499 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002500 __ cmp(left.AsRegisterPairLow<Register>(),
2501 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002502 break;
2503 }
2504 case Primitive::kPrimFloat:
2505 case Primitive::kPrimDouble: {
2506 __ LoadImmediate(out, 0);
2507 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002508 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002509 } else {
2510 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2511 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2512 }
2513 __ vmstat(); // transfer FP status register to ARM APSR.
2514 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002515 break;
2516 }
2517 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002518 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002519 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002520 __ b(&done, EQ);
2521 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2522
2523 __ Bind(&greater);
2524 __ LoadImmediate(out, 1);
2525 __ b(&done);
2526
2527 __ Bind(&less);
2528 __ LoadImmediate(out, -1);
2529
2530 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002531}
2532
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002533void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002534 LocationSummary* locations =
2535 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002536 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2537 locations->SetInAt(i, Location::Any());
2538 }
2539 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002540}
2541
2542void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002543 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002544 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002545}
2546
Calin Juravle52c48962014-12-16 17:02:57 +00002547void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2548 // TODO (ported from quick): revisit Arm barrier kinds
2549 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2550 switch (kind) {
2551 case MemBarrierKind::kAnyStore:
2552 case MemBarrierKind::kLoadAny:
2553 case MemBarrierKind::kAnyAny: {
2554 flavour = DmbOptions::ISH;
2555 break;
2556 }
2557 case MemBarrierKind::kStoreStore: {
2558 flavour = DmbOptions::ISHST;
2559 break;
2560 }
2561 default:
2562 LOG(FATAL) << "Unexpected memory barrier " << kind;
2563 }
2564 __ dmb(flavour);
2565}
2566
2567void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2568 uint32_t offset,
2569 Register out_lo,
2570 Register out_hi) {
2571 if (offset != 0) {
2572 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002573 __ add(IP, addr, ShifterOperand(out_lo));
2574 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002575 }
2576 __ ldrexd(out_lo, out_hi, addr);
2577}
2578
2579void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2580 uint32_t offset,
2581 Register value_lo,
2582 Register value_hi,
2583 Register temp1,
2584 Register temp2) {
2585 Label fail;
2586 if (offset != 0) {
2587 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002588 __ add(IP, addr, ShifterOperand(temp1));
2589 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002590 }
2591 __ Bind(&fail);
2592 // We need a load followed by store. (The address used in a STREX instruction must
2593 // be the same as the address in the most recently executed LDREX instruction.)
2594 __ ldrexd(temp1, temp2, addr);
2595 __ strexd(temp1, value_lo, value_hi, addr);
2596 __ cmp(temp1, ShifterOperand(0));
2597 __ b(&fail, NE);
2598}
2599
2600void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2601 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2602
Nicolas Geoffray39468442014-09-02 15:17:15 +01002603 LocationSummary* locations =
2604 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002605 locations->SetInAt(0, Location::RequiresRegister());
2606 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002607
Calin Juravle34166012014-12-19 17:22:29 +00002608
Calin Juravle52c48962014-12-16 17:02:57 +00002609 Primitive::Type field_type = field_info.GetFieldType();
2610 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002611 bool generate_volatile = field_info.IsVolatile()
2612 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002613 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002614 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002615 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2616 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002617 locations->AddTemp(Location::RequiresRegister());
2618 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002619 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002620 // Arm encoding have some additional constraints for ldrexd/strexd:
2621 // - registers need to be consecutive
2622 // - the first register should be even but not R14.
2623 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2624 // enable Arm encoding.
2625 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2626
2627 locations->AddTemp(Location::RequiresRegister());
2628 locations->AddTemp(Location::RequiresRegister());
2629 if (field_type == Primitive::kPrimDouble) {
2630 // For doubles we need two more registers to copy the value.
2631 locations->AddTemp(Location::RegisterLocation(R2));
2632 locations->AddTemp(Location::RegisterLocation(R3));
2633 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002634 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002635}
2636
Calin Juravle52c48962014-12-16 17:02:57 +00002637void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2638 const FieldInfo& field_info) {
2639 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2640
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002641 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002642 Register base = locations->InAt(0).AsRegister<Register>();
2643 Location value = locations->InAt(1);
2644
2645 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002646 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002647 Primitive::Type field_type = field_info.GetFieldType();
2648 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2649
2650 if (is_volatile) {
2651 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2652 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002653
2654 switch (field_type) {
2655 case Primitive::kPrimBoolean:
2656 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002657 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002658 break;
2659 }
2660
2661 case Primitive::kPrimShort:
2662 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002663 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002664 break;
2665 }
2666
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002667 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002668 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002669 Register value_reg = value.AsRegister<Register>();
2670 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2671 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002672 Register temp = locations->GetTemp(0).AsRegister<Register>();
2673 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002674 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002675 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002676 break;
2677 }
2678
2679 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002680 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002681 GenerateWideAtomicStore(base, offset,
2682 value.AsRegisterPairLow<Register>(),
2683 value.AsRegisterPairHigh<Register>(),
2684 locations->GetTemp(0).AsRegister<Register>(),
2685 locations->GetTemp(1).AsRegister<Register>());
2686 } else {
2687 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2688 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002689 break;
2690 }
2691
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002692 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002693 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002694 break;
2695 }
2696
2697 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002698 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002699 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002700 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2701 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2702
2703 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2704
2705 GenerateWideAtomicStore(base, offset,
2706 value_reg_lo,
2707 value_reg_hi,
2708 locations->GetTemp(2).AsRegister<Register>(),
2709 locations->GetTemp(3).AsRegister<Register>());
2710 } else {
2711 __ StoreDToOffset(value_reg, base, offset);
2712 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002713 break;
2714 }
2715
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002716 case Primitive::kPrimVoid:
2717 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002718 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002719 }
Calin Juravle52c48962014-12-16 17:02:57 +00002720
2721 if (is_volatile) {
2722 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2723 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002724}
2725
Calin Juravle52c48962014-12-16 17:02:57 +00002726void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2727 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002728 LocationSummary* locations =
2729 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002730 locations->SetInAt(0, Location::RequiresRegister());
2731 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002732
Calin Juravle34166012014-12-19 17:22:29 +00002733 bool generate_volatile = field_info.IsVolatile()
2734 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002735 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle34166012014-12-19 17:22:29 +00002736 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002737 // Arm encoding have some additional constraints for ldrexd/strexd:
2738 // - registers need to be consecutive
2739 // - the first register should be even but not R14.
2740 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2741 // enable Arm encoding.
2742 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2743 locations->AddTemp(Location::RequiresRegister());
2744 locations->AddTemp(Location::RequiresRegister());
2745 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002746}
2747
Calin Juravle52c48962014-12-16 17:02:57 +00002748void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2749 const FieldInfo& field_info) {
2750 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002751
Calin Juravle52c48962014-12-16 17:02:57 +00002752 LocationSummary* locations = instruction->GetLocations();
2753 Register base = locations->InAt(0).AsRegister<Register>();
2754 Location out = locations->Out();
2755 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002756 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002757 Primitive::Type field_type = field_info.GetFieldType();
2758 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2759
2760 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002761 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002762 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002763 break;
2764 }
2765
2766 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002767 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002768 break;
2769 }
2770
2771 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002772 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002773 break;
2774 }
2775
2776 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002777 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002778 break;
2779 }
2780
2781 case Primitive::kPrimInt:
2782 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002783 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002784 break;
2785 }
2786
2787 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002788 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002789 GenerateWideAtomicLoad(base, offset,
2790 out.AsRegisterPairLow<Register>(),
2791 out.AsRegisterPairHigh<Register>());
2792 } else {
2793 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2794 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002795 break;
2796 }
2797
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002798 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002799 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002800 break;
2801 }
2802
2803 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002804 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002805 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002806 Register lo = locations->GetTemp(0).AsRegister<Register>();
2807 Register hi = locations->GetTemp(1).AsRegister<Register>();
2808 GenerateWideAtomicLoad(base, offset, lo, hi);
2809 __ vmovdrr(out_reg, lo, hi);
2810 } else {
2811 __ LoadDFromOffset(out_reg, base, offset);
2812 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002813 break;
2814 }
2815
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002816 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002817 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002818 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002819 }
Calin Juravle52c48962014-12-16 17:02:57 +00002820
2821 if (is_volatile) {
2822 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2823 }
2824}
2825
2826void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2827 HandleFieldSet(instruction, instruction->GetFieldInfo());
2828}
2829
2830void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2831 HandleFieldSet(instruction, instruction->GetFieldInfo());
2832}
2833
2834void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2835 HandleFieldGet(instruction, instruction->GetFieldInfo());
2836}
2837
2838void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2839 HandleFieldGet(instruction, instruction->GetFieldInfo());
2840}
2841
2842void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2843 HandleFieldGet(instruction, instruction->GetFieldInfo());
2844}
2845
2846void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2847 HandleFieldGet(instruction, instruction->GetFieldInfo());
2848}
2849
2850void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2851 HandleFieldSet(instruction, instruction->GetFieldInfo());
2852}
2853
2854void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2855 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002856}
2857
2858void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002859 LocationSummary* locations =
2860 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002861 Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks()
2862 ? Location::RequiresRegister()
2863 : Location::RegisterOrConstant(instruction->InputAt(0));
2864 locations->SetInAt(0, loc);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002865 if (instruction->HasUses()) {
2866 locations->SetOut(Location::SameAsFirstInput());
2867 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002868}
2869
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002870void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
2871 Location obj = instruction->GetLocations()->InAt(0);
2872 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2873 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2874}
2875
2876void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002877 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002878 codegen_->AddSlowPath(slow_path);
2879
2880 LocationSummary* locations = instruction->GetLocations();
2881 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002882
2883 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002884 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002885 __ b(slow_path->GetEntryLabel(), EQ);
2886 } else {
2887 DCHECK(obj.IsConstant()) << obj;
2888 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2889 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002890 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002891}
2892
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002893void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2894 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2895 GenerateImplicitNullCheck(instruction);
2896 } else {
2897 GenerateExplicitNullCheck(instruction);
2898 }
2899}
2900
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002901void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002902 LocationSummary* locations =
2903 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002904 locations->SetInAt(0, Location::RequiresRegister());
2905 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2906 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002907}
2908
2909void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2910 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002911 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002912 Location index = locations->InAt(1);
2913
2914 switch (instruction->GetType()) {
2915 case Primitive::kPrimBoolean: {
2916 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002917 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002918 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002919 size_t offset =
2920 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002921 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2922 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002923 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002924 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2925 }
2926 break;
2927 }
2928
2929 case Primitive::kPrimByte: {
2930 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002931 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002932 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002933 size_t offset =
2934 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002935 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2936 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002937 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002938 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2939 }
2940 break;
2941 }
2942
2943 case Primitive::kPrimShort: {
2944 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002945 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002946 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002947 size_t offset =
2948 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002949 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2950 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002951 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002952 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2953 }
2954 break;
2955 }
2956
2957 case Primitive::kPrimChar: {
2958 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002959 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002960 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002961 size_t offset =
2962 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002963 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2964 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002965 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002966 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2967 }
2968 break;
2969 }
2970
2971 case Primitive::kPrimInt:
2972 case Primitive::kPrimNot: {
2973 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2974 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002975 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002976 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002977 size_t offset =
2978 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002979 __ LoadFromOffset(kLoadWord, out, obj, offset);
2980 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002981 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002982 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2983 }
2984 break;
2985 }
2986
2987 case Primitive::kPrimLong: {
2988 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002989 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002990 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002991 size_t offset =
2992 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002993 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002994 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002995 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002996 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002997 }
2998 break;
2999 }
3000
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003001 case Primitive::kPrimFloat: {
3002 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3003 Location out = locations->Out();
3004 DCHECK(out.IsFpuRegister());
3005 if (index.IsConstant()) {
3006 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3007 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3008 } else {
3009 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3010 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3011 }
3012 break;
3013 }
3014
3015 case Primitive::kPrimDouble: {
3016 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3017 Location out = locations->Out();
3018 DCHECK(out.IsFpuRegisterPair());
3019 if (index.IsConstant()) {
3020 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3021 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3022 } else {
3023 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3024 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3025 }
3026 break;
3027 }
3028
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003029 case Primitive::kPrimVoid:
3030 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003031 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003032 }
3033}
3034
3035void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003036 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003037
3038 bool needs_write_barrier =
3039 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3040 bool needs_runtime_call = instruction->NeedsTypeCheck();
3041
Nicolas Geoffray39468442014-09-02 15:17:15 +01003042 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003043 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3044 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003045 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003046 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3047 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3048 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003049 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003050 locations->SetInAt(0, Location::RequiresRegister());
3051 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3052 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003053
3054 if (needs_write_barrier) {
3055 // Temporary registers for the write barrier.
3056 locations->AddTemp(Location::RequiresRegister());
3057 locations->AddTemp(Location::RequiresRegister());
3058 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003059 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003060}
3061
3062void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3063 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003064 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003065 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003066 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003067 bool needs_runtime_call = locations->WillCall();
3068 bool needs_write_barrier =
3069 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003070
3071 switch (value_type) {
3072 case Primitive::kPrimBoolean:
3073 case Primitive::kPrimByte: {
3074 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003075 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003076 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003077 size_t offset =
3078 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003079 __ StoreToOffset(kStoreByte, value, obj, offset);
3080 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003081 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003082 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3083 }
3084 break;
3085 }
3086
3087 case Primitive::kPrimShort:
3088 case Primitive::kPrimChar: {
3089 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003090 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003091 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003092 size_t offset =
3093 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003094 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3095 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003096 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003097 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3098 }
3099 break;
3100 }
3101
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003102 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003103 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003104 if (!needs_runtime_call) {
3105 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003106 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003107 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003108 size_t offset =
3109 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003110 __ StoreToOffset(kStoreWord, value, obj, offset);
3111 } else {
3112 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003113 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003114 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3115 }
3116 if (needs_write_barrier) {
3117 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003118 Register temp = locations->GetTemp(0).AsRegister<Register>();
3119 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003120 codegen_->MarkGCCard(temp, card, obj, value);
3121 }
3122 } else {
3123 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003124 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3125 instruction,
3126 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003127 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003128 break;
3129 }
3130
3131 case Primitive::kPrimLong: {
3132 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003133 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003134 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003135 size_t offset =
3136 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003137 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003138 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003139 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003140 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003141 }
3142 break;
3143 }
3144
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003145 case Primitive::kPrimFloat: {
3146 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3147 Location value = locations->InAt(2);
3148 DCHECK(value.IsFpuRegister());
3149 if (index.IsConstant()) {
3150 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3151 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3152 } else {
3153 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3154 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3155 }
3156 break;
3157 }
3158
3159 case Primitive::kPrimDouble: {
3160 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3161 Location value = locations->InAt(2);
3162 DCHECK(value.IsFpuRegisterPair());
3163 if (index.IsConstant()) {
3164 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3165 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3166 } else {
3167 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3168 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3169 }
3170 break;
3171 }
3172
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003173 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003174 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003175 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003176 }
3177}
3178
3179void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003180 LocationSummary* locations =
3181 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003182 locations->SetInAt(0, Location::RequiresRegister());
3183 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003184}
3185
3186void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3187 LocationSummary* locations = instruction->GetLocations();
3188 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 Register obj = locations->InAt(0).AsRegister<Register>();
3190 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003191 __ LoadFromOffset(kLoadWord, out, obj, offset);
3192}
3193
3194void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003195 LocationSummary* locations =
3196 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003197 locations->SetInAt(0, Location::RequiresRegister());
3198 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003199 if (instruction->HasUses()) {
3200 locations->SetOut(Location::SameAsFirstInput());
3201 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003202}
3203
3204void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3205 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003206 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003207 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003208 codegen_->AddSlowPath(slow_path);
3209
Roland Levillain271ab9c2014-11-27 15:23:57 +00003210 Register index = locations->InAt(0).AsRegister<Register>();
3211 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003212
3213 __ cmp(index, ShifterOperand(length));
3214 __ b(slow_path->GetEntryLabel(), CS);
3215}
3216
3217void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3218 Label is_null;
3219 __ CompareAndBranchIfZero(value, &is_null);
3220 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3221 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3222 __ strb(card, Address(card, temp));
3223 __ Bind(&is_null);
3224}
3225
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003226void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3227 temp->SetLocations(nullptr);
3228}
3229
3230void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3231 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003232 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003233}
3234
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003235void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003236 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003237 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003238}
3239
3240void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003241 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3242}
3243
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003244void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3245 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3246}
3247
3248void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003249 HBasicBlock* block = instruction->GetBlock();
3250 if (block->GetLoopInformation() != nullptr) {
3251 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3252 // The back edge will generate the suspend check.
3253 return;
3254 }
3255 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3256 // The goto will generate the suspend check.
3257 return;
3258 }
3259 GenerateSuspendCheck(instruction, nullptr);
3260}
3261
3262void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3263 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003264 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003265 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003266 codegen_->AddSlowPath(slow_path);
3267
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003268 __ LoadFromOffset(
3269 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3270 __ cmp(IP, ShifterOperand(0));
3271 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003272 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003273 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003274 __ Bind(slow_path->GetReturnLabel());
3275 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003276 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003277 __ b(slow_path->GetEntryLabel());
3278 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003279}
3280
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003281ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3282 return codegen_->GetAssembler();
3283}
3284
3285void ParallelMoveResolverARM::EmitMove(size_t index) {
3286 MoveOperands* move = moves_.Get(index);
3287 Location source = move->GetSource();
3288 Location destination = move->GetDestination();
3289
3290 if (source.IsRegister()) {
3291 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003292 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003293 } else {
3294 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003295 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003296 SP, destination.GetStackIndex());
3297 }
3298 } else if (source.IsStackSlot()) {
3299 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003300 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003301 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003302 } else if (destination.IsFpuRegister()) {
3303 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003304 } else {
3305 DCHECK(destination.IsStackSlot());
3306 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3307 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3308 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003309 } else if (source.IsFpuRegister()) {
3310 if (destination.IsFpuRegister()) {
3311 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003312 } else {
3313 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003314 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3315 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003316 } else if (source.IsDoubleStackSlot()) {
3317 if (destination.IsFpuRegisterPair()) {
3318 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3319 SP, source.GetStackIndex());
3320 } else {
3321 DCHECK(destination.IsDoubleStackSlot()) << destination;
3322 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003323 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003324 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3325 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3326 }
3327 } else {
3328 DCHECK(source.IsConstant()) << source;
3329 HInstruction* constant = source.GetConstant();
3330 if (constant->IsIntConstant()) {
3331 int32_t value = constant->AsIntConstant()->GetValue();
3332 if (destination.IsRegister()) {
3333 __ LoadImmediate(destination.AsRegister<Register>(), value);
3334 } else {
3335 DCHECK(destination.IsStackSlot());
3336 __ LoadImmediate(IP, value);
3337 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3338 }
3339 } else {
3340 DCHECK(constant->IsFloatConstant());
3341 float value = constant->AsFloatConstant()->GetValue();
3342 if (destination.IsFpuRegister()) {
3343 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3344 } else {
3345 DCHECK(destination.IsStackSlot());
3346 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3347 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3348 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003349 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003350 }
3351}
3352
3353void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3354 __ Mov(IP, reg);
3355 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3356 __ StoreToOffset(kStoreWord, IP, SP, mem);
3357}
3358
3359void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3360 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3361 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3362 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3363 SP, mem1 + stack_offset);
3364 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3365 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3366 SP, mem2 + stack_offset);
3367 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3368}
3369
3370void ParallelMoveResolverARM::EmitSwap(size_t index) {
3371 MoveOperands* move = moves_.Get(index);
3372 Location source = move->GetSource();
3373 Location destination = move->GetDestination();
3374
3375 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003376 DCHECK_NE(source.AsRegister<Register>(), IP);
3377 DCHECK_NE(destination.AsRegister<Register>(), IP);
3378 __ Mov(IP, source.AsRegister<Register>());
3379 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3380 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003381 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003382 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003383 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003384 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003385 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3386 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003387 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003388 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003389 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003390 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003391 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3392 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3393 : destination.AsFpuRegister<SRegister>();
3394 int mem = source.IsFpuRegister()
3395 ? destination.GetStackIndex()
3396 : source.GetStackIndex();
3397
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003398 __ vmovrs(IP, reg);
3399 __ LoadFromOffset(kLoadWord, IP, SP, mem);
3400 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003401 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003402 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3403 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003404 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003405 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003406 }
3407}
3408
3409void ParallelMoveResolverARM::SpillScratch(int reg) {
3410 __ Push(static_cast<Register>(reg));
3411}
3412
3413void ParallelMoveResolverARM::RestoreScratch(int reg) {
3414 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003415}
3416
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003417void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003418 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3419 ? LocationSummary::kCallOnSlowPath
3420 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003421 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003422 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003423 locations->SetOut(Location::RequiresRegister());
3424}
3425
3426void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003427 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003428 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003429 DCHECK(!cls->CanCallRuntime());
3430 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003431 codegen_->LoadCurrentMethod(out);
3432 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3433 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003434 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003435 codegen_->LoadCurrentMethod(out);
3436 __ LoadFromOffset(
3437 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3438 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003439
3440 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3441 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3442 codegen_->AddSlowPath(slow_path);
3443 __ cmp(out, ShifterOperand(0));
3444 __ b(slow_path->GetEntryLabel(), EQ);
3445 if (cls->MustGenerateClinitCheck()) {
3446 GenerateClassInitializationCheck(slow_path, out);
3447 } else {
3448 __ Bind(slow_path->GetExitLabel());
3449 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003450 }
3451}
3452
3453void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3454 LocationSummary* locations =
3455 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3456 locations->SetInAt(0, Location::RequiresRegister());
3457 if (check->HasUses()) {
3458 locations->SetOut(Location::SameAsFirstInput());
3459 }
3460}
3461
3462void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003463 // We assume the class is not null.
3464 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3465 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003466 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003467 GenerateClassInitializationCheck(slow_path,
3468 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003469}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003470
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003471void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3472 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003473 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3474 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3475 __ b(slow_path->GetEntryLabel(), LT);
3476 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3477 // properly. Therefore, we do a memory fence.
3478 __ dmb(ISH);
3479 __ Bind(slow_path->GetExitLabel());
3480}
3481
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003482void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3483 LocationSummary* locations =
3484 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3485 locations->SetOut(Location::RequiresRegister());
3486}
3487
3488void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3489 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3490 codegen_->AddSlowPath(slow_path);
3491
Roland Levillain271ab9c2014-11-27 15:23:57 +00003492 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003493 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003494 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3495 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003496 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3497 __ cmp(out, ShifterOperand(0));
3498 __ b(slow_path->GetEntryLabel(), EQ);
3499 __ Bind(slow_path->GetExitLabel());
3500}
3501
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003502void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3503 LocationSummary* locations =
3504 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3505 locations->SetOut(Location::RequiresRegister());
3506}
3507
3508void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003509 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003510 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3511 __ LoadFromOffset(kLoadWord, out, TR, offset);
3512 __ LoadImmediate(IP, 0);
3513 __ StoreToOffset(kStoreWord, IP, TR, offset);
3514}
3515
3516void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3517 LocationSummary* locations =
3518 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3519 InvokeRuntimeCallingConvention calling_convention;
3520 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3521}
3522
3523void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3524 codegen_->InvokeRuntime(
3525 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3526}
3527
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003528void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003529 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3530 ? LocationSummary::kNoCall
3531 : LocationSummary::kCallOnSlowPath;
3532 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3533 locations->SetInAt(0, Location::RequiresRegister());
3534 locations->SetInAt(1, Location::RequiresRegister());
3535 locations->SetOut(Location::RequiresRegister());
3536}
3537
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003538void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003539 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003540 Register obj = locations->InAt(0).AsRegister<Register>();
3541 Register cls = locations->InAt(1).AsRegister<Register>();
3542 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003543 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3544 Label done, zero;
3545 SlowPathCodeARM* slow_path = nullptr;
3546
3547 // Return 0 if `obj` is null.
3548 // TODO: avoid this check if we know obj is not null.
3549 __ cmp(obj, ShifterOperand(0));
3550 __ b(&zero, EQ);
3551 // Compare the class of `obj` with `cls`.
3552 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3553 __ cmp(out, ShifterOperand(cls));
3554 if (instruction->IsClassFinal()) {
3555 // Classes must be equal for the instanceof to succeed.
3556 __ b(&zero, NE);
3557 __ LoadImmediate(out, 1);
3558 __ b(&done);
3559 } else {
3560 // If the classes are not equal, we go into a slow path.
3561 DCHECK(locations->OnlyCallsOnSlowPath());
3562 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003563 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003564 codegen_->AddSlowPath(slow_path);
3565 __ b(slow_path->GetEntryLabel(), NE);
3566 __ LoadImmediate(out, 1);
3567 __ b(&done);
3568 }
3569 __ Bind(&zero);
3570 __ LoadImmediate(out, 0);
3571 if (slow_path != nullptr) {
3572 __ Bind(slow_path->GetExitLabel());
3573 }
3574 __ Bind(&done);
3575}
3576
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003577void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3578 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3579 instruction, LocationSummary::kCallOnSlowPath);
3580 locations->SetInAt(0, Location::RequiresRegister());
3581 locations->SetInAt(1, Location::RequiresRegister());
3582 locations->AddTemp(Location::RequiresRegister());
3583}
3584
3585void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3586 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003587 Register obj = locations->InAt(0).AsRegister<Register>();
3588 Register cls = locations->InAt(1).AsRegister<Register>();
3589 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003590 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3591
3592 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3593 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3594 codegen_->AddSlowPath(slow_path);
3595
3596 // TODO: avoid this check if we know obj is not null.
3597 __ cmp(obj, ShifterOperand(0));
3598 __ b(slow_path->GetExitLabel(), EQ);
3599 // Compare the class of `obj` with `cls`.
3600 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3601 __ cmp(temp, ShifterOperand(cls));
3602 __ b(slow_path->GetEntryLabel(), NE);
3603 __ Bind(slow_path->GetExitLabel());
3604}
3605
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003606void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3607 LocationSummary* locations =
3608 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3609 InvokeRuntimeCallingConvention calling_convention;
3610 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3611}
3612
3613void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3614 codegen_->InvokeRuntime(instruction->IsEnter()
3615 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3616 instruction,
3617 instruction->GetDexPc());
3618}
3619
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003620void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3621void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3622void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3623
3624void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3625 LocationSummary* locations =
3626 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3627 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3628 || instruction->GetResultType() == Primitive::kPrimLong);
3629 locations->SetInAt(0, Location::RequiresRegister());
3630 locations->SetInAt(1, Location::RequiresRegister());
3631 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3632 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3633}
3634
3635void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3636 HandleBitwiseOperation(instruction);
3637}
3638
3639void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3640 HandleBitwiseOperation(instruction);
3641}
3642
3643void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3644 HandleBitwiseOperation(instruction);
3645}
3646
3647void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3648 LocationSummary* locations = instruction->GetLocations();
3649
3650 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003651 Register first = locations->InAt(0).AsRegister<Register>();
3652 Register second = locations->InAt(1).AsRegister<Register>();
3653 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003654 if (instruction->IsAnd()) {
3655 __ and_(out, first, ShifterOperand(second));
3656 } else if (instruction->IsOr()) {
3657 __ orr(out, first, ShifterOperand(second));
3658 } else {
3659 DCHECK(instruction->IsXor());
3660 __ eor(out, first, ShifterOperand(second));
3661 }
3662 } else {
3663 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3664 Location first = locations->InAt(0);
3665 Location second = locations->InAt(1);
3666 Location out = locations->Out();
3667 if (instruction->IsAnd()) {
3668 __ and_(out.AsRegisterPairLow<Register>(),
3669 first.AsRegisterPairLow<Register>(),
3670 ShifterOperand(second.AsRegisterPairLow<Register>()));
3671 __ and_(out.AsRegisterPairHigh<Register>(),
3672 first.AsRegisterPairHigh<Register>(),
3673 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3674 } else if (instruction->IsOr()) {
3675 __ orr(out.AsRegisterPairLow<Register>(),
3676 first.AsRegisterPairLow<Register>(),
3677 ShifterOperand(second.AsRegisterPairLow<Register>()));
3678 __ orr(out.AsRegisterPairHigh<Register>(),
3679 first.AsRegisterPairHigh<Register>(),
3680 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3681 } else {
3682 DCHECK(instruction->IsXor());
3683 __ eor(out.AsRegisterPairLow<Register>(),
3684 first.AsRegisterPairLow<Register>(),
3685 ShifterOperand(second.AsRegisterPairLow<Register>()));
3686 __ eor(out.AsRegisterPairHigh<Register>(),
3687 first.AsRegisterPairHigh<Register>(),
3688 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3689 }
3690 }
3691}
3692
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003693} // namespace arm
3694} // namespace art