blob: 7731a10b1741a1d9934786b033b7f200bce2661b [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 Geoffray6c2dff82015-01-21 14:56:54 +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 Geoffrayf12feb82014-07-17 18:32:41 +010045static constexpr int kCurrentMethodStackOffset = 0;
46
Calin Juravled6fb6cf2014-11-11 19:07:44 +000047static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010048static constexpr size_t kRuntimeParameterCoreRegistersLength =
49 arraysize(kRuntimeParameterCoreRegisters);
Calin Juravled2ec87d2014-12-08 14:24:46 +000050static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000051static constexpr size_t kRuntimeParameterFpuRegistersLength =
52 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000053// We unconditionally allocate R5 to ensure we can do long operations
54// with baseline.
55static constexpr Register kCoreSavedRegisterForBaseline = R5;
56static constexpr Register kCoreCalleeSaves[] =
57 { R5, R6, R7, R8, R10, R11, PC };
58static constexpr SRegister kFpuCalleeSaves[] =
59 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010060
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000061class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010062 public:
63 InvokeRuntimeCallingConvention()
64 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010065 kRuntimeParameterCoreRegistersLength,
66 kRuntimeParameterFpuRegisters,
67 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010068
69 private:
70 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
71};
72
Nicolas Geoffraye5038322014-07-04 09:41:32 +010073#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010074#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010075
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010076class SlowPathCodeARM : public SlowPathCode {
77 public:
78 SlowPathCodeARM() : entry_label_(), exit_label_() {}
79
80 Label* GetEntryLabel() { return &entry_label_; }
81 Label* GetExitLabel() { return &exit_label_; }
82
83 private:
84 Label entry_label_;
85 Label exit_label_;
86
87 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
88};
89
90class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010091 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010092 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010093
Alexandre Rames67555f72014-11-18 10:55:16 +000094 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010095 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010096 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010097 arm_codegen->InvokeRuntime(
98 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010099 }
100
101 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100102 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100103 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
104};
105
Calin Juravled0d48522014-11-04 16:40:20 +0000106class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
107 public:
108 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
109
Alexandre Rames67555f72014-11-18 10:55:16 +0000110 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000111 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
112 __ Bind(GetEntryLabel());
113 arm_codegen->InvokeRuntime(
114 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
115 }
116
117 private:
118 HDivZeroCheck* const instruction_;
119 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
120};
121
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100122class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000123 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000124 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126
Alexandre Rames67555f72014-11-18 10:55:16 +0000127 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100128 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000129 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100130 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100131 arm_codegen->InvokeRuntime(
132 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100133 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100134 if (successor_ == nullptr) {
135 __ b(GetReturnLabel());
136 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100137 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100138 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000139 }
140
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100141 Label* GetReturnLabel() {
142 DCHECK(successor_ == nullptr);
143 return &return_label_;
144 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000145
146 private:
147 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100148 // If not null, the block to branch to after the suspend check.
149 HBasicBlock* const successor_;
150
151 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000152 Label return_label_;
153
154 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
155};
156
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100157class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100158 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100159 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
160 Location index_location,
161 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100162 : instruction_(instruction),
163 index_location_(index_location),
164 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100165
Alexandre Rames67555f72014-11-18 10:55:16 +0000166 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100167 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000169 // We're moving two locations to locations that could overlap, so we need a parallel
170 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100171 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000172 codegen->EmitParallelMoves(
173 index_location_,
174 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
175 length_location_,
176 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100177 arm_codegen->InvokeRuntime(
178 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100179 }
180
181 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100182 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 const Location index_location_;
184 const Location length_location_;
185
186 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
187};
188
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 LoadClassSlowPathARM(HLoadClass* cls,
192 HInstruction* at,
193 uint32_t dex_pc,
194 bool do_clinit)
195 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
196 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
197 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
Alexandre Rames67555f72014-11-18 10:55:16 +0000199 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 LocationSummary* locations = at_->GetLocations();
201
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
203 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000209 int32_t entry_point_offset = do_clinit_
210 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
211 : QUICK_ENTRY_POINT(pInitializeType);
212 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
213
214 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000215 Location out = locations->Out();
216 if (out.IsValid()) {
217 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000218 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
219 }
220 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100221 __ b(GetExitLabel());
222 }
223
224 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000225 // The class this slow path will load.
226 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100227
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000228 // The instruction where this slow path is happening.
229 // (Might be the load class or an initialization check).
230 HInstruction* const at_;
231
232 // The dex PC of `at_`.
233 const uint32_t dex_pc_;
234
235 // Whether to initialize the class.
236 const bool do_clinit_;
237
238 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100239};
240
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000241class LoadStringSlowPathARM : public SlowPathCodeARM {
242 public:
243 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
244
Alexandre Rames67555f72014-11-18 10:55:16 +0000245 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000246 LocationSummary* locations = instruction_->GetLocations();
247 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
248
249 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
250 __ Bind(GetEntryLabel());
251 codegen->SaveLiveRegisters(locations);
252
253 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800254 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
255 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000256 arm_codegen->InvokeRuntime(
257 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
258 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
259
260 codegen->RestoreLiveRegisters(locations);
261 __ b(GetExitLabel());
262 }
263
264 private:
265 HLoadString* const instruction_;
266
267 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
268};
269
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000270class TypeCheckSlowPathARM : public SlowPathCodeARM {
271 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000272 TypeCheckSlowPathARM(HInstruction* instruction,
273 Location class_to_check,
274 Location object_class,
275 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000276 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000277 class_to_check_(class_to_check),
278 object_class_(object_class),
279 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000280
Alexandre Rames67555f72014-11-18 10:55:16 +0000281 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000282 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000283 DCHECK(instruction_->IsCheckCast()
284 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
286 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
287 __ Bind(GetEntryLabel());
288 codegen->SaveLiveRegisters(locations);
289
290 // We're moving two locations to locations that could overlap, so we need a parallel
291 // move resolver.
292 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000293 codegen->EmitParallelMoves(
294 class_to_check_,
295 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
296 object_class_,
297 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000298
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000299 if (instruction_->IsInstanceOf()) {
300 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
301 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
302 } else {
303 DCHECK(instruction_->IsCheckCast());
304 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
305 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000306
307 codegen->RestoreLiveRegisters(locations);
308 __ b(GetExitLabel());
309 }
310
311 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000312 HInstruction* const instruction_;
313 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000314 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000315 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000316
317 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
318};
319
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000320#undef __
321
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100322#undef __
323#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700324
325inline Condition ARMCondition(IfCondition cond) {
326 switch (cond) {
327 case kCondEQ: return EQ;
328 case kCondNE: return NE;
329 case kCondLT: return LT;
330 case kCondLE: return LE;
331 case kCondGT: return GT;
332 case kCondGE: return GE;
333 default:
334 LOG(FATAL) << "Unknown if condition";
335 }
336 return EQ; // Unreachable.
337}
338
339inline Condition ARMOppositeCondition(IfCondition cond) {
340 switch (cond) {
341 case kCondEQ: return NE;
342 case kCondNE: return EQ;
343 case kCondLT: return GE;
344 case kCondLE: return GT;
345 case kCondGT: return LE;
346 case kCondGE: return LT;
347 default:
348 LOG(FATAL) << "Unknown if condition";
349 }
350 return EQ; // Unreachable.
351}
352
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100353void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
354 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
355}
356
357void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000358 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100359}
360
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100361size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
362 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
363 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100364}
365
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100366size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
367 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
368 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100369}
370
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000371size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
372 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
373 return kArmWordSize;
374}
375
376size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
377 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
378 return kArmWordSize;
379}
380
Calin Juravle34166012014-12-19 17:22:29 +0000381CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000382 const ArmInstructionSetFeatures& isa_features,
383 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000384 : CodeGenerator(graph,
385 kNumberOfCoreRegisters,
386 kNumberOfSRegisters,
387 kNumberOfRegisterPairs,
388 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
389 arraysize(kCoreCalleeSaves)),
390 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
391 arraysize(kFpuCalleeSaves)),
392 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100393 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100394 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100395 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100396 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000397 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000398 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000399 // Save one extra register for baseline. Note that on thumb2, there is no easy
400 // instruction to restore just the PC, so this actually helps both baseline
401 // and non-baseline to save and restore at least two registers at entry and exit.
402 AddAllocatedRegister(Location::RegisterLocation(kCoreSavedRegisterForBaseline));
403 // Save the PC register to mimic Quick.
404 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100405}
406
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100407Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100408 switch (type) {
409 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100410 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100411 ArmManagedRegister pair =
412 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100413 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
414 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
415
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100416 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
417 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100418 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100419 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100420 }
421
422 case Primitive::kPrimByte:
423 case Primitive::kPrimBoolean:
424 case Primitive::kPrimChar:
425 case Primitive::kPrimShort:
426 case Primitive::kPrimInt:
427 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100428 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100429 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100430 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
431 ArmManagedRegister current =
432 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
433 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100434 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100435 }
436 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100437 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438 }
439
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000440 case Primitive::kPrimFloat: {
441 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100442 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100443 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100444
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000445 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000446 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
447 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000448 return Location::FpuRegisterPairLocation(reg, reg + 1);
449 }
450
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100451 case Primitive::kPrimVoid:
452 LOG(FATAL) << "Unreachable type " << type;
453 }
454
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100455 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100456}
457
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000458void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100459 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100460 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100461
462 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100463 blocked_core_registers_[SP] = true;
464 blocked_core_registers_[LR] = true;
465 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100466
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100467 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100468 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100469
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100470 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100471 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100472
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000473 if (is_baseline) {
474 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
475 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
476 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000477
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000478 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
479
480 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
481 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
482 }
483 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100484
485 UpdateBlockedPairRegisters();
486}
487
488void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
489 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
490 ArmManagedRegister current =
491 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
492 if (blocked_core_registers_[current.AsRegisterPairLow()]
493 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
494 blocked_register_pairs_[i] = true;
495 }
496 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100497}
498
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100499InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
500 : HGraphVisitor(graph),
501 assembler_(codegen->GetAssembler()),
502 codegen_(codegen) {}
503
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000504static uint32_t LeastSignificantBit(uint32_t mask) {
505 // ffs starts at 1.
506 return ffs(mask) - 1;
507}
508
509void CodeGeneratorARM::ComputeSpillMask() {
510 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
511 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
512 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
513 // We use vpush and vpop for saving and restoring floating point registers, which take
514 // a SRegister and the number of registers to save/restore after that SRegister. We
515 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
516 // but in the range.
517 if (fpu_spill_mask_ != 0) {
518 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
519 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
520 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
521 fpu_spill_mask_ |= (1 << i);
522 }
523 }
524}
525
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000526void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000527 bool skip_overflow_check =
528 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000529 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000530 __ Bind(&frame_entry_label_);
531
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100532 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000533 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
534 __ LoadFromOffset(kLoadWord, IP, IP, 0);
535 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100536 }
537
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000538 // PC is in the list of callee-save to mimic Quick, but we need to push
539 // LR at entry instead.
540 __ PushList((core_spill_mask_ & (~(1 << PC))) | 1 << LR);
541 if (fpu_spill_mask_ != 0) {
542 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
543 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
544 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000545 __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize()));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100546 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000547}
548
549void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000550 __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000551 if (fpu_spill_mask_ != 0) {
552 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
553 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
554 }
555 __ PopList(core_spill_mask_);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000556}
557
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100558void CodeGeneratorARM::Bind(HBasicBlock* block) {
559 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000560}
561
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100562Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
563 switch (load->GetType()) {
564 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100565 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100566 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
567 break;
568
569 case Primitive::kPrimInt:
570 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100571 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100572 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100573
574 case Primitive::kPrimBoolean:
575 case Primitive::kPrimByte:
576 case Primitive::kPrimChar:
577 case Primitive::kPrimShort:
578 case Primitive::kPrimVoid:
579 LOG(FATAL) << "Unexpected type " << load->GetType();
580 }
581
582 LOG(FATAL) << "Unreachable";
583 return Location();
584}
585
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100586Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
587 switch (type) {
588 case Primitive::kPrimBoolean:
589 case Primitive::kPrimByte:
590 case Primitive::kPrimChar:
591 case Primitive::kPrimShort:
592 case Primitive::kPrimInt:
593 case Primitive::kPrimNot: {
594 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000595 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100596 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100597 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100598 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000599 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100600 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100601 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100602
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000603 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100604 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000605 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100606 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000607 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100608 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000609 if (calling_convention.GetRegisterAt(index) == R1) {
610 // Skip R1, and use R2_R3 instead.
611 gp_index_++;
612 index++;
613 }
614 }
615 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
616 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000617 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000618 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000619 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100620 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000621 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
622 }
623 }
624
625 case Primitive::kPrimFloat: {
626 uint32_t stack_index = stack_index_++;
627 if (float_index_ % 2 == 0) {
628 float_index_ = std::max(double_index_, float_index_);
629 }
630 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
631 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
632 } else {
633 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
634 }
635 }
636
637 case Primitive::kPrimDouble: {
638 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
639 uint32_t stack_index = stack_index_;
640 stack_index_ += 2;
641 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
642 uint32_t index = double_index_;
643 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000644 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000645 calling_convention.GetFpuRegisterAt(index),
646 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000647 DCHECK(ExpectedPairLayout(result));
648 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000649 } else {
650 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100651 }
652 }
653
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100654 case Primitive::kPrimVoid:
655 LOG(FATAL) << "Unexpected parameter type " << type;
656 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100657 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100658 return Location();
659}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100660
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000661Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
662 switch (type) {
663 case Primitive::kPrimBoolean:
664 case Primitive::kPrimByte:
665 case Primitive::kPrimChar:
666 case Primitive::kPrimShort:
667 case Primitive::kPrimInt:
668 case Primitive::kPrimNot: {
669 return Location::RegisterLocation(R0);
670 }
671
672 case Primitive::kPrimFloat: {
673 return Location::FpuRegisterLocation(S0);
674 }
675
676 case Primitive::kPrimLong: {
677 return Location::RegisterPairLocation(R0, R1);
678 }
679
680 case Primitive::kPrimDouble: {
681 return Location::FpuRegisterPairLocation(S0, S1);
682 }
683
684 case Primitive::kPrimVoid:
685 return Location();
686 }
687 UNREACHABLE();
688 return Location();
689}
690
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100691void CodeGeneratorARM::Move32(Location destination, Location source) {
692 if (source.Equals(destination)) {
693 return;
694 }
695 if (destination.IsRegister()) {
696 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000697 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100698 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000699 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100700 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000701 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100702 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100703 } else if (destination.IsFpuRegister()) {
704 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000705 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100706 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000707 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100708 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000709 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100710 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100711 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000712 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100713 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000714 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100715 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000716 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100717 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000718 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100719 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
720 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100721 }
722 }
723}
724
725void CodeGeneratorARM::Move64(Location destination, Location source) {
726 if (source.Equals(destination)) {
727 return;
728 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100729 if (destination.IsRegisterPair()) {
730 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000731 EmitParallelMoves(
732 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
733 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
734 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
735 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100736 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000737 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100738 } else {
739 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000740 DCHECK(ExpectedPairLayout(destination));
741 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
742 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100743 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000744 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100745 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000746 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
747 SP,
748 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100749 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000750 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100751 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100752 } else {
753 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100754 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000755 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100756 if (source.AsRegisterPairLow<Register>() == R1) {
757 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100758 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
759 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100760 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100761 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100762 SP, destination.GetStackIndex());
763 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000764 } else if (source.IsFpuRegisterPair()) {
765 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
766 SP,
767 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 } else {
769 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000770 EmitParallelMoves(
771 Location::StackSlot(source.GetStackIndex()),
772 Location::StackSlot(destination.GetStackIndex()),
773 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
774 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100775 }
776 }
777}
778
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100779void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100780 LocationSummary* locations = instruction->GetLocations();
781 if (locations != nullptr && locations->Out().Equals(location)) {
782 return;
783 }
784
Calin Juravlea21f5982014-11-13 15:53:04 +0000785 if (locations != nullptr && locations->Out().IsConstant()) {
786 HConstant* const_to_move = locations->Out().GetConstant();
787 if (const_to_move->IsIntConstant()) {
788 int32_t value = const_to_move->AsIntConstant()->GetValue();
789 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000790 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000791 } else {
792 DCHECK(location.IsStackSlot());
793 __ LoadImmediate(IP, value);
794 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
795 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000796 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000797 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000798 int64_t value = const_to_move->AsLongConstant()->GetValue();
799 if (location.IsRegisterPair()) {
800 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
801 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
802 } else {
803 DCHECK(location.IsDoubleStackSlot());
804 __ LoadImmediate(IP, Low32Bits(value));
805 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
806 __ LoadImmediate(IP, High32Bits(value));
807 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
808 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100809 }
Roland Levillain476df552014-10-09 17:51:36 +0100810 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100811 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
812 switch (instruction->GetType()) {
813 case Primitive::kPrimBoolean:
814 case Primitive::kPrimByte:
815 case Primitive::kPrimChar:
816 case Primitive::kPrimShort:
817 case Primitive::kPrimInt:
818 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100819 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100820 Move32(location, Location::StackSlot(stack_slot));
821 break;
822
823 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 Move64(location, Location::DoubleStackSlot(stack_slot));
826 break;
827
828 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100829 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000831 } else if (instruction->IsTemporary()) {
832 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000833 if (temp_location.IsStackSlot()) {
834 Move32(location, temp_location);
835 } else {
836 DCHECK(temp_location.IsDoubleStackSlot());
837 Move64(location, temp_location);
838 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000839 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100840 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100841 switch (instruction->GetType()) {
842 case Primitive::kPrimBoolean:
843 case Primitive::kPrimByte:
844 case Primitive::kPrimChar:
845 case Primitive::kPrimShort:
846 case Primitive::kPrimNot:
847 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100848 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100849 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100850 break;
851
852 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100853 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100854 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100855 break;
856
857 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100858 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100859 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000860 }
861}
862
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100863void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
864 HInstruction* instruction,
865 uint32_t dex_pc) {
866 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
867 __ blx(LR);
868 RecordPcInfo(instruction, dex_pc);
869 DCHECK(instruction->IsSuspendCheck()
870 || instruction->IsBoundsCheck()
871 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000872 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000873 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100874 || !IsLeafMethod());
875}
876
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000877void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000878 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000879}
880
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000881void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000882 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100883 DCHECK(!successor->IsExitBlock());
884
885 HBasicBlock* block = got->GetBlock();
886 HInstruction* previous = got->GetPrevious();
887
888 HLoopInformation* info = block->GetLoopInformation();
889 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
890 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
891 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
892 return;
893 }
894
895 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
896 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
897 }
898 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000899 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000900 }
901}
902
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000903void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000904 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000905}
906
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000907void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700908 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000909 if (kIsDebugBuild) {
910 __ Comment("Unreachable");
911 __ bkpt(0);
912 }
913}
914
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000915void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100916 LocationSummary* locations =
917 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100918 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100919 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100920 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100921 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000922}
923
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000924void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700925 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100926 if (cond->IsIntConstant()) {
927 // Constant condition, statically compared against 1.
928 int32_t cond_value = cond->AsIntConstant()->GetValue();
929 if (cond_value == 1) {
930 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
931 if_instr->IfTrueSuccessor())) {
932 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100933 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100934 return;
935 } else {
936 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100937 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100938 } else {
939 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
940 // Condition has been materialized, compare the output to 0
941 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000942 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 ShifterOperand(0));
944 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
945 } else {
946 // Condition has not been materialized, use its inputs as the
947 // comparison and its condition as the branch condition.
948 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000949 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000950 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100951 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000952 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100953 } else {
954 DCHECK(locations->InAt(1).IsConstant());
955 int32_t value =
956 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
957 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000958 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
959 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100960 } else {
961 Register temp = IP;
962 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000963 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100964 }
965 }
966 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
967 ARMCondition(cond->AsCondition()->GetCondition()));
968 }
Dave Allison20dfc792014-06-16 20:44:29 -0700969 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100970 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
971 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700972 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000973 }
974}
975
Dave Allison20dfc792014-06-16 20:44:29 -0700976
977void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100978 LocationSummary* locations =
979 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100980 locations->SetInAt(0, Location::RequiresRegister());
981 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100982 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100983 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100984 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000985}
986
Dave Allison20dfc792014-06-16 20:44:29 -0700987void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100988 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100989 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000990 Register left = locations->InAt(0).AsRegister<Register>();
991
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100992 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000993 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100994 } else {
995 DCHECK(locations->InAt(1).IsConstant());
996 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
997 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000998 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
999 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 } else {
1001 Register temp = IP;
1002 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001003 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001004 }
Dave Allison20dfc792014-06-16 20:44:29 -07001005 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001006 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001007 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001008 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001009 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001010 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001011}
1012
1013void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1014 VisitCondition(comp);
1015}
1016
1017void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1018 VisitCondition(comp);
1019}
1020
1021void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1022 VisitCondition(comp);
1023}
1024
1025void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1026 VisitCondition(comp);
1027}
1028
1029void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1030 VisitCondition(comp);
1031}
1032
1033void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1034 VisitCondition(comp);
1035}
1036
1037void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1038 VisitCondition(comp);
1039}
1040
1041void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1042 VisitCondition(comp);
1043}
1044
1045void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1046 VisitCondition(comp);
1047}
1048
1049void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1050 VisitCondition(comp);
1051}
1052
1053void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1054 VisitCondition(comp);
1055}
1056
1057void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1058 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001059}
1060
1061void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001062 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001063}
1064
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001065void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1066 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001067}
1068
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001069void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001070 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001071}
1072
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001073void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001074 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001075 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001076}
1077
1078void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001079 LocationSummary* locations =
1080 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001081 switch (store->InputAt(1)->GetType()) {
1082 case Primitive::kPrimBoolean:
1083 case Primitive::kPrimByte:
1084 case Primitive::kPrimChar:
1085 case Primitive::kPrimShort:
1086 case Primitive::kPrimInt:
1087 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001088 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001089 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1090 break;
1091
1092 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001093 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001094 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1095 break;
1096
1097 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001098 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001099 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001100}
1101
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001102void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001103 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001104}
1105
1106void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001107 LocationSummary* locations =
1108 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001109 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001110}
1111
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001112void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001113 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001114 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001115}
1116
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001117void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001118 LocationSummary* locations =
1119 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001120 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001121}
1122
1123void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1124 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001125 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001126}
1127
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001128void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1129 LocationSummary* locations =
1130 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1131 locations->SetOut(Location::ConstantLocation(constant));
1132}
1133
1134void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1135 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001136 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001137}
1138
1139void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1140 LocationSummary* locations =
1141 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1142 locations->SetOut(Location::ConstantLocation(constant));
1143}
1144
1145void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1146 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001147 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001148}
1149
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001150void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001151 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001152}
1153
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001154void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001155 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001156 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001157}
1158
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001159void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001160 LocationSummary* locations =
1161 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001162 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001163}
1164
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001165void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001166 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001167 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001168}
1169
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001170void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001171 HandleInvoke(invoke);
1172}
1173
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001174void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001175 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001176}
1177
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001178void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001179 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001180
1181 // TODO: Implement all kinds of calls:
1182 // 1) boot -> boot
1183 // 2) app -> boot
1184 // 3) app -> app
1185 //
1186 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1187
1188 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001189 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001190 if (!invoke->IsRecursive()) {
1191 // temp = temp->dex_cache_resolved_methods_;
1192 __ LoadFromOffset(
1193 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
1194 // temp = temp[index_in_cache]
1195 __ LoadFromOffset(
1196 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
1197 // LR = temp[offset_of_quick_compiled_code]
1198 __ LoadFromOffset(kLoadWord, LR, temp,
1199 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1200 kArmWordSize).Int32Value());
1201 // LR()
1202 __ blx(LR);
1203 } else {
1204 __ bl(codegen_->GetFrameEntryLabel());
1205 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001206
1207 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1208 DCHECK(!codegen_->IsLeafMethod());
1209}
1210
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001211void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001212 LocationSummary* locations =
1213 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001214 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001215
1216 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001217 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001218 HInstruction* input = invoke->InputAt(i);
1219 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1220 }
1221
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001222 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001223}
1224
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001225void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1226 HandleInvoke(invoke);
1227}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001228
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001229void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001230 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001231 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1232 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1233 LocationSummary* locations = invoke->GetLocations();
1234 Location receiver = locations->InAt(0);
1235 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1236 // temp = object->GetClass();
1237 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001238 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1239 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001240 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001241 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001242 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001243 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001244 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001245 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001246 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001247 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001248 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001249 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001250 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001251 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001252 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001253 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001254}
1255
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001256void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1257 HandleInvoke(invoke);
1258 // Add the hidden argument.
1259 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1260}
1261
1262void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1263 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001264 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001265 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1266 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1267 LocationSummary* locations = invoke->GetLocations();
1268 Location receiver = locations->InAt(0);
1269 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1270
1271 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001272 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1273 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001274
1275 // temp = object->GetClass();
1276 if (receiver.IsStackSlot()) {
1277 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1278 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1279 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001280 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001281 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001282 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001283 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001284 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001285 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001286 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1287 // LR = temp->GetEntryPoint();
1288 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1289 // LR();
1290 __ blx(LR);
1291 DCHECK(!codegen_->IsLeafMethod());
1292 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1293}
1294
Roland Levillain88cb1752014-10-20 16:36:47 +01001295void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1296 LocationSummary* locations =
1297 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1298 switch (neg->GetResultType()) {
1299 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001300 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001301 Location::OutputOverlap output_overlaps = (neg->GetResultType() == Primitive::kPrimLong)
1302 ? Location::kOutputOverlap
1303 : Location::kNoOutputOverlap;
Roland Levillain88cb1752014-10-20 16:36:47 +01001304 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001305 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001306 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001307 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001308
Roland Levillain88cb1752014-10-20 16:36:47 +01001309 case Primitive::kPrimFloat:
1310 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001311 locations->SetInAt(0, Location::RequiresFpuRegister());
1312 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001313 break;
1314
1315 default:
1316 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1317 }
1318}
1319
1320void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1321 LocationSummary* locations = neg->GetLocations();
1322 Location out = locations->Out();
1323 Location in = locations->InAt(0);
1324 switch (neg->GetResultType()) {
1325 case Primitive::kPrimInt:
1326 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001327 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001328 break;
1329
1330 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001331 DCHECK(in.IsRegisterPair());
1332 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1333 __ rsbs(out.AsRegisterPairLow<Register>(),
1334 in.AsRegisterPairLow<Register>(),
1335 ShifterOperand(0));
1336 // We cannot emit an RSC (Reverse Subtract with Carry)
1337 // instruction here, as it does not exist in the Thumb-2
1338 // instruction set. We use the following approach
1339 // using SBC and SUB instead.
1340 //
1341 // out.hi = -C
1342 __ sbc(out.AsRegisterPairHigh<Register>(),
1343 out.AsRegisterPairHigh<Register>(),
1344 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1345 // out.hi = out.hi - in.hi
1346 __ sub(out.AsRegisterPairHigh<Register>(),
1347 out.AsRegisterPairHigh<Register>(),
1348 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1349 break;
1350
Roland Levillain88cb1752014-10-20 16:36:47 +01001351 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001352 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001353 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001354 break;
1355
Roland Levillain88cb1752014-10-20 16:36:47 +01001356 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001357 DCHECK(in.IsFpuRegisterPair());
1358 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1359 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001360 break;
1361
1362 default:
1363 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1364 }
1365}
1366
Roland Levillaindff1f282014-11-05 14:15:05 +00001367void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001368 Primitive::Type result_type = conversion->GetResultType();
1369 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001370 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001371
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001372 // The float-to-long and double-to-long type conversions rely on a
1373 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001374 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001375 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1376 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001377 ? LocationSummary::kCall
1378 : LocationSummary::kNoCall;
1379 LocationSummary* locations =
1380 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1381
Roland Levillaindff1f282014-11-05 14:15:05 +00001382 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001383 case Primitive::kPrimByte:
1384 switch (input_type) {
1385 case Primitive::kPrimShort:
1386 case Primitive::kPrimInt:
1387 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001388 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001389 locations->SetInAt(0, Location::RequiresRegister());
1390 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1391 break;
1392
1393 default:
1394 LOG(FATAL) << "Unexpected type conversion from " << input_type
1395 << " to " << result_type;
1396 }
1397 break;
1398
Roland Levillain01a8d712014-11-14 16:27:39 +00001399 case Primitive::kPrimShort:
1400 switch (input_type) {
1401 case Primitive::kPrimByte:
1402 case Primitive::kPrimInt:
1403 case Primitive::kPrimChar:
1404 // Processing a Dex `int-to-short' instruction.
1405 locations->SetInAt(0, Location::RequiresRegister());
1406 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1407 break;
1408
1409 default:
1410 LOG(FATAL) << "Unexpected type conversion from " << input_type
1411 << " to " << result_type;
1412 }
1413 break;
1414
Roland Levillain946e1432014-11-11 17:35:19 +00001415 case Primitive::kPrimInt:
1416 switch (input_type) {
1417 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001418 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001419 locations->SetInAt(0, Location::Any());
1420 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1421 break;
1422
1423 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001424 // Processing a Dex `float-to-int' instruction.
1425 locations->SetInAt(0, Location::RequiresFpuRegister());
1426 locations->SetOut(Location::RequiresRegister());
1427 locations->AddTemp(Location::RequiresFpuRegister());
1428 break;
1429
Roland Levillain946e1432014-11-11 17:35:19 +00001430 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001431 // Processing a Dex `double-to-int' instruction.
1432 locations->SetInAt(0, Location::RequiresFpuRegister());
1433 locations->SetOut(Location::RequiresRegister());
1434 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001435 break;
1436
1437 default:
1438 LOG(FATAL) << "Unexpected type conversion from " << input_type
1439 << " to " << result_type;
1440 }
1441 break;
1442
Roland Levillaindff1f282014-11-05 14:15:05 +00001443 case Primitive::kPrimLong:
1444 switch (input_type) {
1445 case Primitive::kPrimByte:
1446 case Primitive::kPrimShort:
1447 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001448 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001449 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001450 locations->SetInAt(0, Location::RequiresRegister());
1451 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1452 break;
1453
Roland Levillain624279f2014-12-04 11:54:28 +00001454 case Primitive::kPrimFloat: {
1455 // Processing a Dex `float-to-long' instruction.
1456 InvokeRuntimeCallingConvention calling_convention;
1457 locations->SetInAt(0, Location::FpuRegisterLocation(
1458 calling_convention.GetFpuRegisterAt(0)));
1459 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1460 break;
1461 }
1462
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001463 case Primitive::kPrimDouble: {
1464 // Processing a Dex `double-to-long' instruction.
1465 InvokeRuntimeCallingConvention calling_convention;
1466 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1467 calling_convention.GetFpuRegisterAt(0),
1468 calling_convention.GetFpuRegisterAt(1)));
1469 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001470 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001471 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001472
1473 default:
1474 LOG(FATAL) << "Unexpected type conversion from " << input_type
1475 << " to " << result_type;
1476 }
1477 break;
1478
Roland Levillain981e4542014-11-14 11:47:14 +00001479 case Primitive::kPrimChar:
1480 switch (input_type) {
1481 case Primitive::kPrimByte:
1482 case Primitive::kPrimShort:
1483 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001484 // Processing a Dex `int-to-char' instruction.
1485 locations->SetInAt(0, Location::RequiresRegister());
1486 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1487 break;
1488
1489 default:
1490 LOG(FATAL) << "Unexpected type conversion from " << input_type
1491 << " to " << result_type;
1492 }
1493 break;
1494
Roland Levillaindff1f282014-11-05 14:15:05 +00001495 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001496 switch (input_type) {
1497 case Primitive::kPrimByte:
1498 case Primitive::kPrimShort:
1499 case Primitive::kPrimInt:
1500 case Primitive::kPrimChar:
1501 // Processing a Dex `int-to-float' instruction.
1502 locations->SetInAt(0, Location::RequiresRegister());
1503 locations->SetOut(Location::RequiresFpuRegister());
1504 break;
1505
1506 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001507 // Processing a Dex `long-to-float' instruction.
1508 locations->SetInAt(0, Location::RequiresRegister());
1509 locations->SetOut(Location::RequiresFpuRegister());
1510 locations->AddTemp(Location::RequiresRegister());
1511 locations->AddTemp(Location::RequiresRegister());
1512 locations->AddTemp(Location::RequiresFpuRegister());
1513 locations->AddTemp(Location::RequiresFpuRegister());
1514 break;
1515
Roland Levillaincff13742014-11-17 14:32:17 +00001516 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001517 // Processing a Dex `double-to-float' instruction.
1518 locations->SetInAt(0, Location::RequiresFpuRegister());
1519 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001520 break;
1521
1522 default:
1523 LOG(FATAL) << "Unexpected type conversion from " << input_type
1524 << " to " << result_type;
1525 };
1526 break;
1527
Roland Levillaindff1f282014-11-05 14:15:05 +00001528 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001529 switch (input_type) {
1530 case Primitive::kPrimByte:
1531 case Primitive::kPrimShort:
1532 case Primitive::kPrimInt:
1533 case Primitive::kPrimChar:
1534 // Processing a Dex `int-to-double' instruction.
1535 locations->SetInAt(0, Location::RequiresRegister());
1536 locations->SetOut(Location::RequiresFpuRegister());
1537 break;
1538
1539 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001540 // Processing a Dex `long-to-double' instruction.
1541 locations->SetInAt(0, Location::RequiresRegister());
1542 locations->SetOut(Location::RequiresFpuRegister());
1543 locations->AddTemp(Location::RequiresRegister());
1544 locations->AddTemp(Location::RequiresRegister());
1545 locations->AddTemp(Location::RequiresFpuRegister());
1546 break;
1547
Roland Levillaincff13742014-11-17 14:32:17 +00001548 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001549 // Processing a Dex `float-to-double' instruction.
1550 locations->SetInAt(0, Location::RequiresFpuRegister());
1551 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001552 break;
1553
1554 default:
1555 LOG(FATAL) << "Unexpected type conversion from " << input_type
1556 << " to " << result_type;
1557 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001558 break;
1559
1560 default:
1561 LOG(FATAL) << "Unexpected type conversion from " << input_type
1562 << " to " << result_type;
1563 }
1564}
1565
1566void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1567 LocationSummary* locations = conversion->GetLocations();
1568 Location out = locations->Out();
1569 Location in = locations->InAt(0);
1570 Primitive::Type result_type = conversion->GetResultType();
1571 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001572 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001573 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001574 case Primitive::kPrimByte:
1575 switch (input_type) {
1576 case Primitive::kPrimShort:
1577 case Primitive::kPrimInt:
1578 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001579 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001580 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001581 break;
1582
1583 default:
1584 LOG(FATAL) << "Unexpected type conversion from " << input_type
1585 << " to " << result_type;
1586 }
1587 break;
1588
Roland Levillain01a8d712014-11-14 16:27:39 +00001589 case Primitive::kPrimShort:
1590 switch (input_type) {
1591 case Primitive::kPrimByte:
1592 case Primitive::kPrimInt:
1593 case Primitive::kPrimChar:
1594 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001595 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001596 break;
1597
1598 default:
1599 LOG(FATAL) << "Unexpected type conversion from " << input_type
1600 << " to " << result_type;
1601 }
1602 break;
1603
Roland Levillain946e1432014-11-11 17:35:19 +00001604 case Primitive::kPrimInt:
1605 switch (input_type) {
1606 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001607 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001608 DCHECK(out.IsRegister());
1609 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001610 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001611 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001612 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001613 } else {
1614 DCHECK(in.IsConstant());
1615 DCHECK(in.GetConstant()->IsLongConstant());
1616 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001617 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001618 }
1619 break;
1620
Roland Levillain3f8f9362014-12-02 17:45:01 +00001621 case Primitive::kPrimFloat: {
1622 // Processing a Dex `float-to-int' instruction.
1623 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1624 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1625 __ vcvtis(temp, temp);
1626 __ vmovrs(out.AsRegister<Register>(), temp);
1627 break;
1628 }
1629
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001630 case Primitive::kPrimDouble: {
1631 // Processing a Dex `double-to-int' instruction.
1632 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1633 DRegister temp_d = FromLowSToD(temp_s);
1634 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1635 __ vcvtid(temp_s, temp_d);
1636 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001637 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001638 }
Roland Levillain946e1432014-11-11 17:35:19 +00001639
1640 default:
1641 LOG(FATAL) << "Unexpected type conversion from " << input_type
1642 << " to " << result_type;
1643 }
1644 break;
1645
Roland Levillaindff1f282014-11-05 14:15:05 +00001646 case Primitive::kPrimLong:
1647 switch (input_type) {
1648 case Primitive::kPrimByte:
1649 case Primitive::kPrimShort:
1650 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001651 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001652 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001653 DCHECK(out.IsRegisterPair());
1654 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001655 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001656 // Sign extension.
1657 __ Asr(out.AsRegisterPairHigh<Register>(),
1658 out.AsRegisterPairLow<Register>(),
1659 31);
1660 break;
1661
1662 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001663 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001664 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1665 conversion,
1666 conversion->GetDexPc());
1667 break;
1668
Roland Levillaindff1f282014-11-05 14:15:05 +00001669 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001670 // Processing a Dex `double-to-long' instruction.
1671 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1672 conversion,
1673 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001674 break;
1675
1676 default:
1677 LOG(FATAL) << "Unexpected type conversion from " << input_type
1678 << " to " << result_type;
1679 }
1680 break;
1681
Roland Levillain981e4542014-11-14 11:47:14 +00001682 case Primitive::kPrimChar:
1683 switch (input_type) {
1684 case Primitive::kPrimByte:
1685 case Primitive::kPrimShort:
1686 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001687 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001688 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001689 break;
1690
1691 default:
1692 LOG(FATAL) << "Unexpected type conversion from " << input_type
1693 << " to " << result_type;
1694 }
1695 break;
1696
Roland Levillaindff1f282014-11-05 14:15:05 +00001697 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001698 switch (input_type) {
1699 case Primitive::kPrimByte:
1700 case Primitive::kPrimShort:
1701 case Primitive::kPrimInt:
1702 case Primitive::kPrimChar: {
1703 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001704 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1705 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001706 break;
1707 }
1708
Roland Levillain6d0e4832014-11-27 18:31:21 +00001709 case Primitive::kPrimLong: {
1710 // Processing a Dex `long-to-float' instruction.
1711 Register low = in.AsRegisterPairLow<Register>();
1712 Register high = in.AsRegisterPairHigh<Register>();
1713 SRegister output = out.AsFpuRegister<SRegister>();
1714 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1715 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1716 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1717 DRegister temp1_d = FromLowSToD(temp1_s);
1718 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1719 DRegister temp2_d = FromLowSToD(temp2_s);
1720
1721 // Operations use doubles for precision reasons (each 32-bit
1722 // half of a long fits in the 53-bit mantissa of a double,
1723 // but not in the 24-bit mantissa of a float). This is
1724 // especially important for the low bits. The result is
1725 // eventually converted to float.
1726
1727 // temp1_d = int-to-double(high)
1728 __ vmovsr(temp1_s, high);
1729 __ vcvtdi(temp1_d, temp1_s);
1730 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1731 // as an immediate value into `temp2_d` does not work, as
1732 // this instruction only transfers 8 significant bits of its
1733 // immediate operand. Instead, use two 32-bit core
1734 // registers to load `k2Pow32EncodingForDouble` into
1735 // `temp2_d`.
1736 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1737 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1738 __ vmovdrr(temp2_d, constant_low, constant_high);
1739 // temp1_d = temp1_d * 2^32
1740 __ vmuld(temp1_d, temp1_d, temp2_d);
1741 // temp2_d = unsigned-to-double(low)
1742 __ vmovsr(temp2_s, low);
1743 __ vcvtdu(temp2_d, temp2_s);
1744 // temp1_d = temp1_d + temp2_d
1745 __ vaddd(temp1_d, temp1_d, temp2_d);
1746 // output = double-to-float(temp1_d);
1747 __ vcvtsd(output, temp1_d);
1748 break;
1749 }
1750
Roland Levillaincff13742014-11-17 14:32:17 +00001751 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001752 // Processing a Dex `double-to-float' instruction.
1753 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1754 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001755 break;
1756
1757 default:
1758 LOG(FATAL) << "Unexpected type conversion from " << input_type
1759 << " to " << result_type;
1760 };
1761 break;
1762
Roland Levillaindff1f282014-11-05 14:15:05 +00001763 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001764 switch (input_type) {
1765 case Primitive::kPrimByte:
1766 case Primitive::kPrimShort:
1767 case Primitive::kPrimInt:
1768 case Primitive::kPrimChar: {
1769 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001770 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001771 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1772 out.AsFpuRegisterPairLow<SRegister>());
1773 break;
1774 }
1775
Roland Levillain647b9ed2014-11-27 12:06:00 +00001776 case Primitive::kPrimLong: {
1777 // Processing a Dex `long-to-double' instruction.
1778 Register low = in.AsRegisterPairLow<Register>();
1779 Register high = in.AsRegisterPairHigh<Register>();
1780 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1781 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001782 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1783 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001784 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1785 DRegister temp_d = FromLowSToD(temp_s);
1786
Roland Levillain647b9ed2014-11-27 12:06:00 +00001787 // out_d = int-to-double(high)
1788 __ vmovsr(out_s, high);
1789 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001790 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1791 // as an immediate value into `temp_d` does not work, as
1792 // this instruction only transfers 8 significant bits of its
1793 // immediate operand. Instead, use two 32-bit core
1794 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1795 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1796 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001797 __ vmovdrr(temp_d, constant_low, constant_high);
1798 // out_d = out_d * 2^32
1799 __ vmuld(out_d, out_d, temp_d);
1800 // temp_d = unsigned-to-double(low)
1801 __ vmovsr(temp_s, low);
1802 __ vcvtdu(temp_d, temp_s);
1803 // out_d = out_d + temp_d
1804 __ vaddd(out_d, out_d, temp_d);
1805 break;
1806 }
1807
Roland Levillaincff13742014-11-17 14:32:17 +00001808 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001809 // Processing a Dex `float-to-double' instruction.
1810 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1811 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001812 break;
1813
1814 default:
1815 LOG(FATAL) << "Unexpected type conversion from " << input_type
1816 << " to " << result_type;
1817 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001818 break;
1819
1820 default:
1821 LOG(FATAL) << "Unexpected type conversion from " << input_type
1822 << " to " << result_type;
1823 }
1824}
1825
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001826void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001827 LocationSummary* locations =
1828 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001829 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001830 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001831 locations->SetInAt(0, Location::RequiresRegister());
1832 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001833 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1834 break;
1835 }
1836
1837 case Primitive::kPrimLong: {
1838 locations->SetInAt(0, Location::RequiresRegister());
1839 locations->SetInAt(1, Location::RequiresRegister());
1840 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001841 break;
1842 }
1843
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001844 case Primitive::kPrimFloat:
1845 case Primitive::kPrimDouble: {
1846 locations->SetInAt(0, Location::RequiresFpuRegister());
1847 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001848 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001849 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001850 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001851
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001852 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001853 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001854 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001855}
1856
1857void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1858 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001859 Location out = locations->Out();
1860 Location first = locations->InAt(0);
1861 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001862 switch (add->GetResultType()) {
1863 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001864 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001865 __ add(out.AsRegister<Register>(),
1866 first.AsRegister<Register>(),
1867 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001868 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001869 __ AddConstant(out.AsRegister<Register>(),
1870 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001871 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001872 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001873 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001874
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001875 case Primitive::kPrimLong: {
1876 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001877 __ adds(out.AsRegisterPairLow<Register>(),
1878 first.AsRegisterPairLow<Register>(),
1879 ShifterOperand(second.AsRegisterPairLow<Register>()));
1880 __ adc(out.AsRegisterPairHigh<Register>(),
1881 first.AsRegisterPairHigh<Register>(),
1882 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001883 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001884 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001885
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001886 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001887 __ vadds(out.AsFpuRegister<SRegister>(),
1888 first.AsFpuRegister<SRegister>(),
1889 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001890 break;
1891
1892 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001893 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1894 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1895 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001896 break;
1897
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001898 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001899 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001900 }
1901}
1902
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001903void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001904 LocationSummary* locations =
1905 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001906 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001907 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001908 locations->SetInAt(0, Location::RequiresRegister());
1909 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001910 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1911 break;
1912 }
1913
1914 case Primitive::kPrimLong: {
1915 locations->SetInAt(0, Location::RequiresRegister());
1916 locations->SetInAt(1, Location::RequiresRegister());
1917 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001918 break;
1919 }
Calin Juravle11351682014-10-23 15:38:15 +01001920 case Primitive::kPrimFloat:
1921 case Primitive::kPrimDouble: {
1922 locations->SetInAt(0, Location::RequiresFpuRegister());
1923 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001924 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001925 break;
Calin Juravle11351682014-10-23 15:38:15 +01001926 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001927 default:
Calin Juravle11351682014-10-23 15:38:15 +01001928 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001929 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001930}
1931
1932void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1933 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001934 Location out = locations->Out();
1935 Location first = locations->InAt(0);
1936 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001937 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001938 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001939 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001940 __ sub(out.AsRegister<Register>(),
1941 first.AsRegister<Register>(),
1942 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001943 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001944 __ AddConstant(out.AsRegister<Register>(),
1945 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001946 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001947 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001948 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001949 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001950
Calin Juravle11351682014-10-23 15:38:15 +01001951 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001952 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001953 __ subs(out.AsRegisterPairLow<Register>(),
1954 first.AsRegisterPairLow<Register>(),
1955 ShifterOperand(second.AsRegisterPairLow<Register>()));
1956 __ sbc(out.AsRegisterPairHigh<Register>(),
1957 first.AsRegisterPairHigh<Register>(),
1958 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001959 break;
Calin Juravle11351682014-10-23 15:38:15 +01001960 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001961
Calin Juravle11351682014-10-23 15:38:15 +01001962 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001963 __ vsubs(out.AsFpuRegister<SRegister>(),
1964 first.AsFpuRegister<SRegister>(),
1965 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001966 break;
Calin Juravle11351682014-10-23 15:38:15 +01001967 }
1968
1969 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001970 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1971 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1972 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001973 break;
1974 }
1975
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001976
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001977 default:
Calin Juravle11351682014-10-23 15:38:15 +01001978 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001979 }
1980}
1981
Calin Juravle34bacdf2014-10-07 20:23:36 +01001982void LocationsBuilderARM::VisitMul(HMul* mul) {
1983 LocationSummary* locations =
1984 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1985 switch (mul->GetResultType()) {
1986 case Primitive::kPrimInt:
1987 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001988 locations->SetInAt(0, Location::RequiresRegister());
1989 locations->SetInAt(1, Location::RequiresRegister());
1990 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001991 break;
1992 }
1993
Calin Juravleb5bfa962014-10-21 18:02:24 +01001994 case Primitive::kPrimFloat:
1995 case Primitive::kPrimDouble: {
1996 locations->SetInAt(0, Location::RequiresFpuRegister());
1997 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001998 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001999 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002000 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002001
2002 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002003 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002004 }
2005}
2006
2007void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2008 LocationSummary* locations = mul->GetLocations();
2009 Location out = locations->Out();
2010 Location first = locations->InAt(0);
2011 Location second = locations->InAt(1);
2012 switch (mul->GetResultType()) {
2013 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002014 __ mul(out.AsRegister<Register>(),
2015 first.AsRegister<Register>(),
2016 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002017 break;
2018 }
2019 case Primitive::kPrimLong: {
2020 Register out_hi = out.AsRegisterPairHigh<Register>();
2021 Register out_lo = out.AsRegisterPairLow<Register>();
2022 Register in1_hi = first.AsRegisterPairHigh<Register>();
2023 Register in1_lo = first.AsRegisterPairLow<Register>();
2024 Register in2_hi = second.AsRegisterPairHigh<Register>();
2025 Register in2_lo = second.AsRegisterPairLow<Register>();
2026
2027 // Extra checks to protect caused by the existence of R1_R2.
2028 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2029 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2030 DCHECK_NE(out_hi, in1_lo);
2031 DCHECK_NE(out_hi, in2_lo);
2032
2033 // input: in1 - 64 bits, in2 - 64 bits
2034 // output: out
2035 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2036 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2037 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2038
2039 // IP <- in1.lo * in2.hi
2040 __ mul(IP, in1_lo, in2_hi);
2041 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2042 __ mla(out_hi, in1_hi, in2_lo, IP);
2043 // out.lo <- (in1.lo * in2.lo)[31:0];
2044 __ umull(out_lo, IP, in1_lo, in2_lo);
2045 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2046 __ add(out_hi, out_hi, ShifterOperand(IP));
2047 break;
2048 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002049
2050 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002051 __ vmuls(out.AsFpuRegister<SRegister>(),
2052 first.AsFpuRegister<SRegister>(),
2053 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002054 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002055 }
2056
2057 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002058 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2059 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2060 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002061 break;
2062 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002063
2064 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002065 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002066 }
2067}
2068
Calin Juravle7c4954d2014-10-28 16:57:40 +00002069void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002070 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2071 ? LocationSummary::kCall
2072 : LocationSummary::kNoCall;
2073 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2074
Calin Juravle7c4954d2014-10-28 16:57:40 +00002075 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002076 case Primitive::kPrimInt: {
2077 locations->SetInAt(0, Location::RequiresRegister());
2078 locations->SetInAt(1, Location::RequiresRegister());
2079 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2080 break;
2081 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002082 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002083 InvokeRuntimeCallingConvention calling_convention;
2084 locations->SetInAt(0, Location::RegisterPairLocation(
2085 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2086 locations->SetInAt(1, Location::RegisterPairLocation(
2087 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002088 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002089 break;
2090 }
2091 case Primitive::kPrimFloat:
2092 case Primitive::kPrimDouble: {
2093 locations->SetInAt(0, Location::RequiresFpuRegister());
2094 locations->SetInAt(1, Location::RequiresFpuRegister());
2095 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2096 break;
2097 }
2098
2099 default:
2100 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2101 }
2102}
2103
2104void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2105 LocationSummary* locations = div->GetLocations();
2106 Location out = locations->Out();
2107 Location first = locations->InAt(0);
2108 Location second = locations->InAt(1);
2109
2110 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002111 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002112 __ sdiv(out.AsRegister<Register>(),
2113 first.AsRegister<Register>(),
2114 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002115 break;
2116 }
2117
Calin Juravle7c4954d2014-10-28 16:57:40 +00002118 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002119 InvokeRuntimeCallingConvention calling_convention;
2120 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2121 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2122 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2123 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2124 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002125 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002126
2127 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002128 break;
2129 }
2130
2131 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002132 __ vdivs(out.AsFpuRegister<SRegister>(),
2133 first.AsFpuRegister<SRegister>(),
2134 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002135 break;
2136 }
2137
2138 case Primitive::kPrimDouble: {
2139 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2140 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2141 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2142 break;
2143 }
2144
2145 default:
2146 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2147 }
2148}
2149
Calin Juravlebacfec32014-11-14 15:54:36 +00002150void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002151 Primitive::Type type = rem->GetResultType();
2152 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2153 ? LocationSummary::kNoCall
2154 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002155 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2156
Calin Juravled2ec87d2014-12-08 14:24:46 +00002157 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002158 case Primitive::kPrimInt: {
2159 locations->SetInAt(0, Location::RequiresRegister());
2160 locations->SetInAt(1, Location::RequiresRegister());
2161 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2162 locations->AddTemp(Location::RequiresRegister());
2163 break;
2164 }
2165 case Primitive::kPrimLong: {
2166 InvokeRuntimeCallingConvention calling_convention;
2167 locations->SetInAt(0, Location::RegisterPairLocation(
2168 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2169 locations->SetInAt(1, Location::RegisterPairLocation(
2170 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2171 // The runtime helper puts the output in R2,R3.
2172 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2173 break;
2174 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002175 case Primitive::kPrimFloat: {
2176 InvokeRuntimeCallingConvention calling_convention;
2177 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2178 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2179 locations->SetOut(Location::FpuRegisterLocation(S0));
2180 break;
2181 }
2182
Calin Juravlebacfec32014-11-14 15:54:36 +00002183 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002184 InvokeRuntimeCallingConvention calling_convention;
2185 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2186 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2187 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2188 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2189 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002190 break;
2191 }
2192
2193 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002194 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002195 }
2196}
2197
2198void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2199 LocationSummary* locations = rem->GetLocations();
2200 Location out = locations->Out();
2201 Location first = locations->InAt(0);
2202 Location second = locations->InAt(1);
2203
Calin Juravled2ec87d2014-12-08 14:24:46 +00002204 Primitive::Type type = rem->GetResultType();
2205 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002206 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002207 Register reg1 = first.AsRegister<Register>();
2208 Register reg2 = second.AsRegister<Register>();
2209 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002210
2211 // temp = reg1 / reg2 (integer division)
2212 // temp = temp * reg2
2213 // dest = reg1 - temp
2214 __ sdiv(temp, reg1, reg2);
2215 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002216 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002217 break;
2218 }
2219
2220 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002221 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2222 break;
2223 }
2224
Calin Juravled2ec87d2014-12-08 14:24:46 +00002225 case Primitive::kPrimFloat: {
2226 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2227 break;
2228 }
2229
Calin Juravlebacfec32014-11-14 15:54:36 +00002230 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002231 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002232 break;
2233 }
2234
2235 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002236 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002237 }
2238}
2239
Calin Juravled0d48522014-11-04 16:40:20 +00002240void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2241 LocationSummary* locations =
2242 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002243 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002244 if (instruction->HasUses()) {
2245 locations->SetOut(Location::SameAsFirstInput());
2246 }
2247}
2248
2249void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2250 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2251 codegen_->AddSlowPath(slow_path);
2252
2253 LocationSummary* locations = instruction->GetLocations();
2254 Location value = locations->InAt(0);
2255
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002256 switch (instruction->GetType()) {
2257 case Primitive::kPrimInt: {
2258 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002259 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002260 __ b(slow_path->GetEntryLabel(), EQ);
2261 } else {
2262 DCHECK(value.IsConstant()) << value;
2263 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2264 __ b(slow_path->GetEntryLabel());
2265 }
2266 }
2267 break;
2268 }
2269 case Primitive::kPrimLong: {
2270 if (value.IsRegisterPair()) {
2271 __ orrs(IP,
2272 value.AsRegisterPairLow<Register>(),
2273 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2274 __ b(slow_path->GetEntryLabel(), EQ);
2275 } else {
2276 DCHECK(value.IsConstant()) << value;
2277 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2278 __ b(slow_path->GetEntryLabel());
2279 }
2280 }
2281 break;
2282 default:
2283 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2284 }
2285 }
Calin Juravled0d48522014-11-04 16:40:20 +00002286}
2287
Calin Juravle9aec02f2014-11-18 23:06:35 +00002288void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2289 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2290
2291 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2292 ? LocationSummary::kCall
2293 : LocationSummary::kNoCall;
2294 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2295
2296 switch (op->GetResultType()) {
2297 case Primitive::kPrimInt: {
2298 locations->SetInAt(0, Location::RequiresRegister());
2299 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2300 locations->SetOut(Location::RequiresRegister());
2301 break;
2302 }
2303 case Primitive::kPrimLong: {
2304 InvokeRuntimeCallingConvention calling_convention;
2305 locations->SetInAt(0, Location::RegisterPairLocation(
2306 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2307 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002308 // The runtime helper puts the output in R0,R1.
2309 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002310 break;
2311 }
2312 default:
2313 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2314 }
2315}
2316
2317void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2318 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2319
2320 LocationSummary* locations = op->GetLocations();
2321 Location out = locations->Out();
2322 Location first = locations->InAt(0);
2323 Location second = locations->InAt(1);
2324
2325 Primitive::Type type = op->GetResultType();
2326 switch (type) {
2327 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002328 Register out_reg = out.AsRegister<Register>();
2329 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002330 // Arm doesn't mask the shift count so we need to do it ourselves.
2331 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002332 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002333 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2334 if (op->IsShl()) {
2335 __ Lsl(out_reg, first_reg, second_reg);
2336 } else if (op->IsShr()) {
2337 __ Asr(out_reg, first_reg, second_reg);
2338 } else {
2339 __ Lsr(out_reg, first_reg, second_reg);
2340 }
2341 } else {
2342 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2343 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2344 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2345 __ Mov(out_reg, first_reg);
2346 } else if (op->IsShl()) {
2347 __ Lsl(out_reg, first_reg, shift_value);
2348 } else if (op->IsShr()) {
2349 __ Asr(out_reg, first_reg, shift_value);
2350 } else {
2351 __ Lsr(out_reg, first_reg, shift_value);
2352 }
2353 }
2354 break;
2355 }
2356 case Primitive::kPrimLong: {
2357 // TODO: Inline the assembly instead of calling the runtime.
2358 InvokeRuntimeCallingConvention calling_convention;
2359 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2360 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002361 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002362 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002363 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002364
2365 int32_t entry_point_offset;
2366 if (op->IsShl()) {
2367 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2368 } else if (op->IsShr()) {
2369 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2370 } else {
2371 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2372 }
2373 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2374 __ blx(LR);
2375 break;
2376 }
2377 default:
2378 LOG(FATAL) << "Unexpected operation type " << type;
2379 }
2380}
2381
2382void LocationsBuilderARM::VisitShl(HShl* shl) {
2383 HandleShift(shl);
2384}
2385
2386void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2387 HandleShift(shl);
2388}
2389
2390void LocationsBuilderARM::VisitShr(HShr* shr) {
2391 HandleShift(shr);
2392}
2393
2394void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2395 HandleShift(shr);
2396}
2397
2398void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2399 HandleShift(ushr);
2400}
2401
2402void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2403 HandleShift(ushr);
2404}
2405
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002406void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002407 LocationSummary* locations =
2408 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002409 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002410 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2411 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2412 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002413}
2414
2415void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2416 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002417 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002418 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002419 codegen_->InvokeRuntime(
2420 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002421}
2422
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002423void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2424 LocationSummary* locations =
2425 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2426 InvokeRuntimeCallingConvention calling_convention;
2427 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002428 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002429 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002430 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002431}
2432
2433void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2434 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002435 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002436 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002437 codegen_->InvokeRuntime(
2438 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002439}
2440
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002441void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002442 LocationSummary* locations =
2443 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002444 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2445 if (location.IsStackSlot()) {
2446 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2447 } else if (location.IsDoubleStackSlot()) {
2448 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002449 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002450 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002451}
2452
2453void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002454 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002455 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002456}
2457
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002458void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002459 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002460 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002461 locations->SetInAt(0, Location::RequiresRegister());
2462 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002463}
2464
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002465void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2466 LocationSummary* locations = not_->GetLocations();
2467 Location out = locations->Out();
2468 Location in = locations->InAt(0);
2469 switch (not_->InputAt(0)->GetType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002470 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002471 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002472 break;
2473
2474 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002475 __ mvn(out.AsRegisterPairLow<Register>(),
2476 ShifterOperand(in.AsRegisterPairLow<Register>()));
2477 __ mvn(out.AsRegisterPairHigh<Register>(),
2478 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002479 break;
2480
2481 default:
2482 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2483 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002484}
2485
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002486void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002487 LocationSummary* locations =
2488 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002489 switch (compare->InputAt(0)->GetType()) {
2490 case Primitive::kPrimLong: {
2491 locations->SetInAt(0, Location::RequiresRegister());
2492 locations->SetInAt(1, Location::RequiresRegister());
2493 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2494 break;
2495 }
2496 case Primitive::kPrimFloat:
2497 case Primitive::kPrimDouble: {
2498 locations->SetInAt(0, Location::RequiresFpuRegister());
2499 locations->SetInAt(1, Location::RequiresFpuRegister());
2500 locations->SetOut(Location::RequiresRegister());
2501 break;
2502 }
2503 default:
2504 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2505 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002506}
2507
2508void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002509 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002510 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002511 Location left = locations->InAt(0);
2512 Location right = locations->InAt(1);
2513
2514 Label less, greater, done;
2515 Primitive::Type type = compare->InputAt(0)->GetType();
2516 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002517 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002518 __ cmp(left.AsRegisterPairHigh<Register>(),
2519 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002520 __ b(&less, LT);
2521 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002522 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2523 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002524 __ cmp(left.AsRegisterPairLow<Register>(),
2525 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002526 break;
2527 }
2528 case Primitive::kPrimFloat:
2529 case Primitive::kPrimDouble: {
2530 __ LoadImmediate(out, 0);
2531 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002532 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002533 } else {
2534 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2535 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2536 }
2537 __ vmstat(); // transfer FP status register to ARM APSR.
2538 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002539 break;
2540 }
2541 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002542 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002543 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002544 __ b(&done, EQ);
2545 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2546
2547 __ Bind(&greater);
2548 __ LoadImmediate(out, 1);
2549 __ b(&done);
2550
2551 __ Bind(&less);
2552 __ LoadImmediate(out, -1);
2553
2554 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002555}
2556
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002557void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002558 LocationSummary* locations =
2559 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002560 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2561 locations->SetInAt(i, Location::Any());
2562 }
2563 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002564}
2565
2566void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002567 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002568 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002569}
2570
Calin Juravle52c48962014-12-16 17:02:57 +00002571void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2572 // TODO (ported from quick): revisit Arm barrier kinds
2573 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2574 switch (kind) {
2575 case MemBarrierKind::kAnyStore:
2576 case MemBarrierKind::kLoadAny:
2577 case MemBarrierKind::kAnyAny: {
2578 flavour = DmbOptions::ISH;
2579 break;
2580 }
2581 case MemBarrierKind::kStoreStore: {
2582 flavour = DmbOptions::ISHST;
2583 break;
2584 }
2585 default:
2586 LOG(FATAL) << "Unexpected memory barrier " << kind;
2587 }
2588 __ dmb(flavour);
2589}
2590
2591void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2592 uint32_t offset,
2593 Register out_lo,
2594 Register out_hi) {
2595 if (offset != 0) {
2596 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002597 __ add(IP, addr, ShifterOperand(out_lo));
2598 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002599 }
2600 __ ldrexd(out_lo, out_hi, addr);
2601}
2602
2603void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2604 uint32_t offset,
2605 Register value_lo,
2606 Register value_hi,
2607 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002608 Register temp2,
2609 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002610 Label fail;
2611 if (offset != 0) {
2612 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002613 __ add(IP, addr, ShifterOperand(temp1));
2614 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002615 }
2616 __ Bind(&fail);
2617 // We need a load followed by store. (The address used in a STREX instruction must
2618 // be the same as the address in the most recently executed LDREX instruction.)
2619 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002620 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002621 __ strexd(temp1, value_lo, value_hi, addr);
2622 __ cmp(temp1, ShifterOperand(0));
2623 __ b(&fail, NE);
2624}
2625
2626void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2627 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2628
Nicolas Geoffray39468442014-09-02 15:17:15 +01002629 LocationSummary* locations =
2630 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002631 locations->SetInAt(0, Location::RequiresRegister());
2632 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002633
Calin Juravle34166012014-12-19 17:22:29 +00002634
Calin Juravle52c48962014-12-16 17:02:57 +00002635 Primitive::Type field_type = field_info.GetFieldType();
2636 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002637 bool generate_volatile = field_info.IsVolatile()
2638 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002639 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002640 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002641 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2642 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002643 locations->AddTemp(Location::RequiresRegister());
2644 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002645 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002646 // Arm encoding have some additional constraints for ldrexd/strexd:
2647 // - registers need to be consecutive
2648 // - the first register should be even but not R14.
2649 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2650 // enable Arm encoding.
2651 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2652
2653 locations->AddTemp(Location::RequiresRegister());
2654 locations->AddTemp(Location::RequiresRegister());
2655 if (field_type == Primitive::kPrimDouble) {
2656 // For doubles we need two more registers to copy the value.
2657 locations->AddTemp(Location::RegisterLocation(R2));
2658 locations->AddTemp(Location::RegisterLocation(R3));
2659 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002660 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002661}
2662
Calin Juravle52c48962014-12-16 17:02:57 +00002663void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2664 const FieldInfo& field_info) {
2665 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2666
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002667 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002668 Register base = locations->InAt(0).AsRegister<Register>();
2669 Location value = locations->InAt(1);
2670
2671 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002672 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002673 Primitive::Type field_type = field_info.GetFieldType();
2674 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2675
2676 if (is_volatile) {
2677 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2678 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002679
2680 switch (field_type) {
2681 case Primitive::kPrimBoolean:
2682 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002683 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002684 break;
2685 }
2686
2687 case Primitive::kPrimShort:
2688 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002689 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002690 break;
2691 }
2692
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002693 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002694 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002695 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002696 break;
2697 }
2698
2699 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002700 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002701 GenerateWideAtomicStore(base, offset,
2702 value.AsRegisterPairLow<Register>(),
2703 value.AsRegisterPairHigh<Register>(),
2704 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002705 locations->GetTemp(1).AsRegister<Register>(),
2706 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002707 } else {
2708 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002709 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002710 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002711 break;
2712 }
2713
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002714 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002715 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002716 break;
2717 }
2718
2719 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002720 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002721 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002722 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2723 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2724
2725 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2726
2727 GenerateWideAtomicStore(base, offset,
2728 value_reg_lo,
2729 value_reg_hi,
2730 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002731 locations->GetTemp(3).AsRegister<Register>(),
2732 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002733 } else {
2734 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002735 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002736 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002737 break;
2738 }
2739
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002740 case Primitive::kPrimVoid:
2741 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002742 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002743 }
Calin Juravle52c48962014-12-16 17:02:57 +00002744
Calin Juravle77520bc2015-01-12 18:45:46 +00002745 // Longs and doubles are handled in the switch.
2746 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2747 codegen_->MaybeRecordImplicitNullCheck(instruction);
2748 }
2749
2750 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2751 Register temp = locations->GetTemp(0).AsRegister<Register>();
2752 Register card = locations->GetTemp(1).AsRegister<Register>();
2753 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2754 }
2755
Calin Juravle52c48962014-12-16 17:02:57 +00002756 if (is_volatile) {
2757 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2758 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002759}
2760
Calin Juravle52c48962014-12-16 17:02:57 +00002761void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2762 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002763 LocationSummary* locations =
2764 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002765 locations->SetInAt(0, Location::RequiresRegister());
2766 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002767
Calin Juravle34166012014-12-19 17:22:29 +00002768 bool generate_volatile = field_info.IsVolatile()
2769 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002770 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle34166012014-12-19 17:22:29 +00002771 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002772 // Arm encoding have some additional constraints for ldrexd/strexd:
2773 // - registers need to be consecutive
2774 // - the first register should be even but not R14.
2775 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2776 // enable Arm encoding.
2777 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2778 locations->AddTemp(Location::RequiresRegister());
2779 locations->AddTemp(Location::RequiresRegister());
2780 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002781}
2782
Calin Juravle52c48962014-12-16 17:02:57 +00002783void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2784 const FieldInfo& field_info) {
2785 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002786
Calin Juravle52c48962014-12-16 17:02:57 +00002787 LocationSummary* locations = instruction->GetLocations();
2788 Register base = locations->InAt(0).AsRegister<Register>();
2789 Location out = locations->Out();
2790 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002791 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002792 Primitive::Type field_type = field_info.GetFieldType();
2793 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2794
2795 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002796 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002797 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002798 break;
2799 }
2800
2801 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002802 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002803 break;
2804 }
2805
2806 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002807 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002808 break;
2809 }
2810
2811 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002812 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002813 break;
2814 }
2815
2816 case Primitive::kPrimInt:
2817 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002818 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002819 break;
2820 }
2821
2822 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002823 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002824 GenerateWideAtomicLoad(base, offset,
2825 out.AsRegisterPairLow<Register>(),
2826 out.AsRegisterPairHigh<Register>());
2827 } else {
2828 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2829 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002830 break;
2831 }
2832
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002833 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002834 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002835 break;
2836 }
2837
2838 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002839 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002840 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002841 Register lo = locations->GetTemp(0).AsRegister<Register>();
2842 Register hi = locations->GetTemp(1).AsRegister<Register>();
2843 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002844 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002845 __ vmovdrr(out_reg, lo, hi);
2846 } else {
2847 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002848 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002849 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002850 break;
2851 }
2852
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002853 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002854 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002855 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002856 }
Calin Juravle52c48962014-12-16 17:02:57 +00002857
Calin Juravle77520bc2015-01-12 18:45:46 +00002858 // Doubles are handled in the switch.
2859 if (field_type != Primitive::kPrimDouble) {
2860 codegen_->MaybeRecordImplicitNullCheck(instruction);
2861 }
2862
Calin Juravle52c48962014-12-16 17:02:57 +00002863 if (is_volatile) {
2864 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2865 }
2866}
2867
2868void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2869 HandleFieldSet(instruction, instruction->GetFieldInfo());
2870}
2871
2872void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2873 HandleFieldSet(instruction, instruction->GetFieldInfo());
2874}
2875
2876void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2877 HandleFieldGet(instruction, instruction->GetFieldInfo());
2878}
2879
2880void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2881 HandleFieldGet(instruction, instruction->GetFieldInfo());
2882}
2883
2884void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2885 HandleFieldGet(instruction, instruction->GetFieldInfo());
2886}
2887
2888void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2889 HandleFieldGet(instruction, instruction->GetFieldInfo());
2890}
2891
2892void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2893 HandleFieldSet(instruction, instruction->GetFieldInfo());
2894}
2895
2896void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2897 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002898}
2899
2900void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002901 LocationSummary* locations =
2902 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002903 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002904 if (instruction->HasUses()) {
2905 locations->SetOut(Location::SameAsFirstInput());
2906 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002907}
2908
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002909void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002910 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2911 return;
2912 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002913 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002914
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002915 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2916 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2917}
2918
2919void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002920 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002921 codegen_->AddSlowPath(slow_path);
2922
2923 LocationSummary* locations = instruction->GetLocations();
2924 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002925
Calin Juravle77520bc2015-01-12 18:45:46 +00002926 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2927 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002928}
2929
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002930void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2931 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2932 GenerateImplicitNullCheck(instruction);
2933 } else {
2934 GenerateExplicitNullCheck(instruction);
2935 }
2936}
2937
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002938void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002939 LocationSummary* locations =
2940 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002941 locations->SetInAt(0, Location::RequiresRegister());
2942 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2943 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002944}
2945
2946void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2947 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002948 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002949 Location index = locations->InAt(1);
2950
2951 switch (instruction->GetType()) {
2952 case Primitive::kPrimBoolean: {
2953 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002954 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002955 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002956 size_t offset =
2957 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002958 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2959 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002960 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002961 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2962 }
2963 break;
2964 }
2965
2966 case Primitive::kPrimByte: {
2967 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002968 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002969 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002970 size_t offset =
2971 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002972 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2973 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002974 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002975 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2976 }
2977 break;
2978 }
2979
2980 case Primitive::kPrimShort: {
2981 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002982 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002983 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002984 size_t offset =
2985 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002986 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2987 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002988 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002989 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2990 }
2991 break;
2992 }
2993
2994 case Primitive::kPrimChar: {
2995 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002996 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002997 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002998 size_t offset =
2999 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003000 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3001 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003002 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003003 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3004 }
3005 break;
3006 }
3007
3008 case Primitive::kPrimInt:
3009 case Primitive::kPrimNot: {
3010 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3011 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003012 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003013 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003014 size_t offset =
3015 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003016 __ LoadFromOffset(kLoadWord, out, obj, offset);
3017 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003018 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003019 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3020 }
3021 break;
3022 }
3023
3024 case Primitive::kPrimLong: {
3025 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003026 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003027 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003028 size_t offset =
3029 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003030 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003031 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003032 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003033 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003034 }
3035 break;
3036 }
3037
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003038 case Primitive::kPrimFloat: {
3039 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3040 Location out = locations->Out();
3041 DCHECK(out.IsFpuRegister());
3042 if (index.IsConstant()) {
3043 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3044 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3045 } else {
3046 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3047 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3048 }
3049 break;
3050 }
3051
3052 case Primitive::kPrimDouble: {
3053 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3054 Location out = locations->Out();
3055 DCHECK(out.IsFpuRegisterPair());
3056 if (index.IsConstant()) {
3057 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3058 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3059 } else {
3060 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3061 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3062 }
3063 break;
3064 }
3065
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003066 case Primitive::kPrimVoid:
3067 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003068 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003069 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003070 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003071}
3072
3073void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003074 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003075
3076 bool needs_write_barrier =
3077 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3078 bool needs_runtime_call = instruction->NeedsTypeCheck();
3079
Nicolas Geoffray39468442014-09-02 15:17:15 +01003080 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003081 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3082 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003083 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003084 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3085 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3086 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003087 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003088 locations->SetInAt(0, Location::RequiresRegister());
3089 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3090 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003091
3092 if (needs_write_barrier) {
3093 // Temporary registers for the write barrier.
3094 locations->AddTemp(Location::RequiresRegister());
3095 locations->AddTemp(Location::RequiresRegister());
3096 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003097 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003098}
3099
3100void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3101 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003102 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003103 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003104 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003105 bool needs_runtime_call = locations->WillCall();
3106 bool needs_write_barrier =
3107 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003108
3109 switch (value_type) {
3110 case Primitive::kPrimBoolean:
3111 case Primitive::kPrimByte: {
3112 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003113 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003114 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003115 size_t offset =
3116 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003117 __ StoreToOffset(kStoreByte, value, obj, offset);
3118 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003119 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003120 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3121 }
3122 break;
3123 }
3124
3125 case Primitive::kPrimShort:
3126 case Primitive::kPrimChar: {
3127 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003128 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003129 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003130 size_t offset =
3131 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003132 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3133 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003134 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003135 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3136 }
3137 break;
3138 }
3139
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003140 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003141 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003142 if (!needs_runtime_call) {
3143 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003144 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003145 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003146 size_t offset =
3147 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003148 __ StoreToOffset(kStoreWord, value, obj, offset);
3149 } else {
3150 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003151 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003152 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3153 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003154 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003155 if (needs_write_barrier) {
3156 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003157 Register temp = locations->GetTemp(0).AsRegister<Register>();
3158 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003159 codegen_->MarkGCCard(temp, card, obj, value);
3160 }
3161 } else {
3162 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003163 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3164 instruction,
3165 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003166 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003167 break;
3168 }
3169
3170 case Primitive::kPrimLong: {
3171 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003172 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003173 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003174 size_t offset =
3175 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003176 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003177 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003178 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003179 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003180 }
3181 break;
3182 }
3183
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003184 case Primitive::kPrimFloat: {
3185 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3186 Location value = locations->InAt(2);
3187 DCHECK(value.IsFpuRegister());
3188 if (index.IsConstant()) {
3189 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3190 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3191 } else {
3192 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3193 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3194 }
3195 break;
3196 }
3197
3198 case Primitive::kPrimDouble: {
3199 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3200 Location value = locations->InAt(2);
3201 DCHECK(value.IsFpuRegisterPair());
3202 if (index.IsConstant()) {
3203 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3204 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3205 } else {
3206 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3207 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3208 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003209
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003210 break;
3211 }
3212
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003213 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003214 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003215 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003216 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003217
3218 // Ints and objects are handled in the switch.
3219 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3220 codegen_->MaybeRecordImplicitNullCheck(instruction);
3221 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003222}
3223
3224void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003225 LocationSummary* locations =
3226 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003227 locations->SetInAt(0, Location::RequiresRegister());
3228 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003229}
3230
3231void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3232 LocationSummary* locations = instruction->GetLocations();
3233 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003234 Register obj = locations->InAt(0).AsRegister<Register>();
3235 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003236 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003237 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003238}
3239
3240void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003241 LocationSummary* locations =
3242 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003243 locations->SetInAt(0, Location::RequiresRegister());
3244 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003245 if (instruction->HasUses()) {
3246 locations->SetOut(Location::SameAsFirstInput());
3247 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003248}
3249
3250void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3251 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003252 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003253 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003254 codegen_->AddSlowPath(slow_path);
3255
Roland Levillain271ab9c2014-11-27 15:23:57 +00003256 Register index = locations->InAt(0).AsRegister<Register>();
3257 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003258
3259 __ cmp(index, ShifterOperand(length));
3260 __ b(slow_path->GetEntryLabel(), CS);
3261}
3262
3263void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3264 Label is_null;
3265 __ CompareAndBranchIfZero(value, &is_null);
3266 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3267 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3268 __ strb(card, Address(card, temp));
3269 __ Bind(&is_null);
3270}
3271
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003272void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3273 temp->SetLocations(nullptr);
3274}
3275
3276void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3277 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003278 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003279}
3280
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003281void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003282 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003283 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003284}
3285
3286void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003287 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3288}
3289
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003290void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3291 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3292}
3293
3294void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003295 HBasicBlock* block = instruction->GetBlock();
3296 if (block->GetLoopInformation() != nullptr) {
3297 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3298 // The back edge will generate the suspend check.
3299 return;
3300 }
3301 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3302 // The goto will generate the suspend check.
3303 return;
3304 }
3305 GenerateSuspendCheck(instruction, nullptr);
3306}
3307
3308void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3309 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003310 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003311 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003312 codegen_->AddSlowPath(slow_path);
3313
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003314 __ LoadFromOffset(
3315 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3316 __ cmp(IP, ShifterOperand(0));
3317 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003318 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003319 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003320 __ Bind(slow_path->GetReturnLabel());
3321 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003322 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003323 __ b(slow_path->GetEntryLabel());
3324 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003325}
3326
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003327ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3328 return codegen_->GetAssembler();
3329}
3330
3331void ParallelMoveResolverARM::EmitMove(size_t index) {
3332 MoveOperands* move = moves_.Get(index);
3333 Location source = move->GetSource();
3334 Location destination = move->GetDestination();
3335
3336 if (source.IsRegister()) {
3337 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003338 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003339 } else {
3340 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003341 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003342 SP, destination.GetStackIndex());
3343 }
3344 } else if (source.IsStackSlot()) {
3345 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003346 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003347 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003348 } else if (destination.IsFpuRegister()) {
3349 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003350 } else {
3351 DCHECK(destination.IsStackSlot());
3352 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3353 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3354 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003355 } else if (source.IsFpuRegister()) {
3356 if (destination.IsFpuRegister()) {
3357 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003358 } else {
3359 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003360 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3361 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003362 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003363 DCHECK(destination.IsDoubleStackSlot()) << destination;
3364 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3365 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3366 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3367 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003368 } else {
3369 DCHECK(source.IsConstant()) << source;
3370 HInstruction* constant = source.GetConstant();
3371 if (constant->IsIntConstant()) {
3372 int32_t value = constant->AsIntConstant()->GetValue();
3373 if (destination.IsRegister()) {
3374 __ LoadImmediate(destination.AsRegister<Register>(), value);
3375 } else {
3376 DCHECK(destination.IsStackSlot());
3377 __ LoadImmediate(IP, value);
3378 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3379 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003380 } else if (constant->IsLongConstant()) {
3381 int64_t value = constant->AsLongConstant()->GetValue();
3382 if (destination.IsRegister()) {
3383 // In the presence of long or double constants, the parallel move resolver will
3384 // split the move into two, but keeps the same constant for both moves. Here,
3385 // we use the low or high part depending on which register this move goes to.
3386 if (destination.reg() % 2 == 0) {
3387 __ LoadImmediate(destination.AsRegister<Register>(), Low32Bits(value));
3388 } else {
3389 __ LoadImmediate(destination.AsRegister<Register>(), High32Bits(value));
3390 }
3391 } else {
3392 DCHECK(destination.IsDoubleStackSlot());
3393 __ LoadImmediate(IP, Low32Bits(value));
3394 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3395 __ LoadImmediate(IP, High32Bits(value));
3396 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3397 }
3398 } else if (constant->IsDoubleConstant()) {
3399 double value = constant->AsDoubleConstant()->GetValue();
3400 uint64_t int_value = bit_cast<uint64_t, double>(value);
3401 if (destination.IsFpuRegister()) {
3402 // In the presence of long or double constants, the parallel move resolver will
3403 // split the move into two, but keeps the same constant for both moves. Here,
3404 // we use the low or high part depending on which register this move goes to.
3405 if (destination.reg() % 2 == 0) {
3406 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3407 bit_cast<float, uint32_t>(Low32Bits(int_value)));
3408 } else {
3409 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3410 bit_cast<float, uint32_t>(High32Bits(int_value)));
3411 }
3412 } else {
3413 DCHECK(destination.IsDoubleStackSlot());
3414 __ LoadImmediate(IP, Low32Bits(int_value));
3415 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3416 __ LoadImmediate(IP, High32Bits(int_value));
3417 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3418 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003419 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003420 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003421 float value = constant->AsFloatConstant()->GetValue();
3422 if (destination.IsFpuRegister()) {
3423 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3424 } else {
3425 DCHECK(destination.IsStackSlot());
3426 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3427 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3428 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003429 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003430 }
3431}
3432
3433void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3434 __ Mov(IP, reg);
3435 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3436 __ StoreToOffset(kStoreWord, IP, SP, mem);
3437}
3438
3439void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3440 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3441 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3442 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3443 SP, mem1 + stack_offset);
3444 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3445 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3446 SP, mem2 + stack_offset);
3447 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3448}
3449
3450void ParallelMoveResolverARM::EmitSwap(size_t index) {
3451 MoveOperands* move = moves_.Get(index);
3452 Location source = move->GetSource();
3453 Location destination = move->GetDestination();
3454
3455 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003456 DCHECK_NE(source.AsRegister<Register>(), IP);
3457 DCHECK_NE(destination.AsRegister<Register>(), IP);
3458 __ Mov(IP, source.AsRegister<Register>());
3459 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3460 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003461 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003462 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003463 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003464 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003465 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3466 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003467 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003468 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003469 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003470 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003471 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3472 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3473 : destination.AsFpuRegister<SRegister>();
3474 int mem = source.IsFpuRegister()
3475 ? destination.GetStackIndex()
3476 : source.GetStackIndex();
3477
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003478 __ vmovrs(IP, reg);
3479 __ LoadFromOffset(kLoadWord, IP, SP, mem);
3480 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003481 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003482 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3483 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003484 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003485 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003486 }
3487}
3488
3489void ParallelMoveResolverARM::SpillScratch(int reg) {
3490 __ Push(static_cast<Register>(reg));
3491}
3492
3493void ParallelMoveResolverARM::RestoreScratch(int reg) {
3494 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003495}
3496
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003497void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003498 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3499 ? LocationSummary::kCallOnSlowPath
3500 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003501 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003502 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003503 locations->SetOut(Location::RequiresRegister());
3504}
3505
3506void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003507 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003508 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003509 DCHECK(!cls->CanCallRuntime());
3510 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003511 codegen_->LoadCurrentMethod(out);
3512 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3513 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003514 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003515 codegen_->LoadCurrentMethod(out);
3516 __ LoadFromOffset(
3517 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3518 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003519
3520 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3521 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3522 codegen_->AddSlowPath(slow_path);
3523 __ cmp(out, ShifterOperand(0));
3524 __ b(slow_path->GetEntryLabel(), EQ);
3525 if (cls->MustGenerateClinitCheck()) {
3526 GenerateClassInitializationCheck(slow_path, out);
3527 } else {
3528 __ Bind(slow_path->GetExitLabel());
3529 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003530 }
3531}
3532
3533void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3534 LocationSummary* locations =
3535 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3536 locations->SetInAt(0, Location::RequiresRegister());
3537 if (check->HasUses()) {
3538 locations->SetOut(Location::SameAsFirstInput());
3539 }
3540}
3541
3542void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003543 // We assume the class is not null.
3544 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3545 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003546 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003547 GenerateClassInitializationCheck(slow_path,
3548 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003549}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003550
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003551void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3552 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003553 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3554 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3555 __ b(slow_path->GetEntryLabel(), LT);
3556 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3557 // properly. Therefore, we do a memory fence.
3558 __ dmb(ISH);
3559 __ Bind(slow_path->GetExitLabel());
3560}
3561
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003562void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3563 LocationSummary* locations =
3564 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3565 locations->SetOut(Location::RequiresRegister());
3566}
3567
3568void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3569 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3570 codegen_->AddSlowPath(slow_path);
3571
Roland Levillain271ab9c2014-11-27 15:23:57 +00003572 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003573 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003574 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3575 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003576 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3577 __ cmp(out, ShifterOperand(0));
3578 __ b(slow_path->GetEntryLabel(), EQ);
3579 __ Bind(slow_path->GetExitLabel());
3580}
3581
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003582void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3583 LocationSummary* locations =
3584 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3585 locations->SetOut(Location::RequiresRegister());
3586}
3587
3588void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003589 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003590 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3591 __ LoadFromOffset(kLoadWord, out, TR, offset);
3592 __ LoadImmediate(IP, 0);
3593 __ StoreToOffset(kStoreWord, IP, TR, offset);
3594}
3595
3596void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3597 LocationSummary* locations =
3598 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3599 InvokeRuntimeCallingConvention calling_convention;
3600 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3601}
3602
3603void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3604 codegen_->InvokeRuntime(
3605 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3606}
3607
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003608void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003609 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3610 ? LocationSummary::kNoCall
3611 : LocationSummary::kCallOnSlowPath;
3612 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3613 locations->SetInAt(0, Location::RequiresRegister());
3614 locations->SetInAt(1, Location::RequiresRegister());
3615 locations->SetOut(Location::RequiresRegister());
3616}
3617
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003618void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003619 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003620 Register obj = locations->InAt(0).AsRegister<Register>();
3621 Register cls = locations->InAt(1).AsRegister<Register>();
3622 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003623 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3624 Label done, zero;
3625 SlowPathCodeARM* slow_path = nullptr;
3626
3627 // Return 0 if `obj` is null.
3628 // TODO: avoid this check if we know obj is not null.
3629 __ cmp(obj, ShifterOperand(0));
3630 __ b(&zero, EQ);
3631 // Compare the class of `obj` with `cls`.
3632 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3633 __ cmp(out, ShifterOperand(cls));
3634 if (instruction->IsClassFinal()) {
3635 // Classes must be equal for the instanceof to succeed.
3636 __ b(&zero, NE);
3637 __ LoadImmediate(out, 1);
3638 __ b(&done);
3639 } else {
3640 // If the classes are not equal, we go into a slow path.
3641 DCHECK(locations->OnlyCallsOnSlowPath());
3642 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003643 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003644 codegen_->AddSlowPath(slow_path);
3645 __ b(slow_path->GetEntryLabel(), NE);
3646 __ LoadImmediate(out, 1);
3647 __ b(&done);
3648 }
3649 __ Bind(&zero);
3650 __ LoadImmediate(out, 0);
3651 if (slow_path != nullptr) {
3652 __ Bind(slow_path->GetExitLabel());
3653 }
3654 __ Bind(&done);
3655}
3656
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003657void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3658 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3659 instruction, LocationSummary::kCallOnSlowPath);
3660 locations->SetInAt(0, Location::RequiresRegister());
3661 locations->SetInAt(1, Location::RequiresRegister());
3662 locations->AddTemp(Location::RequiresRegister());
3663}
3664
3665void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3666 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003667 Register obj = locations->InAt(0).AsRegister<Register>();
3668 Register cls = locations->InAt(1).AsRegister<Register>();
3669 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003670 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3671
3672 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3673 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3674 codegen_->AddSlowPath(slow_path);
3675
3676 // TODO: avoid this check if we know obj is not null.
3677 __ cmp(obj, ShifterOperand(0));
3678 __ b(slow_path->GetExitLabel(), EQ);
3679 // Compare the class of `obj` with `cls`.
3680 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3681 __ cmp(temp, ShifterOperand(cls));
3682 __ b(slow_path->GetEntryLabel(), NE);
3683 __ Bind(slow_path->GetExitLabel());
3684}
3685
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003686void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3687 LocationSummary* locations =
3688 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3689 InvokeRuntimeCallingConvention calling_convention;
3690 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3691}
3692
3693void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3694 codegen_->InvokeRuntime(instruction->IsEnter()
3695 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3696 instruction,
3697 instruction->GetDexPc());
3698}
3699
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003700void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3701void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3702void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3703
3704void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3705 LocationSummary* locations =
3706 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3707 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3708 || instruction->GetResultType() == Primitive::kPrimLong);
3709 locations->SetInAt(0, Location::RequiresRegister());
3710 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003711 Location::OutputOverlap output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong)
3712 ? Location::kOutputOverlap
3713 : Location::kNoOutputOverlap;
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003714 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3715}
3716
3717void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3718 HandleBitwiseOperation(instruction);
3719}
3720
3721void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3722 HandleBitwiseOperation(instruction);
3723}
3724
3725void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3726 HandleBitwiseOperation(instruction);
3727}
3728
3729void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3730 LocationSummary* locations = instruction->GetLocations();
3731
3732 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003733 Register first = locations->InAt(0).AsRegister<Register>();
3734 Register second = locations->InAt(1).AsRegister<Register>();
3735 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003736 if (instruction->IsAnd()) {
3737 __ and_(out, first, ShifterOperand(second));
3738 } else if (instruction->IsOr()) {
3739 __ orr(out, first, ShifterOperand(second));
3740 } else {
3741 DCHECK(instruction->IsXor());
3742 __ eor(out, first, ShifterOperand(second));
3743 }
3744 } else {
3745 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3746 Location first = locations->InAt(0);
3747 Location second = locations->InAt(1);
3748 Location out = locations->Out();
3749 if (instruction->IsAnd()) {
3750 __ and_(out.AsRegisterPairLow<Register>(),
3751 first.AsRegisterPairLow<Register>(),
3752 ShifterOperand(second.AsRegisterPairLow<Register>()));
3753 __ and_(out.AsRegisterPairHigh<Register>(),
3754 first.AsRegisterPairHigh<Register>(),
3755 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3756 } else if (instruction->IsOr()) {
3757 __ orr(out.AsRegisterPairLow<Register>(),
3758 first.AsRegisterPairLow<Register>(),
3759 ShifterOperand(second.AsRegisterPairLow<Register>()));
3760 __ orr(out.AsRegisterPairHigh<Register>(),
3761 first.AsRegisterPairHigh<Register>(),
3762 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3763 } else {
3764 DCHECK(instruction->IsXor());
3765 __ eor(out.AsRegisterPairLow<Register>(),
3766 first.AsRegisterPairLow<Register>(),
3767 ShifterOperand(second.AsRegisterPairLow<Register>()));
3768 __ eor(out.AsRegisterPairHigh<Register>(),
3769 first.AsRegisterPairHigh<Register>(),
3770 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3771 }
3772 }
3773}
3774
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003775} // namespace arm
3776} // namespace art