blob: 9a32ce76fa6f48d13c8b96cfdab33a1f4b3331b9 [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 Geoffray41aedbb2015-01-14 10:49:16 +000040static bool ExpectedPairLayout(Location location) {
41 // We expected this for both core and fpu register pairs.
42 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
43}
44
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +000045static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010046static constexpr int kCurrentMethodStackOffset = 0;
47
Calin Juravled6fb6cf2014-11-11 19:07:44 +000048static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010049static constexpr size_t kRuntimeParameterCoreRegistersLength =
50 arraysize(kRuntimeParameterCoreRegisters);
Calin Juravled2ec87d2014-12-08 14:24:46 +000051static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000052static constexpr size_t kRuntimeParameterFpuRegistersLength =
53 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010054
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 Geoffray1ba0f592014-10-27 15:14:55 +0000480 blocked_fpu_registers_[S16] = true;
481 blocked_fpu_registers_[S17] = true;
482 blocked_fpu_registers_[S18] = true;
483 blocked_fpu_registers_[S19] = true;
484 blocked_fpu_registers_[S20] = true;
485 blocked_fpu_registers_[S21] = true;
486 blocked_fpu_registers_[S22] = true;
487 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000488 blocked_fpu_registers_[S24] = true;
489 blocked_fpu_registers_[S25] = true;
490 blocked_fpu_registers_[S26] = true;
491 blocked_fpu_registers_[S27] = true;
492 blocked_fpu_registers_[S28] = true;
493 blocked_fpu_registers_[S29] = true;
494 blocked_fpu_registers_[S30] = true;
495 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100496
497 UpdateBlockedPairRegisters();
498}
499
500void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
501 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
502 ArmManagedRegister current =
503 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
504 if (blocked_core_registers_[current.AsRegisterPairLow()]
505 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
506 blocked_register_pairs_[i] = true;
507 }
508 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100509}
510
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100511InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
512 : HGraphVisitor(graph),
513 assembler_(codegen->GetAssembler()),
514 codegen_(codegen) {}
515
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000516void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000517 bool skip_overflow_check =
518 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100519 if (!skip_overflow_check) {
Calin Juravle93edf732015-01-20 20:14:07 +0000520 if (GetCompilerOptions().GetImplicitStackOverflowChecks()) {
521 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
522 __ LoadFromOffset(kLoadWord, IP, IP, 0);
523 RecordPcInfo(nullptr, 0);
524 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100525 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100526 AddSlowPath(slow_path);
527
528 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
529 __ cmp(SP, ShifterOperand(IP));
530 __ b(slow_path->GetEntryLabel(), CC);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100531 }
532 }
533
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000534 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
535 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000536
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100537 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100538 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100539 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000540}
541
542void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100543 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000544 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000545}
546
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100547void CodeGeneratorARM::Bind(HBasicBlock* block) {
548 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000549}
550
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100551Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
552 switch (load->GetType()) {
553 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100554 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100555 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
556 break;
557
558 case Primitive::kPrimInt:
559 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100560 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100561 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100562
563 case Primitive::kPrimBoolean:
564 case Primitive::kPrimByte:
565 case Primitive::kPrimChar:
566 case Primitive::kPrimShort:
567 case Primitive::kPrimVoid:
568 LOG(FATAL) << "Unexpected type " << load->GetType();
569 }
570
571 LOG(FATAL) << "Unreachable";
572 return Location();
573}
574
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100575Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
576 switch (type) {
577 case Primitive::kPrimBoolean:
578 case Primitive::kPrimByte:
579 case Primitive::kPrimChar:
580 case Primitive::kPrimShort:
581 case Primitive::kPrimInt:
582 case Primitive::kPrimNot: {
583 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000584 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100585 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100586 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100587 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000588 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100589 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100590 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100591
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000592 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100593 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000594 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100595 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000596 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100597 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000598 if (calling_convention.GetRegisterAt(index) == R1) {
599 // Skip R1, and use R2_R3 instead.
600 gp_index_++;
601 index++;
602 }
603 }
604 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
605 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000606 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000607 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000608 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100609 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000610 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
611 }
612 }
613
614 case Primitive::kPrimFloat: {
615 uint32_t stack_index = stack_index_++;
616 if (float_index_ % 2 == 0) {
617 float_index_ = std::max(double_index_, float_index_);
618 }
619 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
620 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
621 } else {
622 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
623 }
624 }
625
626 case Primitive::kPrimDouble: {
627 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
628 uint32_t stack_index = stack_index_;
629 stack_index_ += 2;
630 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
631 uint32_t index = double_index_;
632 double_index_ += 2;
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +0000633 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000634 calling_convention.GetFpuRegisterAt(index),
635 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +0000636 DCHECK(ExpectedPairLayout(result));
637 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000638 } else {
639 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100640 }
641 }
642
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100643 case Primitive::kPrimVoid:
644 LOG(FATAL) << "Unexpected parameter type " << type;
645 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100646 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100647 return Location();
648}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100649
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000650Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
651 switch (type) {
652 case Primitive::kPrimBoolean:
653 case Primitive::kPrimByte:
654 case Primitive::kPrimChar:
655 case Primitive::kPrimShort:
656 case Primitive::kPrimInt:
657 case Primitive::kPrimNot: {
658 return Location::RegisterLocation(R0);
659 }
660
661 case Primitive::kPrimFloat: {
662 return Location::FpuRegisterLocation(S0);
663 }
664
665 case Primitive::kPrimLong: {
666 return Location::RegisterPairLocation(R0, R1);
667 }
668
669 case Primitive::kPrimDouble: {
670 return Location::FpuRegisterPairLocation(S0, S1);
671 }
672
673 case Primitive::kPrimVoid:
674 return Location();
675 }
676 UNREACHABLE();
677 return Location();
678}
679
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680void CodeGeneratorARM::Move32(Location destination, Location source) {
681 if (source.Equals(destination)) {
682 return;
683 }
684 if (destination.IsRegister()) {
685 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000686 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100687 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000688 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000690 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100691 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100692 } else if (destination.IsFpuRegister()) {
693 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000694 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100695 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000696 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100697 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000698 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100699 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100700 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000701 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100702 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000703 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100704 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000705 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000707 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100708 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
709 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710 }
711 }
712}
713
714void CodeGeneratorARM::Move64(Location destination, Location source) {
715 if (source.Equals(destination)) {
716 return;
717 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100718 if (destination.IsRegisterPair()) {
719 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000720 EmitParallelMoves(
721 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
722 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
723 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
724 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100725 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000726 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100727 } else {
728 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +0000729 DCHECK(ExpectedPairLayout(destination));
730 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
731 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100732 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000733 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100734 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000735 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
736 SP,
737 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100738 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000739 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100740 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100741 } else {
742 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100743 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000744 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100745 if (source.AsRegisterPairLow<Register>() == R1) {
746 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100747 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
748 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100749 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100750 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100751 SP, destination.GetStackIndex());
752 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000753 } else if (source.IsFpuRegisterPair()) {
754 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
755 SP,
756 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100757 } else {
758 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000759 EmitParallelMoves(
760 Location::StackSlot(source.GetStackIndex()),
761 Location::StackSlot(destination.GetStackIndex()),
762 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
763 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100764 }
765 }
766}
767
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100768void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100769 LocationSummary* locations = instruction->GetLocations();
770 if (locations != nullptr && locations->Out().Equals(location)) {
771 return;
772 }
773
Calin Juravlea21f5982014-11-13 15:53:04 +0000774 if (locations != nullptr && locations->Out().IsConstant()) {
775 HConstant* const_to_move = locations->Out().GetConstant();
776 if (const_to_move->IsIntConstant()) {
777 int32_t value = const_to_move->AsIntConstant()->GetValue();
778 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000779 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000780 } else {
781 DCHECK(location.IsStackSlot());
782 __ LoadImmediate(IP, value);
783 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
784 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000785 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000786 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000787 int64_t value = const_to_move->AsLongConstant()->GetValue();
788 if (location.IsRegisterPair()) {
789 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
790 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
791 } else {
792 DCHECK(location.IsDoubleStackSlot());
793 __ LoadImmediate(IP, Low32Bits(value));
794 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
795 __ LoadImmediate(IP, High32Bits(value));
796 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
797 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100798 }
Roland Levillain476df552014-10-09 17:51:36 +0100799 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100800 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
801 switch (instruction->GetType()) {
802 case Primitive::kPrimBoolean:
803 case Primitive::kPrimByte:
804 case Primitive::kPrimChar:
805 case Primitive::kPrimShort:
806 case Primitive::kPrimInt:
807 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100808 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100809 Move32(location, Location::StackSlot(stack_slot));
810 break;
811
812 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100813 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100814 Move64(location, Location::DoubleStackSlot(stack_slot));
815 break;
816
817 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100818 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100819 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000820 } else if (instruction->IsTemporary()) {
821 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000822 if (temp_location.IsStackSlot()) {
823 Move32(location, temp_location);
824 } else {
825 DCHECK(temp_location.IsDoubleStackSlot());
826 Move64(location, temp_location);
827 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000828 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100829 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 switch (instruction->GetType()) {
831 case Primitive::kPrimBoolean:
832 case Primitive::kPrimByte:
833 case Primitive::kPrimChar:
834 case Primitive::kPrimShort:
835 case Primitive::kPrimNot:
836 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100837 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100838 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 break;
840
841 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100842 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100843 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100844 break;
845
846 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100847 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100848 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000849 }
850}
851
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100852void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
853 HInstruction* instruction,
854 uint32_t dex_pc) {
855 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
856 __ blx(LR);
857 RecordPcInfo(instruction, dex_pc);
858 DCHECK(instruction->IsSuspendCheck()
859 || instruction->IsBoundsCheck()
860 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000861 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000862 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100863 || !IsLeafMethod());
864}
865
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000866void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000867 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000868}
869
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000870void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000871 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100872 DCHECK(!successor->IsExitBlock());
873
874 HBasicBlock* block = got->GetBlock();
875 HInstruction* previous = got->GetPrevious();
876
877 HLoopInformation* info = block->GetLoopInformation();
878 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
879 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
880 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
881 return;
882 }
883
884 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
885 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
886 }
887 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000888 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000889 }
890}
891
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000892void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000893 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000894}
895
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000896void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700897 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000898 if (kIsDebugBuild) {
899 __ Comment("Unreachable");
900 __ bkpt(0);
901 }
902}
903
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000904void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100905 LocationSummary* locations =
906 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100907 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100908 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100909 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100910 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000911}
912
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000913void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700914 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100915 if (cond->IsIntConstant()) {
916 // Constant condition, statically compared against 1.
917 int32_t cond_value = cond->AsIntConstant()->GetValue();
918 if (cond_value == 1) {
919 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
920 if_instr->IfTrueSuccessor())) {
921 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100922 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100923 return;
924 } else {
925 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100926 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100927 } else {
928 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
929 // Condition has been materialized, compare the output to 0
930 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000931 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100932 ShifterOperand(0));
933 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
934 } else {
935 // Condition has not been materialized, use its inputs as the
936 // comparison and its condition as the branch condition.
937 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +0000938 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000939 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100940 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000941 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100942 } else {
943 DCHECK(locations->InAt(1).IsConstant());
944 int32_t value =
945 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
946 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000947 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
948 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100949 } else {
950 Register temp = IP;
951 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000952 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100953 }
954 }
955 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
956 ARMCondition(cond->AsCondition()->GetCondition()));
957 }
Dave Allison20dfc792014-06-16 20:44:29 -0700958 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
960 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700961 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000962 }
963}
964
Dave Allison20dfc792014-06-16 20:44:29 -0700965
966void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100967 LocationSummary* locations =
968 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100969 locations->SetInAt(0, Location::RequiresRegister());
970 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100971 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100972 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100973 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000974}
975
Dave Allison20dfc792014-06-16 20:44:29 -0700976void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100977 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100978 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000979 Register left = locations->InAt(0).AsRegister<Register>();
980
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000982 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100983 } else {
984 DCHECK(locations->InAt(1).IsConstant());
985 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
986 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000987 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
988 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100989 } else {
990 Register temp = IP;
991 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000992 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100993 }
Dave Allison20dfc792014-06-16 20:44:29 -0700994 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100995 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000996 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +0000998 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100999 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001000}
1001
1002void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1003 VisitCondition(comp);
1004}
1005
1006void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1007 VisitCondition(comp);
1008}
1009
1010void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1011 VisitCondition(comp);
1012}
1013
1014void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1015 VisitCondition(comp);
1016}
1017
1018void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1019 VisitCondition(comp);
1020}
1021
1022void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1023 VisitCondition(comp);
1024}
1025
1026void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1027 VisitCondition(comp);
1028}
1029
1030void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1031 VisitCondition(comp);
1032}
1033
1034void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1035 VisitCondition(comp);
1036}
1037
1038void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1039 VisitCondition(comp);
1040}
1041
1042void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1043 VisitCondition(comp);
1044}
1045
1046void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1047 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001048}
1049
1050void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001051 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001052}
1053
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001054void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1055 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001056}
1057
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001058void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001059 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001060}
1061
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001062void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001063 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001064 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001065}
1066
1067void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001068 LocationSummary* locations =
1069 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001070 switch (store->InputAt(1)->GetType()) {
1071 case Primitive::kPrimBoolean:
1072 case Primitive::kPrimByte:
1073 case Primitive::kPrimChar:
1074 case Primitive::kPrimShort:
1075 case Primitive::kPrimInt:
1076 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001077 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001078 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1079 break;
1080
1081 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001082 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001083 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1084 break;
1085
1086 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001087 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001088 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001089}
1090
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001091void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001092 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001093}
1094
1095void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001096 LocationSummary* locations =
1097 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001098 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001099}
1100
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001101void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001102 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001103 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001104}
1105
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001106void LocationsBuilderARM::VisitLongConstant(HLongConstant* 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 Geoffray01bc96d2014-04-11 17:43:50 +01001110}
1111
1112void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1113 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001114 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001115}
1116
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001117void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1118 LocationSummary* locations =
1119 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1120 locations->SetOut(Location::ConstantLocation(constant));
1121}
1122
1123void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1124 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001125 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001126}
1127
1128void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1129 LocationSummary* locations =
1130 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1131 locations->SetOut(Location::ConstantLocation(constant));
1132}
1133
1134void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* 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
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001139void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001140 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001141}
1142
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001143void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001144 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001145 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001146}
1147
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001148void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001149 LocationSummary* locations =
1150 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001151 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001152}
1153
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001154void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001155 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001156 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001157}
1158
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001159void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001160 HandleInvoke(invoke);
1161}
1162
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001163void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001164 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001165}
1166
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001167void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001168 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001169
1170 // TODO: Implement all kinds of calls:
1171 // 1) boot -> boot
1172 // 2) app -> boot
1173 // 3) app -> app
1174 //
1175 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1176
1177 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001178 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001179 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001180 __ LoadFromOffset(
1181 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001182 // temp = temp[index_in_cache]
1183 __ LoadFromOffset(
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001184 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001185 // LR = temp[offset_of_quick_compiled_code]
1186 __ LoadFromOffset(kLoadWord, LR, temp,
1187 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1188 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189 // LR()
1190 __ blx(LR);
1191
1192 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1193 DCHECK(!codegen_->IsLeafMethod());
1194}
1195
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001196void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001197 LocationSummary* locations =
1198 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001199 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001200
1201 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001202 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001203 HInstruction* input = invoke->InputAt(i);
1204 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1205 }
1206
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001207 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001208}
1209
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001210void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1211 HandleInvoke(invoke);
1212}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001213
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001214void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001215 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001216 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1217 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1218 LocationSummary* locations = invoke->GetLocations();
1219 Location receiver = locations->InAt(0);
1220 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1221 // temp = object->GetClass();
1222 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001223 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1224 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001225 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001226 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001227 }
1228 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001229 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001230 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001231 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001232 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001233 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001234 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001235 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001236 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001237 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001238}
1239
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001240void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1241 HandleInvoke(invoke);
1242 // Add the hidden argument.
1243 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1244}
1245
1246void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1247 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001248 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001249 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1250 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1251 LocationSummary* locations = invoke->GetLocations();
1252 Location receiver = locations->InAt(0);
1253 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1254
1255 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001256 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1257 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001258
1259 // temp = object->GetClass();
1260 if (receiver.IsStackSlot()) {
1261 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1262 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1263 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001264 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001265 }
1266 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001267 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001268 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001269 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1270 // LR = temp->GetEntryPoint();
1271 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1272 // LR();
1273 __ blx(LR);
1274 DCHECK(!codegen_->IsLeafMethod());
1275 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1276}
1277
Roland Levillain88cb1752014-10-20 16:36:47 +01001278void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1279 LocationSummary* locations =
1280 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1281 switch (neg->GetResultType()) {
1282 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001283 case Primitive::kPrimLong: {
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001284 Location::OutputOverlap output_overlaps = (neg->GetResultType() == Primitive::kPrimLong)
1285 ? Location::kOutputOverlap
1286 : Location::kNoOutputOverlap;
Roland Levillain88cb1752014-10-20 16:36:47 +01001287 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001288 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001289 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001290 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001291
Roland Levillain88cb1752014-10-20 16:36:47 +01001292 case Primitive::kPrimFloat:
1293 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001294 locations->SetInAt(0, Location::RequiresFpuRegister());
1295 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001296 break;
1297
1298 default:
1299 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1300 }
1301}
1302
1303void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1304 LocationSummary* locations = neg->GetLocations();
1305 Location out = locations->Out();
1306 Location in = locations->InAt(0);
1307 switch (neg->GetResultType()) {
1308 case Primitive::kPrimInt:
1309 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001310 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001311 break;
1312
1313 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001314 DCHECK(in.IsRegisterPair());
1315 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1316 __ rsbs(out.AsRegisterPairLow<Register>(),
1317 in.AsRegisterPairLow<Register>(),
1318 ShifterOperand(0));
1319 // We cannot emit an RSC (Reverse Subtract with Carry)
1320 // instruction here, as it does not exist in the Thumb-2
1321 // instruction set. We use the following approach
1322 // using SBC and SUB instead.
1323 //
1324 // out.hi = -C
1325 __ sbc(out.AsRegisterPairHigh<Register>(),
1326 out.AsRegisterPairHigh<Register>(),
1327 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1328 // out.hi = out.hi - in.hi
1329 __ sub(out.AsRegisterPairHigh<Register>(),
1330 out.AsRegisterPairHigh<Register>(),
1331 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1332 break;
1333
Roland Levillain88cb1752014-10-20 16:36:47 +01001334 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001335 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001336 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001337 break;
1338
Roland Levillain88cb1752014-10-20 16:36:47 +01001339 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001340 DCHECK(in.IsFpuRegisterPair());
1341 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1342 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001343 break;
1344
1345 default:
1346 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1347 }
1348}
1349
Roland Levillaindff1f282014-11-05 14:15:05 +00001350void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001351 Primitive::Type result_type = conversion->GetResultType();
1352 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001353 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001354
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001355 // The float-to-long and double-to-long type conversions rely on a
1356 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001357 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001358 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1359 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001360 ? LocationSummary::kCall
1361 : LocationSummary::kNoCall;
1362 LocationSummary* locations =
1363 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1364
Roland Levillaindff1f282014-11-05 14:15:05 +00001365 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001366 case Primitive::kPrimByte:
1367 switch (input_type) {
1368 case Primitive::kPrimShort:
1369 case Primitive::kPrimInt:
1370 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001371 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001372 locations->SetInAt(0, Location::RequiresRegister());
1373 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1374 break;
1375
1376 default:
1377 LOG(FATAL) << "Unexpected type conversion from " << input_type
1378 << " to " << result_type;
1379 }
1380 break;
1381
Roland Levillain01a8d712014-11-14 16:27:39 +00001382 case Primitive::kPrimShort:
1383 switch (input_type) {
1384 case Primitive::kPrimByte:
1385 case Primitive::kPrimInt:
1386 case Primitive::kPrimChar:
1387 // Processing a Dex `int-to-short' instruction.
1388 locations->SetInAt(0, Location::RequiresRegister());
1389 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1390 break;
1391
1392 default:
1393 LOG(FATAL) << "Unexpected type conversion from " << input_type
1394 << " to " << result_type;
1395 }
1396 break;
1397
Roland Levillain946e1432014-11-11 17:35:19 +00001398 case Primitive::kPrimInt:
1399 switch (input_type) {
1400 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001401 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001402 locations->SetInAt(0, Location::Any());
1403 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1404 break;
1405
1406 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001407 // Processing a Dex `float-to-int' instruction.
1408 locations->SetInAt(0, Location::RequiresFpuRegister());
1409 locations->SetOut(Location::RequiresRegister());
1410 locations->AddTemp(Location::RequiresFpuRegister());
1411 break;
1412
Roland Levillain946e1432014-11-11 17:35:19 +00001413 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001414 // Processing a Dex `double-to-int' instruction.
1415 locations->SetInAt(0, Location::RequiresFpuRegister());
1416 locations->SetOut(Location::RequiresRegister());
1417 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001418 break;
1419
1420 default:
1421 LOG(FATAL) << "Unexpected type conversion from " << input_type
1422 << " to " << result_type;
1423 }
1424 break;
1425
Roland Levillaindff1f282014-11-05 14:15:05 +00001426 case Primitive::kPrimLong:
1427 switch (input_type) {
1428 case Primitive::kPrimByte:
1429 case Primitive::kPrimShort:
1430 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001431 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001432 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001433 locations->SetInAt(0, Location::RequiresRegister());
1434 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1435 break;
1436
Roland Levillain624279f2014-12-04 11:54:28 +00001437 case Primitive::kPrimFloat: {
1438 // Processing a Dex `float-to-long' instruction.
1439 InvokeRuntimeCallingConvention calling_convention;
1440 locations->SetInAt(0, Location::FpuRegisterLocation(
1441 calling_convention.GetFpuRegisterAt(0)));
1442 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1443 break;
1444 }
1445
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001446 case Primitive::kPrimDouble: {
1447 // Processing a Dex `double-to-long' instruction.
1448 InvokeRuntimeCallingConvention calling_convention;
1449 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1450 calling_convention.GetFpuRegisterAt(0),
1451 calling_convention.GetFpuRegisterAt(1)));
1452 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001453 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001454 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001455
1456 default:
1457 LOG(FATAL) << "Unexpected type conversion from " << input_type
1458 << " to " << result_type;
1459 }
1460 break;
1461
Roland Levillain981e4542014-11-14 11:47:14 +00001462 case Primitive::kPrimChar:
1463 switch (input_type) {
1464 case Primitive::kPrimByte:
1465 case Primitive::kPrimShort:
1466 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001467 // Processing a Dex `int-to-char' instruction.
1468 locations->SetInAt(0, Location::RequiresRegister());
1469 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1470 break;
1471
1472 default:
1473 LOG(FATAL) << "Unexpected type conversion from " << input_type
1474 << " to " << result_type;
1475 }
1476 break;
1477
Roland Levillaindff1f282014-11-05 14:15:05 +00001478 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001479 switch (input_type) {
1480 case Primitive::kPrimByte:
1481 case Primitive::kPrimShort:
1482 case Primitive::kPrimInt:
1483 case Primitive::kPrimChar:
1484 // Processing a Dex `int-to-float' instruction.
1485 locations->SetInAt(0, Location::RequiresRegister());
1486 locations->SetOut(Location::RequiresFpuRegister());
1487 break;
1488
1489 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001490 // Processing a Dex `long-to-float' instruction.
1491 locations->SetInAt(0, Location::RequiresRegister());
1492 locations->SetOut(Location::RequiresFpuRegister());
1493 locations->AddTemp(Location::RequiresRegister());
1494 locations->AddTemp(Location::RequiresRegister());
1495 locations->AddTemp(Location::RequiresFpuRegister());
1496 locations->AddTemp(Location::RequiresFpuRegister());
1497 break;
1498
Roland Levillaincff13742014-11-17 14:32:17 +00001499 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001500 // Processing a Dex `double-to-float' instruction.
1501 locations->SetInAt(0, Location::RequiresFpuRegister());
1502 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001503 break;
1504
1505 default:
1506 LOG(FATAL) << "Unexpected type conversion from " << input_type
1507 << " to " << result_type;
1508 };
1509 break;
1510
Roland Levillaindff1f282014-11-05 14:15:05 +00001511 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001512 switch (input_type) {
1513 case Primitive::kPrimByte:
1514 case Primitive::kPrimShort:
1515 case Primitive::kPrimInt:
1516 case Primitive::kPrimChar:
1517 // Processing a Dex `int-to-double' instruction.
1518 locations->SetInAt(0, Location::RequiresRegister());
1519 locations->SetOut(Location::RequiresFpuRegister());
1520 break;
1521
1522 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001523 // Processing a Dex `long-to-double' instruction.
1524 locations->SetInAt(0, Location::RequiresRegister());
1525 locations->SetOut(Location::RequiresFpuRegister());
1526 locations->AddTemp(Location::RequiresRegister());
1527 locations->AddTemp(Location::RequiresRegister());
1528 locations->AddTemp(Location::RequiresFpuRegister());
1529 break;
1530
Roland Levillaincff13742014-11-17 14:32:17 +00001531 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001532 // Processing a Dex `float-to-double' instruction.
1533 locations->SetInAt(0, Location::RequiresFpuRegister());
1534 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001535 break;
1536
1537 default:
1538 LOG(FATAL) << "Unexpected type conversion from " << input_type
1539 << " to " << result_type;
1540 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001541 break;
1542
1543 default:
1544 LOG(FATAL) << "Unexpected type conversion from " << input_type
1545 << " to " << result_type;
1546 }
1547}
1548
1549void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1550 LocationSummary* locations = conversion->GetLocations();
1551 Location out = locations->Out();
1552 Location in = locations->InAt(0);
1553 Primitive::Type result_type = conversion->GetResultType();
1554 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001555 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001556 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001557 case Primitive::kPrimByte:
1558 switch (input_type) {
1559 case Primitive::kPrimShort:
1560 case Primitive::kPrimInt:
1561 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001562 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001563 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001564 break;
1565
1566 default:
1567 LOG(FATAL) << "Unexpected type conversion from " << input_type
1568 << " to " << result_type;
1569 }
1570 break;
1571
Roland Levillain01a8d712014-11-14 16:27:39 +00001572 case Primitive::kPrimShort:
1573 switch (input_type) {
1574 case Primitive::kPrimByte:
1575 case Primitive::kPrimInt:
1576 case Primitive::kPrimChar:
1577 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001578 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001579 break;
1580
1581 default:
1582 LOG(FATAL) << "Unexpected type conversion from " << input_type
1583 << " to " << result_type;
1584 }
1585 break;
1586
Roland Levillain946e1432014-11-11 17:35:19 +00001587 case Primitive::kPrimInt:
1588 switch (input_type) {
1589 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001590 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001591 DCHECK(out.IsRegister());
1592 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001593 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001594 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001595 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001596 } else {
1597 DCHECK(in.IsConstant());
1598 DCHECK(in.GetConstant()->IsLongConstant());
1599 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001600 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001601 }
1602 break;
1603
Roland Levillain3f8f9362014-12-02 17:45:01 +00001604 case Primitive::kPrimFloat: {
1605 // Processing a Dex `float-to-int' instruction.
1606 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1607 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1608 __ vcvtis(temp, temp);
1609 __ vmovrs(out.AsRegister<Register>(), temp);
1610 break;
1611 }
1612
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001613 case Primitive::kPrimDouble: {
1614 // Processing a Dex `double-to-int' instruction.
1615 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1616 DRegister temp_d = FromLowSToD(temp_s);
1617 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1618 __ vcvtid(temp_s, temp_d);
1619 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001620 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001621 }
Roland Levillain946e1432014-11-11 17:35:19 +00001622
1623 default:
1624 LOG(FATAL) << "Unexpected type conversion from " << input_type
1625 << " to " << result_type;
1626 }
1627 break;
1628
Roland Levillaindff1f282014-11-05 14:15:05 +00001629 case Primitive::kPrimLong:
1630 switch (input_type) {
1631 case Primitive::kPrimByte:
1632 case Primitive::kPrimShort:
1633 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001634 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001635 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001636 DCHECK(out.IsRegisterPair());
1637 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001638 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001639 // Sign extension.
1640 __ Asr(out.AsRegisterPairHigh<Register>(),
1641 out.AsRegisterPairLow<Register>(),
1642 31);
1643 break;
1644
1645 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001646 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001647 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1648 conversion,
1649 conversion->GetDexPc());
1650 break;
1651
Roland Levillaindff1f282014-11-05 14:15:05 +00001652 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001653 // Processing a Dex `double-to-long' instruction.
1654 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1655 conversion,
1656 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001657 break;
1658
1659 default:
1660 LOG(FATAL) << "Unexpected type conversion from " << input_type
1661 << " to " << result_type;
1662 }
1663 break;
1664
Roland Levillain981e4542014-11-14 11:47:14 +00001665 case Primitive::kPrimChar:
1666 switch (input_type) {
1667 case Primitive::kPrimByte:
1668 case Primitive::kPrimShort:
1669 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001670 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001671 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001672 break;
1673
1674 default:
1675 LOG(FATAL) << "Unexpected type conversion from " << input_type
1676 << " to " << result_type;
1677 }
1678 break;
1679
Roland Levillaindff1f282014-11-05 14:15:05 +00001680 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001681 switch (input_type) {
1682 case Primitive::kPrimByte:
1683 case Primitive::kPrimShort:
1684 case Primitive::kPrimInt:
1685 case Primitive::kPrimChar: {
1686 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001687 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1688 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001689 break;
1690 }
1691
Roland Levillain6d0e4832014-11-27 18:31:21 +00001692 case Primitive::kPrimLong: {
1693 // Processing a Dex `long-to-float' instruction.
1694 Register low = in.AsRegisterPairLow<Register>();
1695 Register high = in.AsRegisterPairHigh<Register>();
1696 SRegister output = out.AsFpuRegister<SRegister>();
1697 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1698 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1699 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1700 DRegister temp1_d = FromLowSToD(temp1_s);
1701 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1702 DRegister temp2_d = FromLowSToD(temp2_s);
1703
1704 // Operations use doubles for precision reasons (each 32-bit
1705 // half of a long fits in the 53-bit mantissa of a double,
1706 // but not in the 24-bit mantissa of a float). This is
1707 // especially important for the low bits. The result is
1708 // eventually converted to float.
1709
1710 // temp1_d = int-to-double(high)
1711 __ vmovsr(temp1_s, high);
1712 __ vcvtdi(temp1_d, temp1_s);
1713 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1714 // as an immediate value into `temp2_d` does not work, as
1715 // this instruction only transfers 8 significant bits of its
1716 // immediate operand. Instead, use two 32-bit core
1717 // registers to load `k2Pow32EncodingForDouble` into
1718 // `temp2_d`.
1719 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1720 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1721 __ vmovdrr(temp2_d, constant_low, constant_high);
1722 // temp1_d = temp1_d * 2^32
1723 __ vmuld(temp1_d, temp1_d, temp2_d);
1724 // temp2_d = unsigned-to-double(low)
1725 __ vmovsr(temp2_s, low);
1726 __ vcvtdu(temp2_d, temp2_s);
1727 // temp1_d = temp1_d + temp2_d
1728 __ vaddd(temp1_d, temp1_d, temp2_d);
1729 // output = double-to-float(temp1_d);
1730 __ vcvtsd(output, temp1_d);
1731 break;
1732 }
1733
Roland Levillaincff13742014-11-17 14:32:17 +00001734 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001735 // Processing a Dex `double-to-float' instruction.
1736 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1737 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001738 break;
1739
1740 default:
1741 LOG(FATAL) << "Unexpected type conversion from " << input_type
1742 << " to " << result_type;
1743 };
1744 break;
1745
Roland Levillaindff1f282014-11-05 14:15:05 +00001746 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001747 switch (input_type) {
1748 case Primitive::kPrimByte:
1749 case Primitive::kPrimShort:
1750 case Primitive::kPrimInt:
1751 case Primitive::kPrimChar: {
1752 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001753 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001754 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1755 out.AsFpuRegisterPairLow<SRegister>());
1756 break;
1757 }
1758
Roland Levillain647b9ed2014-11-27 12:06:00 +00001759 case Primitive::kPrimLong: {
1760 // Processing a Dex `long-to-double' instruction.
1761 Register low = in.AsRegisterPairLow<Register>();
1762 Register high = in.AsRegisterPairHigh<Register>();
1763 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1764 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001765 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1766 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001767 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1768 DRegister temp_d = FromLowSToD(temp_s);
1769
Roland Levillain647b9ed2014-11-27 12:06:00 +00001770 // out_d = int-to-double(high)
1771 __ vmovsr(out_s, high);
1772 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001773 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1774 // as an immediate value into `temp_d` does not work, as
1775 // this instruction only transfers 8 significant bits of its
1776 // immediate operand. Instead, use two 32-bit core
1777 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1778 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1779 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001780 __ vmovdrr(temp_d, constant_low, constant_high);
1781 // out_d = out_d * 2^32
1782 __ vmuld(out_d, out_d, temp_d);
1783 // temp_d = unsigned-to-double(low)
1784 __ vmovsr(temp_s, low);
1785 __ vcvtdu(temp_d, temp_s);
1786 // out_d = out_d + temp_d
1787 __ vaddd(out_d, out_d, temp_d);
1788 break;
1789 }
1790
Roland Levillaincff13742014-11-17 14:32:17 +00001791 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001792 // Processing a Dex `float-to-double' instruction.
1793 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1794 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001795 break;
1796
1797 default:
1798 LOG(FATAL) << "Unexpected type conversion from " << input_type
1799 << " to " << result_type;
1800 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001801 break;
1802
1803 default:
1804 LOG(FATAL) << "Unexpected type conversion from " << input_type
1805 << " to " << result_type;
1806 }
1807}
1808
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001809void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001810 LocationSummary* locations =
1811 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001812 switch (add->GetResultType()) {
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001813 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001814 locations->SetInAt(0, Location::RequiresRegister());
1815 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001816 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1817 break;
1818 }
1819
1820 case Primitive::kPrimLong: {
1821 locations->SetInAt(0, Location::RequiresRegister());
1822 locations->SetInAt(1, Location::RequiresRegister());
1823 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001824 break;
1825 }
1826
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001827 case Primitive::kPrimFloat:
1828 case Primitive::kPrimDouble: {
1829 locations->SetInAt(0, Location::RequiresFpuRegister());
1830 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001831 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001832 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001833 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001834
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001835 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001836 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001837 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001838}
1839
1840void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1841 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001842 Location out = locations->Out();
1843 Location first = locations->InAt(0);
1844 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001845 switch (add->GetResultType()) {
1846 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001847 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001848 __ add(out.AsRegister<Register>(),
1849 first.AsRegister<Register>(),
1850 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001851 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001852 __ AddConstant(out.AsRegister<Register>(),
1853 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001854 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001855 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001856 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001857
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001858 case Primitive::kPrimLong: {
1859 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001860 __ adds(out.AsRegisterPairLow<Register>(),
1861 first.AsRegisterPairLow<Register>(),
1862 ShifterOperand(second.AsRegisterPairLow<Register>()));
1863 __ adc(out.AsRegisterPairHigh<Register>(),
1864 first.AsRegisterPairHigh<Register>(),
1865 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001866 break;
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001867 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001868
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001869 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001870 __ vadds(out.AsFpuRegister<SRegister>(),
1871 first.AsFpuRegister<SRegister>(),
1872 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001873 break;
1874
1875 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001876 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1877 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1878 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001879 break;
1880
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001881 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001882 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001883 }
1884}
1885
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001886void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001887 LocationSummary* locations =
1888 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001889 switch (sub->GetResultType()) {
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001890 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001891 locations->SetInAt(0, Location::RequiresRegister());
1892 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001893 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1894 break;
1895 }
1896
1897 case Primitive::kPrimLong: {
1898 locations->SetInAt(0, Location::RequiresRegister());
1899 locations->SetInAt(1, Location::RequiresRegister());
1900 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001901 break;
1902 }
Calin Juravle11351682014-10-23 15:38:15 +01001903 case Primitive::kPrimFloat:
1904 case Primitive::kPrimDouble: {
1905 locations->SetInAt(0, Location::RequiresFpuRegister());
1906 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001907 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001908 break;
Calin Juravle11351682014-10-23 15:38:15 +01001909 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001910 default:
Calin Juravle11351682014-10-23 15:38:15 +01001911 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001912 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001913}
1914
1915void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1916 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001917 Location out = locations->Out();
1918 Location first = locations->InAt(0);
1919 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001920 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001921 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001922 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001923 __ sub(out.AsRegister<Register>(),
1924 first.AsRegister<Register>(),
1925 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001926 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001927 __ AddConstant(out.AsRegister<Register>(),
1928 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001929 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001930 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001931 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001932 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001933
Calin Juravle11351682014-10-23 15:38:15 +01001934 case Primitive::kPrimLong: {
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00001935 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001936 __ subs(out.AsRegisterPairLow<Register>(),
1937 first.AsRegisterPairLow<Register>(),
1938 ShifterOperand(second.AsRegisterPairLow<Register>()));
1939 __ sbc(out.AsRegisterPairHigh<Register>(),
1940 first.AsRegisterPairHigh<Register>(),
1941 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001942 break;
Calin Juravle11351682014-10-23 15:38:15 +01001943 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001944
Calin Juravle11351682014-10-23 15:38:15 +01001945 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001946 __ vsubs(out.AsFpuRegister<SRegister>(),
1947 first.AsFpuRegister<SRegister>(),
1948 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001949 break;
Calin Juravle11351682014-10-23 15:38:15 +01001950 }
1951
1952 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001953 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1954 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1955 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001956 break;
1957 }
1958
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001959
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001960 default:
Calin Juravle11351682014-10-23 15:38:15 +01001961 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001962 }
1963}
1964
Calin Juravle34bacdf2014-10-07 20:23:36 +01001965void LocationsBuilderARM::VisitMul(HMul* mul) {
1966 LocationSummary* locations =
1967 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1968 switch (mul->GetResultType()) {
1969 case Primitive::kPrimInt:
1970 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001971 locations->SetInAt(0, Location::RequiresRegister());
1972 locations->SetInAt(1, Location::RequiresRegister());
1973 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001974 break;
1975 }
1976
Calin Juravleb5bfa962014-10-21 18:02:24 +01001977 case Primitive::kPrimFloat:
1978 case Primitive::kPrimDouble: {
1979 locations->SetInAt(0, Location::RequiresFpuRegister());
1980 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001981 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001982 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001983 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001984
1985 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001986 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001987 }
1988}
1989
1990void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1991 LocationSummary* locations = mul->GetLocations();
1992 Location out = locations->Out();
1993 Location first = locations->InAt(0);
1994 Location second = locations->InAt(1);
1995 switch (mul->GetResultType()) {
1996 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001997 __ mul(out.AsRegister<Register>(),
1998 first.AsRegister<Register>(),
1999 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002000 break;
2001 }
2002 case Primitive::kPrimLong: {
2003 Register out_hi = out.AsRegisterPairHigh<Register>();
2004 Register out_lo = out.AsRegisterPairLow<Register>();
2005 Register in1_hi = first.AsRegisterPairHigh<Register>();
2006 Register in1_lo = first.AsRegisterPairLow<Register>();
2007 Register in2_hi = second.AsRegisterPairHigh<Register>();
2008 Register in2_lo = second.AsRegisterPairLow<Register>();
2009
2010 // Extra checks to protect caused by the existence of R1_R2.
2011 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2012 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2013 DCHECK_NE(out_hi, in1_lo);
2014 DCHECK_NE(out_hi, in2_lo);
2015
2016 // input: in1 - 64 bits, in2 - 64 bits
2017 // output: out
2018 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2019 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2020 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2021
2022 // IP <- in1.lo * in2.hi
2023 __ mul(IP, in1_lo, in2_hi);
2024 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2025 __ mla(out_hi, in1_hi, in2_lo, IP);
2026 // out.lo <- (in1.lo * in2.lo)[31:0];
2027 __ umull(out_lo, IP, in1_lo, in2_lo);
2028 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2029 __ add(out_hi, out_hi, ShifterOperand(IP));
2030 break;
2031 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002032
2033 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002034 __ vmuls(out.AsFpuRegister<SRegister>(),
2035 first.AsFpuRegister<SRegister>(),
2036 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002037 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002038 }
2039
2040 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002041 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2042 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2043 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002044 break;
2045 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002046
2047 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002048 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002049 }
2050}
2051
Calin Juravle7c4954d2014-10-28 16:57:40 +00002052void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002053 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2054 ? LocationSummary::kCall
2055 : LocationSummary::kNoCall;
2056 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2057
Calin Juravle7c4954d2014-10-28 16:57:40 +00002058 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002059 case Primitive::kPrimInt: {
2060 locations->SetInAt(0, Location::RequiresRegister());
2061 locations->SetInAt(1, Location::RequiresRegister());
2062 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2063 break;
2064 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002065 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002066 InvokeRuntimeCallingConvention calling_convention;
2067 locations->SetInAt(0, Location::RegisterPairLocation(
2068 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2069 locations->SetInAt(1, Location::RegisterPairLocation(
2070 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00002071 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002072 break;
2073 }
2074 case Primitive::kPrimFloat:
2075 case Primitive::kPrimDouble: {
2076 locations->SetInAt(0, Location::RequiresFpuRegister());
2077 locations->SetInAt(1, Location::RequiresFpuRegister());
2078 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2079 break;
2080 }
2081
2082 default:
2083 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2084 }
2085}
2086
2087void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2088 LocationSummary* locations = div->GetLocations();
2089 Location out = locations->Out();
2090 Location first = locations->InAt(0);
2091 Location second = locations->InAt(1);
2092
2093 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002094 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002095 __ sdiv(out.AsRegister<Register>(),
2096 first.AsRegister<Register>(),
2097 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002098 break;
2099 }
2100
Calin Juravle7c4954d2014-10-28 16:57:40 +00002101 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002102 InvokeRuntimeCallingConvention calling_convention;
2103 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2104 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2105 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2106 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2107 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00002108 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002109
2110 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002111 break;
2112 }
2113
2114 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002115 __ vdivs(out.AsFpuRegister<SRegister>(),
2116 first.AsFpuRegister<SRegister>(),
2117 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002118 break;
2119 }
2120
2121 case Primitive::kPrimDouble: {
2122 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2123 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2124 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2125 break;
2126 }
2127
2128 default:
2129 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2130 }
2131}
2132
Calin Juravlebacfec32014-11-14 15:54:36 +00002133void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002134 Primitive::Type type = rem->GetResultType();
2135 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2136 ? LocationSummary::kNoCall
2137 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002138 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2139
Calin Juravled2ec87d2014-12-08 14:24:46 +00002140 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002141 case Primitive::kPrimInt: {
2142 locations->SetInAt(0, Location::RequiresRegister());
2143 locations->SetInAt(1, Location::RequiresRegister());
2144 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2145 locations->AddTemp(Location::RequiresRegister());
2146 break;
2147 }
2148 case Primitive::kPrimLong: {
2149 InvokeRuntimeCallingConvention calling_convention;
2150 locations->SetInAt(0, Location::RegisterPairLocation(
2151 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2152 locations->SetInAt(1, Location::RegisterPairLocation(
2153 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2154 // The runtime helper puts the output in R2,R3.
2155 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2156 break;
2157 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002158 case Primitive::kPrimFloat: {
2159 InvokeRuntimeCallingConvention calling_convention;
2160 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2161 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2162 locations->SetOut(Location::FpuRegisterLocation(S0));
2163 break;
2164 }
2165
Calin Juravlebacfec32014-11-14 15:54:36 +00002166 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002167 InvokeRuntimeCallingConvention calling_convention;
2168 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2169 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2170 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2171 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2172 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002173 break;
2174 }
2175
2176 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002177 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002178 }
2179}
2180
2181void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2182 LocationSummary* locations = rem->GetLocations();
2183 Location out = locations->Out();
2184 Location first = locations->InAt(0);
2185 Location second = locations->InAt(1);
2186
Calin Juravled2ec87d2014-12-08 14:24:46 +00002187 Primitive::Type type = rem->GetResultType();
2188 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002189 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002190 Register reg1 = first.AsRegister<Register>();
2191 Register reg2 = second.AsRegister<Register>();
2192 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002193
2194 // temp = reg1 / reg2 (integer division)
2195 // temp = temp * reg2
2196 // dest = reg1 - temp
2197 __ sdiv(temp, reg1, reg2);
2198 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002199 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002200 break;
2201 }
2202
2203 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002204 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2205 break;
2206 }
2207
Calin Juravled2ec87d2014-12-08 14:24:46 +00002208 case Primitive::kPrimFloat: {
2209 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2210 break;
2211 }
2212
Calin Juravlebacfec32014-11-14 15:54:36 +00002213 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002214 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002215 break;
2216 }
2217
2218 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002219 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002220 }
2221}
2222
Calin Juravled0d48522014-11-04 16:40:20 +00002223void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2224 LocationSummary* locations =
2225 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002226 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002227 if (instruction->HasUses()) {
2228 locations->SetOut(Location::SameAsFirstInput());
2229 }
2230}
2231
2232void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2233 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2234 codegen_->AddSlowPath(slow_path);
2235
2236 LocationSummary* locations = instruction->GetLocations();
2237 Location value = locations->InAt(0);
2238
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002239 switch (instruction->GetType()) {
2240 case Primitive::kPrimInt: {
2241 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002242 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002243 __ b(slow_path->GetEntryLabel(), EQ);
2244 } else {
2245 DCHECK(value.IsConstant()) << value;
2246 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2247 __ b(slow_path->GetEntryLabel());
2248 }
2249 }
2250 break;
2251 }
2252 case Primitive::kPrimLong: {
2253 if (value.IsRegisterPair()) {
2254 __ orrs(IP,
2255 value.AsRegisterPairLow<Register>(),
2256 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2257 __ b(slow_path->GetEntryLabel(), EQ);
2258 } else {
2259 DCHECK(value.IsConstant()) << value;
2260 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2261 __ b(slow_path->GetEntryLabel());
2262 }
2263 }
2264 break;
2265 default:
2266 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2267 }
2268 }
Calin Juravled0d48522014-11-04 16:40:20 +00002269}
2270
Calin Juravle9aec02f2014-11-18 23:06:35 +00002271void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2272 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2273
2274 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2275 ? LocationSummary::kCall
2276 : LocationSummary::kNoCall;
2277 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2278
2279 switch (op->GetResultType()) {
2280 case Primitive::kPrimInt: {
2281 locations->SetInAt(0, Location::RequiresRegister());
2282 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2283 locations->SetOut(Location::RequiresRegister());
2284 break;
2285 }
2286 case Primitive::kPrimLong: {
2287 InvokeRuntimeCallingConvention calling_convention;
2288 locations->SetInAt(0, Location::RegisterPairLocation(
2289 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2290 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00002291 // The runtime helper puts the output in R0,R1.
2292 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002293 break;
2294 }
2295 default:
2296 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2297 }
2298}
2299
2300void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2301 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2302
2303 LocationSummary* locations = op->GetLocations();
2304 Location out = locations->Out();
2305 Location first = locations->InAt(0);
2306 Location second = locations->InAt(1);
2307
2308 Primitive::Type type = op->GetResultType();
2309 switch (type) {
2310 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002311 Register out_reg = out.AsRegister<Register>();
2312 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002313 // Arm doesn't mask the shift count so we need to do it ourselves.
2314 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002315 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002316 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2317 if (op->IsShl()) {
2318 __ Lsl(out_reg, first_reg, second_reg);
2319 } else if (op->IsShr()) {
2320 __ Asr(out_reg, first_reg, second_reg);
2321 } else {
2322 __ Lsr(out_reg, first_reg, second_reg);
2323 }
2324 } else {
2325 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2326 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2327 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2328 __ Mov(out_reg, first_reg);
2329 } else if (op->IsShl()) {
2330 __ Lsl(out_reg, first_reg, shift_value);
2331 } else if (op->IsShr()) {
2332 __ Asr(out_reg, first_reg, shift_value);
2333 } else {
2334 __ Lsr(out_reg, first_reg, shift_value);
2335 }
2336 }
2337 break;
2338 }
2339 case Primitive::kPrimLong: {
2340 // TODO: Inline the assembly instead of calling the runtime.
2341 InvokeRuntimeCallingConvention calling_convention;
2342 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2343 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002344 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002345 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00002346 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002347
2348 int32_t entry_point_offset;
2349 if (op->IsShl()) {
2350 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2351 } else if (op->IsShr()) {
2352 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2353 } else {
2354 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2355 }
2356 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2357 __ blx(LR);
2358 break;
2359 }
2360 default:
2361 LOG(FATAL) << "Unexpected operation type " << type;
2362 }
2363}
2364
2365void LocationsBuilderARM::VisitShl(HShl* shl) {
2366 HandleShift(shl);
2367}
2368
2369void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2370 HandleShift(shl);
2371}
2372
2373void LocationsBuilderARM::VisitShr(HShr* shr) {
2374 HandleShift(shr);
2375}
2376
2377void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2378 HandleShift(shr);
2379}
2380
2381void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2382 HandleShift(ushr);
2383}
2384
2385void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2386 HandleShift(ushr);
2387}
2388
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002389void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002390 LocationSummary* locations =
2391 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002392 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002393 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2394 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2395 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002396}
2397
2398void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2399 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002400 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002401 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002402 codegen_->InvokeRuntime(
2403 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002404}
2405
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002406void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2407 LocationSummary* locations =
2408 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2409 InvokeRuntimeCallingConvention calling_convention;
2410 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002411 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002412 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002413 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002414}
2415
2416void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2417 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002418 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002419 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002420 codegen_->InvokeRuntime(
2421 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002422}
2423
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002424void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002425 LocationSummary* locations =
2426 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002427 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2428 if (location.IsStackSlot()) {
2429 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2430 } else if (location.IsDoubleStackSlot()) {
2431 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002432 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002433 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002434}
2435
2436void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002437 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002438 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002439}
2440
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002441void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002442 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002443 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002444 locations->SetInAt(0, Location::RequiresRegister());
2445 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002446}
2447
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002448void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2449 LocationSummary* locations = not_->GetLocations();
2450 Location out = locations->Out();
2451 Location in = locations->InAt(0);
2452 switch (not_->InputAt(0)->GetType()) {
2453 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002454 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002455 break;
2456
2457 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002458 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002459 break;
2460
2461 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002462 __ mvn(out.AsRegisterPairLow<Register>(),
2463 ShifterOperand(in.AsRegisterPairLow<Register>()));
2464 __ mvn(out.AsRegisterPairHigh<Register>(),
2465 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002466 break;
2467
2468 default:
2469 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2470 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002471}
2472
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002473void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002474 LocationSummary* locations =
2475 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002476 switch (compare->InputAt(0)->GetType()) {
2477 case Primitive::kPrimLong: {
2478 locations->SetInAt(0, Location::RequiresRegister());
2479 locations->SetInAt(1, Location::RequiresRegister());
2480 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2481 break;
2482 }
2483 case Primitive::kPrimFloat:
2484 case Primitive::kPrimDouble: {
2485 locations->SetInAt(0, Location::RequiresFpuRegister());
2486 locations->SetInAt(1, Location::RequiresFpuRegister());
2487 locations->SetOut(Location::RequiresRegister());
2488 break;
2489 }
2490 default:
2491 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2492 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002493}
2494
2495void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002496 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002497 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002498 Location left = locations->InAt(0);
2499 Location right = locations->InAt(1);
2500
2501 Label less, greater, done;
2502 Primitive::Type type = compare->InputAt(0)->GetType();
2503 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002504 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002505 __ cmp(left.AsRegisterPairHigh<Register>(),
2506 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002507 __ b(&less, LT);
2508 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002509 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2510 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002511 __ cmp(left.AsRegisterPairLow<Register>(),
2512 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002513 break;
2514 }
2515 case Primitive::kPrimFloat:
2516 case Primitive::kPrimDouble: {
2517 __ LoadImmediate(out, 0);
2518 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002519 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002520 } else {
2521 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2522 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2523 }
2524 __ vmstat(); // transfer FP status register to ARM APSR.
2525 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002526 break;
2527 }
2528 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002529 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002530 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002531 __ b(&done, EQ);
2532 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2533
2534 __ Bind(&greater);
2535 __ LoadImmediate(out, 1);
2536 __ b(&done);
2537
2538 __ Bind(&less);
2539 __ LoadImmediate(out, -1);
2540
2541 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002542}
2543
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002544void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002545 LocationSummary* locations =
2546 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002547 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2548 locations->SetInAt(i, Location::Any());
2549 }
2550 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002551}
2552
2553void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002554 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002555 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002556}
2557
Calin Juravle52c48962014-12-16 17:02:57 +00002558void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2559 // TODO (ported from quick): revisit Arm barrier kinds
2560 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2561 switch (kind) {
2562 case MemBarrierKind::kAnyStore:
2563 case MemBarrierKind::kLoadAny:
2564 case MemBarrierKind::kAnyAny: {
2565 flavour = DmbOptions::ISH;
2566 break;
2567 }
2568 case MemBarrierKind::kStoreStore: {
2569 flavour = DmbOptions::ISHST;
2570 break;
2571 }
2572 default:
2573 LOG(FATAL) << "Unexpected memory barrier " << kind;
2574 }
2575 __ dmb(flavour);
2576}
2577
2578void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2579 uint32_t offset,
2580 Register out_lo,
2581 Register out_hi) {
2582 if (offset != 0) {
2583 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002584 __ add(IP, addr, ShifterOperand(out_lo));
2585 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002586 }
2587 __ ldrexd(out_lo, out_hi, addr);
2588}
2589
2590void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2591 uint32_t offset,
2592 Register value_lo,
2593 Register value_hi,
2594 Register temp1,
2595 Register temp2) {
2596 Label fail;
2597 if (offset != 0) {
2598 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002599 __ add(IP, addr, ShifterOperand(temp1));
2600 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002601 }
2602 __ Bind(&fail);
2603 // We need a load followed by store. (The address used in a STREX instruction must
2604 // be the same as the address in the most recently executed LDREX instruction.)
2605 __ ldrexd(temp1, temp2, addr);
2606 __ strexd(temp1, value_lo, value_hi, addr);
2607 __ cmp(temp1, ShifterOperand(0));
2608 __ b(&fail, NE);
2609}
2610
2611void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2612 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2613
Nicolas Geoffray39468442014-09-02 15:17:15 +01002614 LocationSummary* locations =
2615 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002616 locations->SetInAt(0, Location::RequiresRegister());
2617 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002618
Calin Juravle34166012014-12-19 17:22:29 +00002619
Calin Juravle52c48962014-12-16 17:02:57 +00002620 Primitive::Type field_type = field_info.GetFieldType();
2621 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002622 bool generate_volatile = field_info.IsVolatile()
2623 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002624 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002625 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002626 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2627 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002628 locations->AddTemp(Location::RequiresRegister());
2629 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002630 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002631 // Arm encoding have some additional constraints for ldrexd/strexd:
2632 // - registers need to be consecutive
2633 // - the first register should be even but not R14.
2634 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2635 // enable Arm encoding.
2636 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2637
2638 locations->AddTemp(Location::RequiresRegister());
2639 locations->AddTemp(Location::RequiresRegister());
2640 if (field_type == Primitive::kPrimDouble) {
2641 // For doubles we need two more registers to copy the value.
2642 locations->AddTemp(Location::RegisterLocation(R2));
2643 locations->AddTemp(Location::RegisterLocation(R3));
2644 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002645 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002646}
2647
Calin Juravle52c48962014-12-16 17:02:57 +00002648void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2649 const FieldInfo& field_info) {
2650 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2651
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002652 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002653 Register base = locations->InAt(0).AsRegister<Register>();
2654 Location value = locations->InAt(1);
2655
2656 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002657 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002658 Primitive::Type field_type = field_info.GetFieldType();
2659 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2660
2661 if (is_volatile) {
2662 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2663 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002664
2665 switch (field_type) {
2666 case Primitive::kPrimBoolean:
2667 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002668 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002669 break;
2670 }
2671
2672 case Primitive::kPrimShort:
2673 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002674 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002675 break;
2676 }
2677
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002678 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002679 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002680 Register value_reg = value.AsRegister<Register>();
2681 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2682 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002683 Register temp = locations->GetTemp(0).AsRegister<Register>();
2684 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002685 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002686 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002687 break;
2688 }
2689
2690 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002691 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002692 GenerateWideAtomicStore(base, offset,
2693 value.AsRegisterPairLow<Register>(),
2694 value.AsRegisterPairHigh<Register>(),
2695 locations->GetTemp(0).AsRegister<Register>(),
2696 locations->GetTemp(1).AsRegister<Register>());
2697 } else {
2698 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2699 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002700 break;
2701 }
2702
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002703 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002704 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002705 break;
2706 }
2707
2708 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002709 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002710 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002711 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2712 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2713
2714 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2715
2716 GenerateWideAtomicStore(base, offset,
2717 value_reg_lo,
2718 value_reg_hi,
2719 locations->GetTemp(2).AsRegister<Register>(),
2720 locations->GetTemp(3).AsRegister<Register>());
2721 } else {
2722 __ StoreDToOffset(value_reg, base, offset);
2723 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002724 break;
2725 }
2726
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002727 case Primitive::kPrimVoid:
2728 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002729 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002730 }
Calin Juravle52c48962014-12-16 17:02:57 +00002731
2732 if (is_volatile) {
2733 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2734 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002735}
2736
Calin Juravle52c48962014-12-16 17:02:57 +00002737void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2738 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002739 LocationSummary* locations =
2740 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002741 locations->SetInAt(0, Location::RequiresRegister());
2742 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002743
Calin Juravle34166012014-12-19 17:22:29 +00002744 bool generate_volatile = field_info.IsVolatile()
2745 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002746 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle34166012014-12-19 17:22:29 +00002747 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002748 // Arm encoding have some additional constraints for ldrexd/strexd:
2749 // - registers need to be consecutive
2750 // - the first register should be even but not R14.
2751 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2752 // enable Arm encoding.
2753 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2754 locations->AddTemp(Location::RequiresRegister());
2755 locations->AddTemp(Location::RequiresRegister());
2756 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002757}
2758
Calin Juravle52c48962014-12-16 17:02:57 +00002759void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2760 const FieldInfo& field_info) {
2761 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002762
Calin Juravle52c48962014-12-16 17:02:57 +00002763 LocationSummary* locations = instruction->GetLocations();
2764 Register base = locations->InAt(0).AsRegister<Register>();
2765 Location out = locations->Out();
2766 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002767 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002768 Primitive::Type field_type = field_info.GetFieldType();
2769 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2770
2771 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002772 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002773 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002774 break;
2775 }
2776
2777 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002778 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002779 break;
2780 }
2781
2782 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002783 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002784 break;
2785 }
2786
2787 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002788 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002789 break;
2790 }
2791
2792 case Primitive::kPrimInt:
2793 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002794 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002795 break;
2796 }
2797
2798 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002799 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002800 GenerateWideAtomicLoad(base, offset,
2801 out.AsRegisterPairLow<Register>(),
2802 out.AsRegisterPairHigh<Register>());
2803 } else {
2804 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2805 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002806 break;
2807 }
2808
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002809 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002810 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002811 break;
2812 }
2813
2814 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002815 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002816 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002817 Register lo = locations->GetTemp(0).AsRegister<Register>();
2818 Register hi = locations->GetTemp(1).AsRegister<Register>();
2819 GenerateWideAtomicLoad(base, offset, lo, hi);
2820 __ vmovdrr(out_reg, lo, hi);
2821 } else {
2822 __ LoadDFromOffset(out_reg, base, offset);
2823 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002824 break;
2825 }
2826
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002827 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002828 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002829 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002830 }
Calin Juravle52c48962014-12-16 17:02:57 +00002831
2832 if (is_volatile) {
2833 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2834 }
2835}
2836
2837void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2838 HandleFieldSet(instruction, instruction->GetFieldInfo());
2839}
2840
2841void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2842 HandleFieldSet(instruction, instruction->GetFieldInfo());
2843}
2844
2845void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2846 HandleFieldGet(instruction, instruction->GetFieldInfo());
2847}
2848
2849void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2850 HandleFieldGet(instruction, instruction->GetFieldInfo());
2851}
2852
2853void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2854 HandleFieldGet(instruction, instruction->GetFieldInfo());
2855}
2856
2857void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2858 HandleFieldGet(instruction, instruction->GetFieldInfo());
2859}
2860
2861void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2862 HandleFieldSet(instruction, instruction->GetFieldInfo());
2863}
2864
2865void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2866 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002867}
2868
2869void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002870 LocationSummary* locations =
2871 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002872 Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks()
2873 ? Location::RequiresRegister()
2874 : Location::RegisterOrConstant(instruction->InputAt(0));
2875 locations->SetInAt(0, loc);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002876 if (instruction->HasUses()) {
2877 locations->SetOut(Location::SameAsFirstInput());
2878 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002879}
2880
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002881void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
2882 Location obj = instruction->GetLocations()->InAt(0);
2883 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2884 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2885}
2886
2887void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002888 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002889 codegen_->AddSlowPath(slow_path);
2890
2891 LocationSummary* locations = instruction->GetLocations();
2892 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002893
2894 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002895 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002896 __ b(slow_path->GetEntryLabel(), EQ);
2897 } else {
2898 DCHECK(obj.IsConstant()) << obj;
2899 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2900 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002901 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002902}
2903
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002904void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2905 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2906 GenerateImplicitNullCheck(instruction);
2907 } else {
2908 GenerateExplicitNullCheck(instruction);
2909 }
2910}
2911
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002912void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002913 LocationSummary* locations =
2914 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002915 locations->SetInAt(0, Location::RequiresRegister());
2916 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2917 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002918}
2919
2920void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2921 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002922 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002923 Location index = locations->InAt(1);
2924
2925 switch (instruction->GetType()) {
2926 case Primitive::kPrimBoolean: {
2927 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002928 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002929 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002930 size_t offset =
2931 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002932 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2933 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002934 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002935 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2936 }
2937 break;
2938 }
2939
2940 case Primitive::kPrimByte: {
2941 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002942 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002943 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002944 size_t offset =
2945 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002946 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2947 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002948 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002949 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2950 }
2951 break;
2952 }
2953
2954 case Primitive::kPrimShort: {
2955 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002956 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002957 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002958 size_t offset =
2959 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002960 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2961 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002962 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002963 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2964 }
2965 break;
2966 }
2967
2968 case Primitive::kPrimChar: {
2969 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002970 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002971 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002972 size_t offset =
2973 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002974 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2975 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002976 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002977 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2978 }
2979 break;
2980 }
2981
2982 case Primitive::kPrimInt:
2983 case Primitive::kPrimNot: {
2984 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2985 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002986 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002987 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002988 size_t offset =
2989 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002990 __ LoadFromOffset(kLoadWord, out, obj, offset);
2991 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002992 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002993 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2994 }
2995 break;
2996 }
2997
2998 case Primitive::kPrimLong: {
2999 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003000 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003001 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003002 size_t offset =
3003 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003004 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003005 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003006 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003007 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003008 }
3009 break;
3010 }
3011
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003012 case Primitive::kPrimFloat: {
3013 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3014 Location out = locations->Out();
3015 DCHECK(out.IsFpuRegister());
3016 if (index.IsConstant()) {
3017 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3018 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3019 } else {
3020 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3021 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3022 }
3023 break;
3024 }
3025
3026 case Primitive::kPrimDouble: {
3027 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3028 Location out = locations->Out();
3029 DCHECK(out.IsFpuRegisterPair());
3030 if (index.IsConstant()) {
3031 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3032 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3033 } else {
3034 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3035 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3036 }
3037 break;
3038 }
3039
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003040 case Primitive::kPrimVoid:
3041 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003042 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003043 }
3044}
3045
3046void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003047 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003048
3049 bool needs_write_barrier =
3050 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3051 bool needs_runtime_call = instruction->NeedsTypeCheck();
3052
Nicolas Geoffray39468442014-09-02 15:17:15 +01003053 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003054 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3055 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003056 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003057 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3058 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3059 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003060 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003061 locations->SetInAt(0, Location::RequiresRegister());
3062 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3063 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003064
3065 if (needs_write_barrier) {
3066 // Temporary registers for the write barrier.
3067 locations->AddTemp(Location::RequiresRegister());
3068 locations->AddTemp(Location::RequiresRegister());
3069 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003070 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003071}
3072
3073void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3074 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003075 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003076 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003077 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003078 bool needs_runtime_call = locations->WillCall();
3079 bool needs_write_barrier =
3080 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003081
3082 switch (value_type) {
3083 case Primitive::kPrimBoolean:
3084 case Primitive::kPrimByte: {
3085 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003086 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003087 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003088 size_t offset =
3089 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003090 __ StoreToOffset(kStoreByte, value, obj, offset);
3091 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003092 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003093 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3094 }
3095 break;
3096 }
3097
3098 case Primitive::kPrimShort:
3099 case Primitive::kPrimChar: {
3100 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003101 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003102 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003103 size_t offset =
3104 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003105 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3106 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003107 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003108 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3109 }
3110 break;
3111 }
3112
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003113 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003114 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003115 if (!needs_runtime_call) {
3116 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003117 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003118 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003119 size_t offset =
3120 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003121 __ StoreToOffset(kStoreWord, value, obj, offset);
3122 } else {
3123 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003124 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003125 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3126 }
3127 if (needs_write_barrier) {
3128 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003129 Register temp = locations->GetTemp(0).AsRegister<Register>();
3130 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003131 codegen_->MarkGCCard(temp, card, obj, value);
3132 }
3133 } else {
3134 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003135 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3136 instruction,
3137 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003138 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003139 break;
3140 }
3141
3142 case Primitive::kPrimLong: {
3143 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003144 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003145 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003146 size_t offset =
3147 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003148 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003149 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003150 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003151 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003152 }
3153 break;
3154 }
3155
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003156 case Primitive::kPrimFloat: {
3157 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3158 Location value = locations->InAt(2);
3159 DCHECK(value.IsFpuRegister());
3160 if (index.IsConstant()) {
3161 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3162 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3163 } else {
3164 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3165 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3166 }
3167 break;
3168 }
3169
3170 case Primitive::kPrimDouble: {
3171 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3172 Location value = locations->InAt(2);
3173 DCHECK(value.IsFpuRegisterPair());
3174 if (index.IsConstant()) {
3175 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3176 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3177 } else {
3178 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3179 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3180 }
3181 break;
3182 }
3183
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003184 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003185 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003186 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003187 }
3188}
3189
3190void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003191 LocationSummary* locations =
3192 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003193 locations->SetInAt(0, Location::RequiresRegister());
3194 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003195}
3196
3197void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3198 LocationSummary* locations = instruction->GetLocations();
3199 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003200 Register obj = locations->InAt(0).AsRegister<Register>();
3201 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003202 __ LoadFromOffset(kLoadWord, out, obj, offset);
3203}
3204
3205void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003206 LocationSummary* locations =
3207 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003208 locations->SetInAt(0, Location::RequiresRegister());
3209 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003210 if (instruction->HasUses()) {
3211 locations->SetOut(Location::SameAsFirstInput());
3212 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003213}
3214
3215void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3216 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003217 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003218 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003219 codegen_->AddSlowPath(slow_path);
3220
Roland Levillain271ab9c2014-11-27 15:23:57 +00003221 Register index = locations->InAt(0).AsRegister<Register>();
3222 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003223
3224 __ cmp(index, ShifterOperand(length));
3225 __ b(slow_path->GetEntryLabel(), CS);
3226}
3227
3228void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3229 Label is_null;
3230 __ CompareAndBranchIfZero(value, &is_null);
3231 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3232 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3233 __ strb(card, Address(card, temp));
3234 __ Bind(&is_null);
3235}
3236
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003237void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3238 temp->SetLocations(nullptr);
3239}
3240
3241void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3242 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003243 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003244}
3245
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003246void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003247 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003248 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003249}
3250
3251void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003252 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3253}
3254
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003255void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3256 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3257}
3258
3259void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003260 HBasicBlock* block = instruction->GetBlock();
3261 if (block->GetLoopInformation() != nullptr) {
3262 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3263 // The back edge will generate the suspend check.
3264 return;
3265 }
3266 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3267 // The goto will generate the suspend check.
3268 return;
3269 }
3270 GenerateSuspendCheck(instruction, nullptr);
3271}
3272
3273void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3274 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003275 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003276 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003277 codegen_->AddSlowPath(slow_path);
3278
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003279 __ LoadFromOffset(
3280 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3281 __ cmp(IP, ShifterOperand(0));
3282 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003283 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003284 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003285 __ Bind(slow_path->GetReturnLabel());
3286 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003287 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003288 __ b(slow_path->GetEntryLabel());
3289 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003290}
3291
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003292ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3293 return codegen_->GetAssembler();
3294}
3295
3296void ParallelMoveResolverARM::EmitMove(size_t index) {
3297 MoveOperands* move = moves_.Get(index);
3298 Location source = move->GetSource();
3299 Location destination = move->GetDestination();
3300
3301 if (source.IsRegister()) {
3302 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003303 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003304 } else {
3305 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003306 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003307 SP, destination.GetStackIndex());
3308 }
3309 } else if (source.IsStackSlot()) {
3310 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003311 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003312 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003313 } else if (destination.IsFpuRegister()) {
3314 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003315 } else {
3316 DCHECK(destination.IsStackSlot());
3317 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3318 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3319 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003320 } else if (source.IsFpuRegister()) {
3321 if (destination.IsFpuRegister()) {
3322 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003323 } else {
3324 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003325 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3326 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003327 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00003328 DCHECK(destination.IsDoubleStackSlot()) << destination;
3329 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3330 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3331 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3332 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003333 } else {
3334 DCHECK(source.IsConstant()) << source;
3335 HInstruction* constant = source.GetConstant();
3336 if (constant->IsIntConstant()) {
3337 int32_t value = constant->AsIntConstant()->GetValue();
3338 if (destination.IsRegister()) {
3339 __ LoadImmediate(destination.AsRegister<Register>(), value);
3340 } else {
3341 DCHECK(destination.IsStackSlot());
3342 __ LoadImmediate(IP, value);
3343 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3344 }
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00003345 } else if (constant->IsLongConstant()) {
3346 int64_t value = constant->AsLongConstant()->GetValue();
3347 if (destination.IsRegister()) {
3348 // In the presence of long or double constants, the parallel move resolver will
3349 // split the move into two, but keeps the same constant for both moves. Here,
3350 // we use the low or high part depending on which register this move goes to.
3351 if (destination.reg() % 2 == 0) {
3352 __ LoadImmediate(destination.AsRegister<Register>(), Low32Bits(value));
3353 } else {
3354 __ LoadImmediate(destination.AsRegister<Register>(), High32Bits(value));
3355 }
3356 } else {
3357 DCHECK(destination.IsDoubleStackSlot());
3358 __ LoadImmediate(IP, Low32Bits(value));
3359 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3360 __ LoadImmediate(IP, High32Bits(value));
3361 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3362 }
3363 } else if (constant->IsDoubleConstant()) {
3364 double value = constant->AsDoubleConstant()->GetValue();
3365 uint64_t int_value = bit_cast<uint64_t, double>(value);
3366 if (destination.IsFpuRegister()) {
3367 // In the presence of long or double constants, the parallel move resolver will
3368 // split the move into two, but keeps the same constant for both moves. Here,
3369 // we use the low or high part depending on which register this move goes to.
3370 if (destination.reg() % 2 == 0) {
3371 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3372 bit_cast<float, uint32_t>(Low32Bits(int_value)));
3373 } else {
3374 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3375 bit_cast<float, uint32_t>(High32Bits(int_value)));
3376 }
3377 } else {
3378 DCHECK(destination.IsDoubleStackSlot());
3379 __ LoadImmediate(IP, Low32Bits(int_value));
3380 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3381 __ LoadImmediate(IP, High32Bits(int_value));
3382 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3383 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003384 } else {
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00003385 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003386 float value = constant->AsFloatConstant()->GetValue();
3387 if (destination.IsFpuRegister()) {
3388 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3389 } else {
3390 DCHECK(destination.IsStackSlot());
3391 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3392 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3393 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003394 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003395 }
3396}
3397
3398void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3399 __ Mov(IP, reg);
3400 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3401 __ StoreToOffset(kStoreWord, IP, SP, mem);
3402}
3403
3404void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3405 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3406 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3407 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3408 SP, mem1 + stack_offset);
3409 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3410 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3411 SP, mem2 + stack_offset);
3412 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3413}
3414
3415void ParallelMoveResolverARM::EmitSwap(size_t index) {
3416 MoveOperands* move = moves_.Get(index);
3417 Location source = move->GetSource();
3418 Location destination = move->GetDestination();
3419
3420 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003421 DCHECK_NE(source.AsRegister<Register>(), IP);
3422 DCHECK_NE(destination.AsRegister<Register>(), IP);
3423 __ Mov(IP, source.AsRegister<Register>());
3424 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3425 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003426 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003427 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003428 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003429 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003430 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3431 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003432 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003433 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003434 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003435 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003436 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3437 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3438 : destination.AsFpuRegister<SRegister>();
3439 int mem = source.IsFpuRegister()
3440 ? destination.GetStackIndex()
3441 : source.GetStackIndex();
3442
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003443 __ vmovrs(IP, reg);
3444 __ LoadFromOffset(kLoadWord, IP, SP, mem);
3445 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003446 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003447 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3448 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003449 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003450 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003451 }
3452}
3453
3454void ParallelMoveResolverARM::SpillScratch(int reg) {
3455 __ Push(static_cast<Register>(reg));
3456}
3457
3458void ParallelMoveResolverARM::RestoreScratch(int reg) {
3459 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003460}
3461
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003462void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003463 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3464 ? LocationSummary::kCallOnSlowPath
3465 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003466 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003467 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003468 locations->SetOut(Location::RequiresRegister());
3469}
3470
3471void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003472 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003473 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003474 DCHECK(!cls->CanCallRuntime());
3475 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003476 codegen_->LoadCurrentMethod(out);
3477 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3478 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003479 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003480 codegen_->LoadCurrentMethod(out);
3481 __ LoadFromOffset(
3482 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3483 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003484
3485 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3486 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3487 codegen_->AddSlowPath(slow_path);
3488 __ cmp(out, ShifterOperand(0));
3489 __ b(slow_path->GetEntryLabel(), EQ);
3490 if (cls->MustGenerateClinitCheck()) {
3491 GenerateClassInitializationCheck(slow_path, out);
3492 } else {
3493 __ Bind(slow_path->GetExitLabel());
3494 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003495 }
3496}
3497
3498void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3499 LocationSummary* locations =
3500 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3501 locations->SetInAt(0, Location::RequiresRegister());
3502 if (check->HasUses()) {
3503 locations->SetOut(Location::SameAsFirstInput());
3504 }
3505}
3506
3507void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003508 // We assume the class is not null.
3509 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3510 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003511 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003512 GenerateClassInitializationCheck(slow_path,
3513 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003514}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003515
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003516void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3517 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003518 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3519 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3520 __ b(slow_path->GetEntryLabel(), LT);
3521 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3522 // properly. Therefore, we do a memory fence.
3523 __ dmb(ISH);
3524 __ Bind(slow_path->GetExitLabel());
3525}
3526
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003527void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3528 LocationSummary* locations =
3529 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3530 locations->SetOut(Location::RequiresRegister());
3531}
3532
3533void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3534 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3535 codegen_->AddSlowPath(slow_path);
3536
Roland Levillain271ab9c2014-11-27 15:23:57 +00003537 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003538 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003539 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3540 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003541 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3542 __ cmp(out, ShifterOperand(0));
3543 __ b(slow_path->GetEntryLabel(), EQ);
3544 __ Bind(slow_path->GetExitLabel());
3545}
3546
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003547void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3548 LocationSummary* locations =
3549 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3550 locations->SetOut(Location::RequiresRegister());
3551}
3552
3553void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003554 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003555 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3556 __ LoadFromOffset(kLoadWord, out, TR, offset);
3557 __ LoadImmediate(IP, 0);
3558 __ StoreToOffset(kStoreWord, IP, TR, offset);
3559}
3560
3561void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3562 LocationSummary* locations =
3563 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3564 InvokeRuntimeCallingConvention calling_convention;
3565 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3566}
3567
3568void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3569 codegen_->InvokeRuntime(
3570 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3571}
3572
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003573void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003574 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3575 ? LocationSummary::kNoCall
3576 : LocationSummary::kCallOnSlowPath;
3577 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3578 locations->SetInAt(0, Location::RequiresRegister());
3579 locations->SetInAt(1, Location::RequiresRegister());
3580 locations->SetOut(Location::RequiresRegister());
3581}
3582
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003583void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003584 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003585 Register obj = locations->InAt(0).AsRegister<Register>();
3586 Register cls = locations->InAt(1).AsRegister<Register>();
3587 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003588 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3589 Label done, zero;
3590 SlowPathCodeARM* slow_path = nullptr;
3591
3592 // Return 0 if `obj` is null.
3593 // TODO: avoid this check if we know obj is not null.
3594 __ cmp(obj, ShifterOperand(0));
3595 __ b(&zero, EQ);
3596 // Compare the class of `obj` with `cls`.
3597 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3598 __ cmp(out, ShifterOperand(cls));
3599 if (instruction->IsClassFinal()) {
3600 // Classes must be equal for the instanceof to succeed.
3601 __ b(&zero, NE);
3602 __ LoadImmediate(out, 1);
3603 __ b(&done);
3604 } else {
3605 // If the classes are not equal, we go into a slow path.
3606 DCHECK(locations->OnlyCallsOnSlowPath());
3607 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003608 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003609 codegen_->AddSlowPath(slow_path);
3610 __ b(slow_path->GetEntryLabel(), NE);
3611 __ LoadImmediate(out, 1);
3612 __ b(&done);
3613 }
3614 __ Bind(&zero);
3615 __ LoadImmediate(out, 0);
3616 if (slow_path != nullptr) {
3617 __ Bind(slow_path->GetExitLabel());
3618 }
3619 __ Bind(&done);
3620}
3621
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003622void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3623 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3624 instruction, LocationSummary::kCallOnSlowPath);
3625 locations->SetInAt(0, Location::RequiresRegister());
3626 locations->SetInAt(1, Location::RequiresRegister());
3627 locations->AddTemp(Location::RequiresRegister());
3628}
3629
3630void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3631 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003632 Register obj = locations->InAt(0).AsRegister<Register>();
3633 Register cls = locations->InAt(1).AsRegister<Register>();
3634 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003635 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3636
3637 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3638 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3639 codegen_->AddSlowPath(slow_path);
3640
3641 // TODO: avoid this check if we know obj is not null.
3642 __ cmp(obj, ShifterOperand(0));
3643 __ b(slow_path->GetExitLabel(), EQ);
3644 // Compare the class of `obj` with `cls`.
3645 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3646 __ cmp(temp, ShifterOperand(cls));
3647 __ b(slow_path->GetEntryLabel(), NE);
3648 __ Bind(slow_path->GetExitLabel());
3649}
3650
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003651void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3652 LocationSummary* locations =
3653 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3654 InvokeRuntimeCallingConvention calling_convention;
3655 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3656}
3657
3658void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3659 codegen_->InvokeRuntime(instruction->IsEnter()
3660 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3661 instruction,
3662 instruction->GetDexPc());
3663}
3664
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003665void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3666void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3667void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3668
3669void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3670 LocationSummary* locations =
3671 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3672 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3673 || instruction->GetResultType() == Primitive::kPrimLong);
3674 locations->SetInAt(0, Location::RequiresRegister());
3675 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray41aedbb2015-01-14 10:49:16 +00003676 Location::OutputOverlap output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong)
3677 ? Location::kOutputOverlap
3678 : Location::kNoOutputOverlap;
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003679 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3680}
3681
3682void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3683 HandleBitwiseOperation(instruction);
3684}
3685
3686void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3687 HandleBitwiseOperation(instruction);
3688}
3689
3690void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3691 HandleBitwiseOperation(instruction);
3692}
3693
3694void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3695 LocationSummary* locations = instruction->GetLocations();
3696
3697 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003698 Register first = locations->InAt(0).AsRegister<Register>();
3699 Register second = locations->InAt(1).AsRegister<Register>();
3700 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003701 if (instruction->IsAnd()) {
3702 __ and_(out, first, ShifterOperand(second));
3703 } else if (instruction->IsOr()) {
3704 __ orr(out, first, ShifterOperand(second));
3705 } else {
3706 DCHECK(instruction->IsXor());
3707 __ eor(out, first, ShifterOperand(second));
3708 }
3709 } else {
3710 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3711 Location first = locations->InAt(0);
3712 Location second = locations->InAt(1);
3713 Location out = locations->Out();
3714 if (instruction->IsAnd()) {
3715 __ and_(out.AsRegisterPairLow<Register>(),
3716 first.AsRegisterPairLow<Register>(),
3717 ShifterOperand(second.AsRegisterPairLow<Register>()));
3718 __ and_(out.AsRegisterPairHigh<Register>(),
3719 first.AsRegisterPairHigh<Register>(),
3720 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3721 } else if (instruction->IsOr()) {
3722 __ orr(out.AsRegisterPairLow<Register>(),
3723 first.AsRegisterPairLow<Register>(),
3724 ShifterOperand(second.AsRegisterPairLow<Register>()));
3725 __ orr(out.AsRegisterPairHigh<Register>(),
3726 first.AsRegisterPairHigh<Register>(),
3727 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3728 } else {
3729 DCHECK(instruction->IsXor());
3730 __ eor(out.AsRegisterPairLow<Register>(),
3731 first.AsRegisterPairLow<Register>(),
3732 ShifterOperand(second.AsRegisterPairLow<Register>()));
3733 __ eor(out.AsRegisterPairHigh<Register>(),
3734 first.AsRegisterPairHigh<Register>(),
3735 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3736 }
3737 }
3738}
3739
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003740} // namespace arm
3741} // namespace art