blob: af385ebe3120835773866f2cf60c25b3b9d9302a [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 Geoffray53f12622015-01-13 18:04:41 +000052static constexpr DRegister DTMP = D7;
53static constexpr SRegister STMP = S14;
54
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000055class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010056 public:
57 InvokeRuntimeCallingConvention()
58 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010059 kRuntimeParameterCoreRegistersLength,
60 kRuntimeParameterFpuRegisters,
61 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010062
63 private:
64 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
65};
66
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010068#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010069
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010070class SlowPathCodeARM : public SlowPathCode {
71 public:
72 SlowPathCodeARM() : entry_label_(), exit_label_() {}
73
74 Label* GetEntryLabel() { return &entry_label_; }
75 Label* GetExitLabel() { return &exit_label_; }
76
77 private:
78 Label entry_label_;
79 Label exit_label_;
80
81 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
82};
83
84class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010086 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010087
Alexandre Rames67555f72014-11-18 10:55:16 +000088 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010089 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010090 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010091 arm_codegen->InvokeRuntime(
92 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010093 }
94
95 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010096 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010097 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
98};
99
Calin Juravled0d48522014-11-04 16:40:20 +0000100class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
101 public:
102 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
103
Alexandre Rames67555f72014-11-18 10:55:16 +0000104 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000105 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
106 __ Bind(GetEntryLabel());
107 arm_codegen->InvokeRuntime(
108 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
109 }
110
111 private:
112 HDivZeroCheck* const instruction_;
113 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
114};
115
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100116class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100117 public:
118 StackOverflowCheckSlowPathARM() {}
119
Alexandre Rames67555f72014-11-18 10:55:16 +0000120 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100121 __ Bind(GetEntryLabel());
122 __ LoadFromOffset(kLoadWord, PC, TR,
123 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
124 }
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
128};
129
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100130class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000131 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000132 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100133 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000134
Alexandre Rames67555f72014-11-18 10:55:16 +0000135 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100136 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000137 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100138 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100139 arm_codegen->InvokeRuntime(
140 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100141 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100142 if (successor_ == nullptr) {
143 __ b(GetReturnLabel());
144 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100145 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100146 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000147 }
148
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100149 Label* GetReturnLabel() {
150 DCHECK(successor_ == nullptr);
151 return &return_label_;
152 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000153
154 private:
155 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100156 // If not null, the block to branch to after the suspend check.
157 HBasicBlock* const successor_;
158
159 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000160 Label return_label_;
161
162 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
163};
164
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100165class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100166 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100167 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
168 Location index_location,
169 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100170 : instruction_(instruction),
171 index_location_(index_location),
172 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100173
Alexandre Rames67555f72014-11-18 10:55:16 +0000174 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100175 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100176 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000177 // We're moving two locations to locations that could overlap, so we need a parallel
178 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100179 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000180 codegen->EmitParallelMoves(
181 index_location_,
182 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
183 length_location_,
184 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100185 arm_codegen->InvokeRuntime(
186 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100187 }
188
189 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100190 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100191 const Location index_location_;
192 const Location length_location_;
193
194 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
195};
196
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000197class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000199 LoadClassSlowPathARM(HLoadClass* cls,
200 HInstruction* at,
201 uint32_t dex_pc,
202 bool do_clinit)
203 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
204 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
205 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206
Alexandre Rames67555f72014-11-18 10:55:16 +0000207 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000208 LocationSummary* locations = at_->GetLocations();
209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
211 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100213
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100214 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000215 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100216 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000217 int32_t entry_point_offset = do_clinit_
218 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
219 : QUICK_ENTRY_POINT(pInitializeType);
220 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
221
222 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000223 Location out = locations->Out();
224 if (out.IsValid()) {
225 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000226 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
227 }
228 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100229 __ b(GetExitLabel());
230 }
231
232 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000233 // The class this slow path will load.
234 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100235
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000236 // The instruction where this slow path is happening.
237 // (Might be the load class or an initialization check).
238 HInstruction* const at_;
239
240 // The dex PC of `at_`.
241 const uint32_t dex_pc_;
242
243 // Whether to initialize the class.
244 const bool do_clinit_;
245
246 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100247};
248
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000249class LoadStringSlowPathARM : public SlowPathCodeARM {
250 public:
251 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
252
Alexandre Rames67555f72014-11-18 10:55:16 +0000253 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000254 LocationSummary* locations = instruction_->GetLocations();
255 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
256
257 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
258 __ Bind(GetEntryLabel());
259 codegen->SaveLiveRegisters(locations);
260
261 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800262 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
263 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000264 arm_codegen->InvokeRuntime(
265 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
266 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
267
268 codegen->RestoreLiveRegisters(locations);
269 __ b(GetExitLabel());
270 }
271
272 private:
273 HLoadString* const instruction_;
274
275 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
276};
277
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000278class TypeCheckSlowPathARM : public SlowPathCodeARM {
279 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000280 TypeCheckSlowPathARM(HInstruction* instruction,
281 Location class_to_check,
282 Location object_class,
283 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000284 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000285 class_to_check_(class_to_check),
286 object_class_(object_class),
287 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000288
Alexandre Rames67555f72014-11-18 10:55:16 +0000289 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000290 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000291 DCHECK(instruction_->IsCheckCast()
292 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000293
294 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
295 __ Bind(GetEntryLabel());
296 codegen->SaveLiveRegisters(locations);
297
298 // We're moving two locations to locations that could overlap, so we need a parallel
299 // move resolver.
300 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000301 codegen->EmitParallelMoves(
302 class_to_check_,
303 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
304 object_class_,
305 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000306
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000307 if (instruction_->IsInstanceOf()) {
308 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
309 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
310 } else {
311 DCHECK(instruction_->IsCheckCast());
312 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
313 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000314
315 codegen->RestoreLiveRegisters(locations);
316 __ b(GetExitLabel());
317 }
318
319 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000320 HInstruction* const instruction_;
321 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000322 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000323 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000324
325 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
326};
327
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000328#undef __
329
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100330#undef __
331#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700332
333inline Condition ARMCondition(IfCondition cond) {
334 switch (cond) {
335 case kCondEQ: return EQ;
336 case kCondNE: return NE;
337 case kCondLT: return LT;
338 case kCondLE: return LE;
339 case kCondGT: return GT;
340 case kCondGE: return GE;
341 default:
342 LOG(FATAL) << "Unknown if condition";
343 }
344 return EQ; // Unreachable.
345}
346
347inline Condition ARMOppositeCondition(IfCondition cond) {
348 switch (cond) {
349 case kCondEQ: return NE;
350 case kCondNE: return EQ;
351 case kCondLT: return GE;
352 case kCondLE: return GT;
353 case kCondGT: return LE;
354 case kCondGE: return LT;
355 default:
356 LOG(FATAL) << "Unknown if condition";
357 }
358 return EQ; // Unreachable.
359}
360
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100361void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
362 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
363}
364
365void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000366 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100367}
368
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100369size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
370 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
371 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100372}
373
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100374size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
375 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
376 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100377}
378
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000379size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
380 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
381 return kArmWordSize;
382}
383
384size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
385 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
386 return kArmWordSize;
387}
388
Calin Juravle34166012014-12-19 17:22:29 +0000389CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
390 const ArmInstructionSetFeatures* isa_features)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000391 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100392 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100393 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100394 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100395 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000396 assembler_(true),
397 isa_features_(isa_features) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100398
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100399size_t CodeGeneratorARM::FrameEntrySpillSize() const {
400 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
401}
402
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100403Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 switch (type) {
405 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100406 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100407 ArmManagedRegister pair =
408 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100409 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
410 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
411
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100412 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
413 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100414 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100415 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100416 }
417
418 case Primitive::kPrimByte:
419 case Primitive::kPrimBoolean:
420 case Primitive::kPrimChar:
421 case Primitive::kPrimShort:
422 case Primitive::kPrimInt:
423 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100424 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100425 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100426 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
427 ArmManagedRegister current =
428 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
429 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100430 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100431 }
432 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100433 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100434 }
435
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000436 case Primitive::kPrimFloat: {
437 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100438 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100439 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000441 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000442 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
443 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000444 return Location::FpuRegisterPairLocation(reg, reg + 1);
445 }
446
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447 case Primitive::kPrimVoid:
448 LOG(FATAL) << "Unreachable type " << type;
449 }
450
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100451 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452}
453
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100455 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100457
458 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100459 blocked_core_registers_[SP] = true;
460 blocked_core_registers_[LR] = true;
461 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100462
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100464 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100465
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100466 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100467 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100468
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000469 // TODO: We currently don't use Quick's callee saved registers.
470 // We always save and restore R6 and R7 to make sure we can use three
471 // register pairs for long operations.
472 blocked_core_registers_[R4] = true;
473 blocked_core_registers_[R5] = true;
474 blocked_core_registers_[R8] = true;
475 blocked_core_registers_[R10] = true;
476 blocked_core_registers_[R11] = true;
477
Nicolas Geoffray53f12622015-01-13 18:04:41 +0000478 // Don't allocate our temporary double register.
479 blocked_fpu_registers_[STMP] = true;
480 blocked_fpu_registers_[STMP + 1] = true;
481 DCHECK_EQ(FromLowSToD(STMP), DTMP);
482
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000483 blocked_fpu_registers_[S16] = true;
484 blocked_fpu_registers_[S17] = true;
485 blocked_fpu_registers_[S18] = true;
486 blocked_fpu_registers_[S19] = true;
487 blocked_fpu_registers_[S20] = true;
488 blocked_fpu_registers_[S21] = true;
489 blocked_fpu_registers_[S22] = true;
490 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000491 blocked_fpu_registers_[S24] = true;
492 blocked_fpu_registers_[S25] = true;
493 blocked_fpu_registers_[S26] = true;
494 blocked_fpu_registers_[S27] = true;
495 blocked_fpu_registers_[S28] = true;
496 blocked_fpu_registers_[S29] = true;
497 blocked_fpu_registers_[S30] = true;
498 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100499
500 UpdateBlockedPairRegisters();
501}
502
503void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
504 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
505 ArmManagedRegister current =
506 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
507 if (blocked_core_registers_[current.AsRegisterPairLow()]
508 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
509 blocked_register_pairs_[i] = true;
510 }
511 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100512}
513
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100514InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
515 : HGraphVisitor(graph),
516 assembler_(codegen->GetAssembler()),
517 codegen_(codegen) {}
518
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000519void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000520 bool skip_overflow_check =
521 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100522 if (!skip_overflow_check) {
523 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100524 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100525 AddSlowPath(slow_path);
526
527 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
528 __ cmp(SP, ShifterOperand(IP));
529 __ b(slow_path->GetEntryLabel(), CC);
530 } else {
531 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100532 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100533 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100534 }
535 }
536
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000537 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
538 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000539
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100540 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100541 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100542 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000543}
544
545void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100546 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000547 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000548}
549
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100550void CodeGeneratorARM::Bind(HBasicBlock* block) {
551 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000552}
553
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100554Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
555 switch (load->GetType()) {
556 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100557 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100558 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
559 break;
560
561 case Primitive::kPrimInt:
562 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100563 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100564 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100565
566 case Primitive::kPrimBoolean:
567 case Primitive::kPrimByte:
568 case Primitive::kPrimChar:
569 case Primitive::kPrimShort:
570 case Primitive::kPrimVoid:
571 LOG(FATAL) << "Unexpected type " << load->GetType();
572 }
573
574 LOG(FATAL) << "Unreachable";
575 return Location();
576}
577
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100578Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
579 switch (type) {
580 case Primitive::kPrimBoolean:
581 case Primitive::kPrimByte:
582 case Primitive::kPrimChar:
583 case Primitive::kPrimShort:
584 case Primitive::kPrimInt:
585 case Primitive::kPrimNot: {
586 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000587 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100588 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100589 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100590 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000591 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100592 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100593 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100594
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000595 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100596 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000597 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100598 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000599 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100600 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100601 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
602 calling_convention.GetRegisterPairAt(index));
603 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100604 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000605 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
606 }
607 }
608
609 case Primitive::kPrimFloat: {
610 uint32_t stack_index = stack_index_++;
611 if (float_index_ % 2 == 0) {
612 float_index_ = std::max(double_index_, float_index_);
613 }
614 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
615 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
616 } else {
617 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
618 }
619 }
620
621 case Primitive::kPrimDouble: {
622 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
623 uint32_t stack_index = stack_index_;
624 stack_index_ += 2;
625 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
626 uint32_t index = double_index_;
627 double_index_ += 2;
628 return Location::FpuRegisterPairLocation(
629 calling_convention.GetFpuRegisterAt(index),
630 calling_convention.GetFpuRegisterAt(index + 1));
631 } else {
632 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100633 }
634 }
635
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100636 case Primitive::kPrimVoid:
637 LOG(FATAL) << "Unexpected parameter type " << type;
638 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100639 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100640 return Location();
641}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100642
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000643Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
644 switch (type) {
645 case Primitive::kPrimBoolean:
646 case Primitive::kPrimByte:
647 case Primitive::kPrimChar:
648 case Primitive::kPrimShort:
649 case Primitive::kPrimInt:
650 case Primitive::kPrimNot: {
651 return Location::RegisterLocation(R0);
652 }
653
654 case Primitive::kPrimFloat: {
655 return Location::FpuRegisterLocation(S0);
656 }
657
658 case Primitive::kPrimLong: {
659 return Location::RegisterPairLocation(R0, R1);
660 }
661
662 case Primitive::kPrimDouble: {
663 return Location::FpuRegisterPairLocation(S0, S1);
664 }
665
666 case Primitive::kPrimVoid:
667 return Location();
668 }
669 UNREACHABLE();
670 return Location();
671}
672
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100673void CodeGeneratorARM::Move32(Location destination, Location source) {
674 if (source.Equals(destination)) {
675 return;
676 }
677 if (destination.IsRegister()) {
678 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000679 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100680 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000681 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100682 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000683 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100684 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100685 } else if (destination.IsFpuRegister()) {
686 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000687 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100688 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000689 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100690 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000691 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100692 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100693 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000694 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100695 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000696 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100697 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000698 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100699 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000700 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100701 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
702 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100703 }
704 }
705}
706
707void CodeGeneratorARM::Move64(Location destination, Location source) {
708 if (source.Equals(destination)) {
709 return;
710 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100711 if (destination.IsRegisterPair()) {
712 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000713 EmitParallelMoves(
714 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
715 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
716 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
717 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100718 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000719 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100720 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000721 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100722 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100723 if (destination.AsRegisterPairLow<Register>() == R1) {
724 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100725 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
726 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100727 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100728 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100729 SP, source.GetStackIndex());
730 }
731 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000732 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100733 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000734 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
735 SP,
736 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100737 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000738 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100739 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 } else {
741 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100742 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000743 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100744 if (source.AsRegisterPairLow<Register>() == R1) {
745 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100746 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
747 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100748 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100749 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100750 SP, destination.GetStackIndex());
751 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000752 } else if (source.IsFpuRegisterPair()) {
753 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
754 SP,
755 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100756 } else {
757 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000758 EmitParallelMoves(
759 Location::StackSlot(source.GetStackIndex()),
760 Location::StackSlot(destination.GetStackIndex()),
761 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
762 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100763 }
764 }
765}
766
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100767void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100768 LocationSummary* locations = instruction->GetLocations();
769 if (locations != nullptr && locations->Out().Equals(location)) {
770 return;
771 }
772
Calin Juravlea21f5982014-11-13 15:53:04 +0000773 if (locations != nullptr && locations->Out().IsConstant()) {
774 HConstant* const_to_move = locations->Out().GetConstant();
775 if (const_to_move->IsIntConstant()) {
776 int32_t value = const_to_move->AsIntConstant()->GetValue();
777 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000778 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000779 } else {
780 DCHECK(location.IsStackSlot());
781 __ LoadImmediate(IP, value);
782 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
783 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000784 } else {
785 DCHECK(const_to_move->IsLongConstant()) << const_to_move;
Calin Juravlea21f5982014-11-13 15:53:04 +0000786 int64_t value = const_to_move->AsLongConstant()->GetValue();
787 if (location.IsRegisterPair()) {
788 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
789 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
790 } else {
791 DCHECK(location.IsDoubleStackSlot());
792 __ LoadImmediate(IP, Low32Bits(value));
793 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
794 __ LoadImmediate(IP, High32Bits(value));
795 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
796 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100797 }
Roland Levillain476df552014-10-09 17:51:36 +0100798 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100799 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
800 switch (instruction->GetType()) {
801 case Primitive::kPrimBoolean:
802 case Primitive::kPrimByte:
803 case Primitive::kPrimChar:
804 case Primitive::kPrimShort:
805 case Primitive::kPrimInt:
806 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100807 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100808 Move32(location, Location::StackSlot(stack_slot));
809 break;
810
811 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100812 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100813 Move64(location, Location::DoubleStackSlot(stack_slot));
814 break;
815
816 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100817 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100818 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000819 } else if (instruction->IsTemporary()) {
820 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000821 if (temp_location.IsStackSlot()) {
822 Move32(location, temp_location);
823 } else {
824 DCHECK(temp_location.IsDoubleStackSlot());
825 Move64(location, temp_location);
826 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000827 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100828 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100829 switch (instruction->GetType()) {
830 case Primitive::kPrimBoolean:
831 case Primitive::kPrimByte:
832 case Primitive::kPrimChar:
833 case Primitive::kPrimShort:
834 case Primitive::kPrimNot:
835 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100836 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100837 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100838 break;
839
840 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100841 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100842 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100843 break;
844
845 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100846 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100847 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000848 }
849}
850
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100851void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
852 HInstruction* instruction,
853 uint32_t dex_pc) {
854 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
855 __ blx(LR);
856 RecordPcInfo(instruction, dex_pc);
857 DCHECK(instruction->IsSuspendCheck()
858 || instruction->IsBoundsCheck()
859 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000860 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000861 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100862 || !IsLeafMethod());
863}
864
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000865void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000866 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000867}
868
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000869void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000870 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100871 DCHECK(!successor->IsExitBlock());
872
873 HBasicBlock* block = got->GetBlock();
874 HInstruction* previous = got->GetPrevious();
875
876 HLoopInformation* info = block->GetLoopInformation();
877 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
878 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
879 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
880 return;
881 }
882
883 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
884 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
885 }
886 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000887 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000888 }
889}
890
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000891void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000892 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000893}
894
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000895void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700896 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000897 if (kIsDebugBuild) {
898 __ Comment("Unreachable");
899 __ bkpt(0);
900 }
901}
902
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000903void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100904 LocationSummary* locations =
905 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100906 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100907 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100908 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100909 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000910}
911
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000912void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700913 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100914 if (cond->IsIntConstant()) {
915 // Constant condition, statically compared against 1.
916 int32_t cond_value = cond->AsIntConstant()->GetValue();
917 if (cond_value == 1) {
918 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
919 if_instr->IfTrueSuccessor())) {
920 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100921 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100922 return;
923 } else {
924 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100925 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100926 } else {
927 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
928 // Condition has been materialized, compare the output to 0
929 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000930 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100931 ShifterOperand(0));
932 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
933 } else {
934 // Condition has not been materialized, use its inputs as the
935 // comparison and its condition as the branch condition.
936 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000937 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100938 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000939 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100940 } else {
941 DCHECK(locations->InAt(1).IsConstant());
942 int32_t value =
943 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
944 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000945 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
946 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100947 } else {
948 Register temp = IP;
949 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000950 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100951 }
952 }
953 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
954 ARMCondition(cond->AsCondition()->GetCondition()));
955 }
Dave Allison20dfc792014-06-16 20:44:29 -0700956 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100957 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
958 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700959 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000960 }
961}
962
Dave Allison20dfc792014-06-16 20:44:29 -0700963
964void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100965 LocationSummary* locations =
966 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100967 locations->SetInAt(0, Location::RequiresRegister());
968 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100969 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100970 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100971 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000972}
973
Dave Allison20dfc792014-06-16 20:44:29 -0700974void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100975 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100976 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000977 Register left = locations->InAt(0).AsRegister<Register>();
978
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100979 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000980 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 } else {
982 DCHECK(locations->InAt(1).IsConstant());
983 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
984 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000985 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
986 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100987 } else {
988 Register temp = IP;
989 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000990 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100991 }
Dave Allison20dfc792014-06-16 20:44:29 -0700992 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100993 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000994 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100995 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +0000996 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700998}
999
1000void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1001 VisitCondition(comp);
1002}
1003
1004void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1005 VisitCondition(comp);
1006}
1007
1008void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1009 VisitCondition(comp);
1010}
1011
1012void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1013 VisitCondition(comp);
1014}
1015
1016void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1017 VisitCondition(comp);
1018}
1019
1020void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1021 VisitCondition(comp);
1022}
1023
1024void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1025 VisitCondition(comp);
1026}
1027
1028void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1029 VisitCondition(comp);
1030}
1031
1032void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1033 VisitCondition(comp);
1034}
1035
1036void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1037 VisitCondition(comp);
1038}
1039
1040void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1041 VisitCondition(comp);
1042}
1043
1044void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1045 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001046}
1047
1048void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001049 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001050}
1051
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001052void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1053 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001054}
1055
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001056void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001057 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001058}
1059
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001060void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001061 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001062 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001063}
1064
1065void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001066 LocationSummary* locations =
1067 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001068 switch (store->InputAt(1)->GetType()) {
1069 case Primitive::kPrimBoolean:
1070 case Primitive::kPrimByte:
1071 case Primitive::kPrimChar:
1072 case Primitive::kPrimShort:
1073 case Primitive::kPrimInt:
1074 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001075 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001076 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1077 break;
1078
1079 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001080 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001081 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1082 break;
1083
1084 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001085 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001086 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001087}
1088
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001089void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001090 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001091}
1092
1093void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001094 LocationSummary* locations =
1095 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001096 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001097}
1098
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001099void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001100 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001101 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001102}
1103
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001104void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001105 LocationSummary* locations =
1106 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001107 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001108}
1109
1110void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1111 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001112 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001113}
1114
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001115void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1116 LocationSummary* locations =
1117 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1118 locations->SetOut(Location::ConstantLocation(constant));
1119}
1120
1121void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1122 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001123 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001124}
1125
1126void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1127 LocationSummary* locations =
1128 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1129 locations->SetOut(Location::ConstantLocation(constant));
1130}
1131
1132void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1133 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001134 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001135}
1136
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001137void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001138 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001139}
1140
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001141void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001142 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001143 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001144}
1145
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001146void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001147 LocationSummary* locations =
1148 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001149 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001150}
1151
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001152void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001153 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001154 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155}
1156
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001157void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001158 HandleInvoke(invoke);
1159}
1160
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001161void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001162 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001163}
1164
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001165void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001166 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001167
1168 // TODO: Implement all kinds of calls:
1169 // 1) boot -> boot
1170 // 2) app -> boot
1171 // 3) app -> app
1172 //
1173 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1174
1175 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001176 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001177 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001178 __ LoadFromOffset(
1179 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001180 // temp = temp[index_in_cache]
1181 __ LoadFromOffset(
1182 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
1183 // LR = temp[offset_of_quick_compiled_code]
1184 __ LoadFromOffset(kLoadWord, LR, temp,
1185 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1186 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001187 // LR()
1188 __ blx(LR);
1189
1190 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1191 DCHECK(!codegen_->IsLeafMethod());
1192}
1193
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001194void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001195 LocationSummary* locations =
1196 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001197 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001198
1199 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001200 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001201 HInstruction* input = invoke->InputAt(i);
1202 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1203 }
1204
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001205 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001206}
1207
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001208void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1209 HandleInvoke(invoke);
1210}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001211
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001212void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001213 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001214 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1215 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1216 LocationSummary* locations = invoke->GetLocations();
1217 Location receiver = locations->InAt(0);
1218 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1219 // temp = object->GetClass();
1220 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001221 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1222 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001223 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001224 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001225 }
1226 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001227 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001228 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001229 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001230 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001231 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001232 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001233 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001234 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001235 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001236}
1237
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001238void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1239 HandleInvoke(invoke);
1240 // Add the hidden argument.
1241 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1242}
1243
1244void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1245 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001246 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001247 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1248 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1249 LocationSummary* locations = invoke->GetLocations();
1250 Location receiver = locations->InAt(0);
1251 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1252
1253 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001254 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1255 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001256
1257 // temp = object->GetClass();
1258 if (receiver.IsStackSlot()) {
1259 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1260 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1261 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001262 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001263 }
1264 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001265 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001266 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001267 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1268 // LR = temp->GetEntryPoint();
1269 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1270 // LR();
1271 __ blx(LR);
1272 DCHECK(!codegen_->IsLeafMethod());
1273 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1274}
1275
Roland Levillain88cb1752014-10-20 16:36:47 +01001276void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1277 LocationSummary* locations =
1278 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1279 switch (neg->GetResultType()) {
1280 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001281 case Primitive::kPrimLong: {
1282 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001283 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001284 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001285 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001286 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001287
Roland Levillain88cb1752014-10-20 16:36:47 +01001288 case Primitive::kPrimFloat:
1289 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001290 locations->SetInAt(0, Location::RequiresFpuRegister());
1291 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001292 break;
1293
1294 default:
1295 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1296 }
1297}
1298
1299void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1300 LocationSummary* locations = neg->GetLocations();
1301 Location out = locations->Out();
1302 Location in = locations->InAt(0);
1303 switch (neg->GetResultType()) {
1304 case Primitive::kPrimInt:
1305 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001306 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001307 break;
1308
1309 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001310 DCHECK(in.IsRegisterPair());
1311 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1312 __ rsbs(out.AsRegisterPairLow<Register>(),
1313 in.AsRegisterPairLow<Register>(),
1314 ShifterOperand(0));
1315 // We cannot emit an RSC (Reverse Subtract with Carry)
1316 // instruction here, as it does not exist in the Thumb-2
1317 // instruction set. We use the following approach
1318 // using SBC and SUB instead.
1319 //
1320 // out.hi = -C
1321 __ sbc(out.AsRegisterPairHigh<Register>(),
1322 out.AsRegisterPairHigh<Register>(),
1323 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1324 // out.hi = out.hi - in.hi
1325 __ sub(out.AsRegisterPairHigh<Register>(),
1326 out.AsRegisterPairHigh<Register>(),
1327 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1328 break;
1329
Roland Levillain88cb1752014-10-20 16:36:47 +01001330 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001331 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001332 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001333 break;
1334
Roland Levillain88cb1752014-10-20 16:36:47 +01001335 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001336 DCHECK(in.IsFpuRegisterPair());
1337 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1338 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001339 break;
1340
1341 default:
1342 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1343 }
1344}
1345
Roland Levillaindff1f282014-11-05 14:15:05 +00001346void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001347 Primitive::Type result_type = conversion->GetResultType();
1348 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001349 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001350
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001351 // The float-to-long and double-to-long type conversions rely on a
1352 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001353 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001354 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1355 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001356 ? LocationSummary::kCall
1357 : LocationSummary::kNoCall;
1358 LocationSummary* locations =
1359 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1360
Roland Levillaindff1f282014-11-05 14:15:05 +00001361 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001362 case Primitive::kPrimByte:
1363 switch (input_type) {
1364 case Primitive::kPrimShort:
1365 case Primitive::kPrimInt:
1366 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001367 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001368 locations->SetInAt(0, Location::RequiresRegister());
1369 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1370 break;
1371
1372 default:
1373 LOG(FATAL) << "Unexpected type conversion from " << input_type
1374 << " to " << result_type;
1375 }
1376 break;
1377
Roland Levillain01a8d712014-11-14 16:27:39 +00001378 case Primitive::kPrimShort:
1379 switch (input_type) {
1380 case Primitive::kPrimByte:
1381 case Primitive::kPrimInt:
1382 case Primitive::kPrimChar:
1383 // Processing a Dex `int-to-short' instruction.
1384 locations->SetInAt(0, Location::RequiresRegister());
1385 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1386 break;
1387
1388 default:
1389 LOG(FATAL) << "Unexpected type conversion from " << input_type
1390 << " to " << result_type;
1391 }
1392 break;
1393
Roland Levillain946e1432014-11-11 17:35:19 +00001394 case Primitive::kPrimInt:
1395 switch (input_type) {
1396 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001397 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001398 locations->SetInAt(0, Location::Any());
1399 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1400 break;
1401
1402 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001403 // Processing a Dex `float-to-int' instruction.
1404 locations->SetInAt(0, Location::RequiresFpuRegister());
1405 locations->SetOut(Location::RequiresRegister());
1406 locations->AddTemp(Location::RequiresFpuRegister());
1407 break;
1408
Roland Levillain946e1432014-11-11 17:35:19 +00001409 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001410 // Processing a Dex `double-to-int' instruction.
1411 locations->SetInAt(0, Location::RequiresFpuRegister());
1412 locations->SetOut(Location::RequiresRegister());
1413 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001414 break;
1415
1416 default:
1417 LOG(FATAL) << "Unexpected type conversion from " << input_type
1418 << " to " << result_type;
1419 }
1420 break;
1421
Roland Levillaindff1f282014-11-05 14:15:05 +00001422 case Primitive::kPrimLong:
1423 switch (input_type) {
1424 case Primitive::kPrimByte:
1425 case Primitive::kPrimShort:
1426 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001427 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001428 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001429 locations->SetInAt(0, Location::RequiresRegister());
1430 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1431 break;
1432
Roland Levillain624279f2014-12-04 11:54:28 +00001433 case Primitive::kPrimFloat: {
1434 // Processing a Dex `float-to-long' instruction.
1435 InvokeRuntimeCallingConvention calling_convention;
1436 locations->SetInAt(0, Location::FpuRegisterLocation(
1437 calling_convention.GetFpuRegisterAt(0)));
1438 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1439 break;
1440 }
1441
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001442 case Primitive::kPrimDouble: {
1443 // Processing a Dex `double-to-long' instruction.
1444 InvokeRuntimeCallingConvention calling_convention;
1445 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1446 calling_convention.GetFpuRegisterAt(0),
1447 calling_convention.GetFpuRegisterAt(1)));
1448 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001449 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001450 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001451
1452 default:
1453 LOG(FATAL) << "Unexpected type conversion from " << input_type
1454 << " to " << result_type;
1455 }
1456 break;
1457
Roland Levillain981e4542014-11-14 11:47:14 +00001458 case Primitive::kPrimChar:
1459 switch (input_type) {
1460 case Primitive::kPrimByte:
1461 case Primitive::kPrimShort:
1462 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001463 // Processing a Dex `int-to-char' instruction.
1464 locations->SetInAt(0, Location::RequiresRegister());
1465 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1466 break;
1467
1468 default:
1469 LOG(FATAL) << "Unexpected type conversion from " << input_type
1470 << " to " << result_type;
1471 }
1472 break;
1473
Roland Levillaindff1f282014-11-05 14:15:05 +00001474 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001475 switch (input_type) {
1476 case Primitive::kPrimByte:
1477 case Primitive::kPrimShort:
1478 case Primitive::kPrimInt:
1479 case Primitive::kPrimChar:
1480 // Processing a Dex `int-to-float' instruction.
1481 locations->SetInAt(0, Location::RequiresRegister());
1482 locations->SetOut(Location::RequiresFpuRegister());
1483 break;
1484
1485 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001486 // Processing a Dex `long-to-float' instruction.
1487 locations->SetInAt(0, Location::RequiresRegister());
1488 locations->SetOut(Location::RequiresFpuRegister());
1489 locations->AddTemp(Location::RequiresRegister());
1490 locations->AddTemp(Location::RequiresRegister());
1491 locations->AddTemp(Location::RequiresFpuRegister());
1492 locations->AddTemp(Location::RequiresFpuRegister());
1493 break;
1494
Roland Levillaincff13742014-11-17 14:32:17 +00001495 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001496 // Processing a Dex `double-to-float' instruction.
1497 locations->SetInAt(0, Location::RequiresFpuRegister());
1498 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001499 break;
1500
1501 default:
1502 LOG(FATAL) << "Unexpected type conversion from " << input_type
1503 << " to " << result_type;
1504 };
1505 break;
1506
Roland Levillaindff1f282014-11-05 14:15:05 +00001507 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001508 switch (input_type) {
1509 case Primitive::kPrimByte:
1510 case Primitive::kPrimShort:
1511 case Primitive::kPrimInt:
1512 case Primitive::kPrimChar:
1513 // Processing a Dex `int-to-double' instruction.
1514 locations->SetInAt(0, Location::RequiresRegister());
1515 locations->SetOut(Location::RequiresFpuRegister());
1516 break;
1517
1518 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001519 // Processing a Dex `long-to-double' instruction.
1520 locations->SetInAt(0, Location::RequiresRegister());
1521 locations->SetOut(Location::RequiresFpuRegister());
1522 locations->AddTemp(Location::RequiresRegister());
1523 locations->AddTemp(Location::RequiresRegister());
1524 locations->AddTemp(Location::RequiresFpuRegister());
1525 break;
1526
Roland Levillaincff13742014-11-17 14:32:17 +00001527 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001528 // Processing a Dex `float-to-double' instruction.
1529 locations->SetInAt(0, Location::RequiresFpuRegister());
1530 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001531 break;
1532
1533 default:
1534 LOG(FATAL) << "Unexpected type conversion from " << input_type
1535 << " to " << result_type;
1536 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001537 break;
1538
1539 default:
1540 LOG(FATAL) << "Unexpected type conversion from " << input_type
1541 << " to " << result_type;
1542 }
1543}
1544
1545void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1546 LocationSummary* locations = conversion->GetLocations();
1547 Location out = locations->Out();
1548 Location in = locations->InAt(0);
1549 Primitive::Type result_type = conversion->GetResultType();
1550 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001551 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001552 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001553 case Primitive::kPrimByte:
1554 switch (input_type) {
1555 case Primitive::kPrimShort:
1556 case Primitive::kPrimInt:
1557 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001558 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001559 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001560 break;
1561
1562 default:
1563 LOG(FATAL) << "Unexpected type conversion from " << input_type
1564 << " to " << result_type;
1565 }
1566 break;
1567
Roland Levillain01a8d712014-11-14 16:27:39 +00001568 case Primitive::kPrimShort:
1569 switch (input_type) {
1570 case Primitive::kPrimByte:
1571 case Primitive::kPrimInt:
1572 case Primitive::kPrimChar:
1573 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001574 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001575 break;
1576
1577 default:
1578 LOG(FATAL) << "Unexpected type conversion from " << input_type
1579 << " to " << result_type;
1580 }
1581 break;
1582
Roland Levillain946e1432014-11-11 17:35:19 +00001583 case Primitive::kPrimInt:
1584 switch (input_type) {
1585 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001586 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001587 DCHECK(out.IsRegister());
1588 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001589 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001590 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001591 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001592 } else {
1593 DCHECK(in.IsConstant());
1594 DCHECK(in.GetConstant()->IsLongConstant());
1595 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001596 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001597 }
1598 break;
1599
Roland Levillain3f8f9362014-12-02 17:45:01 +00001600 case Primitive::kPrimFloat: {
1601 // Processing a Dex `float-to-int' instruction.
1602 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1603 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1604 __ vcvtis(temp, temp);
1605 __ vmovrs(out.AsRegister<Register>(), temp);
1606 break;
1607 }
1608
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001609 case Primitive::kPrimDouble: {
1610 // Processing a Dex `double-to-int' instruction.
1611 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1612 DRegister temp_d = FromLowSToD(temp_s);
1613 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1614 __ vcvtid(temp_s, temp_d);
1615 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001616 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001617 }
Roland Levillain946e1432014-11-11 17:35:19 +00001618
1619 default:
1620 LOG(FATAL) << "Unexpected type conversion from " << input_type
1621 << " to " << result_type;
1622 }
1623 break;
1624
Roland Levillaindff1f282014-11-05 14:15:05 +00001625 case Primitive::kPrimLong:
1626 switch (input_type) {
1627 case Primitive::kPrimByte:
1628 case Primitive::kPrimShort:
1629 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001630 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001631 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001632 DCHECK(out.IsRegisterPair());
1633 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001634 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001635 // Sign extension.
1636 __ Asr(out.AsRegisterPairHigh<Register>(),
1637 out.AsRegisterPairLow<Register>(),
1638 31);
1639 break;
1640
1641 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001642 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001643 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1644 conversion,
1645 conversion->GetDexPc());
1646 break;
1647
Roland Levillaindff1f282014-11-05 14:15:05 +00001648 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001649 // Processing a Dex `double-to-long' instruction.
1650 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1651 conversion,
1652 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001653 break;
1654
1655 default:
1656 LOG(FATAL) << "Unexpected type conversion from " << input_type
1657 << " to " << result_type;
1658 }
1659 break;
1660
Roland Levillain981e4542014-11-14 11:47:14 +00001661 case Primitive::kPrimChar:
1662 switch (input_type) {
1663 case Primitive::kPrimByte:
1664 case Primitive::kPrimShort:
1665 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001666 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001667 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001668 break;
1669
1670 default:
1671 LOG(FATAL) << "Unexpected type conversion from " << input_type
1672 << " to " << result_type;
1673 }
1674 break;
1675
Roland Levillaindff1f282014-11-05 14:15:05 +00001676 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001677 switch (input_type) {
1678 case Primitive::kPrimByte:
1679 case Primitive::kPrimShort:
1680 case Primitive::kPrimInt:
1681 case Primitive::kPrimChar: {
1682 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001683 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1684 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001685 break;
1686 }
1687
Roland Levillain6d0e4832014-11-27 18:31:21 +00001688 case Primitive::kPrimLong: {
1689 // Processing a Dex `long-to-float' instruction.
1690 Register low = in.AsRegisterPairLow<Register>();
1691 Register high = in.AsRegisterPairHigh<Register>();
1692 SRegister output = out.AsFpuRegister<SRegister>();
1693 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1694 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1695 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1696 DRegister temp1_d = FromLowSToD(temp1_s);
1697 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1698 DRegister temp2_d = FromLowSToD(temp2_s);
1699
1700 // Operations use doubles for precision reasons (each 32-bit
1701 // half of a long fits in the 53-bit mantissa of a double,
1702 // but not in the 24-bit mantissa of a float). This is
1703 // especially important for the low bits. The result is
1704 // eventually converted to float.
1705
1706 // temp1_d = int-to-double(high)
1707 __ vmovsr(temp1_s, high);
1708 __ vcvtdi(temp1_d, temp1_s);
1709 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1710 // as an immediate value into `temp2_d` does not work, as
1711 // this instruction only transfers 8 significant bits of its
1712 // immediate operand. Instead, use two 32-bit core
1713 // registers to load `k2Pow32EncodingForDouble` into
1714 // `temp2_d`.
1715 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1716 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1717 __ vmovdrr(temp2_d, constant_low, constant_high);
1718 // temp1_d = temp1_d * 2^32
1719 __ vmuld(temp1_d, temp1_d, temp2_d);
1720 // temp2_d = unsigned-to-double(low)
1721 __ vmovsr(temp2_s, low);
1722 __ vcvtdu(temp2_d, temp2_s);
1723 // temp1_d = temp1_d + temp2_d
1724 __ vaddd(temp1_d, temp1_d, temp2_d);
1725 // output = double-to-float(temp1_d);
1726 __ vcvtsd(output, temp1_d);
1727 break;
1728 }
1729
Roland Levillaincff13742014-11-17 14:32:17 +00001730 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001731 // Processing a Dex `double-to-float' instruction.
1732 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1733 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001734 break;
1735
1736 default:
1737 LOG(FATAL) << "Unexpected type conversion from " << input_type
1738 << " to " << result_type;
1739 };
1740 break;
1741
Roland Levillaindff1f282014-11-05 14:15:05 +00001742 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001743 switch (input_type) {
1744 case Primitive::kPrimByte:
1745 case Primitive::kPrimShort:
1746 case Primitive::kPrimInt:
1747 case Primitive::kPrimChar: {
1748 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001749 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001750 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1751 out.AsFpuRegisterPairLow<SRegister>());
1752 break;
1753 }
1754
Roland Levillain647b9ed2014-11-27 12:06:00 +00001755 case Primitive::kPrimLong: {
1756 // Processing a Dex `long-to-double' instruction.
1757 Register low = in.AsRegisterPairLow<Register>();
1758 Register high = in.AsRegisterPairHigh<Register>();
1759 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1760 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001761 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1762 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001763 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1764 DRegister temp_d = FromLowSToD(temp_s);
1765
Roland Levillain647b9ed2014-11-27 12:06:00 +00001766 // out_d = int-to-double(high)
1767 __ vmovsr(out_s, high);
1768 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001769 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1770 // as an immediate value into `temp_d` does not work, as
1771 // this instruction only transfers 8 significant bits of its
1772 // immediate operand. Instead, use two 32-bit core
1773 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1774 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1775 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001776 __ vmovdrr(temp_d, constant_low, constant_high);
1777 // out_d = out_d * 2^32
1778 __ vmuld(out_d, out_d, temp_d);
1779 // temp_d = unsigned-to-double(low)
1780 __ vmovsr(temp_s, low);
1781 __ vcvtdu(temp_d, temp_s);
1782 // out_d = out_d + temp_d
1783 __ vaddd(out_d, out_d, temp_d);
1784 break;
1785 }
1786
Roland Levillaincff13742014-11-17 14:32:17 +00001787 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001788 // Processing a Dex `float-to-double' instruction.
1789 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1790 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001791 break;
1792
1793 default:
1794 LOG(FATAL) << "Unexpected type conversion from " << input_type
1795 << " to " << result_type;
1796 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001797 break;
1798
1799 default:
1800 LOG(FATAL) << "Unexpected type conversion from " << input_type
1801 << " to " << result_type;
1802 }
1803}
1804
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001805void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001806 LocationSummary* locations =
1807 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001808 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001809 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001810 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001811 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1812 locations->SetInAt(0, Location::RequiresRegister());
1813 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1814 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001815 break;
1816 }
1817
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001818 case Primitive::kPrimFloat:
1819 case Primitive::kPrimDouble: {
1820 locations->SetInAt(0, Location::RequiresFpuRegister());
1821 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001822 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001823 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001824 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001825
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001826 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001827 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001828 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001829}
1830
1831void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1832 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001833 Location out = locations->Out();
1834 Location first = locations->InAt(0);
1835 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001836 switch (add->GetResultType()) {
1837 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001838 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001839 __ add(out.AsRegister<Register>(),
1840 first.AsRegister<Register>(),
1841 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001842 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001843 __ AddConstant(out.AsRegister<Register>(),
1844 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001845 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001846 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001847 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001848
1849 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001850 __ adds(out.AsRegisterPairLow<Register>(),
1851 first.AsRegisterPairLow<Register>(),
1852 ShifterOperand(second.AsRegisterPairLow<Register>()));
1853 __ adc(out.AsRegisterPairHigh<Register>(),
1854 first.AsRegisterPairHigh<Register>(),
1855 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001856 break;
1857
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001858 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001859 __ vadds(out.AsFpuRegister<SRegister>(),
1860 first.AsFpuRegister<SRegister>(),
1861 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001862 break;
1863
1864 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001865 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1866 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1867 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001868 break;
1869
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001870 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001871 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001872 }
1873}
1874
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001875void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001876 LocationSummary* locations =
1877 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001878 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001879 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001880 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001881 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1882 locations->SetInAt(0, Location::RequiresRegister());
1883 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1884 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001885 break;
1886 }
Calin Juravle11351682014-10-23 15:38:15 +01001887 case Primitive::kPrimFloat:
1888 case Primitive::kPrimDouble: {
1889 locations->SetInAt(0, Location::RequiresFpuRegister());
1890 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001891 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001892 break;
Calin Juravle11351682014-10-23 15:38:15 +01001893 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001894 default:
Calin Juravle11351682014-10-23 15:38:15 +01001895 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001896 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001897}
1898
1899void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1900 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001901 Location out = locations->Out();
1902 Location first = locations->InAt(0);
1903 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001904 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001905 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001906 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001907 __ sub(out.AsRegister<Register>(),
1908 first.AsRegister<Register>(),
1909 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001910 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001911 __ AddConstant(out.AsRegister<Register>(),
1912 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001913 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001914 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001915 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001916 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001917
Calin Juravle11351682014-10-23 15:38:15 +01001918 case Primitive::kPrimLong: {
1919 __ subs(out.AsRegisterPairLow<Register>(),
1920 first.AsRegisterPairLow<Register>(),
1921 ShifterOperand(second.AsRegisterPairLow<Register>()));
1922 __ sbc(out.AsRegisterPairHigh<Register>(),
1923 first.AsRegisterPairHigh<Register>(),
1924 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001925 break;
Calin Juravle11351682014-10-23 15:38:15 +01001926 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001927
Calin Juravle11351682014-10-23 15:38:15 +01001928 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001929 __ vsubs(out.AsFpuRegister<SRegister>(),
1930 first.AsFpuRegister<SRegister>(),
1931 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001932 break;
Calin Juravle11351682014-10-23 15:38:15 +01001933 }
1934
1935 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001936 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1937 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1938 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001939 break;
1940 }
1941
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001942
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001943 default:
Calin Juravle11351682014-10-23 15:38:15 +01001944 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001945 }
1946}
1947
Calin Juravle34bacdf2014-10-07 20:23:36 +01001948void LocationsBuilderARM::VisitMul(HMul* mul) {
1949 LocationSummary* locations =
1950 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1951 switch (mul->GetResultType()) {
1952 case Primitive::kPrimInt:
1953 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001954 locations->SetInAt(0, Location::RequiresRegister());
1955 locations->SetInAt(1, Location::RequiresRegister());
1956 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001957 break;
1958 }
1959
Calin Juravleb5bfa962014-10-21 18:02:24 +01001960 case Primitive::kPrimFloat:
1961 case Primitive::kPrimDouble: {
1962 locations->SetInAt(0, Location::RequiresFpuRegister());
1963 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001964 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001965 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001966 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001967
1968 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001969 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001970 }
1971}
1972
1973void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1974 LocationSummary* locations = mul->GetLocations();
1975 Location out = locations->Out();
1976 Location first = locations->InAt(0);
1977 Location second = locations->InAt(1);
1978 switch (mul->GetResultType()) {
1979 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001980 __ mul(out.AsRegister<Register>(),
1981 first.AsRegister<Register>(),
1982 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001983 break;
1984 }
1985 case Primitive::kPrimLong: {
1986 Register out_hi = out.AsRegisterPairHigh<Register>();
1987 Register out_lo = out.AsRegisterPairLow<Register>();
1988 Register in1_hi = first.AsRegisterPairHigh<Register>();
1989 Register in1_lo = first.AsRegisterPairLow<Register>();
1990 Register in2_hi = second.AsRegisterPairHigh<Register>();
1991 Register in2_lo = second.AsRegisterPairLow<Register>();
1992
1993 // Extra checks to protect caused by the existence of R1_R2.
1994 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1995 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1996 DCHECK_NE(out_hi, in1_lo);
1997 DCHECK_NE(out_hi, in2_lo);
1998
1999 // input: in1 - 64 bits, in2 - 64 bits
2000 // output: out
2001 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2002 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2003 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2004
2005 // IP <- in1.lo * in2.hi
2006 __ mul(IP, in1_lo, in2_hi);
2007 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2008 __ mla(out_hi, in1_hi, in2_lo, IP);
2009 // out.lo <- (in1.lo * in2.lo)[31:0];
2010 __ umull(out_lo, IP, in1_lo, in2_lo);
2011 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2012 __ add(out_hi, out_hi, ShifterOperand(IP));
2013 break;
2014 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002015
2016 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002017 __ vmuls(out.AsFpuRegister<SRegister>(),
2018 first.AsFpuRegister<SRegister>(),
2019 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002020 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002021 }
2022
2023 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002024 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2025 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2026 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002027 break;
2028 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002029
2030 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002031 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002032 }
2033}
2034
Calin Juravle7c4954d2014-10-28 16:57:40 +00002035void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002036 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2037 ? LocationSummary::kCall
2038 : LocationSummary::kNoCall;
2039 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2040
Calin Juravle7c4954d2014-10-28 16:57:40 +00002041 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002042 case Primitive::kPrimInt: {
2043 locations->SetInAt(0, Location::RequiresRegister());
2044 locations->SetInAt(1, Location::RequiresRegister());
2045 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2046 break;
2047 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002048 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002049 InvokeRuntimeCallingConvention calling_convention;
2050 locations->SetInAt(0, Location::RegisterPairLocation(
2051 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2052 locations->SetInAt(1, Location::RegisterPairLocation(
2053 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2054 // The runtime helper puts the output in R0,R2.
2055 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002056 break;
2057 }
2058 case Primitive::kPrimFloat:
2059 case Primitive::kPrimDouble: {
2060 locations->SetInAt(0, Location::RequiresFpuRegister());
2061 locations->SetInAt(1, Location::RequiresFpuRegister());
2062 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2063 break;
2064 }
2065
2066 default:
2067 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2068 }
2069}
2070
2071void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2072 LocationSummary* locations = div->GetLocations();
2073 Location out = locations->Out();
2074 Location first = locations->InAt(0);
2075 Location second = locations->InAt(1);
2076
2077 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002078 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002079 __ sdiv(out.AsRegister<Register>(),
2080 first.AsRegister<Register>(),
2081 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002082 break;
2083 }
2084
Calin Juravle7c4954d2014-10-28 16:57:40 +00002085 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002086 InvokeRuntimeCallingConvention calling_convention;
2087 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2088 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2089 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2090 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2091 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2092 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2093
2094 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002095 break;
2096 }
2097
2098 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002099 __ vdivs(out.AsFpuRegister<SRegister>(),
2100 first.AsFpuRegister<SRegister>(),
2101 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002102 break;
2103 }
2104
2105 case Primitive::kPrimDouble: {
2106 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2107 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2108 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2109 break;
2110 }
2111
2112 default:
2113 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2114 }
2115}
2116
Calin Juravlebacfec32014-11-14 15:54:36 +00002117void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002118 Primitive::Type type = rem->GetResultType();
2119 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2120 ? LocationSummary::kNoCall
2121 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002122 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2123
Calin Juravled2ec87d2014-12-08 14:24:46 +00002124 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002125 case Primitive::kPrimInt: {
2126 locations->SetInAt(0, Location::RequiresRegister());
2127 locations->SetInAt(1, Location::RequiresRegister());
2128 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2129 locations->AddTemp(Location::RequiresRegister());
2130 break;
2131 }
2132 case Primitive::kPrimLong: {
2133 InvokeRuntimeCallingConvention calling_convention;
2134 locations->SetInAt(0, Location::RegisterPairLocation(
2135 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2136 locations->SetInAt(1, Location::RegisterPairLocation(
2137 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2138 // The runtime helper puts the output in R2,R3.
2139 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2140 break;
2141 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002142 case Primitive::kPrimFloat: {
2143 InvokeRuntimeCallingConvention calling_convention;
2144 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2145 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2146 locations->SetOut(Location::FpuRegisterLocation(S0));
2147 break;
2148 }
2149
Calin Juravlebacfec32014-11-14 15:54:36 +00002150 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002151 InvokeRuntimeCallingConvention calling_convention;
2152 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2153 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2154 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2155 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2156 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002157 break;
2158 }
2159
2160 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002161 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002162 }
2163}
2164
2165void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2166 LocationSummary* locations = rem->GetLocations();
2167 Location out = locations->Out();
2168 Location first = locations->InAt(0);
2169 Location second = locations->InAt(1);
2170
Calin Juravled2ec87d2014-12-08 14:24:46 +00002171 Primitive::Type type = rem->GetResultType();
2172 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002173 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002174 Register reg1 = first.AsRegister<Register>();
2175 Register reg2 = second.AsRegister<Register>();
2176 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002177
2178 // temp = reg1 / reg2 (integer division)
2179 // temp = temp * reg2
2180 // dest = reg1 - temp
2181 __ sdiv(temp, reg1, reg2);
2182 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002183 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002184 break;
2185 }
2186
2187 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002188 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2189 break;
2190 }
2191
Calin Juravled2ec87d2014-12-08 14:24:46 +00002192 case Primitive::kPrimFloat: {
2193 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2194 break;
2195 }
2196
Calin Juravlebacfec32014-11-14 15:54:36 +00002197 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002198 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002199 break;
2200 }
2201
2202 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002203 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002204 }
2205}
2206
Calin Juravled0d48522014-11-04 16:40:20 +00002207void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2208 LocationSummary* locations =
2209 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002210 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002211 if (instruction->HasUses()) {
2212 locations->SetOut(Location::SameAsFirstInput());
2213 }
2214}
2215
2216void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2217 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2218 codegen_->AddSlowPath(slow_path);
2219
2220 LocationSummary* locations = instruction->GetLocations();
2221 Location value = locations->InAt(0);
2222
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002223 switch (instruction->GetType()) {
2224 case Primitive::kPrimInt: {
2225 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002226 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002227 __ b(slow_path->GetEntryLabel(), EQ);
2228 } else {
2229 DCHECK(value.IsConstant()) << value;
2230 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2231 __ b(slow_path->GetEntryLabel());
2232 }
2233 }
2234 break;
2235 }
2236 case Primitive::kPrimLong: {
2237 if (value.IsRegisterPair()) {
2238 __ orrs(IP,
2239 value.AsRegisterPairLow<Register>(),
2240 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2241 __ b(slow_path->GetEntryLabel(), EQ);
2242 } else {
2243 DCHECK(value.IsConstant()) << value;
2244 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2245 __ b(slow_path->GetEntryLabel());
2246 }
2247 }
2248 break;
2249 default:
2250 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2251 }
2252 }
Calin Juravled0d48522014-11-04 16:40:20 +00002253}
2254
Calin Juravle9aec02f2014-11-18 23:06:35 +00002255void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2256 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2257
2258 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2259 ? LocationSummary::kCall
2260 : LocationSummary::kNoCall;
2261 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2262
2263 switch (op->GetResultType()) {
2264 case Primitive::kPrimInt: {
2265 locations->SetInAt(0, Location::RequiresRegister());
2266 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2267 locations->SetOut(Location::RequiresRegister());
2268 break;
2269 }
2270 case Primitive::kPrimLong: {
2271 InvokeRuntimeCallingConvention calling_convention;
2272 locations->SetInAt(0, Location::RegisterPairLocation(
2273 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2274 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2275 // The runtime helper puts the output in R0,R2.
2276 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2277 break;
2278 }
2279 default:
2280 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2281 }
2282}
2283
2284void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2285 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2286
2287 LocationSummary* locations = op->GetLocations();
2288 Location out = locations->Out();
2289 Location first = locations->InAt(0);
2290 Location second = locations->InAt(1);
2291
2292 Primitive::Type type = op->GetResultType();
2293 switch (type) {
2294 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002295 Register out_reg = out.AsRegister<Register>();
2296 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002297 // Arm doesn't mask the shift count so we need to do it ourselves.
2298 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002299 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002300 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2301 if (op->IsShl()) {
2302 __ Lsl(out_reg, first_reg, second_reg);
2303 } else if (op->IsShr()) {
2304 __ Asr(out_reg, first_reg, second_reg);
2305 } else {
2306 __ Lsr(out_reg, first_reg, second_reg);
2307 }
2308 } else {
2309 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2310 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2311 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2312 __ Mov(out_reg, first_reg);
2313 } else if (op->IsShl()) {
2314 __ Lsl(out_reg, first_reg, shift_value);
2315 } else if (op->IsShr()) {
2316 __ Asr(out_reg, first_reg, shift_value);
2317 } else {
2318 __ Lsr(out_reg, first_reg, shift_value);
2319 }
2320 }
2321 break;
2322 }
2323 case Primitive::kPrimLong: {
2324 // TODO: Inline the assembly instead of calling the runtime.
2325 InvokeRuntimeCallingConvention calling_convention;
2326 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2327 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002328 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002329 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2330 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2331
2332 int32_t entry_point_offset;
2333 if (op->IsShl()) {
2334 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2335 } else if (op->IsShr()) {
2336 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2337 } else {
2338 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2339 }
2340 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2341 __ blx(LR);
2342 break;
2343 }
2344 default:
2345 LOG(FATAL) << "Unexpected operation type " << type;
2346 }
2347}
2348
2349void LocationsBuilderARM::VisitShl(HShl* shl) {
2350 HandleShift(shl);
2351}
2352
2353void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2354 HandleShift(shl);
2355}
2356
2357void LocationsBuilderARM::VisitShr(HShr* shr) {
2358 HandleShift(shr);
2359}
2360
2361void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2362 HandleShift(shr);
2363}
2364
2365void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2366 HandleShift(ushr);
2367}
2368
2369void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2370 HandleShift(ushr);
2371}
2372
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002373void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002374 LocationSummary* locations =
2375 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002376 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002377 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2378 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2379 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002380}
2381
2382void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2383 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002384 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002385 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002386 codegen_->InvokeRuntime(
2387 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002388}
2389
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002390void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2391 LocationSummary* locations =
2392 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2393 InvokeRuntimeCallingConvention calling_convention;
2394 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002395 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002396 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002397 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002398}
2399
2400void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2401 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002402 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002403 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002404 codegen_->InvokeRuntime(
2405 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002406}
2407
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002408void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002409 LocationSummary* locations =
2410 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002411 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2412 if (location.IsStackSlot()) {
2413 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2414 } else if (location.IsDoubleStackSlot()) {
2415 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002416 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002417 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002418}
2419
2420void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002421 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002422 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002423}
2424
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002425void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002426 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002427 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002428 locations->SetInAt(0, Location::RequiresRegister());
2429 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002430}
2431
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002432void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2433 LocationSummary* locations = not_->GetLocations();
2434 Location out = locations->Out();
2435 Location in = locations->InAt(0);
2436 switch (not_->InputAt(0)->GetType()) {
2437 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002438 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002439 break;
2440
2441 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002442 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002443 break;
2444
2445 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002446 __ mvn(out.AsRegisterPairLow<Register>(),
2447 ShifterOperand(in.AsRegisterPairLow<Register>()));
2448 __ mvn(out.AsRegisterPairHigh<Register>(),
2449 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002450 break;
2451
2452 default:
2453 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2454 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002455}
2456
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002457void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002458 LocationSummary* locations =
2459 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002460 switch (compare->InputAt(0)->GetType()) {
2461 case Primitive::kPrimLong: {
2462 locations->SetInAt(0, Location::RequiresRegister());
2463 locations->SetInAt(1, Location::RequiresRegister());
2464 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2465 break;
2466 }
2467 case Primitive::kPrimFloat:
2468 case Primitive::kPrimDouble: {
2469 locations->SetInAt(0, Location::RequiresFpuRegister());
2470 locations->SetInAt(1, Location::RequiresFpuRegister());
2471 locations->SetOut(Location::RequiresRegister());
2472 break;
2473 }
2474 default:
2475 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2476 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002477}
2478
2479void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002480 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002481 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002482 Location left = locations->InAt(0);
2483 Location right = locations->InAt(1);
2484
2485 Label less, greater, done;
2486 Primitive::Type type = compare->InputAt(0)->GetType();
2487 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002488 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002489 __ cmp(left.AsRegisterPairHigh<Register>(),
2490 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002491 __ b(&less, LT);
2492 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002493 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2494 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002495 __ cmp(left.AsRegisterPairLow<Register>(),
2496 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002497 break;
2498 }
2499 case Primitive::kPrimFloat:
2500 case Primitive::kPrimDouble: {
2501 __ LoadImmediate(out, 0);
2502 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002503 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002504 } else {
2505 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2506 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2507 }
2508 __ vmstat(); // transfer FP status register to ARM APSR.
2509 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002510 break;
2511 }
2512 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002513 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002514 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002515 __ b(&done, EQ);
2516 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2517
2518 __ Bind(&greater);
2519 __ LoadImmediate(out, 1);
2520 __ b(&done);
2521
2522 __ Bind(&less);
2523 __ LoadImmediate(out, -1);
2524
2525 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002526}
2527
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002528void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002529 LocationSummary* locations =
2530 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002531 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2532 locations->SetInAt(i, Location::Any());
2533 }
2534 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002535}
2536
2537void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002538 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002539 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002540}
2541
Calin Juravle52c48962014-12-16 17:02:57 +00002542void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2543 // TODO (ported from quick): revisit Arm barrier kinds
2544 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2545 switch (kind) {
2546 case MemBarrierKind::kAnyStore:
2547 case MemBarrierKind::kLoadAny:
2548 case MemBarrierKind::kAnyAny: {
2549 flavour = DmbOptions::ISH;
2550 break;
2551 }
2552 case MemBarrierKind::kStoreStore: {
2553 flavour = DmbOptions::ISHST;
2554 break;
2555 }
2556 default:
2557 LOG(FATAL) << "Unexpected memory barrier " << kind;
2558 }
2559 __ dmb(flavour);
2560}
2561
2562void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2563 uint32_t offset,
2564 Register out_lo,
2565 Register out_hi) {
2566 if (offset != 0) {
2567 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002568 __ add(IP, addr, ShifterOperand(out_lo));
2569 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002570 }
2571 __ ldrexd(out_lo, out_hi, addr);
2572}
2573
2574void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2575 uint32_t offset,
2576 Register value_lo,
2577 Register value_hi,
2578 Register temp1,
2579 Register temp2) {
2580 Label fail;
2581 if (offset != 0) {
2582 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002583 __ add(IP, addr, ShifterOperand(temp1));
2584 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002585 }
2586 __ Bind(&fail);
2587 // We need a load followed by store. (The address used in a STREX instruction must
2588 // be the same as the address in the most recently executed LDREX instruction.)
2589 __ ldrexd(temp1, temp2, addr);
2590 __ strexd(temp1, value_lo, value_hi, addr);
2591 __ cmp(temp1, ShifterOperand(0));
2592 __ b(&fail, NE);
2593}
2594
2595void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2596 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2597
Nicolas Geoffray39468442014-09-02 15:17:15 +01002598 LocationSummary* locations =
2599 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002600 locations->SetInAt(0, Location::RequiresRegister());
2601 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002602
Calin Juravle34166012014-12-19 17:22:29 +00002603
Calin Juravle52c48962014-12-16 17:02:57 +00002604 Primitive::Type field_type = field_info.GetFieldType();
2605 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002606 bool generate_volatile = field_info.IsVolatile()
2607 && is_wide
2608 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002609 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002610 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2611 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002612 locations->AddTemp(Location::RequiresRegister());
2613 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002614 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002615 // Arm encoding have some additional constraints for ldrexd/strexd:
2616 // - registers need to be consecutive
2617 // - the first register should be even but not R14.
2618 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2619 // enable Arm encoding.
2620 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2621
2622 locations->AddTemp(Location::RequiresRegister());
2623 locations->AddTemp(Location::RequiresRegister());
2624 if (field_type == Primitive::kPrimDouble) {
2625 // For doubles we need two more registers to copy the value.
2626 locations->AddTemp(Location::RegisterLocation(R2));
2627 locations->AddTemp(Location::RegisterLocation(R3));
2628 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002629 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002630}
2631
Calin Juravle52c48962014-12-16 17:02:57 +00002632void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2633 const FieldInfo& field_info) {
2634 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2635
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002636 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002637 Register base = locations->InAt(0).AsRegister<Register>();
2638 Location value = locations->InAt(1);
2639
2640 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002641 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002642 Primitive::Type field_type = field_info.GetFieldType();
2643 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2644
2645 if (is_volatile) {
2646 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2647 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002648
2649 switch (field_type) {
2650 case Primitive::kPrimBoolean:
2651 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002652 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002653 break;
2654 }
2655
2656 case Primitive::kPrimShort:
2657 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002658 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002659 break;
2660 }
2661
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002662 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002663 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002664 Register value_reg = value.AsRegister<Register>();
2665 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2666 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002667 Register temp = locations->GetTemp(0).AsRegister<Register>();
2668 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002669 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002670 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002671 break;
2672 }
2673
2674 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002675 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002676 GenerateWideAtomicStore(base, offset,
2677 value.AsRegisterPairLow<Register>(),
2678 value.AsRegisterPairHigh<Register>(),
2679 locations->GetTemp(0).AsRegister<Register>(),
2680 locations->GetTemp(1).AsRegister<Register>());
2681 } else {
2682 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2683 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002684 break;
2685 }
2686
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002687 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002688 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002689 break;
2690 }
2691
2692 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002693 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002694 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002695 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2696 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2697
2698 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2699
2700 GenerateWideAtomicStore(base, offset,
2701 value_reg_lo,
2702 value_reg_hi,
2703 locations->GetTemp(2).AsRegister<Register>(),
2704 locations->GetTemp(3).AsRegister<Register>());
2705 } else {
2706 __ StoreDToOffset(value_reg, base, offset);
2707 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002708 break;
2709 }
2710
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002711 case Primitive::kPrimVoid:
2712 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002713 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002714 }
Calin Juravle52c48962014-12-16 17:02:57 +00002715
2716 if (is_volatile) {
2717 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2718 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002719}
2720
Calin Juravle52c48962014-12-16 17:02:57 +00002721void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2722 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002723 LocationSummary* locations =
2724 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002725 locations->SetInAt(0, Location::RequiresRegister());
2726 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002727
Calin Juravle34166012014-12-19 17:22:29 +00002728 bool generate_volatile = field_info.IsVolatile()
2729 && (field_info.GetFieldType() == Primitive::kPrimDouble)
2730 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
2731 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002732 // Arm encoding have some additional constraints for ldrexd/strexd:
2733 // - registers need to be consecutive
2734 // - the first register should be even but not R14.
2735 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2736 // enable Arm encoding.
2737 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2738 locations->AddTemp(Location::RequiresRegister());
2739 locations->AddTemp(Location::RequiresRegister());
2740 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002741}
2742
Calin Juravle52c48962014-12-16 17:02:57 +00002743void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2744 const FieldInfo& field_info) {
2745 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002746
Calin Juravle52c48962014-12-16 17:02:57 +00002747 LocationSummary* locations = instruction->GetLocations();
2748 Register base = locations->InAt(0).AsRegister<Register>();
2749 Location out = locations->Out();
2750 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002751 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002752 Primitive::Type field_type = field_info.GetFieldType();
2753 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2754
2755 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002756 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002757 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002758 break;
2759 }
2760
2761 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002762 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002763 break;
2764 }
2765
2766 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002767 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002768 break;
2769 }
2770
2771 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002772 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002773 break;
2774 }
2775
2776 case Primitive::kPrimInt:
2777 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002778 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002779 break;
2780 }
2781
2782 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002783 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002784 GenerateWideAtomicLoad(base, offset,
2785 out.AsRegisterPairLow<Register>(),
2786 out.AsRegisterPairHigh<Register>());
2787 } else {
2788 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2789 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002790 break;
2791 }
2792
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002793 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002794 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002795 break;
2796 }
2797
2798 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002799 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002800 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002801 Register lo = locations->GetTemp(0).AsRegister<Register>();
2802 Register hi = locations->GetTemp(1).AsRegister<Register>();
2803 GenerateWideAtomicLoad(base, offset, lo, hi);
2804 __ vmovdrr(out_reg, lo, hi);
2805 } else {
2806 __ LoadDFromOffset(out_reg, base, offset);
2807 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002808 break;
2809 }
2810
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002811 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002812 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002813 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002814 }
Calin Juravle52c48962014-12-16 17:02:57 +00002815
2816 if (is_volatile) {
2817 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2818 }
2819}
2820
2821void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2822 HandleFieldSet(instruction, instruction->GetFieldInfo());
2823}
2824
2825void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2826 HandleFieldSet(instruction, instruction->GetFieldInfo());
2827}
2828
2829void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2830 HandleFieldGet(instruction, instruction->GetFieldInfo());
2831}
2832
2833void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2834 HandleFieldGet(instruction, instruction->GetFieldInfo());
2835}
2836
2837void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2838 HandleFieldGet(instruction, instruction->GetFieldInfo());
2839}
2840
2841void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2842 HandleFieldGet(instruction, instruction->GetFieldInfo());
2843}
2844
2845void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2846 HandleFieldSet(instruction, instruction->GetFieldInfo());
2847}
2848
2849void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2850 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002851}
2852
2853void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002854 LocationSummary* locations =
2855 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002856 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002857 if (instruction->HasUses()) {
2858 locations->SetOut(Location::SameAsFirstInput());
2859 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002860}
2861
2862void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002863 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002864 codegen_->AddSlowPath(slow_path);
2865
2866 LocationSummary* locations = instruction->GetLocations();
2867 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002868
2869 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002870 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002871 __ b(slow_path->GetEntryLabel(), EQ);
2872 } else {
2873 DCHECK(obj.IsConstant()) << obj;
2874 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2875 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002876 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002877}
2878
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002879void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002880 LocationSummary* locations =
2881 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002882 locations->SetInAt(0, Location::RequiresRegister());
2883 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2884 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002885}
2886
2887void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2888 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002889 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002890 Location index = locations->InAt(1);
2891
2892 switch (instruction->GetType()) {
2893 case Primitive::kPrimBoolean: {
2894 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002895 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002896 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002897 size_t offset =
2898 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002899 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2900 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002901 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002902 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2903 }
2904 break;
2905 }
2906
2907 case Primitive::kPrimByte: {
2908 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002909 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002910 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002911 size_t offset =
2912 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002913 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2914 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002915 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002916 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2917 }
2918 break;
2919 }
2920
2921 case Primitive::kPrimShort: {
2922 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002923 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002924 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002925 size_t offset =
2926 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002927 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2928 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002929 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002930 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2931 }
2932 break;
2933 }
2934
2935 case Primitive::kPrimChar: {
2936 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002937 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002938 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002939 size_t offset =
2940 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002941 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2942 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002943 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002944 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2945 }
2946 break;
2947 }
2948
2949 case Primitive::kPrimInt:
2950 case Primitive::kPrimNot: {
2951 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2952 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002953 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002954 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002955 size_t offset =
2956 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002957 __ LoadFromOffset(kLoadWord, out, obj, offset);
2958 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002959 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002960 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2961 }
2962 break;
2963 }
2964
2965 case Primitive::kPrimLong: {
2966 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002967 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002968 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002969 size_t offset =
2970 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002971 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002972 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002973 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002974 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002975 }
2976 break;
2977 }
2978
Nicolas Geoffray840e5462015-01-07 16:01:24 +00002979 case Primitive::kPrimFloat: {
2980 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2981 Location out = locations->Out();
2982 DCHECK(out.IsFpuRegister());
2983 if (index.IsConstant()) {
2984 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2985 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
2986 } else {
2987 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
2988 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
2989 }
2990 break;
2991 }
2992
2993 case Primitive::kPrimDouble: {
2994 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2995 Location out = locations->Out();
2996 DCHECK(out.IsFpuRegisterPair());
2997 if (index.IsConstant()) {
2998 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
2999 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3000 } else {
3001 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3002 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3003 }
3004 break;
3005 }
3006
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003007 case Primitive::kPrimVoid:
3008 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003009 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003010 }
3011}
3012
3013void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003014 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003015
3016 bool needs_write_barrier =
3017 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3018 bool needs_runtime_call = instruction->NeedsTypeCheck();
3019
Nicolas Geoffray39468442014-09-02 15:17:15 +01003020 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003021 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3022 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003023 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003024 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3025 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3026 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003027 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003028 locations->SetInAt(0, Location::RequiresRegister());
3029 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3030 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003031
3032 if (needs_write_barrier) {
3033 // Temporary registers for the write barrier.
3034 locations->AddTemp(Location::RequiresRegister());
3035 locations->AddTemp(Location::RequiresRegister());
3036 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003037 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003038}
3039
3040void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3041 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003042 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003043 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003044 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003045 bool needs_runtime_call = locations->WillCall();
3046 bool needs_write_barrier =
3047 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003048
3049 switch (value_type) {
3050 case Primitive::kPrimBoolean:
3051 case Primitive::kPrimByte: {
3052 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003053 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003054 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003055 size_t offset =
3056 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003057 __ StoreToOffset(kStoreByte, value, obj, offset);
3058 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003059 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003060 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3061 }
3062 break;
3063 }
3064
3065 case Primitive::kPrimShort:
3066 case Primitive::kPrimChar: {
3067 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003068 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003069 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003070 size_t offset =
3071 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003072 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3073 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003074 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003075 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3076 }
3077 break;
3078 }
3079
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003080 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003081 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003082 if (!needs_runtime_call) {
3083 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003084 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003085 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003086 size_t offset =
3087 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003088 __ StoreToOffset(kStoreWord, value, obj, offset);
3089 } else {
3090 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003091 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003092 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3093 }
3094 if (needs_write_barrier) {
3095 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003096 Register temp = locations->GetTemp(0).AsRegister<Register>();
3097 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003098 codegen_->MarkGCCard(temp, card, obj, value);
3099 }
3100 } else {
3101 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003102 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3103 instruction,
3104 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003105 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003106 break;
3107 }
3108
3109 case Primitive::kPrimLong: {
3110 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003111 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003112 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003113 size_t offset =
3114 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003115 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003116 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003117 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003118 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003119 }
3120 break;
3121 }
3122
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003123 case Primitive::kPrimFloat: {
3124 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3125 Location value = locations->InAt(2);
3126 DCHECK(value.IsFpuRegister());
3127 if (index.IsConstant()) {
3128 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3129 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3130 } else {
3131 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3132 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3133 }
3134 break;
3135 }
3136
3137 case Primitive::kPrimDouble: {
3138 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3139 Location value = locations->InAt(2);
3140 DCHECK(value.IsFpuRegisterPair());
3141 if (index.IsConstant()) {
3142 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3143 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3144 } else {
3145 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3146 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3147 }
3148 break;
3149 }
3150
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003151 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003152 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003153 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003154 }
3155}
3156
3157void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003158 LocationSummary* locations =
3159 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003160 locations->SetInAt(0, Location::RequiresRegister());
3161 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003162}
3163
3164void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3165 LocationSummary* locations = instruction->GetLocations();
3166 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003167 Register obj = locations->InAt(0).AsRegister<Register>();
3168 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003169 __ LoadFromOffset(kLoadWord, out, obj, offset);
3170}
3171
3172void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003173 LocationSummary* locations =
3174 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003175 locations->SetInAt(0, Location::RequiresRegister());
3176 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003177 if (instruction->HasUses()) {
3178 locations->SetOut(Location::SameAsFirstInput());
3179 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003180}
3181
3182void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3183 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003184 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003185 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003186 codegen_->AddSlowPath(slow_path);
3187
Roland Levillain271ab9c2014-11-27 15:23:57 +00003188 Register index = locations->InAt(0).AsRegister<Register>();
3189 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003190
3191 __ cmp(index, ShifterOperand(length));
3192 __ b(slow_path->GetEntryLabel(), CS);
3193}
3194
3195void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3196 Label is_null;
3197 __ CompareAndBranchIfZero(value, &is_null);
3198 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3199 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3200 __ strb(card, Address(card, temp));
3201 __ Bind(&is_null);
3202}
3203
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003204void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3205 temp->SetLocations(nullptr);
3206}
3207
3208void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3209 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003210 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003211}
3212
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003213void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003214 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003215 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003216}
3217
3218void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003219 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3220}
3221
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003222void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3223 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3224}
3225
3226void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003227 HBasicBlock* block = instruction->GetBlock();
3228 if (block->GetLoopInformation() != nullptr) {
3229 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3230 // The back edge will generate the suspend check.
3231 return;
3232 }
3233 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3234 // The goto will generate the suspend check.
3235 return;
3236 }
3237 GenerateSuspendCheck(instruction, nullptr);
3238}
3239
3240void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3241 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003242 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003243 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003244 codegen_->AddSlowPath(slow_path);
3245
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003246 __ LoadFromOffset(
3247 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3248 __ cmp(IP, ShifterOperand(0));
3249 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003250 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003251 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003252 __ Bind(slow_path->GetReturnLabel());
3253 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003254 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003255 __ b(slow_path->GetEntryLabel());
3256 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003257}
3258
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003259ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3260 return codegen_->GetAssembler();
3261}
3262
3263void ParallelMoveResolverARM::EmitMove(size_t index) {
3264 MoveOperands* move = moves_.Get(index);
3265 Location source = move->GetSource();
3266 Location destination = move->GetDestination();
3267
3268 if (source.IsRegister()) {
3269 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003270 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003271 } else {
3272 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003273 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003274 SP, destination.GetStackIndex());
3275 }
3276 } else if (source.IsStackSlot()) {
3277 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003278 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003279 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003280 } else if (destination.IsFpuRegister()) {
3281 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003282 } else {
3283 DCHECK(destination.IsStackSlot());
3284 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3285 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3286 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003287 } else if (source.IsFpuRegister()) {
3288 if (destination.IsFpuRegister()) {
3289 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003290 } else {
3291 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003292 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3293 }
3294 } else if (source.IsFpuRegisterPair()) {
3295 if (destination.IsFpuRegisterPair()) {
3296 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3297 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3298 } else {
3299 DCHECK(destination.IsDoubleStackSlot()) << destination;
3300 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3301 SP, destination.GetStackIndex());
3302 }
3303 } else if (source.IsDoubleStackSlot()) {
3304 if (destination.IsFpuRegisterPair()) {
3305 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3306 SP, source.GetStackIndex());
3307 } else {
3308 DCHECK(destination.IsDoubleStackSlot()) << destination;
3309 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003310 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003311 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3312 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3313 }
3314 } else {
3315 DCHECK(source.IsConstant()) << source;
3316 HInstruction* constant = source.GetConstant();
3317 if (constant->IsIntConstant()) {
3318 int32_t value = constant->AsIntConstant()->GetValue();
3319 if (destination.IsRegister()) {
3320 __ LoadImmediate(destination.AsRegister<Register>(), value);
3321 } else {
3322 DCHECK(destination.IsStackSlot());
3323 __ LoadImmediate(IP, value);
3324 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3325 }
3326 } else {
3327 DCHECK(constant->IsFloatConstant());
3328 float value = constant->AsFloatConstant()->GetValue();
3329 if (destination.IsFpuRegister()) {
3330 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3331 } else {
3332 DCHECK(destination.IsStackSlot());
3333 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3334 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3335 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003336 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003337 }
3338}
3339
3340void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3341 __ Mov(IP, reg);
3342 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3343 __ StoreToOffset(kStoreWord, IP, SP, mem);
3344}
3345
3346void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3347 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3348 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3349 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3350 SP, mem1 + stack_offset);
3351 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3352 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3353 SP, mem2 + stack_offset);
3354 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3355}
3356
3357void ParallelMoveResolverARM::EmitSwap(size_t index) {
3358 MoveOperands* move = moves_.Get(index);
3359 Location source = move->GetSource();
3360 Location destination = move->GetDestination();
3361
3362 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003363 DCHECK_NE(source.AsRegister<Register>(), IP);
3364 DCHECK_NE(destination.AsRegister<Register>(), IP);
3365 __ Mov(IP, source.AsRegister<Register>());
3366 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3367 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003368 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003369 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003370 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003371 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003372 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3373 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003374 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003375 __ vmovs(STMP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003376 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003377 __ vmovs(destination.AsFpuRegister<SRegister>(), STMP);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003378 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3379 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3380 : destination.AsFpuRegister<SRegister>();
3381 int mem = source.IsFpuRegister()
3382 ? destination.GetStackIndex()
3383 : source.GetStackIndex();
3384
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003385 __ vmovs(STMP, reg);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003386 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003387 __ StoreSToOffset(STMP, SP, mem);
3388 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
3389 __ vmovd(DTMP, FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3390 __ vmovd(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3391 FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()));
3392 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), DTMP);
3393 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3394 DRegister reg = source.IsFpuRegisterPair()
3395 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3396 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3397 int mem = source.IsFpuRegisterPair()
3398 ? destination.GetStackIndex()
3399 : source.GetStackIndex();
3400
3401 __ vmovd(DTMP, reg);
3402 __ LoadDFromOffset(reg, SP, mem);
3403 __ StoreDToOffset(DTMP, SP, mem);
3404 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
3405 // TODO: We could use DTMP and ask for a pair scratch register (float or core).
3406 // This would save four instructions if two scratch registers are available, and
3407 // two instructions if not.
3408 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3409 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003410 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003411 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003412 }
3413}
3414
3415void ParallelMoveResolverARM::SpillScratch(int reg) {
3416 __ Push(static_cast<Register>(reg));
3417}
3418
3419void ParallelMoveResolverARM::RestoreScratch(int reg) {
3420 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003421}
3422
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003423void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003424 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3425 ? LocationSummary::kCallOnSlowPath
3426 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003427 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003428 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003429 locations->SetOut(Location::RequiresRegister());
3430}
3431
3432void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003433 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003434 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003435 DCHECK(!cls->CanCallRuntime());
3436 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003437 codegen_->LoadCurrentMethod(out);
3438 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3439 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003440 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003441 codegen_->LoadCurrentMethod(out);
3442 __ LoadFromOffset(
3443 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3444 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003445
3446 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3447 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3448 codegen_->AddSlowPath(slow_path);
3449 __ cmp(out, ShifterOperand(0));
3450 __ b(slow_path->GetEntryLabel(), EQ);
3451 if (cls->MustGenerateClinitCheck()) {
3452 GenerateClassInitializationCheck(slow_path, out);
3453 } else {
3454 __ Bind(slow_path->GetExitLabel());
3455 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003456 }
3457}
3458
3459void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3460 LocationSummary* locations =
3461 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3462 locations->SetInAt(0, Location::RequiresRegister());
3463 if (check->HasUses()) {
3464 locations->SetOut(Location::SameAsFirstInput());
3465 }
3466}
3467
3468void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003469 // We assume the class is not null.
3470 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3471 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003472 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003473 GenerateClassInitializationCheck(slow_path,
3474 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003475}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003476
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003477void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3478 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003479 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3480 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3481 __ b(slow_path->GetEntryLabel(), LT);
3482 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3483 // properly. Therefore, we do a memory fence.
3484 __ dmb(ISH);
3485 __ Bind(slow_path->GetExitLabel());
3486}
3487
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003488void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3489 LocationSummary* locations =
3490 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3491 locations->SetOut(Location::RequiresRegister());
3492}
3493
3494void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3495 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3496 codegen_->AddSlowPath(slow_path);
3497
Roland Levillain271ab9c2014-11-27 15:23:57 +00003498 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003499 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003500 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3501 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003502 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3503 __ cmp(out, ShifterOperand(0));
3504 __ b(slow_path->GetEntryLabel(), EQ);
3505 __ Bind(slow_path->GetExitLabel());
3506}
3507
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003508void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3509 LocationSummary* locations =
3510 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3511 locations->SetOut(Location::RequiresRegister());
3512}
3513
3514void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003515 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003516 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3517 __ LoadFromOffset(kLoadWord, out, TR, offset);
3518 __ LoadImmediate(IP, 0);
3519 __ StoreToOffset(kStoreWord, IP, TR, offset);
3520}
3521
3522void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3523 LocationSummary* locations =
3524 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3525 InvokeRuntimeCallingConvention calling_convention;
3526 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3527}
3528
3529void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3530 codegen_->InvokeRuntime(
3531 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3532}
3533
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003534void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003535 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3536 ? LocationSummary::kNoCall
3537 : LocationSummary::kCallOnSlowPath;
3538 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3539 locations->SetInAt(0, Location::RequiresRegister());
3540 locations->SetInAt(1, Location::RequiresRegister());
3541 locations->SetOut(Location::RequiresRegister());
3542}
3543
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003544void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003545 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003546 Register obj = locations->InAt(0).AsRegister<Register>();
3547 Register cls = locations->InAt(1).AsRegister<Register>();
3548 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003549 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3550 Label done, zero;
3551 SlowPathCodeARM* slow_path = nullptr;
3552
3553 // Return 0 if `obj` is null.
3554 // TODO: avoid this check if we know obj is not null.
3555 __ cmp(obj, ShifterOperand(0));
3556 __ b(&zero, EQ);
3557 // Compare the class of `obj` with `cls`.
3558 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3559 __ cmp(out, ShifterOperand(cls));
3560 if (instruction->IsClassFinal()) {
3561 // Classes must be equal for the instanceof to succeed.
3562 __ b(&zero, NE);
3563 __ LoadImmediate(out, 1);
3564 __ b(&done);
3565 } else {
3566 // If the classes are not equal, we go into a slow path.
3567 DCHECK(locations->OnlyCallsOnSlowPath());
3568 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003569 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003570 codegen_->AddSlowPath(slow_path);
3571 __ b(slow_path->GetEntryLabel(), NE);
3572 __ LoadImmediate(out, 1);
3573 __ b(&done);
3574 }
3575 __ Bind(&zero);
3576 __ LoadImmediate(out, 0);
3577 if (slow_path != nullptr) {
3578 __ Bind(slow_path->GetExitLabel());
3579 }
3580 __ Bind(&done);
3581}
3582
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003583void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3584 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3585 instruction, LocationSummary::kCallOnSlowPath);
3586 locations->SetInAt(0, Location::RequiresRegister());
3587 locations->SetInAt(1, Location::RequiresRegister());
3588 locations->AddTemp(Location::RequiresRegister());
3589}
3590
3591void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3592 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003593 Register obj = locations->InAt(0).AsRegister<Register>();
3594 Register cls = locations->InAt(1).AsRegister<Register>();
3595 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003596 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3597
3598 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3599 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3600 codegen_->AddSlowPath(slow_path);
3601
3602 // TODO: avoid this check if we know obj is not null.
3603 __ cmp(obj, ShifterOperand(0));
3604 __ b(slow_path->GetExitLabel(), EQ);
3605 // Compare the class of `obj` with `cls`.
3606 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3607 __ cmp(temp, ShifterOperand(cls));
3608 __ b(slow_path->GetEntryLabel(), NE);
3609 __ Bind(slow_path->GetExitLabel());
3610}
3611
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003612void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3613 LocationSummary* locations =
3614 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3615 InvokeRuntimeCallingConvention calling_convention;
3616 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3617}
3618
3619void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3620 codegen_->InvokeRuntime(instruction->IsEnter()
3621 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3622 instruction,
3623 instruction->GetDexPc());
3624}
3625
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003626void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3627void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3628void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3629
3630void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3631 LocationSummary* locations =
3632 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3633 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3634 || instruction->GetResultType() == Primitive::kPrimLong);
3635 locations->SetInAt(0, Location::RequiresRegister());
3636 locations->SetInAt(1, Location::RequiresRegister());
3637 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3638 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3639}
3640
3641void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3642 HandleBitwiseOperation(instruction);
3643}
3644
3645void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3646 HandleBitwiseOperation(instruction);
3647}
3648
3649void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3650 HandleBitwiseOperation(instruction);
3651}
3652
3653void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3654 LocationSummary* locations = instruction->GetLocations();
3655
3656 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003657 Register first = locations->InAt(0).AsRegister<Register>();
3658 Register second = locations->InAt(1).AsRegister<Register>();
3659 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003660 if (instruction->IsAnd()) {
3661 __ and_(out, first, ShifterOperand(second));
3662 } else if (instruction->IsOr()) {
3663 __ orr(out, first, ShifterOperand(second));
3664 } else {
3665 DCHECK(instruction->IsXor());
3666 __ eor(out, first, ShifterOperand(second));
3667 }
3668 } else {
3669 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3670 Location first = locations->InAt(0);
3671 Location second = locations->InAt(1);
3672 Location out = locations->Out();
3673 if (instruction->IsAnd()) {
3674 __ and_(out.AsRegisterPairLow<Register>(),
3675 first.AsRegisterPairLow<Register>(),
3676 ShifterOperand(second.AsRegisterPairLow<Register>()));
3677 __ and_(out.AsRegisterPairHigh<Register>(),
3678 first.AsRegisterPairHigh<Register>(),
3679 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3680 } else if (instruction->IsOr()) {
3681 __ orr(out.AsRegisterPairLow<Register>(),
3682 first.AsRegisterPairLow<Register>(),
3683 ShifterOperand(second.AsRegisterPairLow<Register>()));
3684 __ orr(out.AsRegisterPairHigh<Register>(),
3685 first.AsRegisterPairHigh<Register>(),
3686 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3687 } else {
3688 DCHECK(instruction->IsXor());
3689 __ eor(out.AsRegisterPairLow<Register>(),
3690 first.AsRegisterPairLow<Register>(),
3691 ShifterOperand(second.AsRegisterPairLow<Register>()));
3692 __ eor(out.AsRegisterPairHigh<Register>(),
3693 first.AsRegisterPairHigh<Register>(),
3694 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3695 }
3696 }
3697}
3698
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003699} // namespace arm
3700} // namespace art