blob: 1841f062265a914ada616818b91c465da3f7e6dc [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 the PC register to mimic Quick.
400 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100401}
402
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100403Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 switch (type) {
405 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100406 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100407 ArmManagedRegister pair =
408 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100409 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
410 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
411
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100412 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
413 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100414 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100415 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100416 }
417
418 case Primitive::kPrimByte:
419 case Primitive::kPrimBoolean:
420 case Primitive::kPrimChar:
421 case Primitive::kPrimShort:
422 case Primitive::kPrimInt:
423 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100424 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100425 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100426 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
427 ArmManagedRegister current =
428 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
429 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100430 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100431 }
432 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100433 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100434 }
435
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000436 case Primitive::kPrimFloat: {
437 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100438 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100439 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000441 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000442 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
443 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000444 return Location::FpuRegisterPairLocation(reg, reg + 1);
445 }
446
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447 case Primitive::kPrimVoid:
448 LOG(FATAL) << "Unreachable type " << type;
449 }
450
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100451 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452}
453
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000454void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100455 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100457
458 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100459 blocked_core_registers_[SP] = true;
460 blocked_core_registers_[LR] = true;
461 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100462
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100464 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100465
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100466 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100467 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100468
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000469 if (is_baseline) {
470 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
471 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
472 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000473
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000474 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
475
476 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
477 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
478 }
479 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100480
481 UpdateBlockedPairRegisters();
482}
483
484void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
485 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
486 ArmManagedRegister current =
487 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
488 if (blocked_core_registers_[current.AsRegisterPairLow()]
489 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
490 blocked_register_pairs_[i] = true;
491 }
492 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100493}
494
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100495InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
496 : HGraphVisitor(graph),
497 assembler_(codegen->GetAssembler()),
498 codegen_(codegen) {}
499
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000500static uint32_t LeastSignificantBit(uint32_t mask) {
501 // ffs starts at 1.
502 return ffs(mask) - 1;
503}
504
505void CodeGeneratorARM::ComputeSpillMask() {
506 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000507 // Save one extra register for baseline. Note that on thumb2, there is no easy
508 // instruction to restore just the PC, so this actually helps both baseline
509 // and non-baseline to save and restore at least two registers at entry and exit.
510 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000511 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 Geoffrayc0572a42015-02-06 14:35:25 +0000532 if (HasEmptyFrame()) {
533 return;
534 }
535
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100536 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000537 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
538 __ LoadFromOffset(kLoadWord, IP, IP, 0);
539 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100540 }
541
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000542 // PC is in the list of callee-save to mimic Quick, but we need to push
543 // LR at entry instead.
544 __ PushList((core_spill_mask_ & (~(1 << PC))) | 1 << LR);
545 if (fpu_spill_mask_ != 0) {
546 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
547 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
548 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000549 __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize()));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100550 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000551}
552
553void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000554 if (HasEmptyFrame()) {
555 __ bx(LR);
556 return;
557 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000558 __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000559 if (fpu_spill_mask_ != 0) {
560 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
561 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
562 }
563 __ PopList(core_spill_mask_);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000564}
565
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100566void CodeGeneratorARM::Bind(HBasicBlock* block) {
567 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000568}
569
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100570Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
571 switch (load->GetType()) {
572 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100573 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100574 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
575 break;
576
577 case Primitive::kPrimInt:
578 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100579 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100580 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100581
582 case Primitive::kPrimBoolean:
583 case Primitive::kPrimByte:
584 case Primitive::kPrimChar:
585 case Primitive::kPrimShort:
586 case Primitive::kPrimVoid:
587 LOG(FATAL) << "Unexpected type " << load->GetType();
588 }
589
590 LOG(FATAL) << "Unreachable";
591 return Location();
592}
593
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100594Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
595 switch (type) {
596 case Primitive::kPrimBoolean:
597 case Primitive::kPrimByte:
598 case Primitive::kPrimChar:
599 case Primitive::kPrimShort:
600 case Primitive::kPrimInt:
601 case Primitive::kPrimNot: {
602 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000603 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100604 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100605 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100606 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000607 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100608 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100609 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100610
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000611 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100612 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000613 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100614 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000615 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100616 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000617 if (calling_convention.GetRegisterAt(index) == R1) {
618 // Skip R1, and use R2_R3 instead.
619 gp_index_++;
620 index++;
621 }
622 }
623 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
624 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000625 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000626 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000627 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100628 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000629 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
630 }
631 }
632
633 case Primitive::kPrimFloat: {
634 uint32_t stack_index = stack_index_++;
635 if (float_index_ % 2 == 0) {
636 float_index_ = std::max(double_index_, float_index_);
637 }
638 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
639 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
640 } else {
641 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
642 }
643 }
644
645 case Primitive::kPrimDouble: {
646 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
647 uint32_t stack_index = stack_index_;
648 stack_index_ += 2;
649 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
650 uint32_t index = double_index_;
651 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000652 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000653 calling_convention.GetFpuRegisterAt(index),
654 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000655 DCHECK(ExpectedPairLayout(result));
656 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000657 } else {
658 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100659 }
660 }
661
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100662 case Primitive::kPrimVoid:
663 LOG(FATAL) << "Unexpected parameter type " << type;
664 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100665 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100666 return Location();
667}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100668
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000669Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
670 switch (type) {
671 case Primitive::kPrimBoolean:
672 case Primitive::kPrimByte:
673 case Primitive::kPrimChar:
674 case Primitive::kPrimShort:
675 case Primitive::kPrimInt:
676 case Primitive::kPrimNot: {
677 return Location::RegisterLocation(R0);
678 }
679
680 case Primitive::kPrimFloat: {
681 return Location::FpuRegisterLocation(S0);
682 }
683
684 case Primitive::kPrimLong: {
685 return Location::RegisterPairLocation(R0, R1);
686 }
687
688 case Primitive::kPrimDouble: {
689 return Location::FpuRegisterPairLocation(S0, S1);
690 }
691
692 case Primitive::kPrimVoid:
693 return Location();
694 }
695 UNREACHABLE();
696 return Location();
697}
698
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100699void CodeGeneratorARM::Move32(Location destination, Location source) {
700 if (source.Equals(destination)) {
701 return;
702 }
703 if (destination.IsRegister()) {
704 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000705 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100706 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000707 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100708 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000709 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100711 } else if (destination.IsFpuRegister()) {
712 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000713 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100714 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000715 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100716 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000717 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100718 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100719 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000720 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100721 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000722 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100723 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000724 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100725 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000726 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100727 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
728 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100729 }
730 }
731}
732
733void CodeGeneratorARM::Move64(Location destination, Location source) {
734 if (source.Equals(destination)) {
735 return;
736 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100737 if (destination.IsRegisterPair()) {
738 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000739 EmitParallelMoves(
740 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
741 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
742 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
743 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100744 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000745 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100746 } else {
747 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000748 DCHECK(ExpectedPairLayout(destination));
749 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
750 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100751 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000752 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100753 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000754 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
755 SP,
756 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100757 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000758 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100759 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100760 } else {
761 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100762 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000763 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100764 if (source.AsRegisterPairLow<Register>() == R1) {
765 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100766 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
767 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100769 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100770 SP, destination.GetStackIndex());
771 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000772 } else if (source.IsFpuRegisterPair()) {
773 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
774 SP,
775 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776 } else {
777 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000778 EmitParallelMoves(
779 Location::StackSlot(source.GetStackIndex()),
780 Location::StackSlot(destination.GetStackIndex()),
781 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
782 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100783 }
784 }
785}
786
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100787void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100788 LocationSummary* locations = instruction->GetLocations();
789 if (locations != nullptr && locations->Out().Equals(location)) {
790 return;
791 }
792
Calin Juravlea21f5982014-11-13 15:53:04 +0000793 if (locations != nullptr && locations->Out().IsConstant()) {
794 HConstant* const_to_move = locations->Out().GetConstant();
795 if (const_to_move->IsIntConstant()) {
796 int32_t value = const_to_move->AsIntConstant()->GetValue();
797 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000798 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000799 } else {
800 DCHECK(location.IsStackSlot());
801 __ LoadImmediate(IP, value);
802 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
803 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000804 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000805 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000806 int64_t value = const_to_move->AsLongConstant()->GetValue();
807 if (location.IsRegisterPair()) {
808 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
809 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
810 } else {
811 DCHECK(location.IsDoubleStackSlot());
812 __ LoadImmediate(IP, Low32Bits(value));
813 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
814 __ LoadImmediate(IP, High32Bits(value));
815 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
816 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100817 }
Roland Levillain476df552014-10-09 17:51:36 +0100818 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100819 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
820 switch (instruction->GetType()) {
821 case Primitive::kPrimBoolean:
822 case Primitive::kPrimByte:
823 case Primitive::kPrimChar:
824 case Primitive::kPrimShort:
825 case Primitive::kPrimInt:
826 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100827 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100828 Move32(location, Location::StackSlot(stack_slot));
829 break;
830
831 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100832 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100833 Move64(location, Location::DoubleStackSlot(stack_slot));
834 break;
835
836 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100837 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100838 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000839 } else if (instruction->IsTemporary()) {
840 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000841 if (temp_location.IsStackSlot()) {
842 Move32(location, temp_location);
843 } else {
844 DCHECK(temp_location.IsDoubleStackSlot());
845 Move64(location, temp_location);
846 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000847 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100848 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 switch (instruction->GetType()) {
850 case Primitive::kPrimBoolean:
851 case Primitive::kPrimByte:
852 case Primitive::kPrimChar:
853 case Primitive::kPrimShort:
854 case Primitive::kPrimNot:
855 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100856 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100857 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100858 break;
859
860 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100861 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100862 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100863 break;
864
865 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100866 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100867 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000868 }
869}
870
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100871void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
872 HInstruction* instruction,
873 uint32_t dex_pc) {
874 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
875 __ blx(LR);
876 RecordPcInfo(instruction, dex_pc);
877 DCHECK(instruction->IsSuspendCheck()
878 || instruction->IsBoundsCheck()
879 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000880 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000881 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100882 || !IsLeafMethod());
883}
884
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000885void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000886 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000887}
888
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000889void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000890 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100891 DCHECK(!successor->IsExitBlock());
892
893 HBasicBlock* block = got->GetBlock();
894 HInstruction* previous = got->GetPrevious();
895
896 HLoopInformation* info = block->GetLoopInformation();
897 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
898 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
899 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
900 return;
901 }
902
903 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
904 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
905 }
906 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000907 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000908 }
909}
910
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000911void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000912 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000913}
914
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000915void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700916 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000917 if (kIsDebugBuild) {
918 __ Comment("Unreachable");
919 __ bkpt(0);
920 }
921}
922
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000923void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100924 LocationSummary* locations =
925 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100926 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100927 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100928 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100929 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000930}
931
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000932void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700933 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100934 if (cond->IsIntConstant()) {
935 // Constant condition, statically compared against 1.
936 int32_t cond_value = cond->AsIntConstant()->GetValue();
937 if (cond_value == 1) {
938 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
939 if_instr->IfTrueSuccessor())) {
940 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100941 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100942 return;
943 } else {
944 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100945 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100946 } else {
947 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
948 // Condition has been materialized, compare the output to 0
949 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000950 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100951 ShifterOperand(0));
952 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
953 } else {
954 // Condition has not been materialized, use its inputs as the
955 // comparison and its condition as the branch condition.
956 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000957 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000958 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000960 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100961 } else {
962 DCHECK(locations->InAt(1).IsConstant());
963 int32_t value =
964 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
965 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000966 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
967 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100968 } else {
969 Register temp = IP;
970 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000971 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100972 }
973 }
974 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
975 ARMCondition(cond->AsCondition()->GetCondition()));
976 }
Dave Allison20dfc792014-06-16 20:44:29 -0700977 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100978 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
979 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700980 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000981 }
982}
983
Dave Allison20dfc792014-06-16 20:44:29 -0700984
985void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100986 LocationSummary* locations =
987 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100988 locations->SetInAt(0, Location::RequiresRegister());
989 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100990 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100991 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100992 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000993}
994
Dave Allison20dfc792014-06-16 20:44:29 -0700995void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000998 Register left = locations->InAt(0).AsRegister<Register>();
999
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001001 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001002 } else {
1003 DCHECK(locations->InAt(1).IsConstant());
1004 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
1005 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001006 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1007 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001008 } else {
1009 Register temp = IP;
1010 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001011 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001012 }
Dave Allison20dfc792014-06-16 20:44:29 -07001013 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001014 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001015 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001016 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001017 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001018 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001019}
1020
1021void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1022 VisitCondition(comp);
1023}
1024
1025void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1026 VisitCondition(comp);
1027}
1028
1029void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1030 VisitCondition(comp);
1031}
1032
1033void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1034 VisitCondition(comp);
1035}
1036
1037void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1038 VisitCondition(comp);
1039}
1040
1041void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1042 VisitCondition(comp);
1043}
1044
1045void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1046 VisitCondition(comp);
1047}
1048
1049void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1050 VisitCondition(comp);
1051}
1052
1053void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1054 VisitCondition(comp);
1055}
1056
1057void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1058 VisitCondition(comp);
1059}
1060
1061void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1062 VisitCondition(comp);
1063}
1064
1065void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1066 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001067}
1068
1069void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001070 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001071}
1072
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001073void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1074 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001075}
1076
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001077void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001078 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001079}
1080
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001081void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001082 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001083 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001084}
1085
1086void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001087 LocationSummary* locations =
1088 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001089 switch (store->InputAt(1)->GetType()) {
1090 case Primitive::kPrimBoolean:
1091 case Primitive::kPrimByte:
1092 case Primitive::kPrimChar:
1093 case Primitive::kPrimShort:
1094 case Primitive::kPrimInt:
1095 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001096 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001097 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1098 break;
1099
1100 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001101 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001102 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1103 break;
1104
1105 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001106 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001107 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001108}
1109
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001110void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001111 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001112}
1113
1114void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001115 LocationSummary* locations =
1116 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001117 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001118}
1119
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001120void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001121 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001122 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001123}
1124
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001125void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001126 LocationSummary* locations =
1127 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001128 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001129}
1130
1131void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1132 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001133 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001134}
1135
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001136void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1137 LocationSummary* locations =
1138 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1139 locations->SetOut(Location::ConstantLocation(constant));
1140}
1141
1142void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1143 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001144 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001145}
1146
1147void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1148 LocationSummary* locations =
1149 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1150 locations->SetOut(Location::ConstantLocation(constant));
1151}
1152
1153void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1154 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001155 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001156}
1157
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001158void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001159 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001160}
1161
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001162void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001163 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001164 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001165}
1166
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001167void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001168 LocationSummary* locations =
1169 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001170 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001171}
1172
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001173void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001174 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001175 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001176}
1177
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001178void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001179 HandleInvoke(invoke);
1180}
1181
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001182void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001183 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001184 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001185}
1186
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001187void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001188 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189
1190 // TODO: Implement all kinds of calls:
1191 // 1) boot -> boot
1192 // 2) app -> boot
1193 // 3) app -> app
1194 //
1195 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1196
1197 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001198 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001199 if (!invoke->IsRecursive()) {
1200 // temp = temp->dex_cache_resolved_methods_;
1201 __ LoadFromOffset(
1202 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
1203 // temp = temp[index_in_cache]
1204 __ LoadFromOffset(
1205 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
1206 // LR = temp[offset_of_quick_compiled_code]
1207 __ LoadFromOffset(kLoadWord, LR, temp,
1208 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1209 kArmWordSize).Int32Value());
1210 // LR()
1211 __ blx(LR);
1212 } else {
1213 __ bl(codegen_->GetFrameEntryLabel());
1214 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001215
1216 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1217 DCHECK(!codegen_->IsLeafMethod());
1218}
1219
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001220void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001221 LocationSummary* locations =
1222 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001223 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001224
1225 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001226 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001227 HInstruction* input = invoke->InputAt(i);
1228 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1229 }
1230
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001231 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001232}
1233
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001234void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1235 HandleInvoke(invoke);
1236}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001237
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001238void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001239 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001240 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1241 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1242 LocationSummary* locations = invoke->GetLocations();
1243 Location receiver = locations->InAt(0);
1244 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1245 // temp = object->GetClass();
1246 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001247 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1248 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001249 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001250 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001251 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001252 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001253 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001254 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001255 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001256 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001257 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001258 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001259 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001260 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001261 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001262 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001263}
1264
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001265void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1266 HandleInvoke(invoke);
1267 // Add the hidden argument.
1268 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1269}
1270
1271void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1272 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001273 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001274 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1275 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1276 LocationSummary* locations = invoke->GetLocations();
1277 Location receiver = locations->InAt(0);
1278 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1279
1280 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001281 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1282 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001283
1284 // temp = object->GetClass();
1285 if (receiver.IsStackSlot()) {
1286 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1287 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1288 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001289 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001290 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001291 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001292 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001293 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001294 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001295 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1296 // LR = temp->GetEntryPoint();
1297 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1298 // LR();
1299 __ blx(LR);
1300 DCHECK(!codegen_->IsLeafMethod());
1301 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1302}
1303
Roland Levillain88cb1752014-10-20 16:36:47 +01001304void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1305 LocationSummary* locations =
1306 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1307 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001308 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001309 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001310 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1311 break;
1312 }
1313 case Primitive::kPrimLong: {
1314 locations->SetInAt(0, Location::RequiresRegister());
1315 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001316 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001317 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001318
Roland Levillain88cb1752014-10-20 16:36:47 +01001319 case Primitive::kPrimFloat:
1320 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001321 locations->SetInAt(0, Location::RequiresFpuRegister());
1322 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001323 break;
1324
1325 default:
1326 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1327 }
1328}
1329
1330void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1331 LocationSummary* locations = neg->GetLocations();
1332 Location out = locations->Out();
1333 Location in = locations->InAt(0);
1334 switch (neg->GetResultType()) {
1335 case Primitive::kPrimInt:
1336 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001337 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001338 break;
1339
1340 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001341 DCHECK(in.IsRegisterPair());
1342 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1343 __ rsbs(out.AsRegisterPairLow<Register>(),
1344 in.AsRegisterPairLow<Register>(),
1345 ShifterOperand(0));
1346 // We cannot emit an RSC (Reverse Subtract with Carry)
1347 // instruction here, as it does not exist in the Thumb-2
1348 // instruction set. We use the following approach
1349 // using SBC and SUB instead.
1350 //
1351 // out.hi = -C
1352 __ sbc(out.AsRegisterPairHigh<Register>(),
1353 out.AsRegisterPairHigh<Register>(),
1354 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1355 // out.hi = out.hi - in.hi
1356 __ sub(out.AsRegisterPairHigh<Register>(),
1357 out.AsRegisterPairHigh<Register>(),
1358 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1359 break;
1360
Roland Levillain88cb1752014-10-20 16:36:47 +01001361 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001362 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001363 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001364 break;
1365
Roland Levillain88cb1752014-10-20 16:36:47 +01001366 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001367 DCHECK(in.IsFpuRegisterPair());
1368 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1369 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001370 break;
1371
1372 default:
1373 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1374 }
1375}
1376
Roland Levillaindff1f282014-11-05 14:15:05 +00001377void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001378 Primitive::Type result_type = conversion->GetResultType();
1379 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001380 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001381
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001382 // The float-to-long and double-to-long type conversions rely on a
1383 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001384 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001385 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1386 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001387 ? LocationSummary::kCall
1388 : LocationSummary::kNoCall;
1389 LocationSummary* locations =
1390 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1391
Roland Levillaindff1f282014-11-05 14:15:05 +00001392 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001393 case Primitive::kPrimByte:
1394 switch (input_type) {
1395 case Primitive::kPrimShort:
1396 case Primitive::kPrimInt:
1397 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001398 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001399 locations->SetInAt(0, Location::RequiresRegister());
1400 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1401 break;
1402
1403 default:
1404 LOG(FATAL) << "Unexpected type conversion from " << input_type
1405 << " to " << result_type;
1406 }
1407 break;
1408
Roland Levillain01a8d712014-11-14 16:27:39 +00001409 case Primitive::kPrimShort:
1410 switch (input_type) {
1411 case Primitive::kPrimByte:
1412 case Primitive::kPrimInt:
1413 case Primitive::kPrimChar:
1414 // Processing a Dex `int-to-short' instruction.
1415 locations->SetInAt(0, Location::RequiresRegister());
1416 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1417 break;
1418
1419 default:
1420 LOG(FATAL) << "Unexpected type conversion from " << input_type
1421 << " to " << result_type;
1422 }
1423 break;
1424
Roland Levillain946e1432014-11-11 17:35:19 +00001425 case Primitive::kPrimInt:
1426 switch (input_type) {
1427 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001428 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001429 locations->SetInAt(0, Location::Any());
1430 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1431 break;
1432
1433 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001434 // Processing a Dex `float-to-int' instruction.
1435 locations->SetInAt(0, Location::RequiresFpuRegister());
1436 locations->SetOut(Location::RequiresRegister());
1437 locations->AddTemp(Location::RequiresFpuRegister());
1438 break;
1439
Roland Levillain946e1432014-11-11 17:35:19 +00001440 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001441 // Processing a Dex `double-to-int' instruction.
1442 locations->SetInAt(0, Location::RequiresFpuRegister());
1443 locations->SetOut(Location::RequiresRegister());
1444 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001445 break;
1446
1447 default:
1448 LOG(FATAL) << "Unexpected type conversion from " << input_type
1449 << " to " << result_type;
1450 }
1451 break;
1452
Roland Levillaindff1f282014-11-05 14:15:05 +00001453 case Primitive::kPrimLong:
1454 switch (input_type) {
1455 case Primitive::kPrimByte:
1456 case Primitive::kPrimShort:
1457 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001458 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001459 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001460 locations->SetInAt(0, Location::RequiresRegister());
1461 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1462 break;
1463
Roland Levillain624279f2014-12-04 11:54:28 +00001464 case Primitive::kPrimFloat: {
1465 // Processing a Dex `float-to-long' instruction.
1466 InvokeRuntimeCallingConvention calling_convention;
1467 locations->SetInAt(0, Location::FpuRegisterLocation(
1468 calling_convention.GetFpuRegisterAt(0)));
1469 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1470 break;
1471 }
1472
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001473 case Primitive::kPrimDouble: {
1474 // Processing a Dex `double-to-long' instruction.
1475 InvokeRuntimeCallingConvention calling_convention;
1476 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1477 calling_convention.GetFpuRegisterAt(0),
1478 calling_convention.GetFpuRegisterAt(1)));
1479 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001480 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001481 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001482
1483 default:
1484 LOG(FATAL) << "Unexpected type conversion from " << input_type
1485 << " to " << result_type;
1486 }
1487 break;
1488
Roland Levillain981e4542014-11-14 11:47:14 +00001489 case Primitive::kPrimChar:
1490 switch (input_type) {
1491 case Primitive::kPrimByte:
1492 case Primitive::kPrimShort:
1493 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001494 // Processing a Dex `int-to-char' instruction.
1495 locations->SetInAt(0, Location::RequiresRegister());
1496 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1497 break;
1498
1499 default:
1500 LOG(FATAL) << "Unexpected type conversion from " << input_type
1501 << " to " << result_type;
1502 }
1503 break;
1504
Roland Levillaindff1f282014-11-05 14:15:05 +00001505 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001506 switch (input_type) {
1507 case Primitive::kPrimByte:
1508 case Primitive::kPrimShort:
1509 case Primitive::kPrimInt:
1510 case Primitive::kPrimChar:
1511 // Processing a Dex `int-to-float' instruction.
1512 locations->SetInAt(0, Location::RequiresRegister());
1513 locations->SetOut(Location::RequiresFpuRegister());
1514 break;
1515
1516 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001517 // Processing a Dex `long-to-float' instruction.
1518 locations->SetInAt(0, Location::RequiresRegister());
1519 locations->SetOut(Location::RequiresFpuRegister());
1520 locations->AddTemp(Location::RequiresRegister());
1521 locations->AddTemp(Location::RequiresRegister());
1522 locations->AddTemp(Location::RequiresFpuRegister());
1523 locations->AddTemp(Location::RequiresFpuRegister());
1524 break;
1525
Roland Levillaincff13742014-11-17 14:32:17 +00001526 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001527 // Processing a Dex `double-to-float' instruction.
1528 locations->SetInAt(0, Location::RequiresFpuRegister());
1529 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001530 break;
1531
1532 default:
1533 LOG(FATAL) << "Unexpected type conversion from " << input_type
1534 << " to " << result_type;
1535 };
1536 break;
1537
Roland Levillaindff1f282014-11-05 14:15:05 +00001538 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001539 switch (input_type) {
1540 case Primitive::kPrimByte:
1541 case Primitive::kPrimShort:
1542 case Primitive::kPrimInt:
1543 case Primitive::kPrimChar:
1544 // Processing a Dex `int-to-double' instruction.
1545 locations->SetInAt(0, Location::RequiresRegister());
1546 locations->SetOut(Location::RequiresFpuRegister());
1547 break;
1548
1549 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001550 // Processing a Dex `long-to-double' instruction.
1551 locations->SetInAt(0, Location::RequiresRegister());
1552 locations->SetOut(Location::RequiresFpuRegister());
1553 locations->AddTemp(Location::RequiresRegister());
1554 locations->AddTemp(Location::RequiresRegister());
1555 locations->AddTemp(Location::RequiresFpuRegister());
1556 break;
1557
Roland Levillaincff13742014-11-17 14:32:17 +00001558 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001559 // Processing a Dex `float-to-double' instruction.
1560 locations->SetInAt(0, Location::RequiresFpuRegister());
1561 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001562 break;
1563
1564 default:
1565 LOG(FATAL) << "Unexpected type conversion from " << input_type
1566 << " to " << result_type;
1567 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001568 break;
1569
1570 default:
1571 LOG(FATAL) << "Unexpected type conversion from " << input_type
1572 << " to " << result_type;
1573 }
1574}
1575
1576void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1577 LocationSummary* locations = conversion->GetLocations();
1578 Location out = locations->Out();
1579 Location in = locations->InAt(0);
1580 Primitive::Type result_type = conversion->GetResultType();
1581 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001582 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001583 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001584 case Primitive::kPrimByte:
1585 switch (input_type) {
1586 case Primitive::kPrimShort:
1587 case Primitive::kPrimInt:
1588 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001589 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001590 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001591 break;
1592
1593 default:
1594 LOG(FATAL) << "Unexpected type conversion from " << input_type
1595 << " to " << result_type;
1596 }
1597 break;
1598
Roland Levillain01a8d712014-11-14 16:27:39 +00001599 case Primitive::kPrimShort:
1600 switch (input_type) {
1601 case Primitive::kPrimByte:
1602 case Primitive::kPrimInt:
1603 case Primitive::kPrimChar:
1604 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001605 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001606 break;
1607
1608 default:
1609 LOG(FATAL) << "Unexpected type conversion from " << input_type
1610 << " to " << result_type;
1611 }
1612 break;
1613
Roland Levillain946e1432014-11-11 17:35:19 +00001614 case Primitive::kPrimInt:
1615 switch (input_type) {
1616 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001617 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001618 DCHECK(out.IsRegister());
1619 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001620 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001621 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001622 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001623 } else {
1624 DCHECK(in.IsConstant());
1625 DCHECK(in.GetConstant()->IsLongConstant());
1626 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001627 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001628 }
1629 break;
1630
Roland Levillain3f8f9362014-12-02 17:45:01 +00001631 case Primitive::kPrimFloat: {
1632 // Processing a Dex `float-to-int' instruction.
1633 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1634 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1635 __ vcvtis(temp, temp);
1636 __ vmovrs(out.AsRegister<Register>(), temp);
1637 break;
1638 }
1639
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001640 case Primitive::kPrimDouble: {
1641 // Processing a Dex `double-to-int' instruction.
1642 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1643 DRegister temp_d = FromLowSToD(temp_s);
1644 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1645 __ vcvtid(temp_s, temp_d);
1646 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001647 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001648 }
Roland Levillain946e1432014-11-11 17:35:19 +00001649
1650 default:
1651 LOG(FATAL) << "Unexpected type conversion from " << input_type
1652 << " to " << result_type;
1653 }
1654 break;
1655
Roland Levillaindff1f282014-11-05 14:15:05 +00001656 case Primitive::kPrimLong:
1657 switch (input_type) {
1658 case Primitive::kPrimByte:
1659 case Primitive::kPrimShort:
1660 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001661 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001662 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001663 DCHECK(out.IsRegisterPair());
1664 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001665 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001666 // Sign extension.
1667 __ Asr(out.AsRegisterPairHigh<Register>(),
1668 out.AsRegisterPairLow<Register>(),
1669 31);
1670 break;
1671
1672 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001673 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001674 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1675 conversion,
1676 conversion->GetDexPc());
1677 break;
1678
Roland Levillaindff1f282014-11-05 14:15:05 +00001679 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001680 // Processing a Dex `double-to-long' instruction.
1681 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1682 conversion,
1683 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001684 break;
1685
1686 default:
1687 LOG(FATAL) << "Unexpected type conversion from " << input_type
1688 << " to " << result_type;
1689 }
1690 break;
1691
Roland Levillain981e4542014-11-14 11:47:14 +00001692 case Primitive::kPrimChar:
1693 switch (input_type) {
1694 case Primitive::kPrimByte:
1695 case Primitive::kPrimShort:
1696 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001697 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001698 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001699 break;
1700
1701 default:
1702 LOG(FATAL) << "Unexpected type conversion from " << input_type
1703 << " to " << result_type;
1704 }
1705 break;
1706
Roland Levillaindff1f282014-11-05 14:15:05 +00001707 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001708 switch (input_type) {
1709 case Primitive::kPrimByte:
1710 case Primitive::kPrimShort:
1711 case Primitive::kPrimInt:
1712 case Primitive::kPrimChar: {
1713 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001714 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1715 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001716 break;
1717 }
1718
Roland Levillain6d0e4832014-11-27 18:31:21 +00001719 case Primitive::kPrimLong: {
1720 // Processing a Dex `long-to-float' instruction.
1721 Register low = in.AsRegisterPairLow<Register>();
1722 Register high = in.AsRegisterPairHigh<Register>();
1723 SRegister output = out.AsFpuRegister<SRegister>();
1724 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1725 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1726 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1727 DRegister temp1_d = FromLowSToD(temp1_s);
1728 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1729 DRegister temp2_d = FromLowSToD(temp2_s);
1730
1731 // Operations use doubles for precision reasons (each 32-bit
1732 // half of a long fits in the 53-bit mantissa of a double,
1733 // but not in the 24-bit mantissa of a float). This is
1734 // especially important for the low bits. The result is
1735 // eventually converted to float.
1736
1737 // temp1_d = int-to-double(high)
1738 __ vmovsr(temp1_s, high);
1739 __ vcvtdi(temp1_d, temp1_s);
1740 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1741 // as an immediate value into `temp2_d` does not work, as
1742 // this instruction only transfers 8 significant bits of its
1743 // immediate operand. Instead, use two 32-bit core
1744 // registers to load `k2Pow32EncodingForDouble` into
1745 // `temp2_d`.
1746 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1747 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1748 __ vmovdrr(temp2_d, constant_low, constant_high);
1749 // temp1_d = temp1_d * 2^32
1750 __ vmuld(temp1_d, temp1_d, temp2_d);
1751 // temp2_d = unsigned-to-double(low)
1752 __ vmovsr(temp2_s, low);
1753 __ vcvtdu(temp2_d, temp2_s);
1754 // temp1_d = temp1_d + temp2_d
1755 __ vaddd(temp1_d, temp1_d, temp2_d);
1756 // output = double-to-float(temp1_d);
1757 __ vcvtsd(output, temp1_d);
1758 break;
1759 }
1760
Roland Levillaincff13742014-11-17 14:32:17 +00001761 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001762 // Processing a Dex `double-to-float' instruction.
1763 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1764 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001765 break;
1766
1767 default:
1768 LOG(FATAL) << "Unexpected type conversion from " << input_type
1769 << " to " << result_type;
1770 };
1771 break;
1772
Roland Levillaindff1f282014-11-05 14:15:05 +00001773 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001774 switch (input_type) {
1775 case Primitive::kPrimByte:
1776 case Primitive::kPrimShort:
1777 case Primitive::kPrimInt:
1778 case Primitive::kPrimChar: {
1779 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001780 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001781 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1782 out.AsFpuRegisterPairLow<SRegister>());
1783 break;
1784 }
1785
Roland Levillain647b9ed2014-11-27 12:06:00 +00001786 case Primitive::kPrimLong: {
1787 // Processing a Dex `long-to-double' instruction.
1788 Register low = in.AsRegisterPairLow<Register>();
1789 Register high = in.AsRegisterPairHigh<Register>();
1790 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1791 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001792 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1793 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001794 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1795 DRegister temp_d = FromLowSToD(temp_s);
1796
Roland Levillain647b9ed2014-11-27 12:06:00 +00001797 // out_d = int-to-double(high)
1798 __ vmovsr(out_s, high);
1799 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001800 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1801 // as an immediate value into `temp_d` does not work, as
1802 // this instruction only transfers 8 significant bits of its
1803 // immediate operand. Instead, use two 32-bit core
1804 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1805 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1806 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001807 __ vmovdrr(temp_d, constant_low, constant_high);
1808 // out_d = out_d * 2^32
1809 __ vmuld(out_d, out_d, temp_d);
1810 // temp_d = unsigned-to-double(low)
1811 __ vmovsr(temp_s, low);
1812 __ vcvtdu(temp_d, temp_s);
1813 // out_d = out_d + temp_d
1814 __ vaddd(out_d, out_d, temp_d);
1815 break;
1816 }
1817
Roland Levillaincff13742014-11-17 14:32:17 +00001818 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001819 // Processing a Dex `float-to-double' instruction.
1820 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1821 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001822 break;
1823
1824 default:
1825 LOG(FATAL) << "Unexpected type conversion from " << input_type
1826 << " to " << result_type;
1827 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001828 break;
1829
1830 default:
1831 LOG(FATAL) << "Unexpected type conversion from " << input_type
1832 << " to " << result_type;
1833 }
1834}
1835
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001836void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001837 LocationSummary* locations =
1838 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001839 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001840 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001841 locations->SetInAt(0, Location::RequiresRegister());
1842 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001843 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1844 break;
1845 }
1846
1847 case Primitive::kPrimLong: {
1848 locations->SetInAt(0, Location::RequiresRegister());
1849 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001850 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001851 break;
1852 }
1853
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001854 case Primitive::kPrimFloat:
1855 case Primitive::kPrimDouble: {
1856 locations->SetInAt(0, Location::RequiresFpuRegister());
1857 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001858 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001859 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001860 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001861
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001862 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001863 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001864 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001865}
1866
1867void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1868 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001869 Location out = locations->Out();
1870 Location first = locations->InAt(0);
1871 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001872 switch (add->GetResultType()) {
1873 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001874 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001875 __ add(out.AsRegister<Register>(),
1876 first.AsRegister<Register>(),
1877 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001878 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001879 __ AddConstant(out.AsRegister<Register>(),
1880 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001881 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001882 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001883 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001884
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001885 case Primitive::kPrimLong: {
1886 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001887 __ adds(out.AsRegisterPairLow<Register>(),
1888 first.AsRegisterPairLow<Register>(),
1889 ShifterOperand(second.AsRegisterPairLow<Register>()));
1890 __ adc(out.AsRegisterPairHigh<Register>(),
1891 first.AsRegisterPairHigh<Register>(),
1892 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001893 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001894 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001895
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001896 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001897 __ vadds(out.AsFpuRegister<SRegister>(),
1898 first.AsFpuRegister<SRegister>(),
1899 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001900 break;
1901
1902 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001903 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1904 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1905 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001906 break;
1907
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001908 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001909 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001910 }
1911}
1912
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001913void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001914 LocationSummary* locations =
1915 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001916 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001917 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001918 locations->SetInAt(0, Location::RequiresRegister());
1919 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001920 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1921 break;
1922 }
1923
1924 case Primitive::kPrimLong: {
1925 locations->SetInAt(0, Location::RequiresRegister());
1926 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001927 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001928 break;
1929 }
Calin Juravle11351682014-10-23 15:38:15 +01001930 case Primitive::kPrimFloat:
1931 case Primitive::kPrimDouble: {
1932 locations->SetInAt(0, Location::RequiresFpuRegister());
1933 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001934 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001935 break;
Calin Juravle11351682014-10-23 15:38:15 +01001936 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001937 default:
Calin Juravle11351682014-10-23 15:38:15 +01001938 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001939 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001940}
1941
1942void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1943 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001944 Location out = locations->Out();
1945 Location first = locations->InAt(0);
1946 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001947 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001948 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001949 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001950 __ sub(out.AsRegister<Register>(),
1951 first.AsRegister<Register>(),
1952 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001953 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001954 __ AddConstant(out.AsRegister<Register>(),
1955 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001956 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001957 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001958 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001959 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001960
Calin Juravle11351682014-10-23 15:38:15 +01001961 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001962 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001963 __ subs(out.AsRegisterPairLow<Register>(),
1964 first.AsRegisterPairLow<Register>(),
1965 ShifterOperand(second.AsRegisterPairLow<Register>()));
1966 __ sbc(out.AsRegisterPairHigh<Register>(),
1967 first.AsRegisterPairHigh<Register>(),
1968 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001969 break;
Calin Juravle11351682014-10-23 15:38:15 +01001970 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001971
Calin Juravle11351682014-10-23 15:38:15 +01001972 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001973 __ vsubs(out.AsFpuRegister<SRegister>(),
1974 first.AsFpuRegister<SRegister>(),
1975 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001976 break;
Calin Juravle11351682014-10-23 15:38:15 +01001977 }
1978
1979 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001980 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1981 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1982 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001983 break;
1984 }
1985
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001986
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001987 default:
Calin Juravle11351682014-10-23 15:38:15 +01001988 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001989 }
1990}
1991
Calin Juravle34bacdf2014-10-07 20:23:36 +01001992void LocationsBuilderARM::VisitMul(HMul* mul) {
1993 LocationSummary* locations =
1994 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1995 switch (mul->GetResultType()) {
1996 case Primitive::kPrimInt:
1997 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001998 locations->SetInAt(0, Location::RequiresRegister());
1999 locations->SetInAt(1, Location::RequiresRegister());
2000 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002001 break;
2002 }
2003
Calin Juravleb5bfa962014-10-21 18:02:24 +01002004 case Primitive::kPrimFloat:
2005 case Primitive::kPrimDouble: {
2006 locations->SetInAt(0, Location::RequiresFpuRegister());
2007 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002008 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002009 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002010 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002011
2012 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002013 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002014 }
2015}
2016
2017void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2018 LocationSummary* locations = mul->GetLocations();
2019 Location out = locations->Out();
2020 Location first = locations->InAt(0);
2021 Location second = locations->InAt(1);
2022 switch (mul->GetResultType()) {
2023 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002024 __ mul(out.AsRegister<Register>(),
2025 first.AsRegister<Register>(),
2026 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002027 break;
2028 }
2029 case Primitive::kPrimLong: {
2030 Register out_hi = out.AsRegisterPairHigh<Register>();
2031 Register out_lo = out.AsRegisterPairLow<Register>();
2032 Register in1_hi = first.AsRegisterPairHigh<Register>();
2033 Register in1_lo = first.AsRegisterPairLow<Register>();
2034 Register in2_hi = second.AsRegisterPairHigh<Register>();
2035 Register in2_lo = second.AsRegisterPairLow<Register>();
2036
2037 // Extra checks to protect caused by the existence of R1_R2.
2038 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2039 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2040 DCHECK_NE(out_hi, in1_lo);
2041 DCHECK_NE(out_hi, in2_lo);
2042
2043 // input: in1 - 64 bits, in2 - 64 bits
2044 // output: out
2045 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2046 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2047 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2048
2049 // IP <- in1.lo * in2.hi
2050 __ mul(IP, in1_lo, in2_hi);
2051 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2052 __ mla(out_hi, in1_hi, in2_lo, IP);
2053 // out.lo <- (in1.lo * in2.lo)[31:0];
2054 __ umull(out_lo, IP, in1_lo, in2_lo);
2055 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2056 __ add(out_hi, out_hi, ShifterOperand(IP));
2057 break;
2058 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002059
2060 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002061 __ vmuls(out.AsFpuRegister<SRegister>(),
2062 first.AsFpuRegister<SRegister>(),
2063 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002064 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002065 }
2066
2067 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002068 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2069 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2070 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002071 break;
2072 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002073
2074 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002075 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002076 }
2077}
2078
Calin Juravle7c4954d2014-10-28 16:57:40 +00002079void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002080 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2081 ? LocationSummary::kCall
2082 : LocationSummary::kNoCall;
2083 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2084
Calin Juravle7c4954d2014-10-28 16:57:40 +00002085 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002086 case Primitive::kPrimInt: {
2087 locations->SetInAt(0, Location::RequiresRegister());
2088 locations->SetInAt(1, Location::RequiresRegister());
2089 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2090 break;
2091 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002092 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002093 InvokeRuntimeCallingConvention calling_convention;
2094 locations->SetInAt(0, Location::RegisterPairLocation(
2095 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2096 locations->SetInAt(1, Location::RegisterPairLocation(
2097 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002098 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002099 break;
2100 }
2101 case Primitive::kPrimFloat:
2102 case Primitive::kPrimDouble: {
2103 locations->SetInAt(0, Location::RequiresFpuRegister());
2104 locations->SetInAt(1, Location::RequiresFpuRegister());
2105 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2106 break;
2107 }
2108
2109 default:
2110 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2111 }
2112}
2113
2114void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2115 LocationSummary* locations = div->GetLocations();
2116 Location out = locations->Out();
2117 Location first = locations->InAt(0);
2118 Location second = locations->InAt(1);
2119
2120 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002121 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002122 __ sdiv(out.AsRegister<Register>(),
2123 first.AsRegister<Register>(),
2124 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002125 break;
2126 }
2127
Calin Juravle7c4954d2014-10-28 16:57:40 +00002128 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002129 InvokeRuntimeCallingConvention calling_convention;
2130 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2131 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2132 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2133 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2134 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002135 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002136
2137 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002138 break;
2139 }
2140
2141 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002142 __ vdivs(out.AsFpuRegister<SRegister>(),
2143 first.AsFpuRegister<SRegister>(),
2144 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002145 break;
2146 }
2147
2148 case Primitive::kPrimDouble: {
2149 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2150 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2151 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2152 break;
2153 }
2154
2155 default:
2156 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2157 }
2158}
2159
Calin Juravlebacfec32014-11-14 15:54:36 +00002160void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002161 Primitive::Type type = rem->GetResultType();
2162 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2163 ? LocationSummary::kNoCall
2164 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002165 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2166
Calin Juravled2ec87d2014-12-08 14:24:46 +00002167 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002168 case Primitive::kPrimInt: {
2169 locations->SetInAt(0, Location::RequiresRegister());
2170 locations->SetInAt(1, Location::RequiresRegister());
2171 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2172 locations->AddTemp(Location::RequiresRegister());
2173 break;
2174 }
2175 case Primitive::kPrimLong: {
2176 InvokeRuntimeCallingConvention calling_convention;
2177 locations->SetInAt(0, Location::RegisterPairLocation(
2178 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2179 locations->SetInAt(1, Location::RegisterPairLocation(
2180 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2181 // The runtime helper puts the output in R2,R3.
2182 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2183 break;
2184 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002185 case Primitive::kPrimFloat: {
2186 InvokeRuntimeCallingConvention calling_convention;
2187 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2188 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2189 locations->SetOut(Location::FpuRegisterLocation(S0));
2190 break;
2191 }
2192
Calin Juravlebacfec32014-11-14 15:54:36 +00002193 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002194 InvokeRuntimeCallingConvention calling_convention;
2195 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2196 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2197 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2198 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2199 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002200 break;
2201 }
2202
2203 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002204 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002205 }
2206}
2207
2208void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2209 LocationSummary* locations = rem->GetLocations();
2210 Location out = locations->Out();
2211 Location first = locations->InAt(0);
2212 Location second = locations->InAt(1);
2213
Calin Juravled2ec87d2014-12-08 14:24:46 +00002214 Primitive::Type type = rem->GetResultType();
2215 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002216 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002217 Register reg1 = first.AsRegister<Register>();
2218 Register reg2 = second.AsRegister<Register>();
2219 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002220
2221 // temp = reg1 / reg2 (integer division)
2222 // temp = temp * reg2
2223 // dest = reg1 - temp
2224 __ sdiv(temp, reg1, reg2);
2225 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002226 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002227 break;
2228 }
2229
2230 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002231 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2232 break;
2233 }
2234
Calin Juravled2ec87d2014-12-08 14:24:46 +00002235 case Primitive::kPrimFloat: {
2236 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2237 break;
2238 }
2239
Calin Juravlebacfec32014-11-14 15:54:36 +00002240 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002241 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002242 break;
2243 }
2244
2245 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002246 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002247 }
2248}
2249
Calin Juravled0d48522014-11-04 16:40:20 +00002250void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2251 LocationSummary* locations =
2252 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002253 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002254 if (instruction->HasUses()) {
2255 locations->SetOut(Location::SameAsFirstInput());
2256 }
2257}
2258
2259void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2260 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2261 codegen_->AddSlowPath(slow_path);
2262
2263 LocationSummary* locations = instruction->GetLocations();
2264 Location value = locations->InAt(0);
2265
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002266 switch (instruction->GetType()) {
2267 case Primitive::kPrimInt: {
2268 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002269 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002270 __ b(slow_path->GetEntryLabel(), EQ);
2271 } else {
2272 DCHECK(value.IsConstant()) << value;
2273 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2274 __ b(slow_path->GetEntryLabel());
2275 }
2276 }
2277 break;
2278 }
2279 case Primitive::kPrimLong: {
2280 if (value.IsRegisterPair()) {
2281 __ orrs(IP,
2282 value.AsRegisterPairLow<Register>(),
2283 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2284 __ b(slow_path->GetEntryLabel(), EQ);
2285 } else {
2286 DCHECK(value.IsConstant()) << value;
2287 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2288 __ b(slow_path->GetEntryLabel());
2289 }
2290 }
2291 break;
2292 default:
2293 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2294 }
2295 }
Calin Juravled0d48522014-11-04 16:40:20 +00002296}
2297
Calin Juravle9aec02f2014-11-18 23:06:35 +00002298void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2299 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2300
2301 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2302 ? LocationSummary::kCall
2303 : LocationSummary::kNoCall;
2304 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2305
2306 switch (op->GetResultType()) {
2307 case Primitive::kPrimInt: {
2308 locations->SetInAt(0, Location::RequiresRegister());
2309 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002310 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002311 break;
2312 }
2313 case Primitive::kPrimLong: {
2314 InvokeRuntimeCallingConvention calling_convention;
2315 locations->SetInAt(0, Location::RegisterPairLocation(
2316 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2317 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002318 // The runtime helper puts the output in R0,R1.
2319 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002320 break;
2321 }
2322 default:
2323 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2324 }
2325}
2326
2327void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2328 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2329
2330 LocationSummary* locations = op->GetLocations();
2331 Location out = locations->Out();
2332 Location first = locations->InAt(0);
2333 Location second = locations->InAt(1);
2334
2335 Primitive::Type type = op->GetResultType();
2336 switch (type) {
2337 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002338 Register out_reg = out.AsRegister<Register>();
2339 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002340 // Arm doesn't mask the shift count so we need to do it ourselves.
2341 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002342 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002343 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2344 if (op->IsShl()) {
2345 __ Lsl(out_reg, first_reg, second_reg);
2346 } else if (op->IsShr()) {
2347 __ Asr(out_reg, first_reg, second_reg);
2348 } else {
2349 __ Lsr(out_reg, first_reg, second_reg);
2350 }
2351 } else {
2352 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2353 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2354 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2355 __ Mov(out_reg, first_reg);
2356 } else if (op->IsShl()) {
2357 __ Lsl(out_reg, first_reg, shift_value);
2358 } else if (op->IsShr()) {
2359 __ Asr(out_reg, first_reg, shift_value);
2360 } else {
2361 __ Lsr(out_reg, first_reg, shift_value);
2362 }
2363 }
2364 break;
2365 }
2366 case Primitive::kPrimLong: {
2367 // TODO: Inline the assembly instead of calling the runtime.
2368 InvokeRuntimeCallingConvention calling_convention;
2369 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2370 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002371 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002372 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002373 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002374
2375 int32_t entry_point_offset;
2376 if (op->IsShl()) {
2377 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2378 } else if (op->IsShr()) {
2379 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2380 } else {
2381 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2382 }
2383 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2384 __ blx(LR);
2385 break;
2386 }
2387 default:
2388 LOG(FATAL) << "Unexpected operation type " << type;
2389 }
2390}
2391
2392void LocationsBuilderARM::VisitShl(HShl* shl) {
2393 HandleShift(shl);
2394}
2395
2396void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2397 HandleShift(shl);
2398}
2399
2400void LocationsBuilderARM::VisitShr(HShr* shr) {
2401 HandleShift(shr);
2402}
2403
2404void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2405 HandleShift(shr);
2406}
2407
2408void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2409 HandleShift(ushr);
2410}
2411
2412void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2413 HandleShift(ushr);
2414}
2415
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002416void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002417 LocationSummary* locations =
2418 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002419 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002420 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2421 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2422 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002423}
2424
2425void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2426 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002427 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002428 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002429 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2430 instruction,
2431 instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002432}
2433
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002434void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2435 LocationSummary* locations =
2436 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2437 InvokeRuntimeCallingConvention calling_convention;
2438 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002439 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002440 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002441 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002442}
2443
2444void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2445 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002446 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002447 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002448 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2449 instruction,
2450 instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002451}
2452
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002453void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002454 LocationSummary* locations =
2455 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002456 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2457 if (location.IsStackSlot()) {
2458 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2459 } else if (location.IsDoubleStackSlot()) {
2460 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002461 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002462 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002463}
2464
2465void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002466 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002467 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002468}
2469
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002470void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002471 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002472 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002473 locations->SetInAt(0, Location::RequiresRegister());
2474 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002475}
2476
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002477void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2478 LocationSummary* locations = not_->GetLocations();
2479 Location out = locations->Out();
2480 Location in = locations->InAt(0);
2481 switch (not_->InputAt(0)->GetType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002482 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002483 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002484 break;
2485
2486 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002487 __ mvn(out.AsRegisterPairLow<Register>(),
2488 ShifterOperand(in.AsRegisterPairLow<Register>()));
2489 __ mvn(out.AsRegisterPairHigh<Register>(),
2490 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002491 break;
2492
2493 default:
2494 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2495 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002496}
2497
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002498void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002499 LocationSummary* locations =
2500 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002501 switch (compare->InputAt(0)->GetType()) {
2502 case Primitive::kPrimLong: {
2503 locations->SetInAt(0, Location::RequiresRegister());
2504 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002505 // Output overlaps because it is written before doing the low comparison.
2506 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002507 break;
2508 }
2509 case Primitive::kPrimFloat:
2510 case Primitive::kPrimDouble: {
2511 locations->SetInAt(0, Location::RequiresFpuRegister());
2512 locations->SetInAt(1, Location::RequiresFpuRegister());
2513 locations->SetOut(Location::RequiresRegister());
2514 break;
2515 }
2516 default:
2517 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2518 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002519}
2520
2521void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002522 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002523 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002524 Location left = locations->InAt(0);
2525 Location right = locations->InAt(1);
2526
2527 Label less, greater, done;
2528 Primitive::Type type = compare->InputAt(0)->GetType();
2529 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002530 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002531 __ cmp(left.AsRegisterPairHigh<Register>(),
2532 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002533 __ b(&less, LT);
2534 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002535 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2536 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002537 __ cmp(left.AsRegisterPairLow<Register>(),
2538 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002539 break;
2540 }
2541 case Primitive::kPrimFloat:
2542 case Primitive::kPrimDouble: {
2543 __ LoadImmediate(out, 0);
2544 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002545 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002546 } else {
2547 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2548 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2549 }
2550 __ vmstat(); // transfer FP status register to ARM APSR.
2551 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002552 break;
2553 }
2554 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002555 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002556 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002557 __ b(&done, EQ);
2558 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2559
2560 __ Bind(&greater);
2561 __ LoadImmediate(out, 1);
2562 __ b(&done);
2563
2564 __ Bind(&less);
2565 __ LoadImmediate(out, -1);
2566
2567 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002568}
2569
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002570void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002571 LocationSummary* locations =
2572 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002573 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2574 locations->SetInAt(i, Location::Any());
2575 }
2576 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002577}
2578
2579void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002580 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002581 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002582}
2583
Calin Juravle52c48962014-12-16 17:02:57 +00002584void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2585 // TODO (ported from quick): revisit Arm barrier kinds
2586 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2587 switch (kind) {
2588 case MemBarrierKind::kAnyStore:
2589 case MemBarrierKind::kLoadAny:
2590 case MemBarrierKind::kAnyAny: {
2591 flavour = DmbOptions::ISH;
2592 break;
2593 }
2594 case MemBarrierKind::kStoreStore: {
2595 flavour = DmbOptions::ISHST;
2596 break;
2597 }
2598 default:
2599 LOG(FATAL) << "Unexpected memory barrier " << kind;
2600 }
2601 __ dmb(flavour);
2602}
2603
2604void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2605 uint32_t offset,
2606 Register out_lo,
2607 Register out_hi) {
2608 if (offset != 0) {
2609 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002610 __ add(IP, addr, ShifterOperand(out_lo));
2611 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002612 }
2613 __ ldrexd(out_lo, out_hi, addr);
2614}
2615
2616void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2617 uint32_t offset,
2618 Register value_lo,
2619 Register value_hi,
2620 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002621 Register temp2,
2622 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002623 Label fail;
2624 if (offset != 0) {
2625 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002626 __ add(IP, addr, ShifterOperand(temp1));
2627 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002628 }
2629 __ Bind(&fail);
2630 // We need a load followed by store. (The address used in a STREX instruction must
2631 // be the same as the address in the most recently executed LDREX instruction.)
2632 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002633 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002634 __ strexd(temp1, value_lo, value_hi, addr);
2635 __ cmp(temp1, ShifterOperand(0));
2636 __ b(&fail, NE);
2637}
2638
2639void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2640 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2641
Nicolas Geoffray39468442014-09-02 15:17:15 +01002642 LocationSummary* locations =
2643 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002644 locations->SetInAt(0, Location::RequiresRegister());
2645 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002646
Calin Juravle34166012014-12-19 17:22:29 +00002647
Calin Juravle52c48962014-12-16 17:02:57 +00002648 Primitive::Type field_type = field_info.GetFieldType();
2649 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002650 bool generate_volatile = field_info.IsVolatile()
2651 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002652 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002653 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002654 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2655 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002656 locations->AddTemp(Location::RequiresRegister());
2657 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002658 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002659 // Arm encoding have some additional constraints for ldrexd/strexd:
2660 // - registers need to be consecutive
2661 // - the first register should be even but not R14.
2662 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2663 // enable Arm encoding.
2664 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2665
2666 locations->AddTemp(Location::RequiresRegister());
2667 locations->AddTemp(Location::RequiresRegister());
2668 if (field_type == Primitive::kPrimDouble) {
2669 // For doubles we need two more registers to copy the value.
2670 locations->AddTemp(Location::RegisterLocation(R2));
2671 locations->AddTemp(Location::RegisterLocation(R3));
2672 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002673 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002674}
2675
Calin Juravle52c48962014-12-16 17:02:57 +00002676void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2677 const FieldInfo& field_info) {
2678 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2679
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002680 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002681 Register base = locations->InAt(0).AsRegister<Register>();
2682 Location value = locations->InAt(1);
2683
2684 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002685 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002686 Primitive::Type field_type = field_info.GetFieldType();
2687 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2688
2689 if (is_volatile) {
2690 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2691 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002692
2693 switch (field_type) {
2694 case Primitive::kPrimBoolean:
2695 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002696 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002697 break;
2698 }
2699
2700 case Primitive::kPrimShort:
2701 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002702 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002703 break;
2704 }
2705
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002706 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002707 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002708 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002709 break;
2710 }
2711
2712 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002713 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002714 GenerateWideAtomicStore(base, offset,
2715 value.AsRegisterPairLow<Register>(),
2716 value.AsRegisterPairHigh<Register>(),
2717 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002718 locations->GetTemp(1).AsRegister<Register>(),
2719 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002720 } else {
2721 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002722 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002723 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002724 break;
2725 }
2726
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002727 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002728 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002729 break;
2730 }
2731
2732 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002733 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002734 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002735 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2736 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2737
2738 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2739
2740 GenerateWideAtomicStore(base, offset,
2741 value_reg_lo,
2742 value_reg_hi,
2743 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002744 locations->GetTemp(3).AsRegister<Register>(),
2745 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002746 } else {
2747 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002748 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002749 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002750 break;
2751 }
2752
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002753 case Primitive::kPrimVoid:
2754 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002755 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002756 }
Calin Juravle52c48962014-12-16 17:02:57 +00002757
Calin Juravle77520bc2015-01-12 18:45:46 +00002758 // Longs and doubles are handled in the switch.
2759 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2760 codegen_->MaybeRecordImplicitNullCheck(instruction);
2761 }
2762
2763 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2764 Register temp = locations->GetTemp(0).AsRegister<Register>();
2765 Register card = locations->GetTemp(1).AsRegister<Register>();
2766 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2767 }
2768
Calin Juravle52c48962014-12-16 17:02:57 +00002769 if (is_volatile) {
2770 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2771 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002772}
2773
Calin Juravle52c48962014-12-16 17:02:57 +00002774void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2775 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002776 LocationSummary* locations =
2777 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002778 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002779
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002780 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002781 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002782 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002783 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2784 locations->SetOut(Location::RequiresRegister(),
2785 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2786 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002787 // Arm encoding have some additional constraints for ldrexd/strexd:
2788 // - registers need to be consecutive
2789 // - the first register should be even but not R14.
2790 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2791 // enable Arm encoding.
2792 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2793 locations->AddTemp(Location::RequiresRegister());
2794 locations->AddTemp(Location::RequiresRegister());
2795 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002796}
2797
Calin Juravle52c48962014-12-16 17:02:57 +00002798void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2799 const FieldInfo& field_info) {
2800 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002801
Calin Juravle52c48962014-12-16 17:02:57 +00002802 LocationSummary* locations = instruction->GetLocations();
2803 Register base = locations->InAt(0).AsRegister<Register>();
2804 Location out = locations->Out();
2805 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002806 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002807 Primitive::Type field_type = field_info.GetFieldType();
2808 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2809
2810 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002811 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002812 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002813 break;
2814 }
2815
2816 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002817 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002818 break;
2819 }
2820
2821 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002822 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002823 break;
2824 }
2825
2826 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002827 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002828 break;
2829 }
2830
2831 case Primitive::kPrimInt:
2832 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002833 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002834 break;
2835 }
2836
2837 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002838 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002839 GenerateWideAtomicLoad(base, offset,
2840 out.AsRegisterPairLow<Register>(),
2841 out.AsRegisterPairHigh<Register>());
2842 } else {
2843 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2844 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002845 break;
2846 }
2847
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002848 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002849 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002850 break;
2851 }
2852
2853 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002854 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002855 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002856 Register lo = locations->GetTemp(0).AsRegister<Register>();
2857 Register hi = locations->GetTemp(1).AsRegister<Register>();
2858 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002859 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002860 __ vmovdrr(out_reg, lo, hi);
2861 } else {
2862 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002863 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002864 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002865 break;
2866 }
2867
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002868 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002869 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002870 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002871 }
Calin Juravle52c48962014-12-16 17:02:57 +00002872
Calin Juravle77520bc2015-01-12 18:45:46 +00002873 // Doubles are handled in the switch.
2874 if (field_type != Primitive::kPrimDouble) {
2875 codegen_->MaybeRecordImplicitNullCheck(instruction);
2876 }
2877
Calin Juravle52c48962014-12-16 17:02:57 +00002878 if (is_volatile) {
2879 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2880 }
2881}
2882
2883void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2884 HandleFieldSet(instruction, instruction->GetFieldInfo());
2885}
2886
2887void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2888 HandleFieldSet(instruction, instruction->GetFieldInfo());
2889}
2890
2891void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2892 HandleFieldGet(instruction, instruction->GetFieldInfo());
2893}
2894
2895void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2896 HandleFieldGet(instruction, instruction->GetFieldInfo());
2897}
2898
2899void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2900 HandleFieldGet(instruction, instruction->GetFieldInfo());
2901}
2902
2903void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2904 HandleFieldGet(instruction, instruction->GetFieldInfo());
2905}
2906
2907void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2908 HandleFieldSet(instruction, instruction->GetFieldInfo());
2909}
2910
2911void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2912 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002913}
2914
2915void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002916 LocationSummary* locations =
2917 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002918 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002919 if (instruction->HasUses()) {
2920 locations->SetOut(Location::SameAsFirstInput());
2921 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002922}
2923
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002924void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002925 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2926 return;
2927 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002928 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002929
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002930 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2931 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2932}
2933
2934void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002935 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002936 codegen_->AddSlowPath(slow_path);
2937
2938 LocationSummary* locations = instruction->GetLocations();
2939 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002940
Calin Juravle77520bc2015-01-12 18:45:46 +00002941 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2942 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002943}
2944
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002945void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2946 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2947 GenerateImplicitNullCheck(instruction);
2948 } else {
2949 GenerateExplicitNullCheck(instruction);
2950 }
2951}
2952
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002953void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002954 LocationSummary* locations =
2955 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002956 locations->SetInAt(0, Location::RequiresRegister());
2957 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2958 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002959}
2960
2961void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2962 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002963 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002964 Location index = locations->InAt(1);
2965
2966 switch (instruction->GetType()) {
2967 case Primitive::kPrimBoolean: {
2968 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002969 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002970 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002971 size_t offset =
2972 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002973 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2974 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002975 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002976 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2977 }
2978 break;
2979 }
2980
2981 case Primitive::kPrimByte: {
2982 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002983 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002984 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002985 size_t offset =
2986 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002987 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2988 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002989 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002990 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2991 }
2992 break;
2993 }
2994
2995 case Primitive::kPrimShort: {
2996 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002997 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002998 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002999 size_t offset =
3000 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003001 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3002 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003003 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003004 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3005 }
3006 break;
3007 }
3008
3009 case Primitive::kPrimChar: {
3010 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003011 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003012 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003013 size_t offset =
3014 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003015 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3016 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003017 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003018 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3019 }
3020 break;
3021 }
3022
3023 case Primitive::kPrimInt:
3024 case Primitive::kPrimNot: {
3025 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3026 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003027 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003028 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003029 size_t offset =
3030 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003031 __ LoadFromOffset(kLoadWord, out, obj, offset);
3032 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003033 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003034 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3035 }
3036 break;
3037 }
3038
3039 case Primitive::kPrimLong: {
3040 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003041 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003042 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003043 size_t offset =
3044 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003045 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003046 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003047 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003048 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003049 }
3050 break;
3051 }
3052
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003053 case Primitive::kPrimFloat: {
3054 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3055 Location out = locations->Out();
3056 DCHECK(out.IsFpuRegister());
3057 if (index.IsConstant()) {
3058 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3059 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3060 } else {
3061 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3062 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3063 }
3064 break;
3065 }
3066
3067 case Primitive::kPrimDouble: {
3068 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3069 Location out = locations->Out();
3070 DCHECK(out.IsFpuRegisterPair());
3071 if (index.IsConstant()) {
3072 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3073 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3074 } else {
3075 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3076 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3077 }
3078 break;
3079 }
3080
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003081 case Primitive::kPrimVoid:
3082 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003083 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003084 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003085 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003086}
3087
3088void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003089 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003090
3091 bool needs_write_barrier =
3092 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3093 bool needs_runtime_call = instruction->NeedsTypeCheck();
3094
Nicolas Geoffray39468442014-09-02 15:17:15 +01003095 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003096 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3097 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003098 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003099 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3100 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3101 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003102 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003103 locations->SetInAt(0, Location::RequiresRegister());
3104 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3105 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003106
3107 if (needs_write_barrier) {
3108 // Temporary registers for the write barrier.
3109 locations->AddTemp(Location::RequiresRegister());
3110 locations->AddTemp(Location::RequiresRegister());
3111 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003112 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003113}
3114
3115void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3116 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003117 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003118 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003119 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003120 bool needs_runtime_call = locations->WillCall();
3121 bool needs_write_barrier =
3122 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003123
3124 switch (value_type) {
3125 case Primitive::kPrimBoolean:
3126 case Primitive::kPrimByte: {
3127 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_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_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003132 __ StoreToOffset(kStoreByte, value, obj, offset);
3133 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003134 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003135 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3136 }
3137 break;
3138 }
3139
3140 case Primitive::kPrimShort:
3141 case Primitive::kPrimChar: {
3142 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003143 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003144 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003145 size_t offset =
3146 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003147 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3148 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003149 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003150 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3151 }
3152 break;
3153 }
3154
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003155 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003156 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003157 if (!needs_runtime_call) {
3158 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003159 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003160 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003161 size_t offset =
3162 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003163 __ StoreToOffset(kStoreWord, value, obj, offset);
3164 } else {
3165 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003166 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003167 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3168 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003169 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003170 if (needs_write_barrier) {
3171 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003172 Register temp = locations->GetTemp(0).AsRegister<Register>();
3173 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003174 codegen_->MarkGCCard(temp, card, obj, value);
3175 }
3176 } else {
3177 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003178 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3179 instruction,
3180 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003181 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003182 break;
3183 }
3184
3185 case Primitive::kPrimLong: {
3186 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003187 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003188 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003189 size_t offset =
3190 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003191 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003192 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003193 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003194 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003195 }
3196 break;
3197 }
3198
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003199 case Primitive::kPrimFloat: {
3200 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3201 Location value = locations->InAt(2);
3202 DCHECK(value.IsFpuRegister());
3203 if (index.IsConstant()) {
3204 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3205 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3206 } else {
3207 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3208 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3209 }
3210 break;
3211 }
3212
3213 case Primitive::kPrimDouble: {
3214 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3215 Location value = locations->InAt(2);
3216 DCHECK(value.IsFpuRegisterPair());
3217 if (index.IsConstant()) {
3218 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3219 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3220 } else {
3221 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3222 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3223 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003224
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003225 break;
3226 }
3227
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003228 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003229 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003230 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003231 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003232
3233 // Ints and objects are handled in the switch.
3234 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3235 codegen_->MaybeRecordImplicitNullCheck(instruction);
3236 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003237}
3238
3239void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003240 LocationSummary* locations =
3241 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003242 locations->SetInAt(0, Location::RequiresRegister());
3243 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003244}
3245
3246void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3247 LocationSummary* locations = instruction->GetLocations();
3248 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003249 Register obj = locations->InAt(0).AsRegister<Register>();
3250 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003251 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003252 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003253}
3254
3255void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003256 LocationSummary* locations =
3257 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003258 locations->SetInAt(0, Location::RequiresRegister());
3259 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003260 if (instruction->HasUses()) {
3261 locations->SetOut(Location::SameAsFirstInput());
3262 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003263}
3264
3265void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3266 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003267 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003268 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003269 codegen_->AddSlowPath(slow_path);
3270
Roland Levillain271ab9c2014-11-27 15:23:57 +00003271 Register index = locations->InAt(0).AsRegister<Register>();
3272 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003273
3274 __ cmp(index, ShifterOperand(length));
3275 __ b(slow_path->GetEntryLabel(), CS);
3276}
3277
3278void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3279 Label is_null;
3280 __ CompareAndBranchIfZero(value, &is_null);
3281 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3282 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3283 __ strb(card, Address(card, temp));
3284 __ Bind(&is_null);
3285}
3286
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003287void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3288 temp->SetLocations(nullptr);
3289}
3290
3291void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3292 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003293 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003294}
3295
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003296void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003297 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003298 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003299}
3300
3301void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003302 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3303}
3304
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003305void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3306 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3307}
3308
3309void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003310 HBasicBlock* block = instruction->GetBlock();
3311 if (block->GetLoopInformation() != nullptr) {
3312 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3313 // The back edge will generate the suspend check.
3314 return;
3315 }
3316 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3317 // The goto will generate the suspend check.
3318 return;
3319 }
3320 GenerateSuspendCheck(instruction, nullptr);
3321}
3322
3323void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3324 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003325 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003326 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003327 codegen_->AddSlowPath(slow_path);
3328
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003329 __ LoadFromOffset(
3330 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3331 __ cmp(IP, ShifterOperand(0));
3332 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003333 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003334 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003335 __ Bind(slow_path->GetReturnLabel());
3336 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003337 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003338 __ b(slow_path->GetEntryLabel());
3339 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003340}
3341
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003342ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3343 return codegen_->GetAssembler();
3344}
3345
3346void ParallelMoveResolverARM::EmitMove(size_t index) {
3347 MoveOperands* move = moves_.Get(index);
3348 Location source = move->GetSource();
3349 Location destination = move->GetDestination();
3350
3351 if (source.IsRegister()) {
3352 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003353 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003354 } else {
3355 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003356 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003357 SP, destination.GetStackIndex());
3358 }
3359 } else if (source.IsStackSlot()) {
3360 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003361 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003362 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003363 } else if (destination.IsFpuRegister()) {
3364 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003365 } else {
3366 DCHECK(destination.IsStackSlot());
3367 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3368 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3369 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003370 } else if (source.IsFpuRegister()) {
3371 if (destination.IsFpuRegister()) {
3372 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003373 } else {
3374 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003375 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3376 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003377 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003378 DCHECK(destination.IsDoubleStackSlot()) << destination;
3379 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3380 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3381 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3382 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003383 } else {
3384 DCHECK(source.IsConstant()) << source;
3385 HInstruction* constant = source.GetConstant();
3386 if (constant->IsIntConstant()) {
3387 int32_t value = constant->AsIntConstant()->GetValue();
3388 if (destination.IsRegister()) {
3389 __ LoadImmediate(destination.AsRegister<Register>(), value);
3390 } else {
3391 DCHECK(destination.IsStackSlot());
3392 __ LoadImmediate(IP, value);
3393 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3394 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003395 } else if (constant->IsLongConstant()) {
3396 int64_t value = constant->AsLongConstant()->GetValue();
3397 if (destination.IsRegister()) {
3398 // In the presence of long or double constants, the parallel move resolver will
3399 // split the move into two, but keeps the same constant for both moves. Here,
3400 // we use the low or high part depending on which register this move goes to.
3401 if (destination.reg() % 2 == 0) {
3402 __ LoadImmediate(destination.AsRegister<Register>(), Low32Bits(value));
3403 } else {
3404 __ LoadImmediate(destination.AsRegister<Register>(), High32Bits(value));
3405 }
3406 } else {
3407 DCHECK(destination.IsDoubleStackSlot());
3408 __ LoadImmediate(IP, Low32Bits(value));
3409 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3410 __ LoadImmediate(IP, High32Bits(value));
3411 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3412 }
3413 } else if (constant->IsDoubleConstant()) {
3414 double value = constant->AsDoubleConstant()->GetValue();
3415 uint64_t int_value = bit_cast<uint64_t, double>(value);
3416 if (destination.IsFpuRegister()) {
3417 // In the presence of long or double constants, the parallel move resolver will
3418 // split the move into two, but keeps the same constant for both moves. Here,
3419 // we use the low or high part depending on which register this move goes to.
3420 if (destination.reg() % 2 == 0) {
3421 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3422 bit_cast<float, uint32_t>(Low32Bits(int_value)));
3423 } else {
3424 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3425 bit_cast<float, uint32_t>(High32Bits(int_value)));
3426 }
3427 } else {
3428 DCHECK(destination.IsDoubleStackSlot());
3429 __ LoadImmediate(IP, Low32Bits(int_value));
3430 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3431 __ LoadImmediate(IP, High32Bits(int_value));
3432 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3433 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003434 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003435 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003436 float value = constant->AsFloatConstant()->GetValue();
3437 if (destination.IsFpuRegister()) {
3438 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3439 } else {
3440 DCHECK(destination.IsStackSlot());
3441 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3442 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3443 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003444 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003445 }
3446}
3447
3448void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3449 __ Mov(IP, reg);
3450 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3451 __ StoreToOffset(kStoreWord, IP, SP, mem);
3452}
3453
3454void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3455 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3456 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3457 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3458 SP, mem1 + stack_offset);
3459 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3460 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3461 SP, mem2 + stack_offset);
3462 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3463}
3464
3465void ParallelMoveResolverARM::EmitSwap(size_t index) {
3466 MoveOperands* move = moves_.Get(index);
3467 Location source = move->GetSource();
3468 Location destination = move->GetDestination();
3469
3470 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003471 DCHECK_NE(source.AsRegister<Register>(), IP);
3472 DCHECK_NE(destination.AsRegister<Register>(), IP);
3473 __ Mov(IP, source.AsRegister<Register>());
3474 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3475 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003476 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003477 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003478 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003479 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003480 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3481 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003482 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003483 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003484 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003485 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003486 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3487 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3488 : destination.AsFpuRegister<SRegister>();
3489 int mem = source.IsFpuRegister()
3490 ? destination.GetStackIndex()
3491 : source.GetStackIndex();
3492
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003493 __ vmovrs(IP, reg);
3494 __ LoadFromOffset(kLoadWord, IP, SP, mem);
3495 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003496 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003497 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3498 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003499 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003500 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003501 }
3502}
3503
3504void ParallelMoveResolverARM::SpillScratch(int reg) {
3505 __ Push(static_cast<Register>(reg));
3506}
3507
3508void ParallelMoveResolverARM::RestoreScratch(int reg) {
3509 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003510}
3511
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003512void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003513 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3514 ? LocationSummary::kCallOnSlowPath
3515 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003516 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003517 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003518 locations->SetOut(Location::RequiresRegister());
3519}
3520
3521void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003522 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003523 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003524 DCHECK(!cls->CanCallRuntime());
3525 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003526 codegen_->LoadCurrentMethod(out);
3527 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3528 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003529 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003530 codegen_->LoadCurrentMethod(out);
3531 __ LoadFromOffset(
3532 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3533 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003534
3535 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3536 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3537 codegen_->AddSlowPath(slow_path);
3538 __ cmp(out, ShifterOperand(0));
3539 __ b(slow_path->GetEntryLabel(), EQ);
3540 if (cls->MustGenerateClinitCheck()) {
3541 GenerateClassInitializationCheck(slow_path, out);
3542 } else {
3543 __ Bind(slow_path->GetExitLabel());
3544 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003545 }
3546}
3547
3548void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3549 LocationSummary* locations =
3550 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3551 locations->SetInAt(0, Location::RequiresRegister());
3552 if (check->HasUses()) {
3553 locations->SetOut(Location::SameAsFirstInput());
3554 }
3555}
3556
3557void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003558 // We assume the class is not null.
3559 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3560 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003561 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003562 GenerateClassInitializationCheck(slow_path,
3563 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003564}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003565
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003566void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3567 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003568 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3569 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3570 __ b(slow_path->GetEntryLabel(), LT);
3571 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3572 // properly. Therefore, we do a memory fence.
3573 __ dmb(ISH);
3574 __ Bind(slow_path->GetExitLabel());
3575}
3576
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003577void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3578 LocationSummary* locations =
3579 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3580 locations->SetOut(Location::RequiresRegister());
3581}
3582
3583void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3584 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3585 codegen_->AddSlowPath(slow_path);
3586
Roland Levillain271ab9c2014-11-27 15:23:57 +00003587 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003588 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003589 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3590 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003591 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3592 __ cmp(out, ShifterOperand(0));
3593 __ b(slow_path->GetEntryLabel(), EQ);
3594 __ Bind(slow_path->GetExitLabel());
3595}
3596
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003597void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3598 LocationSummary* locations =
3599 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3600 locations->SetOut(Location::RequiresRegister());
3601}
3602
3603void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003604 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003605 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3606 __ LoadFromOffset(kLoadWord, out, TR, offset);
3607 __ LoadImmediate(IP, 0);
3608 __ StoreToOffset(kStoreWord, IP, TR, offset);
3609}
3610
3611void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3612 LocationSummary* locations =
3613 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3614 InvokeRuntimeCallingConvention calling_convention;
3615 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3616}
3617
3618void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3619 codegen_->InvokeRuntime(
3620 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3621}
3622
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003623void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003624 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3625 ? LocationSummary::kNoCall
3626 : LocationSummary::kCallOnSlowPath;
3627 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3628 locations->SetInAt(0, Location::RequiresRegister());
3629 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003630 // The out register is used as a temporary, so it overlaps with the inputs.
3631 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003632}
3633
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003634void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003635 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003636 Register obj = locations->InAt(0).AsRegister<Register>();
3637 Register cls = locations->InAt(1).AsRegister<Register>();
3638 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003639 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3640 Label done, zero;
3641 SlowPathCodeARM* slow_path = nullptr;
3642
3643 // Return 0 if `obj` is null.
3644 // TODO: avoid this check if we know obj is not null.
3645 __ cmp(obj, ShifterOperand(0));
3646 __ b(&zero, EQ);
3647 // Compare the class of `obj` with `cls`.
3648 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3649 __ cmp(out, ShifterOperand(cls));
3650 if (instruction->IsClassFinal()) {
3651 // Classes must be equal for the instanceof to succeed.
3652 __ b(&zero, NE);
3653 __ LoadImmediate(out, 1);
3654 __ b(&done);
3655 } else {
3656 // If the classes are not equal, we go into a slow path.
3657 DCHECK(locations->OnlyCallsOnSlowPath());
3658 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003659 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003660 codegen_->AddSlowPath(slow_path);
3661 __ b(slow_path->GetEntryLabel(), NE);
3662 __ LoadImmediate(out, 1);
3663 __ b(&done);
3664 }
3665 __ Bind(&zero);
3666 __ LoadImmediate(out, 0);
3667 if (slow_path != nullptr) {
3668 __ Bind(slow_path->GetExitLabel());
3669 }
3670 __ Bind(&done);
3671}
3672
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003673void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3674 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3675 instruction, LocationSummary::kCallOnSlowPath);
3676 locations->SetInAt(0, Location::RequiresRegister());
3677 locations->SetInAt(1, Location::RequiresRegister());
3678 locations->AddTemp(Location::RequiresRegister());
3679}
3680
3681void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3682 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003683 Register obj = locations->InAt(0).AsRegister<Register>();
3684 Register cls = locations->InAt(1).AsRegister<Register>();
3685 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003686 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3687
3688 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3689 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3690 codegen_->AddSlowPath(slow_path);
3691
3692 // TODO: avoid this check if we know obj is not null.
3693 __ cmp(obj, ShifterOperand(0));
3694 __ b(slow_path->GetExitLabel(), EQ);
3695 // Compare the class of `obj` with `cls`.
3696 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3697 __ cmp(temp, ShifterOperand(cls));
3698 __ b(slow_path->GetEntryLabel(), NE);
3699 __ Bind(slow_path->GetExitLabel());
3700}
3701
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003702void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3703 LocationSummary* locations =
3704 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3705 InvokeRuntimeCallingConvention calling_convention;
3706 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3707}
3708
3709void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3710 codegen_->InvokeRuntime(instruction->IsEnter()
3711 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3712 instruction,
3713 instruction->GetDexPc());
3714}
3715
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003716void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3717void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3718void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3719
3720void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3721 LocationSummary* locations =
3722 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3723 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3724 || instruction->GetResultType() == Primitive::kPrimLong);
3725 locations->SetInAt(0, Location::RequiresRegister());
3726 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003727 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003728}
3729
3730void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3731 HandleBitwiseOperation(instruction);
3732}
3733
3734void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3735 HandleBitwiseOperation(instruction);
3736}
3737
3738void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3739 HandleBitwiseOperation(instruction);
3740}
3741
3742void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3743 LocationSummary* locations = instruction->GetLocations();
3744
3745 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003746 Register first = locations->InAt(0).AsRegister<Register>();
3747 Register second = locations->InAt(1).AsRegister<Register>();
3748 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003749 if (instruction->IsAnd()) {
3750 __ and_(out, first, ShifterOperand(second));
3751 } else if (instruction->IsOr()) {
3752 __ orr(out, first, ShifterOperand(second));
3753 } else {
3754 DCHECK(instruction->IsXor());
3755 __ eor(out, first, ShifterOperand(second));
3756 }
3757 } else {
3758 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3759 Location first = locations->InAt(0);
3760 Location second = locations->InAt(1);
3761 Location out = locations->Out();
3762 if (instruction->IsAnd()) {
3763 __ and_(out.AsRegisterPairLow<Register>(),
3764 first.AsRegisterPairLow<Register>(),
3765 ShifterOperand(second.AsRegisterPairLow<Register>()));
3766 __ and_(out.AsRegisterPairHigh<Register>(),
3767 first.AsRegisterPairHigh<Register>(),
3768 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3769 } else if (instruction->IsOr()) {
3770 __ orr(out.AsRegisterPairLow<Register>(),
3771 first.AsRegisterPairLow<Register>(),
3772 ShifterOperand(second.AsRegisterPairLow<Register>()));
3773 __ orr(out.AsRegisterPairHigh<Register>(),
3774 first.AsRegisterPairHigh<Register>(),
3775 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3776 } else {
3777 DCHECK(instruction->IsXor());
3778 __ eor(out.AsRegisterPairLow<Register>(),
3779 first.AsRegisterPairLow<Register>(),
3780 ShifterOperand(second.AsRegisterPairLow<Register>()));
3781 __ eor(out.AsRegisterPairHigh<Register>(),
3782 first.AsRegisterPairHigh<Register>(),
3783 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3784 }
3785 }
3786}
3787
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003788} // namespace arm
3789} // namespace art