blob: 2d3fa5f252e3cdabc16f196bb28c4098947c6987 [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,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000390 const ArmInstructionSetFeatures& isa_features,
391 const CompilerOptions& compiler_options)
392 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters,
393 kNumberOfRegisterPairs, compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100394 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100395 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100396 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100397 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000398 assembler_(true),
399 isa_features_(isa_features) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100400
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100401size_t CodeGeneratorARM::FrameEntrySpillSize() const {
402 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
403}
404
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100405Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100406 switch (type) {
407 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100408 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100409 ArmManagedRegister pair =
410 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100411 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
412 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
413
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100414 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
415 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100416 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100417 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100418 }
419
420 case Primitive::kPrimByte:
421 case Primitive::kPrimBoolean:
422 case Primitive::kPrimChar:
423 case Primitive::kPrimShort:
424 case Primitive::kPrimInt:
425 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100426 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100427 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100428 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
429 ArmManagedRegister current =
430 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
431 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100432 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100433 }
434 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100435 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100436 }
437
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000438 case Primitive::kPrimFloat: {
439 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100440 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100441 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000443 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000444 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
445 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000446 return Location::FpuRegisterPairLocation(reg, reg + 1);
447 }
448
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100449 case Primitive::kPrimVoid:
450 LOG(FATAL) << "Unreachable type " << type;
451 }
452
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100453 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100454}
455
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100457 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100458 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100459
460 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100461 blocked_core_registers_[SP] = true;
462 blocked_core_registers_[LR] = true;
463 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100464
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100465 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100466 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100467
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100468 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100469 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100470
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000471 // TODO: We currently don't use Quick's callee saved registers.
472 // We always save and restore R6 and R7 to make sure we can use three
473 // register pairs for long operations.
474 blocked_core_registers_[R4] = true;
475 blocked_core_registers_[R5] = true;
476 blocked_core_registers_[R8] = true;
477 blocked_core_registers_[R10] = true;
478 blocked_core_registers_[R11] = true;
479
Nicolas Geoffray53f12622015-01-13 18:04:41 +0000480 // Don't allocate our temporary double register.
481 blocked_fpu_registers_[STMP] = true;
482 blocked_fpu_registers_[STMP + 1] = true;
483 DCHECK_EQ(FromLowSToD(STMP), DTMP);
484
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000485 blocked_fpu_registers_[S16] = true;
486 blocked_fpu_registers_[S17] = true;
487 blocked_fpu_registers_[S18] = true;
488 blocked_fpu_registers_[S19] = true;
489 blocked_fpu_registers_[S20] = true;
490 blocked_fpu_registers_[S21] = true;
491 blocked_fpu_registers_[S22] = true;
492 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000493 blocked_fpu_registers_[S24] = true;
494 blocked_fpu_registers_[S25] = true;
495 blocked_fpu_registers_[S26] = true;
496 blocked_fpu_registers_[S27] = true;
497 blocked_fpu_registers_[S28] = true;
498 blocked_fpu_registers_[S29] = true;
499 blocked_fpu_registers_[S30] = true;
500 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100501
502 UpdateBlockedPairRegisters();
503}
504
505void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
506 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
507 ArmManagedRegister current =
508 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
509 if (blocked_core_registers_[current.AsRegisterPairLow()]
510 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
511 blocked_register_pairs_[i] = true;
512 }
513 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100514}
515
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100516InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
517 : HGraphVisitor(graph),
518 assembler_(codegen->GetAssembler()),
519 codegen_(codegen) {}
520
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000521void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000522 bool skip_overflow_check =
523 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100524 if (!skip_overflow_check) {
525 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100526 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100527 AddSlowPath(slow_path);
528
529 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
530 __ cmp(SP, ShifterOperand(IP));
531 __ b(slow_path->GetEntryLabel(), CC);
532 } else {
533 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100534 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100535 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100536 }
537 }
538
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000539 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
540 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000541
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100542 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100543 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100544 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000545}
546
547void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100548 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000549 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000550}
551
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100552void CodeGeneratorARM::Bind(HBasicBlock* block) {
553 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000554}
555
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100556Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
557 switch (load->GetType()) {
558 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100559 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100560 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
561 break;
562
563 case Primitive::kPrimInt:
564 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100565 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100566 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100567
568 case Primitive::kPrimBoolean:
569 case Primitive::kPrimByte:
570 case Primitive::kPrimChar:
571 case Primitive::kPrimShort:
572 case Primitive::kPrimVoid:
573 LOG(FATAL) << "Unexpected type " << load->GetType();
574 }
575
576 LOG(FATAL) << "Unreachable";
577 return Location();
578}
579
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100580Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
581 switch (type) {
582 case Primitive::kPrimBoolean:
583 case Primitive::kPrimByte:
584 case Primitive::kPrimChar:
585 case Primitive::kPrimShort:
586 case Primitive::kPrimInt:
587 case Primitive::kPrimNot: {
588 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000589 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100590 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100591 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100592 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000593 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100594 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100595 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100596
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000597 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100598 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000599 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100600 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000601 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100602 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000603 if (calling_convention.GetRegisterAt(index) == R1) {
604 // Skip R1, and use R2_R3 instead.
605 gp_index_++;
606 index++;
607 }
608 }
609 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
610 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000611 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000612 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000613 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100614 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000615 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
616 }
617 }
618
619 case Primitive::kPrimFloat: {
620 uint32_t stack_index = stack_index_++;
621 if (float_index_ % 2 == 0) {
622 float_index_ = std::max(double_index_, float_index_);
623 }
624 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
625 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
626 } else {
627 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
628 }
629 }
630
631 case Primitive::kPrimDouble: {
632 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
633 uint32_t stack_index = stack_index_;
634 stack_index_ += 2;
635 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
636 uint32_t index = double_index_;
637 double_index_ += 2;
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000638 DCHECK_EQ(calling_convention.GetFpuRegisterAt(index) + 1,
639 calling_convention.GetFpuRegisterAt(index + 1));
640 DCHECK_EQ(calling_convention.GetFpuRegisterAt(index) & 1, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000641 return Location::FpuRegisterPairLocation(
642 calling_convention.GetFpuRegisterAt(index),
643 calling_convention.GetFpuRegisterAt(index + 1));
644 } else {
645 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100646 }
647 }
648
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100649 case Primitive::kPrimVoid:
650 LOG(FATAL) << "Unexpected parameter type " << type;
651 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100652 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100653 return Location();
654}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100655
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000656Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
657 switch (type) {
658 case Primitive::kPrimBoolean:
659 case Primitive::kPrimByte:
660 case Primitive::kPrimChar:
661 case Primitive::kPrimShort:
662 case Primitive::kPrimInt:
663 case Primitive::kPrimNot: {
664 return Location::RegisterLocation(R0);
665 }
666
667 case Primitive::kPrimFloat: {
668 return Location::FpuRegisterLocation(S0);
669 }
670
671 case Primitive::kPrimLong: {
672 return Location::RegisterPairLocation(R0, R1);
673 }
674
675 case Primitive::kPrimDouble: {
676 return Location::FpuRegisterPairLocation(S0, S1);
677 }
678
679 case Primitive::kPrimVoid:
680 return Location();
681 }
682 UNREACHABLE();
683 return Location();
684}
685
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100686void CodeGeneratorARM::Move32(Location destination, Location source) {
687 if (source.Equals(destination)) {
688 return;
689 }
690 if (destination.IsRegister()) {
691 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000692 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100693 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000694 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100695 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000696 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100697 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100698 } else if (destination.IsFpuRegister()) {
699 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000700 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100701 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000702 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100703 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000704 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100705 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000707 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100708 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000709 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100710 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000711 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000713 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100714 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
715 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100716 }
717 }
718}
719
720void CodeGeneratorARM::Move64(Location destination, Location source) {
721 if (source.Equals(destination)) {
722 return;
723 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100724 if (destination.IsRegisterPair()) {
725 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000726 EmitParallelMoves(
727 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
728 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
729 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
730 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100731 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000732 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100733 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000734 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100735 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100736 if (destination.AsRegisterPairLow<Register>() == R1) {
737 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100738 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
739 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100741 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100742 SP, source.GetStackIndex());
743 }
744 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000745 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100746 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000747 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
748 SP,
749 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100750 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000751 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100752 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100753 } else {
754 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100755 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000756 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100757 if (source.AsRegisterPairLow<Register>() == R1) {
758 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100759 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
760 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100761 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100762 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100763 SP, destination.GetStackIndex());
764 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000765 } else if (source.IsFpuRegisterPair()) {
766 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
767 SP,
768 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100769 } else {
770 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000771 EmitParallelMoves(
772 Location::StackSlot(source.GetStackIndex()),
773 Location::StackSlot(destination.GetStackIndex()),
774 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
775 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776 }
777 }
778}
779
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100780void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100781 LocationSummary* locations = instruction->GetLocations();
782 if (locations != nullptr && locations->Out().Equals(location)) {
783 return;
784 }
785
Calin Juravlea21f5982014-11-13 15:53:04 +0000786 if (locations != nullptr && locations->Out().IsConstant()) {
787 HConstant* const_to_move = locations->Out().GetConstant();
788 if (const_to_move->IsIntConstant()) {
789 int32_t value = const_to_move->AsIntConstant()->GetValue();
790 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000791 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000792 } else {
793 DCHECK(location.IsStackSlot());
794 __ LoadImmediate(IP, value);
795 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
796 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000797 } else {
798 DCHECK(const_to_move->IsLongConstant()) << const_to_move;
Calin Juravlea21f5982014-11-13 15:53:04 +0000799 int64_t value = const_to_move->AsLongConstant()->GetValue();
800 if (location.IsRegisterPair()) {
801 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
802 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
803 } else {
804 DCHECK(location.IsDoubleStackSlot());
805 __ LoadImmediate(IP, Low32Bits(value));
806 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
807 __ LoadImmediate(IP, High32Bits(value));
808 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
809 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100810 }
Roland Levillain476df552014-10-09 17:51:36 +0100811 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100812 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
813 switch (instruction->GetType()) {
814 case Primitive::kPrimBoolean:
815 case Primitive::kPrimByte:
816 case Primitive::kPrimChar:
817 case Primitive::kPrimShort:
818 case Primitive::kPrimInt:
819 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100820 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100821 Move32(location, Location::StackSlot(stack_slot));
822 break;
823
824 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100825 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100826 Move64(location, Location::DoubleStackSlot(stack_slot));
827 break;
828
829 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100830 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100831 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000832 } else if (instruction->IsTemporary()) {
833 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000834 if (temp_location.IsStackSlot()) {
835 Move32(location, temp_location);
836 } else {
837 DCHECK(temp_location.IsDoubleStackSlot());
838 Move64(location, temp_location);
839 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000840 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100841 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100842 switch (instruction->GetType()) {
843 case Primitive::kPrimBoolean:
844 case Primitive::kPrimByte:
845 case Primitive::kPrimChar:
846 case Primitive::kPrimShort:
847 case Primitive::kPrimNot:
848 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100849 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100850 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100851 break;
852
853 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100854 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100855 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100856 break;
857
858 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100859 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100860 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000861 }
862}
863
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100864void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
865 HInstruction* instruction,
866 uint32_t dex_pc) {
867 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
868 __ blx(LR);
869 RecordPcInfo(instruction, dex_pc);
870 DCHECK(instruction->IsSuspendCheck()
871 || instruction->IsBoundsCheck()
872 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000873 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000874 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100875 || !IsLeafMethod());
876}
877
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000878void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000879 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000880}
881
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000882void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000883 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100884 DCHECK(!successor->IsExitBlock());
885
886 HBasicBlock* block = got->GetBlock();
887 HInstruction* previous = got->GetPrevious();
888
889 HLoopInformation* info = block->GetLoopInformation();
890 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
891 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
892 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
893 return;
894 }
895
896 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
897 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
898 }
899 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000900 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000901 }
902}
903
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000904void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000905 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000906}
907
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000908void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700909 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000910 if (kIsDebugBuild) {
911 __ Comment("Unreachable");
912 __ bkpt(0);
913 }
914}
915
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000916void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100917 LocationSummary* locations =
918 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100919 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100920 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100921 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100922 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000923}
924
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000925void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700926 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100927 if (cond->IsIntConstant()) {
928 // Constant condition, statically compared against 1.
929 int32_t cond_value = cond->AsIntConstant()->GetValue();
930 if (cond_value == 1) {
931 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
932 if_instr->IfTrueSuccessor())) {
933 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100934 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100935 return;
936 } else {
937 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100938 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100939 } else {
940 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
941 // Condition has been materialized, compare the output to 0
942 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000943 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100944 ShifterOperand(0));
945 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
946 } else {
947 // Condition has not been materialized, use its inputs as the
948 // comparison and its condition as the branch condition.
949 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000950 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100951 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000952 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100953 } else {
954 DCHECK(locations->InAt(1).IsConstant());
955 int32_t value =
956 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
957 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000958 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
959 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100960 } else {
961 Register temp = IP;
962 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000963 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100964 }
965 }
966 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
967 ARMCondition(cond->AsCondition()->GetCondition()));
968 }
Dave Allison20dfc792014-06-16 20:44:29 -0700969 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100970 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
971 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700972 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000973 }
974}
975
Dave Allison20dfc792014-06-16 20:44:29 -0700976
977void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100978 LocationSummary* locations =
979 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100980 locations->SetInAt(0, Location::RequiresRegister());
981 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100982 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100983 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100984 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000985}
986
Dave Allison20dfc792014-06-16 20:44:29 -0700987void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100988 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100989 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000990 Register left = locations->InAt(0).AsRegister<Register>();
991
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100992 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000993 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100994 } else {
995 DCHECK(locations->InAt(1).IsConstant());
996 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
997 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000998 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
999 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 } else {
1001 Register temp = IP;
1002 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001003 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001004 }
Dave Allison20dfc792014-06-16 20:44:29 -07001005 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001006 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001007 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001008 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001009 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001010 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001011}
1012
1013void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1014 VisitCondition(comp);
1015}
1016
1017void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1018 VisitCondition(comp);
1019}
1020
1021void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1022 VisitCondition(comp);
1023}
1024
1025void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1026 VisitCondition(comp);
1027}
1028
1029void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1030 VisitCondition(comp);
1031}
1032
1033void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1034 VisitCondition(comp);
1035}
1036
1037void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1038 VisitCondition(comp);
1039}
1040
1041void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1042 VisitCondition(comp);
1043}
1044
1045void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1046 VisitCondition(comp);
1047}
1048
1049void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1050 VisitCondition(comp);
1051}
1052
1053void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1054 VisitCondition(comp);
1055}
1056
1057void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1058 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001059}
1060
1061void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001062 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001063}
1064
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001065void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1066 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001067}
1068
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001069void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001070 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001071}
1072
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001073void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001074 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001075 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001076}
1077
1078void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001079 LocationSummary* locations =
1080 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001081 switch (store->InputAt(1)->GetType()) {
1082 case Primitive::kPrimBoolean:
1083 case Primitive::kPrimByte:
1084 case Primitive::kPrimChar:
1085 case Primitive::kPrimShort:
1086 case Primitive::kPrimInt:
1087 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001088 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001089 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1090 break;
1091
1092 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001093 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001094 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1095 break;
1096
1097 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001098 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001099 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001100}
1101
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001102void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001103 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001104}
1105
1106void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001107 LocationSummary* locations =
1108 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001109 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001110}
1111
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001112void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001113 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001114 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001115}
1116
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001117void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001118 LocationSummary* locations =
1119 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001120 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001121}
1122
1123void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1124 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001125 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001126}
1127
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001128void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1129 LocationSummary* locations =
1130 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1131 locations->SetOut(Location::ConstantLocation(constant));
1132}
1133
1134void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1135 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001136 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001137}
1138
1139void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1140 LocationSummary* locations =
1141 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1142 locations->SetOut(Location::ConstantLocation(constant));
1143}
1144
1145void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1146 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001147 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001148}
1149
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001150void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001151 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001152}
1153
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001154void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001155 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001156 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001157}
1158
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001159void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001160 LocationSummary* locations =
1161 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001162 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001163}
1164
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001165void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001166 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001167 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001168}
1169
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001170void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001171 HandleInvoke(invoke);
1172}
1173
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001174void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001175 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001176}
1177
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001178void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001179 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001180
1181 // TODO: Implement all kinds of calls:
1182 // 1) boot -> boot
1183 // 2) app -> boot
1184 // 3) app -> app
1185 //
1186 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1187
1188 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001189 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001190 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001191 __ LoadFromOffset(
1192 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001193 // temp = temp[index_in_cache]
1194 __ LoadFromOffset(
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001195 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001196 // LR = temp[offset_of_quick_compiled_code]
1197 __ LoadFromOffset(kLoadWord, LR, temp,
1198 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1199 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001200 // LR()
1201 __ blx(LR);
1202
1203 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1204 DCHECK(!codegen_->IsLeafMethod());
1205}
1206
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001207void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001208 LocationSummary* locations =
1209 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001210 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001211
1212 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001213 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001214 HInstruction* input = invoke->InputAt(i);
1215 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1216 }
1217
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001218 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001219}
1220
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001221void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1222 HandleInvoke(invoke);
1223}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001224
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001225void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001226 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001227 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1228 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1229 LocationSummary* locations = invoke->GetLocations();
1230 Location receiver = locations->InAt(0);
1231 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1232 // temp = object->GetClass();
1233 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001234 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1235 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001236 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001237 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001238 }
1239 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001240 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001241 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001242 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001243 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001244 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001245 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001246 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001247 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001248 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001249}
1250
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001251void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1252 HandleInvoke(invoke);
1253 // Add the hidden argument.
1254 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1255}
1256
1257void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1258 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001259 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001260 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1261 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1262 LocationSummary* locations = invoke->GetLocations();
1263 Location receiver = locations->InAt(0);
1264 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1265
1266 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001267 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1268 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001269
1270 // temp = object->GetClass();
1271 if (receiver.IsStackSlot()) {
1272 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1273 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1274 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001275 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001276 }
1277 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001278 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001279 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001280 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1281 // LR = temp->GetEntryPoint();
1282 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1283 // LR();
1284 __ blx(LR);
1285 DCHECK(!codegen_->IsLeafMethod());
1286 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1287}
1288
Roland Levillain88cb1752014-10-20 16:36:47 +01001289void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1290 LocationSummary* locations =
1291 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1292 switch (neg->GetResultType()) {
1293 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001294 case Primitive::kPrimLong: {
1295 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001296 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001297 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001298 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001299 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001300
Roland Levillain88cb1752014-10-20 16:36:47 +01001301 case Primitive::kPrimFloat:
1302 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001303 locations->SetInAt(0, Location::RequiresFpuRegister());
1304 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001305 break;
1306
1307 default:
1308 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1309 }
1310}
1311
1312void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1313 LocationSummary* locations = neg->GetLocations();
1314 Location out = locations->Out();
1315 Location in = locations->InAt(0);
1316 switch (neg->GetResultType()) {
1317 case Primitive::kPrimInt:
1318 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001319 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001320 break;
1321
1322 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001323 DCHECK(in.IsRegisterPair());
1324 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1325 __ rsbs(out.AsRegisterPairLow<Register>(),
1326 in.AsRegisterPairLow<Register>(),
1327 ShifterOperand(0));
1328 // We cannot emit an RSC (Reverse Subtract with Carry)
1329 // instruction here, as it does not exist in the Thumb-2
1330 // instruction set. We use the following approach
1331 // using SBC and SUB instead.
1332 //
1333 // out.hi = -C
1334 __ sbc(out.AsRegisterPairHigh<Register>(),
1335 out.AsRegisterPairHigh<Register>(),
1336 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1337 // out.hi = out.hi - in.hi
1338 __ sub(out.AsRegisterPairHigh<Register>(),
1339 out.AsRegisterPairHigh<Register>(),
1340 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1341 break;
1342
Roland Levillain88cb1752014-10-20 16:36:47 +01001343 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001344 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001345 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001346 break;
1347
Roland Levillain88cb1752014-10-20 16:36:47 +01001348 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001349 DCHECK(in.IsFpuRegisterPair());
1350 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1351 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001352 break;
1353
1354 default:
1355 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1356 }
1357}
1358
Roland Levillaindff1f282014-11-05 14:15:05 +00001359void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001360 Primitive::Type result_type = conversion->GetResultType();
1361 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001362 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001363
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001364 // The float-to-long and double-to-long type conversions rely on a
1365 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001366 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001367 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1368 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001369 ? LocationSummary::kCall
1370 : LocationSummary::kNoCall;
1371 LocationSummary* locations =
1372 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1373
Roland Levillaindff1f282014-11-05 14:15:05 +00001374 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001375 case Primitive::kPrimByte:
1376 switch (input_type) {
1377 case Primitive::kPrimShort:
1378 case Primitive::kPrimInt:
1379 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001380 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001381 locations->SetInAt(0, Location::RequiresRegister());
1382 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1383 break;
1384
1385 default:
1386 LOG(FATAL) << "Unexpected type conversion from " << input_type
1387 << " to " << result_type;
1388 }
1389 break;
1390
Roland Levillain01a8d712014-11-14 16:27:39 +00001391 case Primitive::kPrimShort:
1392 switch (input_type) {
1393 case Primitive::kPrimByte:
1394 case Primitive::kPrimInt:
1395 case Primitive::kPrimChar:
1396 // Processing a Dex `int-to-short' instruction.
1397 locations->SetInAt(0, Location::RequiresRegister());
1398 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1399 break;
1400
1401 default:
1402 LOG(FATAL) << "Unexpected type conversion from " << input_type
1403 << " to " << result_type;
1404 }
1405 break;
1406
Roland Levillain946e1432014-11-11 17:35:19 +00001407 case Primitive::kPrimInt:
1408 switch (input_type) {
1409 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001410 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001411 locations->SetInAt(0, Location::Any());
1412 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1413 break;
1414
1415 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001416 // Processing a Dex `float-to-int' instruction.
1417 locations->SetInAt(0, Location::RequiresFpuRegister());
1418 locations->SetOut(Location::RequiresRegister());
1419 locations->AddTemp(Location::RequiresFpuRegister());
1420 break;
1421
Roland Levillain946e1432014-11-11 17:35:19 +00001422 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001423 // Processing a Dex `double-to-int' instruction.
1424 locations->SetInAt(0, Location::RequiresFpuRegister());
1425 locations->SetOut(Location::RequiresRegister());
1426 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001427 break;
1428
1429 default:
1430 LOG(FATAL) << "Unexpected type conversion from " << input_type
1431 << " to " << result_type;
1432 }
1433 break;
1434
Roland Levillaindff1f282014-11-05 14:15:05 +00001435 case Primitive::kPrimLong:
1436 switch (input_type) {
1437 case Primitive::kPrimByte:
1438 case Primitive::kPrimShort:
1439 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001440 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001441 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001442 locations->SetInAt(0, Location::RequiresRegister());
1443 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1444 break;
1445
Roland Levillain624279f2014-12-04 11:54:28 +00001446 case Primitive::kPrimFloat: {
1447 // Processing a Dex `float-to-long' instruction.
1448 InvokeRuntimeCallingConvention calling_convention;
1449 locations->SetInAt(0, Location::FpuRegisterLocation(
1450 calling_convention.GetFpuRegisterAt(0)));
1451 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1452 break;
1453 }
1454
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001455 case Primitive::kPrimDouble: {
1456 // Processing a Dex `double-to-long' instruction.
1457 InvokeRuntimeCallingConvention calling_convention;
1458 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1459 calling_convention.GetFpuRegisterAt(0),
1460 calling_convention.GetFpuRegisterAt(1)));
1461 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001462 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001463 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001464
1465 default:
1466 LOG(FATAL) << "Unexpected type conversion from " << input_type
1467 << " to " << result_type;
1468 }
1469 break;
1470
Roland Levillain981e4542014-11-14 11:47:14 +00001471 case Primitive::kPrimChar:
1472 switch (input_type) {
1473 case Primitive::kPrimByte:
1474 case Primitive::kPrimShort:
1475 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001476 // Processing a Dex `int-to-char' instruction.
1477 locations->SetInAt(0, Location::RequiresRegister());
1478 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1479 break;
1480
1481 default:
1482 LOG(FATAL) << "Unexpected type conversion from " << input_type
1483 << " to " << result_type;
1484 }
1485 break;
1486
Roland Levillaindff1f282014-11-05 14:15:05 +00001487 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001488 switch (input_type) {
1489 case Primitive::kPrimByte:
1490 case Primitive::kPrimShort:
1491 case Primitive::kPrimInt:
1492 case Primitive::kPrimChar:
1493 // Processing a Dex `int-to-float' instruction.
1494 locations->SetInAt(0, Location::RequiresRegister());
1495 locations->SetOut(Location::RequiresFpuRegister());
1496 break;
1497
1498 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001499 // Processing a Dex `long-to-float' instruction.
1500 locations->SetInAt(0, Location::RequiresRegister());
1501 locations->SetOut(Location::RequiresFpuRegister());
1502 locations->AddTemp(Location::RequiresRegister());
1503 locations->AddTemp(Location::RequiresRegister());
1504 locations->AddTemp(Location::RequiresFpuRegister());
1505 locations->AddTemp(Location::RequiresFpuRegister());
1506 break;
1507
Roland Levillaincff13742014-11-17 14:32:17 +00001508 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001509 // Processing a Dex `double-to-float' instruction.
1510 locations->SetInAt(0, Location::RequiresFpuRegister());
1511 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001512 break;
1513
1514 default:
1515 LOG(FATAL) << "Unexpected type conversion from " << input_type
1516 << " to " << result_type;
1517 };
1518 break;
1519
Roland Levillaindff1f282014-11-05 14:15:05 +00001520 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001521 switch (input_type) {
1522 case Primitive::kPrimByte:
1523 case Primitive::kPrimShort:
1524 case Primitive::kPrimInt:
1525 case Primitive::kPrimChar:
1526 // Processing a Dex `int-to-double' instruction.
1527 locations->SetInAt(0, Location::RequiresRegister());
1528 locations->SetOut(Location::RequiresFpuRegister());
1529 break;
1530
1531 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001532 // Processing a Dex `long-to-double' instruction.
1533 locations->SetInAt(0, Location::RequiresRegister());
1534 locations->SetOut(Location::RequiresFpuRegister());
1535 locations->AddTemp(Location::RequiresRegister());
1536 locations->AddTemp(Location::RequiresRegister());
1537 locations->AddTemp(Location::RequiresFpuRegister());
1538 break;
1539
Roland Levillaincff13742014-11-17 14:32:17 +00001540 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001541 // Processing a Dex `float-to-double' instruction.
1542 locations->SetInAt(0, Location::RequiresFpuRegister());
1543 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001544 break;
1545
1546 default:
1547 LOG(FATAL) << "Unexpected type conversion from " << input_type
1548 << " to " << result_type;
1549 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001550 break;
1551
1552 default:
1553 LOG(FATAL) << "Unexpected type conversion from " << input_type
1554 << " to " << result_type;
1555 }
1556}
1557
1558void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1559 LocationSummary* locations = conversion->GetLocations();
1560 Location out = locations->Out();
1561 Location in = locations->InAt(0);
1562 Primitive::Type result_type = conversion->GetResultType();
1563 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001564 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001565 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001566 case Primitive::kPrimByte:
1567 switch (input_type) {
1568 case Primitive::kPrimShort:
1569 case Primitive::kPrimInt:
1570 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001571 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001572 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001573 break;
1574
1575 default:
1576 LOG(FATAL) << "Unexpected type conversion from " << input_type
1577 << " to " << result_type;
1578 }
1579 break;
1580
Roland Levillain01a8d712014-11-14 16:27:39 +00001581 case Primitive::kPrimShort:
1582 switch (input_type) {
1583 case Primitive::kPrimByte:
1584 case Primitive::kPrimInt:
1585 case Primitive::kPrimChar:
1586 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001587 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001588 break;
1589
1590 default:
1591 LOG(FATAL) << "Unexpected type conversion from " << input_type
1592 << " to " << result_type;
1593 }
1594 break;
1595
Roland Levillain946e1432014-11-11 17:35:19 +00001596 case Primitive::kPrimInt:
1597 switch (input_type) {
1598 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001599 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001600 DCHECK(out.IsRegister());
1601 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001602 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001603 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001604 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001605 } else {
1606 DCHECK(in.IsConstant());
1607 DCHECK(in.GetConstant()->IsLongConstant());
1608 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001609 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001610 }
1611 break;
1612
Roland Levillain3f8f9362014-12-02 17:45:01 +00001613 case Primitive::kPrimFloat: {
1614 // Processing a Dex `float-to-int' instruction.
1615 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1616 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1617 __ vcvtis(temp, temp);
1618 __ vmovrs(out.AsRegister<Register>(), temp);
1619 break;
1620 }
1621
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001622 case Primitive::kPrimDouble: {
1623 // Processing a Dex `double-to-int' instruction.
1624 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1625 DRegister temp_d = FromLowSToD(temp_s);
1626 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1627 __ vcvtid(temp_s, temp_d);
1628 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001629 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001630 }
Roland Levillain946e1432014-11-11 17:35:19 +00001631
1632 default:
1633 LOG(FATAL) << "Unexpected type conversion from " << input_type
1634 << " to " << result_type;
1635 }
1636 break;
1637
Roland Levillaindff1f282014-11-05 14:15:05 +00001638 case Primitive::kPrimLong:
1639 switch (input_type) {
1640 case Primitive::kPrimByte:
1641 case Primitive::kPrimShort:
1642 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001643 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001644 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001645 DCHECK(out.IsRegisterPair());
1646 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001647 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001648 // Sign extension.
1649 __ Asr(out.AsRegisterPairHigh<Register>(),
1650 out.AsRegisterPairLow<Register>(),
1651 31);
1652 break;
1653
1654 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001655 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001656 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1657 conversion,
1658 conversion->GetDexPc());
1659 break;
1660
Roland Levillaindff1f282014-11-05 14:15:05 +00001661 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001662 // Processing a Dex `double-to-long' instruction.
1663 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1664 conversion,
1665 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001666 break;
1667
1668 default:
1669 LOG(FATAL) << "Unexpected type conversion from " << input_type
1670 << " to " << result_type;
1671 }
1672 break;
1673
Roland Levillain981e4542014-11-14 11:47:14 +00001674 case Primitive::kPrimChar:
1675 switch (input_type) {
1676 case Primitive::kPrimByte:
1677 case Primitive::kPrimShort:
1678 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001679 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001680 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001681 break;
1682
1683 default:
1684 LOG(FATAL) << "Unexpected type conversion from " << input_type
1685 << " to " << result_type;
1686 }
1687 break;
1688
Roland Levillaindff1f282014-11-05 14:15:05 +00001689 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001690 switch (input_type) {
1691 case Primitive::kPrimByte:
1692 case Primitive::kPrimShort:
1693 case Primitive::kPrimInt:
1694 case Primitive::kPrimChar: {
1695 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001696 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1697 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001698 break;
1699 }
1700
Roland Levillain6d0e4832014-11-27 18:31:21 +00001701 case Primitive::kPrimLong: {
1702 // Processing a Dex `long-to-float' instruction.
1703 Register low = in.AsRegisterPairLow<Register>();
1704 Register high = in.AsRegisterPairHigh<Register>();
1705 SRegister output = out.AsFpuRegister<SRegister>();
1706 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1707 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1708 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1709 DRegister temp1_d = FromLowSToD(temp1_s);
1710 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1711 DRegister temp2_d = FromLowSToD(temp2_s);
1712
1713 // Operations use doubles for precision reasons (each 32-bit
1714 // half of a long fits in the 53-bit mantissa of a double,
1715 // but not in the 24-bit mantissa of a float). This is
1716 // especially important for the low bits. The result is
1717 // eventually converted to float.
1718
1719 // temp1_d = int-to-double(high)
1720 __ vmovsr(temp1_s, high);
1721 __ vcvtdi(temp1_d, temp1_s);
1722 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1723 // as an immediate value into `temp2_d` does not work, as
1724 // this instruction only transfers 8 significant bits of its
1725 // immediate operand. Instead, use two 32-bit core
1726 // registers to load `k2Pow32EncodingForDouble` into
1727 // `temp2_d`.
1728 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1729 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1730 __ vmovdrr(temp2_d, constant_low, constant_high);
1731 // temp1_d = temp1_d * 2^32
1732 __ vmuld(temp1_d, temp1_d, temp2_d);
1733 // temp2_d = unsigned-to-double(low)
1734 __ vmovsr(temp2_s, low);
1735 __ vcvtdu(temp2_d, temp2_s);
1736 // temp1_d = temp1_d + temp2_d
1737 __ vaddd(temp1_d, temp1_d, temp2_d);
1738 // output = double-to-float(temp1_d);
1739 __ vcvtsd(output, temp1_d);
1740 break;
1741 }
1742
Roland Levillaincff13742014-11-17 14:32:17 +00001743 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001744 // Processing a Dex `double-to-float' instruction.
1745 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1746 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001747 break;
1748
1749 default:
1750 LOG(FATAL) << "Unexpected type conversion from " << input_type
1751 << " to " << result_type;
1752 };
1753 break;
1754
Roland Levillaindff1f282014-11-05 14:15:05 +00001755 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001756 switch (input_type) {
1757 case Primitive::kPrimByte:
1758 case Primitive::kPrimShort:
1759 case Primitive::kPrimInt:
1760 case Primitive::kPrimChar: {
1761 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001762 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001763 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1764 out.AsFpuRegisterPairLow<SRegister>());
1765 break;
1766 }
1767
Roland Levillain647b9ed2014-11-27 12:06:00 +00001768 case Primitive::kPrimLong: {
1769 // Processing a Dex `long-to-double' instruction.
1770 Register low = in.AsRegisterPairLow<Register>();
1771 Register high = in.AsRegisterPairHigh<Register>();
1772 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1773 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001774 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1775 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001776 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1777 DRegister temp_d = FromLowSToD(temp_s);
1778
Roland Levillain647b9ed2014-11-27 12:06:00 +00001779 // out_d = int-to-double(high)
1780 __ vmovsr(out_s, high);
1781 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001782 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1783 // as an immediate value into `temp_d` does not work, as
1784 // this instruction only transfers 8 significant bits of its
1785 // immediate operand. Instead, use two 32-bit core
1786 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1787 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1788 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001789 __ vmovdrr(temp_d, constant_low, constant_high);
1790 // out_d = out_d * 2^32
1791 __ vmuld(out_d, out_d, temp_d);
1792 // temp_d = unsigned-to-double(low)
1793 __ vmovsr(temp_s, low);
1794 __ vcvtdu(temp_d, temp_s);
1795 // out_d = out_d + temp_d
1796 __ vaddd(out_d, out_d, temp_d);
1797 break;
1798 }
1799
Roland Levillaincff13742014-11-17 14:32:17 +00001800 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001801 // Processing a Dex `float-to-double' instruction.
1802 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1803 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001804 break;
1805
1806 default:
1807 LOG(FATAL) << "Unexpected type conversion from " << input_type
1808 << " to " << result_type;
1809 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001810 break;
1811
1812 default:
1813 LOG(FATAL) << "Unexpected type conversion from " << input_type
1814 << " to " << result_type;
1815 }
1816}
1817
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001818void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001819 LocationSummary* locations =
1820 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001821 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001822 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001823 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001824 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1825 locations->SetInAt(0, Location::RequiresRegister());
1826 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1827 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001828 break;
1829 }
1830
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001831 case Primitive::kPrimFloat:
1832 case Primitive::kPrimDouble: {
1833 locations->SetInAt(0, Location::RequiresFpuRegister());
1834 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001835 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001836 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001837 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001838
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001839 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001840 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001841 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001842}
1843
1844void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1845 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001846 Location out = locations->Out();
1847 Location first = locations->InAt(0);
1848 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001849 switch (add->GetResultType()) {
1850 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001851 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001852 __ add(out.AsRegister<Register>(),
1853 first.AsRegister<Register>(),
1854 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001855 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001856 __ AddConstant(out.AsRegister<Register>(),
1857 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001858 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001859 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001860 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001861
1862 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001863 __ adds(out.AsRegisterPairLow<Register>(),
1864 first.AsRegisterPairLow<Register>(),
1865 ShifterOperand(second.AsRegisterPairLow<Register>()));
1866 __ adc(out.AsRegisterPairHigh<Register>(),
1867 first.AsRegisterPairHigh<Register>(),
1868 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001869 break;
1870
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001871 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001872 __ vadds(out.AsFpuRegister<SRegister>(),
1873 first.AsFpuRegister<SRegister>(),
1874 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001875 break;
1876
1877 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001878 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1879 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1880 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001881 break;
1882
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001883 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001884 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001885 }
1886}
1887
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001888void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001889 LocationSummary* locations =
1890 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001891 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001892 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001893 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001894 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1895 locations->SetInAt(0, Location::RequiresRegister());
1896 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1897 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001898 break;
1899 }
Calin Juravle11351682014-10-23 15:38:15 +01001900 case Primitive::kPrimFloat:
1901 case Primitive::kPrimDouble: {
1902 locations->SetInAt(0, Location::RequiresFpuRegister());
1903 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001904 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001905 break;
Calin Juravle11351682014-10-23 15:38:15 +01001906 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001907 default:
Calin Juravle11351682014-10-23 15:38:15 +01001908 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001909 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001910}
1911
1912void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1913 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001914 Location out = locations->Out();
1915 Location first = locations->InAt(0);
1916 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001917 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001918 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001919 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001920 __ sub(out.AsRegister<Register>(),
1921 first.AsRegister<Register>(),
1922 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001923 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001924 __ AddConstant(out.AsRegister<Register>(),
1925 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001926 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001927 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001928 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001929 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001930
Calin Juravle11351682014-10-23 15:38:15 +01001931 case Primitive::kPrimLong: {
1932 __ subs(out.AsRegisterPairLow<Register>(),
1933 first.AsRegisterPairLow<Register>(),
1934 ShifterOperand(second.AsRegisterPairLow<Register>()));
1935 __ sbc(out.AsRegisterPairHigh<Register>(),
1936 first.AsRegisterPairHigh<Register>(),
1937 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001938 break;
Calin Juravle11351682014-10-23 15:38:15 +01001939 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001940
Calin Juravle11351682014-10-23 15:38:15 +01001941 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001942 __ vsubs(out.AsFpuRegister<SRegister>(),
1943 first.AsFpuRegister<SRegister>(),
1944 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001945 break;
Calin Juravle11351682014-10-23 15:38:15 +01001946 }
1947
1948 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001949 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1950 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1951 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001952 break;
1953 }
1954
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001955
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001956 default:
Calin Juravle11351682014-10-23 15:38:15 +01001957 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001958 }
1959}
1960
Calin Juravle34bacdf2014-10-07 20:23:36 +01001961void LocationsBuilderARM::VisitMul(HMul* mul) {
1962 LocationSummary* locations =
1963 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1964 switch (mul->GetResultType()) {
1965 case Primitive::kPrimInt:
1966 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001967 locations->SetInAt(0, Location::RequiresRegister());
1968 locations->SetInAt(1, Location::RequiresRegister());
1969 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001970 break;
1971 }
1972
Calin Juravleb5bfa962014-10-21 18:02:24 +01001973 case Primitive::kPrimFloat:
1974 case Primitive::kPrimDouble: {
1975 locations->SetInAt(0, Location::RequiresFpuRegister());
1976 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001977 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001978 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001979 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001980
1981 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001982 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001983 }
1984}
1985
1986void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1987 LocationSummary* locations = mul->GetLocations();
1988 Location out = locations->Out();
1989 Location first = locations->InAt(0);
1990 Location second = locations->InAt(1);
1991 switch (mul->GetResultType()) {
1992 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001993 __ mul(out.AsRegister<Register>(),
1994 first.AsRegister<Register>(),
1995 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001996 break;
1997 }
1998 case Primitive::kPrimLong: {
1999 Register out_hi = out.AsRegisterPairHigh<Register>();
2000 Register out_lo = out.AsRegisterPairLow<Register>();
2001 Register in1_hi = first.AsRegisterPairHigh<Register>();
2002 Register in1_lo = first.AsRegisterPairLow<Register>();
2003 Register in2_hi = second.AsRegisterPairHigh<Register>();
2004 Register in2_lo = second.AsRegisterPairLow<Register>();
2005
2006 // Extra checks to protect caused by the existence of R1_R2.
2007 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2008 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2009 DCHECK_NE(out_hi, in1_lo);
2010 DCHECK_NE(out_hi, in2_lo);
2011
2012 // input: in1 - 64 bits, in2 - 64 bits
2013 // output: out
2014 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2015 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2016 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2017
2018 // IP <- in1.lo * in2.hi
2019 __ mul(IP, in1_lo, in2_hi);
2020 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2021 __ mla(out_hi, in1_hi, in2_lo, IP);
2022 // out.lo <- (in1.lo * in2.lo)[31:0];
2023 __ umull(out_lo, IP, in1_lo, in2_lo);
2024 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2025 __ add(out_hi, out_hi, ShifterOperand(IP));
2026 break;
2027 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002028
2029 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002030 __ vmuls(out.AsFpuRegister<SRegister>(),
2031 first.AsFpuRegister<SRegister>(),
2032 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002033 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002034 }
2035
2036 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002037 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2038 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2039 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002040 break;
2041 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002042
2043 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002044 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002045 }
2046}
2047
Calin Juravle7c4954d2014-10-28 16:57:40 +00002048void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002049 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2050 ? LocationSummary::kCall
2051 : LocationSummary::kNoCall;
2052 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2053
Calin Juravle7c4954d2014-10-28 16:57:40 +00002054 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002055 case Primitive::kPrimInt: {
2056 locations->SetInAt(0, Location::RequiresRegister());
2057 locations->SetInAt(1, Location::RequiresRegister());
2058 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2059 break;
2060 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002061 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002062 InvokeRuntimeCallingConvention calling_convention;
2063 locations->SetInAt(0, Location::RegisterPairLocation(
2064 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2065 locations->SetInAt(1, Location::RegisterPairLocation(
2066 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2067 // The runtime helper puts the output in R0,R2.
2068 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002069 break;
2070 }
2071 case Primitive::kPrimFloat:
2072 case Primitive::kPrimDouble: {
2073 locations->SetInAt(0, Location::RequiresFpuRegister());
2074 locations->SetInAt(1, Location::RequiresFpuRegister());
2075 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2076 break;
2077 }
2078
2079 default:
2080 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2081 }
2082}
2083
2084void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2085 LocationSummary* locations = div->GetLocations();
2086 Location out = locations->Out();
2087 Location first = locations->InAt(0);
2088 Location second = locations->InAt(1);
2089
2090 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002091 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002092 __ sdiv(out.AsRegister<Register>(),
2093 first.AsRegister<Register>(),
2094 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002095 break;
2096 }
2097
Calin Juravle7c4954d2014-10-28 16:57:40 +00002098 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002099 InvokeRuntimeCallingConvention calling_convention;
2100 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2101 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2102 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2103 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2104 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2105 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2106
2107 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002108 break;
2109 }
2110
2111 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002112 __ vdivs(out.AsFpuRegister<SRegister>(),
2113 first.AsFpuRegister<SRegister>(),
2114 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002115 break;
2116 }
2117
2118 case Primitive::kPrimDouble: {
2119 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2120 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2121 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2122 break;
2123 }
2124
2125 default:
2126 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2127 }
2128}
2129
Calin Juravlebacfec32014-11-14 15:54:36 +00002130void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002131 Primitive::Type type = rem->GetResultType();
2132 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2133 ? LocationSummary::kNoCall
2134 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002135 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2136
Calin Juravled2ec87d2014-12-08 14:24:46 +00002137 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002138 case Primitive::kPrimInt: {
2139 locations->SetInAt(0, Location::RequiresRegister());
2140 locations->SetInAt(1, Location::RequiresRegister());
2141 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2142 locations->AddTemp(Location::RequiresRegister());
2143 break;
2144 }
2145 case Primitive::kPrimLong: {
2146 InvokeRuntimeCallingConvention calling_convention;
2147 locations->SetInAt(0, Location::RegisterPairLocation(
2148 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2149 locations->SetInAt(1, Location::RegisterPairLocation(
2150 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2151 // The runtime helper puts the output in R2,R3.
2152 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2153 break;
2154 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002155 case Primitive::kPrimFloat: {
2156 InvokeRuntimeCallingConvention calling_convention;
2157 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2158 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2159 locations->SetOut(Location::FpuRegisterLocation(S0));
2160 break;
2161 }
2162
Calin Juravlebacfec32014-11-14 15:54:36 +00002163 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002164 InvokeRuntimeCallingConvention calling_convention;
2165 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2166 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2167 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2168 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2169 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002170 break;
2171 }
2172
2173 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002174 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002175 }
2176}
2177
2178void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2179 LocationSummary* locations = rem->GetLocations();
2180 Location out = locations->Out();
2181 Location first = locations->InAt(0);
2182 Location second = locations->InAt(1);
2183
Calin Juravled2ec87d2014-12-08 14:24:46 +00002184 Primitive::Type type = rem->GetResultType();
2185 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002186 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002187 Register reg1 = first.AsRegister<Register>();
2188 Register reg2 = second.AsRegister<Register>();
2189 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002190
2191 // temp = reg1 / reg2 (integer division)
2192 // temp = temp * reg2
2193 // dest = reg1 - temp
2194 __ sdiv(temp, reg1, reg2);
2195 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002196 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002197 break;
2198 }
2199
2200 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002201 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2202 break;
2203 }
2204
Calin Juravled2ec87d2014-12-08 14:24:46 +00002205 case Primitive::kPrimFloat: {
2206 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2207 break;
2208 }
2209
Calin Juravlebacfec32014-11-14 15:54:36 +00002210 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002211 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002212 break;
2213 }
2214
2215 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002216 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002217 }
2218}
2219
Calin Juravled0d48522014-11-04 16:40:20 +00002220void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2221 LocationSummary* locations =
2222 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002223 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002224 if (instruction->HasUses()) {
2225 locations->SetOut(Location::SameAsFirstInput());
2226 }
2227}
2228
2229void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2230 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2231 codegen_->AddSlowPath(slow_path);
2232
2233 LocationSummary* locations = instruction->GetLocations();
2234 Location value = locations->InAt(0);
2235
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002236 switch (instruction->GetType()) {
2237 case Primitive::kPrimInt: {
2238 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002239 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002240 __ b(slow_path->GetEntryLabel(), EQ);
2241 } else {
2242 DCHECK(value.IsConstant()) << value;
2243 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2244 __ b(slow_path->GetEntryLabel());
2245 }
2246 }
2247 break;
2248 }
2249 case Primitive::kPrimLong: {
2250 if (value.IsRegisterPair()) {
2251 __ orrs(IP,
2252 value.AsRegisterPairLow<Register>(),
2253 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2254 __ b(slow_path->GetEntryLabel(), EQ);
2255 } else {
2256 DCHECK(value.IsConstant()) << value;
2257 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2258 __ b(slow_path->GetEntryLabel());
2259 }
2260 }
2261 break;
2262 default:
2263 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2264 }
2265 }
Calin Juravled0d48522014-11-04 16:40:20 +00002266}
2267
Calin Juravle9aec02f2014-11-18 23:06:35 +00002268void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2269 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2270
2271 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2272 ? LocationSummary::kCall
2273 : LocationSummary::kNoCall;
2274 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2275
2276 switch (op->GetResultType()) {
2277 case Primitive::kPrimInt: {
2278 locations->SetInAt(0, Location::RequiresRegister());
2279 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2280 locations->SetOut(Location::RequiresRegister());
2281 break;
2282 }
2283 case Primitive::kPrimLong: {
2284 InvokeRuntimeCallingConvention calling_convention;
2285 locations->SetInAt(0, Location::RegisterPairLocation(
2286 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2287 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2288 // The runtime helper puts the output in R0,R2.
2289 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2290 break;
2291 }
2292 default:
2293 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2294 }
2295}
2296
2297void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2298 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2299
2300 LocationSummary* locations = op->GetLocations();
2301 Location out = locations->Out();
2302 Location first = locations->InAt(0);
2303 Location second = locations->InAt(1);
2304
2305 Primitive::Type type = op->GetResultType();
2306 switch (type) {
2307 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002308 Register out_reg = out.AsRegister<Register>();
2309 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002310 // Arm doesn't mask the shift count so we need to do it ourselves.
2311 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002312 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002313 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2314 if (op->IsShl()) {
2315 __ Lsl(out_reg, first_reg, second_reg);
2316 } else if (op->IsShr()) {
2317 __ Asr(out_reg, first_reg, second_reg);
2318 } else {
2319 __ Lsr(out_reg, first_reg, second_reg);
2320 }
2321 } else {
2322 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2323 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2324 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2325 __ Mov(out_reg, first_reg);
2326 } else if (op->IsShl()) {
2327 __ Lsl(out_reg, first_reg, shift_value);
2328 } else if (op->IsShr()) {
2329 __ Asr(out_reg, first_reg, shift_value);
2330 } else {
2331 __ Lsr(out_reg, first_reg, shift_value);
2332 }
2333 }
2334 break;
2335 }
2336 case Primitive::kPrimLong: {
2337 // TODO: Inline the assembly instead of calling the runtime.
2338 InvokeRuntimeCallingConvention calling_convention;
2339 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2340 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002341 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002342 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2343 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2344
2345 int32_t entry_point_offset;
2346 if (op->IsShl()) {
2347 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2348 } else if (op->IsShr()) {
2349 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2350 } else {
2351 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2352 }
2353 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2354 __ blx(LR);
2355 break;
2356 }
2357 default:
2358 LOG(FATAL) << "Unexpected operation type " << type;
2359 }
2360}
2361
2362void LocationsBuilderARM::VisitShl(HShl* shl) {
2363 HandleShift(shl);
2364}
2365
2366void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2367 HandleShift(shl);
2368}
2369
2370void LocationsBuilderARM::VisitShr(HShr* shr) {
2371 HandleShift(shr);
2372}
2373
2374void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2375 HandleShift(shr);
2376}
2377
2378void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2379 HandleShift(ushr);
2380}
2381
2382void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2383 HandleShift(ushr);
2384}
2385
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002386void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002387 LocationSummary* locations =
2388 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002389 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002390 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2391 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2392 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002393}
2394
2395void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2396 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002397 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002398 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002399 codegen_->InvokeRuntime(
2400 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002401}
2402
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002403void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2404 LocationSummary* locations =
2405 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2406 InvokeRuntimeCallingConvention calling_convention;
2407 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002408 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002409 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002410 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002411}
2412
2413void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2414 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002415 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002416 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002417 codegen_->InvokeRuntime(
2418 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002419}
2420
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002421void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002422 LocationSummary* locations =
2423 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002424 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2425 if (location.IsStackSlot()) {
2426 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2427 } else if (location.IsDoubleStackSlot()) {
2428 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002429 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002430 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002431}
2432
2433void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002434 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002435 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002436}
2437
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002438void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002439 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002440 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002441 locations->SetInAt(0, Location::RequiresRegister());
2442 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002443}
2444
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002445void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2446 LocationSummary* locations = not_->GetLocations();
2447 Location out = locations->Out();
2448 Location in = locations->InAt(0);
2449 switch (not_->InputAt(0)->GetType()) {
2450 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002451 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002452 break;
2453
2454 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002455 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002456 break;
2457
2458 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002459 __ mvn(out.AsRegisterPairLow<Register>(),
2460 ShifterOperand(in.AsRegisterPairLow<Register>()));
2461 __ mvn(out.AsRegisterPairHigh<Register>(),
2462 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002463 break;
2464
2465 default:
2466 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2467 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002468}
2469
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002470void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002471 LocationSummary* locations =
2472 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002473 switch (compare->InputAt(0)->GetType()) {
2474 case Primitive::kPrimLong: {
2475 locations->SetInAt(0, Location::RequiresRegister());
2476 locations->SetInAt(1, Location::RequiresRegister());
2477 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2478 break;
2479 }
2480 case Primitive::kPrimFloat:
2481 case Primitive::kPrimDouble: {
2482 locations->SetInAt(0, Location::RequiresFpuRegister());
2483 locations->SetInAt(1, Location::RequiresFpuRegister());
2484 locations->SetOut(Location::RequiresRegister());
2485 break;
2486 }
2487 default:
2488 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2489 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002490}
2491
2492void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002493 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002494 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002495 Location left = locations->InAt(0);
2496 Location right = locations->InAt(1);
2497
2498 Label less, greater, done;
2499 Primitive::Type type = compare->InputAt(0)->GetType();
2500 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002501 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002502 __ cmp(left.AsRegisterPairHigh<Register>(),
2503 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002504 __ b(&less, LT);
2505 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002506 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2507 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002508 __ cmp(left.AsRegisterPairLow<Register>(),
2509 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002510 break;
2511 }
2512 case Primitive::kPrimFloat:
2513 case Primitive::kPrimDouble: {
2514 __ LoadImmediate(out, 0);
2515 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002516 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002517 } else {
2518 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2519 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2520 }
2521 __ vmstat(); // transfer FP status register to ARM APSR.
2522 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002523 break;
2524 }
2525 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002526 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002527 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002528 __ b(&done, EQ);
2529 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2530
2531 __ Bind(&greater);
2532 __ LoadImmediate(out, 1);
2533 __ b(&done);
2534
2535 __ Bind(&less);
2536 __ LoadImmediate(out, -1);
2537
2538 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002539}
2540
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002541void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002542 LocationSummary* locations =
2543 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002544 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2545 locations->SetInAt(i, Location::Any());
2546 }
2547 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002548}
2549
2550void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002551 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002552 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002553}
2554
Calin Juravle52c48962014-12-16 17:02:57 +00002555void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2556 // TODO (ported from quick): revisit Arm barrier kinds
2557 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2558 switch (kind) {
2559 case MemBarrierKind::kAnyStore:
2560 case MemBarrierKind::kLoadAny:
2561 case MemBarrierKind::kAnyAny: {
2562 flavour = DmbOptions::ISH;
2563 break;
2564 }
2565 case MemBarrierKind::kStoreStore: {
2566 flavour = DmbOptions::ISHST;
2567 break;
2568 }
2569 default:
2570 LOG(FATAL) << "Unexpected memory barrier " << kind;
2571 }
2572 __ dmb(flavour);
2573}
2574
2575void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2576 uint32_t offset,
2577 Register out_lo,
2578 Register out_hi) {
2579 if (offset != 0) {
2580 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002581 __ add(IP, addr, ShifterOperand(out_lo));
2582 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002583 }
2584 __ ldrexd(out_lo, out_hi, addr);
2585}
2586
2587void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2588 uint32_t offset,
2589 Register value_lo,
2590 Register value_hi,
2591 Register temp1,
2592 Register temp2) {
2593 Label fail;
2594 if (offset != 0) {
2595 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002596 __ add(IP, addr, ShifterOperand(temp1));
2597 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002598 }
2599 __ Bind(&fail);
2600 // We need a load followed by store. (The address used in a STREX instruction must
2601 // be the same as the address in the most recently executed LDREX instruction.)
2602 __ ldrexd(temp1, temp2, addr);
2603 __ strexd(temp1, value_lo, value_hi, addr);
2604 __ cmp(temp1, ShifterOperand(0));
2605 __ b(&fail, NE);
2606}
2607
2608void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2609 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2610
Nicolas Geoffray39468442014-09-02 15:17:15 +01002611 LocationSummary* locations =
2612 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002613 locations->SetInAt(0, Location::RequiresRegister());
2614 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002615
Calin Juravle34166012014-12-19 17:22:29 +00002616
Calin Juravle52c48962014-12-16 17:02:57 +00002617 Primitive::Type field_type = field_info.GetFieldType();
2618 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002619 bool generate_volatile = field_info.IsVolatile()
2620 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002621 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002622 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002623 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2624 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002625 locations->AddTemp(Location::RequiresRegister());
2626 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002627 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002628 // Arm encoding have some additional constraints for ldrexd/strexd:
2629 // - registers need to be consecutive
2630 // - the first register should be even but not R14.
2631 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2632 // enable Arm encoding.
2633 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2634
2635 locations->AddTemp(Location::RequiresRegister());
2636 locations->AddTemp(Location::RequiresRegister());
2637 if (field_type == Primitive::kPrimDouble) {
2638 // For doubles we need two more registers to copy the value.
2639 locations->AddTemp(Location::RegisterLocation(R2));
2640 locations->AddTemp(Location::RegisterLocation(R3));
2641 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002642 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002643}
2644
Calin Juravle52c48962014-12-16 17:02:57 +00002645void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2646 const FieldInfo& field_info) {
2647 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2648
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002649 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002650 Register base = locations->InAt(0).AsRegister<Register>();
2651 Location value = locations->InAt(1);
2652
2653 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002654 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002655 Primitive::Type field_type = field_info.GetFieldType();
2656 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2657
2658 if (is_volatile) {
2659 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2660 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002661
2662 switch (field_type) {
2663 case Primitive::kPrimBoolean:
2664 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002665 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002666 break;
2667 }
2668
2669 case Primitive::kPrimShort:
2670 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002671 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002672 break;
2673 }
2674
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002675 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002676 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002677 Register value_reg = value.AsRegister<Register>();
2678 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2679 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002680 Register temp = locations->GetTemp(0).AsRegister<Register>();
2681 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002682 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002683 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002684 break;
2685 }
2686
2687 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002688 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002689 GenerateWideAtomicStore(base, offset,
2690 value.AsRegisterPairLow<Register>(),
2691 value.AsRegisterPairHigh<Register>(),
2692 locations->GetTemp(0).AsRegister<Register>(),
2693 locations->GetTemp(1).AsRegister<Register>());
2694 } else {
2695 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2696 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002697 break;
2698 }
2699
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002700 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002701 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002702 break;
2703 }
2704
2705 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002706 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002707 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002708 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2709 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2710
2711 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2712
2713 GenerateWideAtomicStore(base, offset,
2714 value_reg_lo,
2715 value_reg_hi,
2716 locations->GetTemp(2).AsRegister<Register>(),
2717 locations->GetTemp(3).AsRegister<Register>());
2718 } else {
2719 __ StoreDToOffset(value_reg, base, offset);
2720 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002721 break;
2722 }
2723
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002724 case Primitive::kPrimVoid:
2725 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002726 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002727 }
Calin Juravle52c48962014-12-16 17:02:57 +00002728
2729 if (is_volatile) {
2730 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2731 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002732}
2733
Calin Juravle52c48962014-12-16 17:02:57 +00002734void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2735 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002736 LocationSummary* locations =
2737 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002738 locations->SetInAt(0, Location::RequiresRegister());
2739 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002740
Calin Juravle34166012014-12-19 17:22:29 +00002741 bool generate_volatile = field_info.IsVolatile()
2742 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002743 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle34166012014-12-19 17:22:29 +00002744 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002745 // Arm encoding have some additional constraints for ldrexd/strexd:
2746 // - registers need to be consecutive
2747 // - the first register should be even but not R14.
2748 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2749 // enable Arm encoding.
2750 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2751 locations->AddTemp(Location::RequiresRegister());
2752 locations->AddTemp(Location::RequiresRegister());
2753 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002754}
2755
Calin Juravle52c48962014-12-16 17:02:57 +00002756void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2757 const FieldInfo& field_info) {
2758 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002759
Calin Juravle52c48962014-12-16 17:02:57 +00002760 LocationSummary* locations = instruction->GetLocations();
2761 Register base = locations->InAt(0).AsRegister<Register>();
2762 Location out = locations->Out();
2763 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002764 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002765 Primitive::Type field_type = field_info.GetFieldType();
2766 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2767
2768 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002769 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002770 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002771 break;
2772 }
2773
2774 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002775 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002776 break;
2777 }
2778
2779 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002780 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002781 break;
2782 }
2783
2784 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002785 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002786 break;
2787 }
2788
2789 case Primitive::kPrimInt:
2790 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002791 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002792 break;
2793 }
2794
2795 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002796 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002797 GenerateWideAtomicLoad(base, offset,
2798 out.AsRegisterPairLow<Register>(),
2799 out.AsRegisterPairHigh<Register>());
2800 } else {
2801 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2802 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002803 break;
2804 }
2805
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002806 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002807 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002808 break;
2809 }
2810
2811 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002812 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002813 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002814 Register lo = locations->GetTemp(0).AsRegister<Register>();
2815 Register hi = locations->GetTemp(1).AsRegister<Register>();
2816 GenerateWideAtomicLoad(base, offset, lo, hi);
2817 __ vmovdrr(out_reg, lo, hi);
2818 } else {
2819 __ LoadDFromOffset(out_reg, base, offset);
2820 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002821 break;
2822 }
2823
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002824 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002825 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002826 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002827 }
Calin Juravle52c48962014-12-16 17:02:57 +00002828
2829 if (is_volatile) {
2830 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2831 }
2832}
2833
2834void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2835 HandleFieldSet(instruction, instruction->GetFieldInfo());
2836}
2837
2838void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2839 HandleFieldSet(instruction, instruction->GetFieldInfo());
2840}
2841
2842void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2843 HandleFieldGet(instruction, instruction->GetFieldInfo());
2844}
2845
2846void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2847 HandleFieldGet(instruction, instruction->GetFieldInfo());
2848}
2849
2850void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2851 HandleFieldGet(instruction, instruction->GetFieldInfo());
2852}
2853
2854void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2855 HandleFieldGet(instruction, instruction->GetFieldInfo());
2856}
2857
2858void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2859 HandleFieldSet(instruction, instruction->GetFieldInfo());
2860}
2861
2862void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2863 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002864}
2865
2866void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002867 LocationSummary* locations =
2868 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002869 Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks()
2870 ? Location::RequiresRegister()
2871 : Location::RegisterOrConstant(instruction->InputAt(0));
2872 locations->SetInAt(0, loc);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002873 if (instruction->HasUses()) {
2874 locations->SetOut(Location::SameAsFirstInput());
2875 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002876}
2877
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002878void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
2879 Location obj = instruction->GetLocations()->InAt(0);
2880 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2881 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2882}
2883
2884void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002885 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002886 codegen_->AddSlowPath(slow_path);
2887
2888 LocationSummary* locations = instruction->GetLocations();
2889 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002890
2891 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002892 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002893 __ b(slow_path->GetEntryLabel(), EQ);
2894 } else {
2895 DCHECK(obj.IsConstant()) << obj;
2896 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2897 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002898 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002899}
2900
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002901void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2902 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2903 GenerateImplicitNullCheck(instruction);
2904 } else {
2905 GenerateExplicitNullCheck(instruction);
2906 }
2907}
2908
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002909void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002910 LocationSummary* locations =
2911 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002912 locations->SetInAt(0, Location::RequiresRegister());
2913 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2914 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002915}
2916
2917void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2918 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002919 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002920 Location index = locations->InAt(1);
2921
2922 switch (instruction->GetType()) {
2923 case Primitive::kPrimBoolean: {
2924 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002925 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002926 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002927 size_t offset =
2928 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002929 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2930 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002931 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002932 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2933 }
2934 break;
2935 }
2936
2937 case Primitive::kPrimByte: {
2938 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002939 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002940 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002941 size_t offset =
2942 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002943 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2944 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002945 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002946 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2947 }
2948 break;
2949 }
2950
2951 case Primitive::kPrimShort: {
2952 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_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_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002957 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2958 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002959 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002960 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2961 }
2962 break;
2963 }
2964
2965 case Primitive::kPrimChar: {
2966 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002967 Register out = locations->Out().AsRegister<Register>();
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_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002971 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2972 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002973 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002974 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2975 }
2976 break;
2977 }
2978
2979 case Primitive::kPrimInt:
2980 case Primitive::kPrimNot: {
2981 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2982 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002983 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002984 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002985 size_t offset =
2986 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002987 __ LoadFromOffset(kLoadWord, out, obj, offset);
2988 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002989 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002990 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2991 }
2992 break;
2993 }
2994
2995 case Primitive::kPrimLong: {
2996 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002997 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002998 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002999 size_t offset =
3000 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003001 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003002 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003003 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003004 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003005 }
3006 break;
3007 }
3008
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003009 case Primitive::kPrimFloat: {
3010 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3011 Location out = locations->Out();
3012 DCHECK(out.IsFpuRegister());
3013 if (index.IsConstant()) {
3014 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3015 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3016 } else {
3017 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3018 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3019 }
3020 break;
3021 }
3022
3023 case Primitive::kPrimDouble: {
3024 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3025 Location out = locations->Out();
3026 DCHECK(out.IsFpuRegisterPair());
3027 if (index.IsConstant()) {
3028 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3029 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3030 } else {
3031 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3032 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3033 }
3034 break;
3035 }
3036
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003037 case Primitive::kPrimVoid:
3038 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003039 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003040 }
3041}
3042
3043void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003044 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003045
3046 bool needs_write_barrier =
3047 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3048 bool needs_runtime_call = instruction->NeedsTypeCheck();
3049
Nicolas Geoffray39468442014-09-02 15:17:15 +01003050 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003051 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3052 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003053 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003054 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3055 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3056 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003057 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003058 locations->SetInAt(0, Location::RequiresRegister());
3059 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3060 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003061
3062 if (needs_write_barrier) {
3063 // Temporary registers for the write barrier.
3064 locations->AddTemp(Location::RequiresRegister());
3065 locations->AddTemp(Location::RequiresRegister());
3066 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003067 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003068}
3069
3070void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3071 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003072 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003073 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003074 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003075 bool needs_runtime_call = locations->WillCall();
3076 bool needs_write_barrier =
3077 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003078
3079 switch (value_type) {
3080 case Primitive::kPrimBoolean:
3081 case Primitive::kPrimByte: {
3082 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003083 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003084 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003085 size_t offset =
3086 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003087 __ StoreToOffset(kStoreByte, value, obj, offset);
3088 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003089 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003090 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3091 }
3092 break;
3093 }
3094
3095 case Primitive::kPrimShort:
3096 case Primitive::kPrimChar: {
3097 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003098 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003099 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003100 size_t offset =
3101 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003102 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3103 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003104 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003105 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3106 }
3107 break;
3108 }
3109
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003110 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003111 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003112 if (!needs_runtime_call) {
3113 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003114 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003115 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003116 size_t offset =
3117 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003118 __ StoreToOffset(kStoreWord, value, obj, offset);
3119 } else {
3120 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003121 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003122 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3123 }
3124 if (needs_write_barrier) {
3125 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003126 Register temp = locations->GetTemp(0).AsRegister<Register>();
3127 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003128 codegen_->MarkGCCard(temp, card, obj, value);
3129 }
3130 } else {
3131 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003132 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3133 instruction,
3134 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003135 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003136 break;
3137 }
3138
3139 case Primitive::kPrimLong: {
3140 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003141 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003142 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003143 size_t offset =
3144 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003145 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003146 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003147 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003148 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003149 }
3150 break;
3151 }
3152
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003153 case Primitive::kPrimFloat: {
3154 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3155 Location value = locations->InAt(2);
3156 DCHECK(value.IsFpuRegister());
3157 if (index.IsConstant()) {
3158 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3159 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3160 } else {
3161 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3162 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3163 }
3164 break;
3165 }
3166
3167 case Primitive::kPrimDouble: {
3168 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3169 Location value = locations->InAt(2);
3170 DCHECK(value.IsFpuRegisterPair());
3171 if (index.IsConstant()) {
3172 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3173 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3174 } else {
3175 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3176 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3177 }
3178 break;
3179 }
3180
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003181 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003182 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003183 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003184 }
3185}
3186
3187void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003188 LocationSummary* locations =
3189 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003190 locations->SetInAt(0, Location::RequiresRegister());
3191 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003192}
3193
3194void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3195 LocationSummary* locations = instruction->GetLocations();
3196 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003197 Register obj = locations->InAt(0).AsRegister<Register>();
3198 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003199 __ LoadFromOffset(kLoadWord, out, obj, offset);
3200}
3201
3202void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003203 LocationSummary* locations =
3204 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003205 locations->SetInAt(0, Location::RequiresRegister());
3206 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003207 if (instruction->HasUses()) {
3208 locations->SetOut(Location::SameAsFirstInput());
3209 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003210}
3211
3212void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3213 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003214 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003215 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003216 codegen_->AddSlowPath(slow_path);
3217
Roland Levillain271ab9c2014-11-27 15:23:57 +00003218 Register index = locations->InAt(0).AsRegister<Register>();
3219 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003220
3221 __ cmp(index, ShifterOperand(length));
3222 __ b(slow_path->GetEntryLabel(), CS);
3223}
3224
3225void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3226 Label is_null;
3227 __ CompareAndBranchIfZero(value, &is_null);
3228 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3229 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3230 __ strb(card, Address(card, temp));
3231 __ Bind(&is_null);
3232}
3233
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003234void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3235 temp->SetLocations(nullptr);
3236}
3237
3238void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3239 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003240 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003241}
3242
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003243void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003244 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003245 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003246}
3247
3248void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003249 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3250}
3251
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003252void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3253 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3254}
3255
3256void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003257 HBasicBlock* block = instruction->GetBlock();
3258 if (block->GetLoopInformation() != nullptr) {
3259 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3260 // The back edge will generate the suspend check.
3261 return;
3262 }
3263 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3264 // The goto will generate the suspend check.
3265 return;
3266 }
3267 GenerateSuspendCheck(instruction, nullptr);
3268}
3269
3270void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3271 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003272 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003273 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003274 codegen_->AddSlowPath(slow_path);
3275
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003276 __ LoadFromOffset(
3277 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3278 __ cmp(IP, ShifterOperand(0));
3279 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003280 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003281 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003282 __ Bind(slow_path->GetReturnLabel());
3283 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003284 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003285 __ b(slow_path->GetEntryLabel());
3286 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003287}
3288
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003289ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3290 return codegen_->GetAssembler();
3291}
3292
3293void ParallelMoveResolverARM::EmitMove(size_t index) {
3294 MoveOperands* move = moves_.Get(index);
3295 Location source = move->GetSource();
3296 Location destination = move->GetDestination();
3297
3298 if (source.IsRegister()) {
3299 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003300 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003301 } else {
3302 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003303 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003304 SP, destination.GetStackIndex());
3305 }
3306 } else if (source.IsStackSlot()) {
3307 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003308 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003309 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003310 } else if (destination.IsFpuRegister()) {
3311 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003312 } else {
3313 DCHECK(destination.IsStackSlot());
3314 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3315 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3316 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003317 } else if (source.IsFpuRegister()) {
3318 if (destination.IsFpuRegister()) {
3319 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003320 } else {
3321 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003322 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3323 }
3324 } else if (source.IsFpuRegisterPair()) {
3325 if (destination.IsFpuRegisterPair()) {
3326 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3327 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3328 } else {
3329 DCHECK(destination.IsDoubleStackSlot()) << destination;
3330 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3331 SP, destination.GetStackIndex());
3332 }
3333 } else if (source.IsDoubleStackSlot()) {
3334 if (destination.IsFpuRegisterPair()) {
3335 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3336 SP, source.GetStackIndex());
3337 } else {
3338 DCHECK(destination.IsDoubleStackSlot()) << destination;
3339 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003340 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003341 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3342 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3343 }
3344 } else {
3345 DCHECK(source.IsConstant()) << source;
3346 HInstruction* constant = source.GetConstant();
3347 if (constant->IsIntConstant()) {
3348 int32_t value = constant->AsIntConstant()->GetValue();
3349 if (destination.IsRegister()) {
3350 __ LoadImmediate(destination.AsRegister<Register>(), value);
3351 } else {
3352 DCHECK(destination.IsStackSlot());
3353 __ LoadImmediate(IP, value);
3354 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3355 }
3356 } else {
3357 DCHECK(constant->IsFloatConstant());
3358 float value = constant->AsFloatConstant()->GetValue();
3359 if (destination.IsFpuRegister()) {
3360 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3361 } else {
3362 DCHECK(destination.IsStackSlot());
3363 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3364 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3365 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003366 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003367 }
3368}
3369
3370void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3371 __ Mov(IP, reg);
3372 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3373 __ StoreToOffset(kStoreWord, IP, SP, mem);
3374}
3375
3376void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3377 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3378 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3379 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3380 SP, mem1 + stack_offset);
3381 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3382 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3383 SP, mem2 + stack_offset);
3384 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3385}
3386
3387void ParallelMoveResolverARM::EmitSwap(size_t index) {
3388 MoveOperands* move = moves_.Get(index);
3389 Location source = move->GetSource();
3390 Location destination = move->GetDestination();
3391
3392 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003393 DCHECK_NE(source.AsRegister<Register>(), IP);
3394 DCHECK_NE(destination.AsRegister<Register>(), IP);
3395 __ Mov(IP, source.AsRegister<Register>());
3396 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3397 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003398 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003399 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003400 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003401 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003402 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3403 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003404 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003405 __ vmovs(STMP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003406 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003407 __ vmovs(destination.AsFpuRegister<SRegister>(), STMP);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003408 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3409 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3410 : destination.AsFpuRegister<SRegister>();
3411 int mem = source.IsFpuRegister()
3412 ? destination.GetStackIndex()
3413 : source.GetStackIndex();
3414
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003415 __ vmovs(STMP, reg);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003416 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003417 __ StoreSToOffset(STMP, SP, mem);
3418 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
3419 __ vmovd(DTMP, FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3420 __ vmovd(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3421 FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()));
3422 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), DTMP);
3423 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3424 DRegister reg = source.IsFpuRegisterPair()
3425 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3426 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3427 int mem = source.IsFpuRegisterPair()
3428 ? destination.GetStackIndex()
3429 : source.GetStackIndex();
3430
3431 __ vmovd(DTMP, reg);
3432 __ LoadDFromOffset(reg, SP, mem);
3433 __ StoreDToOffset(DTMP, SP, mem);
3434 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
3435 // TODO: We could use DTMP and ask for a pair scratch register (float or core).
3436 // This would save four instructions if two scratch registers are available, and
3437 // two instructions if not.
3438 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3439 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003440 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003441 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003442 }
3443}
3444
3445void ParallelMoveResolverARM::SpillScratch(int reg) {
3446 __ Push(static_cast<Register>(reg));
3447}
3448
3449void ParallelMoveResolverARM::RestoreScratch(int reg) {
3450 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003451}
3452
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003453void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003454 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3455 ? LocationSummary::kCallOnSlowPath
3456 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003457 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003458 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003459 locations->SetOut(Location::RequiresRegister());
3460}
3461
3462void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003463 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003464 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003465 DCHECK(!cls->CanCallRuntime());
3466 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003467 codegen_->LoadCurrentMethod(out);
3468 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3469 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003470 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003471 codegen_->LoadCurrentMethod(out);
3472 __ LoadFromOffset(
3473 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3474 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003475
3476 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3477 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3478 codegen_->AddSlowPath(slow_path);
3479 __ cmp(out, ShifterOperand(0));
3480 __ b(slow_path->GetEntryLabel(), EQ);
3481 if (cls->MustGenerateClinitCheck()) {
3482 GenerateClassInitializationCheck(slow_path, out);
3483 } else {
3484 __ Bind(slow_path->GetExitLabel());
3485 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003486 }
3487}
3488
3489void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3490 LocationSummary* locations =
3491 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3492 locations->SetInAt(0, Location::RequiresRegister());
3493 if (check->HasUses()) {
3494 locations->SetOut(Location::SameAsFirstInput());
3495 }
3496}
3497
3498void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003499 // We assume the class is not null.
3500 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3501 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003502 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003503 GenerateClassInitializationCheck(slow_path,
3504 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003505}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003506
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003507void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3508 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003509 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3510 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3511 __ b(slow_path->GetEntryLabel(), LT);
3512 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3513 // properly. Therefore, we do a memory fence.
3514 __ dmb(ISH);
3515 __ Bind(slow_path->GetExitLabel());
3516}
3517
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003518void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3519 LocationSummary* locations =
3520 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3521 locations->SetOut(Location::RequiresRegister());
3522}
3523
3524void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3525 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3526 codegen_->AddSlowPath(slow_path);
3527
Roland Levillain271ab9c2014-11-27 15:23:57 +00003528 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003529 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003530 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3531 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003532 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3533 __ cmp(out, ShifterOperand(0));
3534 __ b(slow_path->GetEntryLabel(), EQ);
3535 __ Bind(slow_path->GetExitLabel());
3536}
3537
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003538void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3539 LocationSummary* locations =
3540 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3541 locations->SetOut(Location::RequiresRegister());
3542}
3543
3544void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003545 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003546 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3547 __ LoadFromOffset(kLoadWord, out, TR, offset);
3548 __ LoadImmediate(IP, 0);
3549 __ StoreToOffset(kStoreWord, IP, TR, offset);
3550}
3551
3552void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3553 LocationSummary* locations =
3554 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3555 InvokeRuntimeCallingConvention calling_convention;
3556 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3557}
3558
3559void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3560 codegen_->InvokeRuntime(
3561 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3562}
3563
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003564void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003565 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3566 ? LocationSummary::kNoCall
3567 : LocationSummary::kCallOnSlowPath;
3568 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3569 locations->SetInAt(0, Location::RequiresRegister());
3570 locations->SetInAt(1, Location::RequiresRegister());
3571 locations->SetOut(Location::RequiresRegister());
3572}
3573
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003574void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003575 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003576 Register obj = locations->InAt(0).AsRegister<Register>();
3577 Register cls = locations->InAt(1).AsRegister<Register>();
3578 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003579 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3580 Label done, zero;
3581 SlowPathCodeARM* slow_path = nullptr;
3582
3583 // Return 0 if `obj` is null.
3584 // TODO: avoid this check if we know obj is not null.
3585 __ cmp(obj, ShifterOperand(0));
3586 __ b(&zero, EQ);
3587 // Compare the class of `obj` with `cls`.
3588 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3589 __ cmp(out, ShifterOperand(cls));
3590 if (instruction->IsClassFinal()) {
3591 // Classes must be equal for the instanceof to succeed.
3592 __ b(&zero, NE);
3593 __ LoadImmediate(out, 1);
3594 __ b(&done);
3595 } else {
3596 // If the classes are not equal, we go into a slow path.
3597 DCHECK(locations->OnlyCallsOnSlowPath());
3598 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003599 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003600 codegen_->AddSlowPath(slow_path);
3601 __ b(slow_path->GetEntryLabel(), NE);
3602 __ LoadImmediate(out, 1);
3603 __ b(&done);
3604 }
3605 __ Bind(&zero);
3606 __ LoadImmediate(out, 0);
3607 if (slow_path != nullptr) {
3608 __ Bind(slow_path->GetExitLabel());
3609 }
3610 __ Bind(&done);
3611}
3612
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003613void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3614 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3615 instruction, LocationSummary::kCallOnSlowPath);
3616 locations->SetInAt(0, Location::RequiresRegister());
3617 locations->SetInAt(1, Location::RequiresRegister());
3618 locations->AddTemp(Location::RequiresRegister());
3619}
3620
3621void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3622 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003623 Register obj = locations->InAt(0).AsRegister<Register>();
3624 Register cls = locations->InAt(1).AsRegister<Register>();
3625 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003626 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3627
3628 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3629 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3630 codegen_->AddSlowPath(slow_path);
3631
3632 // TODO: avoid this check if we know obj is not null.
3633 __ cmp(obj, ShifterOperand(0));
3634 __ b(slow_path->GetExitLabel(), EQ);
3635 // Compare the class of `obj` with `cls`.
3636 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3637 __ cmp(temp, ShifterOperand(cls));
3638 __ b(slow_path->GetEntryLabel(), NE);
3639 __ Bind(slow_path->GetExitLabel());
3640}
3641
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003642void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3643 LocationSummary* locations =
3644 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3645 InvokeRuntimeCallingConvention calling_convention;
3646 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3647}
3648
3649void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3650 codegen_->InvokeRuntime(instruction->IsEnter()
3651 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3652 instruction,
3653 instruction->GetDexPc());
3654}
3655
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003656void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3657void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3658void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3659
3660void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3661 LocationSummary* locations =
3662 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3663 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3664 || instruction->GetResultType() == Primitive::kPrimLong);
3665 locations->SetInAt(0, Location::RequiresRegister());
3666 locations->SetInAt(1, Location::RequiresRegister());
3667 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3668 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3669}
3670
3671void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3672 HandleBitwiseOperation(instruction);
3673}
3674
3675void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3676 HandleBitwiseOperation(instruction);
3677}
3678
3679void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3680 HandleBitwiseOperation(instruction);
3681}
3682
3683void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3684 LocationSummary* locations = instruction->GetLocations();
3685
3686 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003687 Register first = locations->InAt(0).AsRegister<Register>();
3688 Register second = locations->InAt(1).AsRegister<Register>();
3689 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003690 if (instruction->IsAnd()) {
3691 __ and_(out, first, ShifterOperand(second));
3692 } else if (instruction->IsOr()) {
3693 __ orr(out, first, ShifterOperand(second));
3694 } else {
3695 DCHECK(instruction->IsXor());
3696 __ eor(out, first, ShifterOperand(second));
3697 }
3698 } else {
3699 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3700 Location first = locations->InAt(0);
3701 Location second = locations->InAt(1);
3702 Location out = locations->Out();
3703 if (instruction->IsAnd()) {
3704 __ and_(out.AsRegisterPairLow<Register>(),
3705 first.AsRegisterPairLow<Register>(),
3706 ShifterOperand(second.AsRegisterPairLow<Register>()));
3707 __ and_(out.AsRegisterPairHigh<Register>(),
3708 first.AsRegisterPairHigh<Register>(),
3709 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3710 } else if (instruction->IsOr()) {
3711 __ orr(out.AsRegisterPairLow<Register>(),
3712 first.AsRegisterPairLow<Register>(),
3713 ShifterOperand(second.AsRegisterPairLow<Register>()));
3714 __ orr(out.AsRegisterPairHigh<Register>(),
3715 first.AsRegisterPairHigh<Register>(),
3716 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3717 } else {
3718 DCHECK(instruction->IsXor());
3719 __ eor(out.AsRegisterPairLow<Register>(),
3720 first.AsRegisterPairLow<Register>(),
3721 ShifterOperand(second.AsRegisterPairLow<Register>()));
3722 __ eor(out.AsRegisterPairHigh<Register>(),
3723 first.AsRegisterPairHigh<Register>(),
3724 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3725 }
3726 }
3727}
3728
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003729} // namespace arm
3730} // namespace art