blob: b0a56d58a346815b9c5c78f1687fe4e6369e4120 [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
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070019#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010020#include "gc/accounting/card_table.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070021#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000022#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010023#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070024#include "thread.h"
Roland Levillain3adfd1b2014-11-11 14:48:08 +000025#include "utils/assembler.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010026#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010028#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000029
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000030namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010031
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032namespace arm {
33
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000034static DRegister FromLowSToD(SRegister reg) {
35 DCHECK_EQ(reg % 2, 0);
36 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010037}
38
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010039static constexpr bool kExplicitStackOverflowCheck = false;
40
41static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
42static constexpr int kCurrentMethodStackOffset = 0;
43
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2 };
45static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { };
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010048static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010049
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000050class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051 public:
52 InvokeRuntimeCallingConvention()
53 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 kRuntimeParameterCoreRegistersLength,
55 kRuntimeParameterFpuRegisters,
56 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010057
58 private:
59 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
60};
61
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010063#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010065class SlowPathCodeARM : public SlowPathCode {
66 public:
67 SlowPathCodeARM() : entry_label_(), exit_label_() {}
68
69 Label* GetEntryLabel() { return &entry_label_; }
70 Label* GetExitLabel() { return &exit_label_; }
71
72 private:
73 Label entry_label_;
74 Label exit_label_;
75
76 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
77};
78
79class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010081 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082
83 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010086 arm_codegen->InvokeRuntime(
87 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 }
89
90 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010091 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010092 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
93};
94
Calin Juravled0d48522014-11-04 16:40:20 +000095class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
96 public:
97 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
98
99 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
100 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
101 __ Bind(GetEntryLabel());
102 arm_codegen->InvokeRuntime(
103 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
104 }
105
106 private:
107 HDivZeroCheck* const instruction_;
108 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
109};
110
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100111class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100112 public:
113 StackOverflowCheckSlowPathARM() {}
114
115 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
116 __ Bind(GetEntryLabel());
117 __ LoadFromOffset(kLoadWord, PC, TR,
118 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
119 }
120
121 private:
122 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
123};
124
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100125class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100127 explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
128 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000129
130 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100131 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100133 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100134 arm_codegen->InvokeRuntime(
135 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100136 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100137 if (successor_ == nullptr) {
138 __ b(GetReturnLabel());
139 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100140 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100141 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000142 }
143
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100144 Label* GetReturnLabel() {
145 DCHECK(successor_ == nullptr);
146 return &return_label_;
147 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000148
149 private:
150 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100151 // If not null, the block to branch to after the suspend check.
152 HBasicBlock* const successor_;
153
154 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000155 Label return_label_;
156
157 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
158};
159
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100160class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100161 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100162 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
163 Location index_location,
164 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100165 : instruction_(instruction),
166 index_location_(index_location),
167 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168
169 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100170 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100171 __ Bind(GetEntryLabel());
172 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100173 arm_codegen->Move32(
174 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
175 arm_codegen->Move32(
176 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
177 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
199 virtual 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
245 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
246 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;
254 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
255 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
256 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
281 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
282 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 Geoffray57a88d42014-11-10 15:09:21 +0000293 MoveOperands move1(class_to_check_,
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000294 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
295 nullptr);
296 MoveOperands move2(object_class_,
297 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
298 nullptr);
299 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
300 parallel_move.AddMove(&move1);
301 parallel_move.AddMove(&move2);
302 arm_codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
303
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000304 if (instruction_->IsInstanceOf()) {
305 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
306 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
307 } else {
308 DCHECK(instruction_->IsCheckCast());
309 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
310 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000311
312 codegen->RestoreLiveRegisters(locations);
313 __ b(GetExitLabel());
314 }
315
316 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000317 HInstruction* const instruction_;
318 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000319 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000320 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000321
322 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
323};
324
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000325#undef __
326
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100327#undef __
328#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700329
330inline Condition ARMCondition(IfCondition cond) {
331 switch (cond) {
332 case kCondEQ: return EQ;
333 case kCondNE: return NE;
334 case kCondLT: return LT;
335 case kCondLE: return LE;
336 case kCondGT: return GT;
337 case kCondGE: return GE;
338 default:
339 LOG(FATAL) << "Unknown if condition";
340 }
341 return EQ; // Unreachable.
342}
343
344inline Condition ARMOppositeCondition(IfCondition cond) {
345 switch (cond) {
346 case kCondEQ: return NE;
347 case kCondNE: return EQ;
348 case kCondLT: return GE;
349 case kCondLE: return GT;
350 case kCondGT: return LE;
351 case kCondGE: return LT;
352 default:
353 LOG(FATAL) << "Unknown if condition";
354 }
355 return EQ; // Unreachable.
356}
357
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100358void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
359 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
360}
361
362void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000363 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100364}
365
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100366size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
367 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
368 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100369}
370
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100371size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
372 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
373 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100374}
375
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100376CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000377 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100378 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100379 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100380 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100381 move_resolver_(graph->GetArena(), this),
382 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100383
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100384size_t CodeGeneratorARM::FrameEntrySpillSize() const {
385 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
386}
387
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100388Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100389 switch (type) {
390 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100391 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 ArmManagedRegister pair =
393 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100394 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
395 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
396
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100397 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
398 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100399 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100400 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100401 }
402
403 case Primitive::kPrimByte:
404 case Primitive::kPrimBoolean:
405 case Primitive::kPrimChar:
406 case Primitive::kPrimShort:
407 case Primitive::kPrimInt:
408 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100409 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100410 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100411 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
412 ArmManagedRegister current =
413 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
414 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100415 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100416 }
417 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100418 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100419 }
420
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000421 case Primitive::kPrimFloat: {
422 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100423 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100424 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100425
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000426 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000427 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
428 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000429 return Location::FpuRegisterPairLocation(reg, reg + 1);
430 }
431
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100432 case Primitive::kPrimVoid:
433 LOG(FATAL) << "Unreachable type " << type;
434 }
435
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100436 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100437}
438
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100439void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100441 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442
443 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100444 blocked_core_registers_[SP] = true;
445 blocked_core_registers_[LR] = true;
446 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100448 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100449 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100450
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100451 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100452 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100453
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100454 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100455 // We always save and restore R6 and R7 to make sure we can use three
456 // register pairs for long operations.
Nicolas Geoffray44b819e2014-11-06 12:00:54 +0000457 blocked_core_registers_[R4] = true;
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100458 blocked_core_registers_[R5] = true;
459 blocked_core_registers_[R8] = true;
460 blocked_core_registers_[R10] = true;
461 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100462
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000463 blocked_fpu_registers_[S16] = true;
464 blocked_fpu_registers_[S17] = true;
465 blocked_fpu_registers_[S18] = true;
466 blocked_fpu_registers_[S19] = true;
467 blocked_fpu_registers_[S20] = true;
468 blocked_fpu_registers_[S21] = true;
469 blocked_fpu_registers_[S22] = true;
470 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000471 blocked_fpu_registers_[S24] = true;
472 blocked_fpu_registers_[S25] = true;
473 blocked_fpu_registers_[S26] = true;
474 blocked_fpu_registers_[S27] = true;
475 blocked_fpu_registers_[S28] = true;
476 blocked_fpu_registers_[S29] = true;
477 blocked_fpu_registers_[S30] = true;
478 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100479
480 UpdateBlockedPairRegisters();
481}
482
483void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
484 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
485 ArmManagedRegister current =
486 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
487 if (blocked_core_registers_[current.AsRegisterPairLow()]
488 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
489 blocked_register_pairs_[i] = true;
490 }
491 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100492}
493
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100494InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
495 : HGraphVisitor(graph),
496 assembler_(codegen->GetAssembler()),
497 codegen_(codegen) {}
498
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000499void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700500 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100501 if (!skip_overflow_check) {
502 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100503 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100504 AddSlowPath(slow_path);
505
506 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
507 __ cmp(SP, ShifterOperand(IP));
508 __ b(slow_path->GetEntryLabel(), CC);
509 } else {
510 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100511 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100512 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100513 }
514 }
515
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100516 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
517 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000518
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100519 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100520 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100521 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000522}
523
524void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100525 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100526 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000527}
528
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100529void CodeGeneratorARM::Bind(HBasicBlock* block) {
530 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000531}
532
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100533Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
534 switch (load->GetType()) {
535 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100536 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100537 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
538 break;
539
540 case Primitive::kPrimInt:
541 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100542 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100543 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100544
545 case Primitive::kPrimBoolean:
546 case Primitive::kPrimByte:
547 case Primitive::kPrimChar:
548 case Primitive::kPrimShort:
549 case Primitive::kPrimVoid:
550 LOG(FATAL) << "Unexpected type " << load->GetType();
551 }
552
553 LOG(FATAL) << "Unreachable";
554 return Location();
555}
556
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100557Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
558 switch (type) {
559 case Primitive::kPrimBoolean:
560 case Primitive::kPrimByte:
561 case Primitive::kPrimChar:
562 case Primitive::kPrimShort:
563 case Primitive::kPrimInt:
564 case Primitive::kPrimNot: {
565 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000566 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100567 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100568 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100569 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000570 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100571 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100572 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100573
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000574 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100575 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000576 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100577 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000578 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100579 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100580 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
581 calling_convention.GetRegisterPairAt(index));
582 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100583 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000584 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100585 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000586 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
587 }
588 }
589
590 case Primitive::kPrimFloat: {
591 uint32_t stack_index = stack_index_++;
592 if (float_index_ % 2 == 0) {
593 float_index_ = std::max(double_index_, float_index_);
594 }
595 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
596 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
597 } else {
598 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
599 }
600 }
601
602 case Primitive::kPrimDouble: {
603 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
604 uint32_t stack_index = stack_index_;
605 stack_index_ += 2;
606 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
607 uint32_t index = double_index_;
608 double_index_ += 2;
609 return Location::FpuRegisterPairLocation(
610 calling_convention.GetFpuRegisterAt(index),
611 calling_convention.GetFpuRegisterAt(index + 1));
612 } else {
613 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100614 }
615 }
616
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100617 case Primitive::kPrimVoid:
618 LOG(FATAL) << "Unexpected parameter type " << type;
619 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100620 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100621 return Location();
622}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100623
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000624Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
625 switch (type) {
626 case Primitive::kPrimBoolean:
627 case Primitive::kPrimByte:
628 case Primitive::kPrimChar:
629 case Primitive::kPrimShort:
630 case Primitive::kPrimInt:
631 case Primitive::kPrimNot: {
632 return Location::RegisterLocation(R0);
633 }
634
635 case Primitive::kPrimFloat: {
636 return Location::FpuRegisterLocation(S0);
637 }
638
639 case Primitive::kPrimLong: {
640 return Location::RegisterPairLocation(R0, R1);
641 }
642
643 case Primitive::kPrimDouble: {
644 return Location::FpuRegisterPairLocation(S0, S1);
645 }
646
647 case Primitive::kPrimVoid:
648 return Location();
649 }
650 UNREACHABLE();
651 return Location();
652}
653
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100654void CodeGeneratorARM::Move32(Location destination, Location source) {
655 if (source.Equals(destination)) {
656 return;
657 }
658 if (destination.IsRegister()) {
659 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100660 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100661 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000662 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100663 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100664 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100665 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100666 } else if (destination.IsFpuRegister()) {
667 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100669 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000670 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100671 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000672 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100673 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100674 } else {
675 DCHECK(destination.IsStackSlot());
676 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100677 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100678 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000679 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100681 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100682 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
683 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100684 }
685 }
686}
687
688void CodeGeneratorARM::Move64(Location destination, Location source) {
689 if (source.Equals(destination)) {
690 return;
691 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100692 if (destination.IsRegisterPair()) {
693 if (source.IsRegisterPair()) {
694 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
695 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100696 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000697 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100698 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000699 uint16_t register_index = source.GetQuickParameterRegisterIndex();
700 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100701 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100702 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000703 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100704 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000705 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 } else {
707 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100708 if (destination.AsRegisterPairLow<Register>() == R1) {
709 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100710 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
711 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100713 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100714 SP, source.GetStackIndex());
715 }
716 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000717 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100718 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000719 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
720 SP,
721 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100722 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000723 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100724 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100725 } else if (destination.IsQuickParameter()) {
726 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000727 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
728 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100729 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000730 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100731 source.AsRegisterPairLow<Register>());
732 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000733 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100734 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000735 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100736 } else {
737 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000738 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000739 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100740 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000741 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100742 }
743 } else {
744 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100745 if (source.IsRegisterPair()) {
746 if (source.AsRegisterPairLow<Register>() == R1) {
747 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100748 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
749 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100750 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100751 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100752 SP, destination.GetStackIndex());
753 }
754 } else if (source.IsQuickParameter()) {
755 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000756 uint16_t register_index = source.GetQuickParameterRegisterIndex();
757 uint16_t stack_index = source.GetQuickParameterStackIndex();
758 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100759 SP, destination.GetStackIndex());
760 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000761 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100762 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000763 } else if (source.IsFpuRegisterPair()) {
764 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
765 SP,
766 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100767 } else {
768 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100769 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
770 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
771 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
772 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100773 }
774 }
775}
776
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100777void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100778 LocationSummary* locations = instruction->GetLocations();
779 if (locations != nullptr && locations->Out().Equals(location)) {
780 return;
781 }
782
Roland Levillain476df552014-10-09 17:51:36 +0100783 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100784 int32_t value = instruction->AsIntConstant()->GetValue();
785 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100786 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100787 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100788 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100789 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100790 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791 }
Roland Levillain476df552014-10-09 17:51:36 +0100792 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100793 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100794 if (location.IsRegisterPair()) {
795 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
796 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100797 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100798 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100799 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100800 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100801 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100802 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100803 }
Roland Levillain476df552014-10-09 17:51:36 +0100804 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100805 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
806 switch (instruction->GetType()) {
807 case Primitive::kPrimBoolean:
808 case Primitive::kPrimByte:
809 case Primitive::kPrimChar:
810 case Primitive::kPrimShort:
811 case Primitive::kPrimInt:
812 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100813 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100814 Move32(location, Location::StackSlot(stack_slot));
815 break;
816
817 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100818 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100819 Move64(location, Location::DoubleStackSlot(stack_slot));
820 break;
821
822 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100823 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100824 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000825 } else if (instruction->IsTemporary()) {
826 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
827 Move32(location, temp_location);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000828 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100829 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 switch (instruction->GetType()) {
831 case Primitive::kPrimBoolean:
832 case Primitive::kPrimByte:
833 case Primitive::kPrimChar:
834 case Primitive::kPrimShort:
835 case Primitive::kPrimNot:
836 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100837 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100838 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 break;
840
841 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100842 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100843 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100844 break;
845
846 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100847 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100848 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000849 }
850}
851
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100852void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
853 HInstruction* instruction,
854 uint32_t dex_pc) {
855 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
856 __ blx(LR);
857 RecordPcInfo(instruction, dex_pc);
858 DCHECK(instruction->IsSuspendCheck()
859 || instruction->IsBoundsCheck()
860 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000861 || instruction->IsDivZeroCheck()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100862 || !IsLeafMethod());
863}
864
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000865void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000866 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000867}
868
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000869void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000870 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100871 DCHECK(!successor->IsExitBlock());
872
873 HBasicBlock* block = got->GetBlock();
874 HInstruction* previous = got->GetPrevious();
875
876 HLoopInformation* info = block->GetLoopInformation();
877 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
878 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
879 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
880 return;
881 }
882
883 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
884 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
885 }
886 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000887 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000888 }
889}
890
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000891void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000892 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000893}
894
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000895void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700896 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000897 if (kIsDebugBuild) {
898 __ Comment("Unreachable");
899 __ bkpt(0);
900 }
901}
902
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000903void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100904 LocationSummary* locations =
905 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100906 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100907 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100908 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100909 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000910}
911
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000912void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700913 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100914 if (cond->IsIntConstant()) {
915 // Constant condition, statically compared against 1.
916 int32_t cond_value = cond->AsIntConstant()->GetValue();
917 if (cond_value == 1) {
918 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
919 if_instr->IfTrueSuccessor())) {
920 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100921 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100922 return;
923 } else {
924 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100925 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100926 } else {
927 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
928 // Condition has been materialized, compare the output to 0
929 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
930 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
931 ShifterOperand(0));
932 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
933 } else {
934 // Condition has not been materialized, use its inputs as the
935 // comparison and its condition as the branch condition.
936 LocationSummary* locations = cond->GetLocations();
937 if (locations->InAt(1).IsRegister()) {
938 __ cmp(locations->InAt(0).As<Register>(),
939 ShifterOperand(locations->InAt(1).As<Register>()));
940 } else {
941 DCHECK(locations->InAt(1).IsConstant());
942 int32_t value =
943 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
944 ShifterOperand operand;
945 if (ShifterOperand::CanHoldArm(value, &operand)) {
946 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
947 } else {
948 Register temp = IP;
949 __ LoadImmediate(temp, value);
950 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
951 }
952 }
953 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
954 ARMCondition(cond->AsCondition()->GetCondition()));
955 }
Dave Allison20dfc792014-06-16 20:44:29 -0700956 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100957 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
958 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700959 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000960 }
961}
962
Dave Allison20dfc792014-06-16 20:44:29 -0700963
964void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100965 LocationSummary* locations =
966 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100967 locations->SetInAt(0, Location::RequiresRegister());
968 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100969 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100970 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100971 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000972}
973
Dave Allison20dfc792014-06-16 20:44:29 -0700974void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100975 if (!comp->NeedsMaterialization()) return;
976
977 LocationSummary* locations = comp->GetLocations();
978 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100979 __ cmp(locations->InAt(0).As<Register>(),
980 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 } else {
982 DCHECK(locations->InAt(1).IsConstant());
983 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
984 ShifterOperand operand;
985 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100986 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100987 } else {
988 Register temp = IP;
989 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100990 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100991 }
Dave Allison20dfc792014-06-16 20:44:29 -0700992 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100993 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100994 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100995 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100996 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700998}
999
1000void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1001 VisitCondition(comp);
1002}
1003
1004void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1005 VisitCondition(comp);
1006}
1007
1008void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1009 VisitCondition(comp);
1010}
1011
1012void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1013 VisitCondition(comp);
1014}
1015
1016void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1017 VisitCondition(comp);
1018}
1019
1020void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1021 VisitCondition(comp);
1022}
1023
1024void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1025 VisitCondition(comp);
1026}
1027
1028void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1029 VisitCondition(comp);
1030}
1031
1032void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1033 VisitCondition(comp);
1034}
1035
1036void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1037 VisitCondition(comp);
1038}
1039
1040void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1041 VisitCondition(comp);
1042}
1043
1044void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1045 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001046}
1047
1048void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001049 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001050}
1051
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001052void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1053 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001054}
1055
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001056void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001057 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001058}
1059
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001060void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001061 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001062 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001063}
1064
1065void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001066 LocationSummary* locations =
1067 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001068 switch (store->InputAt(1)->GetType()) {
1069 case Primitive::kPrimBoolean:
1070 case Primitive::kPrimByte:
1071 case Primitive::kPrimChar:
1072 case Primitive::kPrimShort:
1073 case Primitive::kPrimInt:
1074 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001075 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001076 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1077 break;
1078
1079 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001080 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001081 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1082 break;
1083
1084 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001085 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001086 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001087}
1088
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001089void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001090 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001091}
1092
1093void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001094 LocationSummary* locations =
1095 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001096 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001097}
1098
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001099void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001100 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001101 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001102}
1103
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001104void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001105 LocationSummary* locations =
1106 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001107 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001108}
1109
1110void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1111 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001112 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001113}
1114
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001115void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1116 LocationSummary* locations =
1117 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1118 locations->SetOut(Location::ConstantLocation(constant));
1119}
1120
1121void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1122 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001123 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001124}
1125
1126void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1127 LocationSummary* locations =
1128 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1129 locations->SetOut(Location::ConstantLocation(constant));
1130}
1131
1132void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1133 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001134 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001135}
1136
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001137void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001138 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001139}
1140
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001141void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001142 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001143 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001144}
1145
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001146void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001147 LocationSummary* locations =
1148 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001149 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001150}
1151
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001152void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001153 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001154 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155}
1156
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001157void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001158 HandleInvoke(invoke);
1159}
1160
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001161void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001162 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001163}
1164
1165void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001166 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001167
1168 // TODO: Implement all kinds of calls:
1169 // 1) boot -> boot
1170 // 2) app -> boot
1171 // 3) app -> app
1172 //
1173 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1174
1175 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001176 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001177 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001178 __ LoadFromOffset(
1179 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001180 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001181 __ LoadFromOffset(
1182 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001183 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001184 __ LoadFromOffset(kLoadWord, LR, temp,
1185 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001186 // LR()
1187 __ blx(LR);
1188
1189 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1190 DCHECK(!codegen_->IsLeafMethod());
1191}
1192
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001193void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001194 LocationSummary* locations =
1195 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001196 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001197
1198 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001199 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001200 HInstruction* input = invoke->InputAt(i);
1201 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1202 }
1203
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001204 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001205}
1206
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001207void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1208 HandleInvoke(invoke);
1209}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001210
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001211void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001212 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001213 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1214 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1215 LocationSummary* locations = invoke->GetLocations();
1216 Location receiver = locations->InAt(0);
1217 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1218 // temp = object->GetClass();
1219 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001220 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1221 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001222 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001223 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001224 }
1225 // temp = temp->GetMethodAt(method_offset);
1226 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001227 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001228 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001229 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001230 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001231 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001232 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001233 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001234}
1235
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001236void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1237 HandleInvoke(invoke);
1238 // Add the hidden argument.
1239 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1240}
1241
1242void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1243 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1244 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
1245 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1246 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1247 LocationSummary* locations = invoke->GetLocations();
1248 Location receiver = locations->InAt(0);
1249 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1250
1251 // Set the hidden argument.
1252 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex());
1253
1254 // temp = object->GetClass();
1255 if (receiver.IsStackSlot()) {
1256 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1257 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1258 } else {
1259 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
1260 }
1261 // temp = temp->GetImtEntryAt(method_offset);
1262 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
1263 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1264 // LR = temp->GetEntryPoint();
1265 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1266 // LR();
1267 __ blx(LR);
1268 DCHECK(!codegen_->IsLeafMethod());
1269 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1270}
1271
Roland Levillain88cb1752014-10-20 16:36:47 +01001272void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1273 LocationSummary* locations =
1274 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1275 switch (neg->GetResultType()) {
1276 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001277 case Primitive::kPrimLong: {
1278 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001279 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001280 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001281 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001282 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001283
Roland Levillain88cb1752014-10-20 16:36:47 +01001284 case Primitive::kPrimFloat:
1285 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001286 locations->SetInAt(0, Location::RequiresFpuRegister());
1287 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001288 break;
1289
1290 default:
1291 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1292 }
1293}
1294
1295void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1296 LocationSummary* locations = neg->GetLocations();
1297 Location out = locations->Out();
1298 Location in = locations->InAt(0);
1299 switch (neg->GetResultType()) {
1300 case Primitive::kPrimInt:
1301 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001302 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001303 break;
1304
1305 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001306 DCHECK(in.IsRegisterPair());
1307 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1308 __ rsbs(out.AsRegisterPairLow<Register>(),
1309 in.AsRegisterPairLow<Register>(),
1310 ShifterOperand(0));
1311 // We cannot emit an RSC (Reverse Subtract with Carry)
1312 // instruction here, as it does not exist in the Thumb-2
1313 // instruction set. We use the following approach
1314 // using SBC and SUB instead.
1315 //
1316 // out.hi = -C
1317 __ sbc(out.AsRegisterPairHigh<Register>(),
1318 out.AsRegisterPairHigh<Register>(),
1319 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1320 // out.hi = out.hi - in.hi
1321 __ sub(out.AsRegisterPairHigh<Register>(),
1322 out.AsRegisterPairHigh<Register>(),
1323 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1324 break;
1325
Roland Levillain88cb1752014-10-20 16:36:47 +01001326 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001327 DCHECK(in.IsFpuRegister());
1328 __ vnegs(out.As<SRegister>(), in.As<SRegister>());
1329 break;
1330
Roland Levillain88cb1752014-10-20 16:36:47 +01001331 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001332 DCHECK(in.IsFpuRegisterPair());
1333 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1334 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001335 break;
1336
1337 default:
1338 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1339 }
1340}
1341
Roland Levillaindff1f282014-11-05 14:15:05 +00001342void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1343 LocationSummary* locations =
1344 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1345 Primitive::Type result_type = conversion->GetResultType();
1346 Primitive::Type input_type = conversion->GetInputType();
1347 switch (result_type) {
1348 case Primitive::kPrimLong:
1349 switch (input_type) {
1350 case Primitive::kPrimByte:
1351 case Primitive::kPrimShort:
1352 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001353 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001354 // int-to-long conversion.
1355 locations->SetInAt(0, Location::RequiresRegister());
1356 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1357 break;
1358
1359 case Primitive::kPrimFloat:
1360 case Primitive::kPrimDouble:
1361 LOG(FATAL) << "Type conversion from " << input_type << " to "
1362 << result_type << " not yet implemented";
1363 break;
1364
1365 default:
1366 LOG(FATAL) << "Unexpected type conversion from " << input_type
1367 << " to " << result_type;
1368 }
1369 break;
1370
Roland Levillain3adfd1b2014-11-11 14:48:08 +00001371 case Primitive::kPrimInt:
Roland Levillaindff1f282014-11-05 14:15:05 +00001372 case Primitive::kPrimFloat:
1373 case Primitive::kPrimDouble:
1374 LOG(FATAL) << "Type conversion from " << input_type
1375 << " to " << result_type << " not yet implemented";
1376 break;
1377
1378 default:
1379 LOG(FATAL) << "Unexpected type conversion from " << input_type
1380 << " to " << result_type;
1381 }
1382}
1383
1384void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1385 LocationSummary* locations = conversion->GetLocations();
1386 Location out = locations->Out();
1387 Location in = locations->InAt(0);
1388 Primitive::Type result_type = conversion->GetResultType();
1389 Primitive::Type input_type = conversion->GetInputType();
1390 switch (result_type) {
1391 case Primitive::kPrimLong:
1392 switch (input_type) {
1393 case Primitive::kPrimByte:
1394 case Primitive::kPrimShort:
1395 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001396 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001397 // int-to-long conversion.
1398 DCHECK(out.IsRegisterPair());
1399 DCHECK(in.IsRegister());
1400 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1401 // Sign extension.
1402 __ Asr(out.AsRegisterPairHigh<Register>(),
1403 out.AsRegisterPairLow<Register>(),
1404 31);
1405 break;
1406
1407 case Primitive::kPrimFloat:
1408 case Primitive::kPrimDouble:
1409 LOG(FATAL) << "Type conversion from " << input_type << " to "
1410 << result_type << " not yet implemented";
1411 break;
1412
1413 default:
1414 LOG(FATAL) << "Unexpected type conversion from " << input_type
1415 << " to " << result_type;
1416 }
1417 break;
1418
Roland Levillain3adfd1b2014-11-11 14:48:08 +00001419 case Primitive::kPrimInt:
Roland Levillaindff1f282014-11-05 14:15:05 +00001420 case Primitive::kPrimFloat:
1421 case Primitive::kPrimDouble:
1422 LOG(FATAL) << "Type conversion from " << input_type
1423 << " to " << result_type << " not yet implemented";
1424 break;
1425
1426 default:
1427 LOG(FATAL) << "Unexpected type conversion from " << input_type
1428 << " to " << result_type;
1429 }
1430}
1431
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001432void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001433 LocationSummary* locations =
1434 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001435 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001436 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001437 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001438 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1439 locations->SetInAt(0, Location::RequiresRegister());
1440 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1441 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001442 break;
1443 }
1444
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001445 case Primitive::kPrimFloat:
1446 case Primitive::kPrimDouble: {
1447 locations->SetInAt(0, Location::RequiresFpuRegister());
1448 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001449 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001450 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001451 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001452
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001453 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001454 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001455 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001456}
1457
1458void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1459 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001460 Location out = locations->Out();
1461 Location first = locations->InAt(0);
1462 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001463 switch (add->GetResultType()) {
1464 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001465 if (second.IsRegister()) {
1466 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001467 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001468 __ AddConstant(out.As<Register>(),
1469 first.As<Register>(),
1470 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001471 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001472 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001473
1474 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001475 __ adds(out.AsRegisterPairLow<Register>(),
1476 first.AsRegisterPairLow<Register>(),
1477 ShifterOperand(second.AsRegisterPairLow<Register>()));
1478 __ adc(out.AsRegisterPairHigh<Register>(),
1479 first.AsRegisterPairHigh<Register>(),
1480 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001481 break;
1482
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001483 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001484 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001485 break;
1486
1487 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001488 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1489 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1490 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001491 break;
1492
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001493 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001494 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001495 }
1496}
1497
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001498void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001499 LocationSummary* locations =
1500 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001501 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001502 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001503 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001504 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1505 locations->SetInAt(0, Location::RequiresRegister());
1506 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1507 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001508 break;
1509 }
Calin Juravle11351682014-10-23 15:38:15 +01001510 case Primitive::kPrimFloat:
1511 case Primitive::kPrimDouble: {
1512 locations->SetInAt(0, Location::RequiresFpuRegister());
1513 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001514 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001515 break;
Calin Juravle11351682014-10-23 15:38:15 +01001516 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001517 default:
Calin Juravle11351682014-10-23 15:38:15 +01001518 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001519 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001520}
1521
1522void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1523 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001524 Location out = locations->Out();
1525 Location first = locations->InAt(0);
1526 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001527 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001528 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001529 if (second.IsRegister()) {
1530 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001531 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001532 __ AddConstant(out.As<Register>(),
1533 first.As<Register>(),
1534 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001535 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001536 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001537 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001538
Calin Juravle11351682014-10-23 15:38:15 +01001539 case Primitive::kPrimLong: {
1540 __ subs(out.AsRegisterPairLow<Register>(),
1541 first.AsRegisterPairLow<Register>(),
1542 ShifterOperand(second.AsRegisterPairLow<Register>()));
1543 __ sbc(out.AsRegisterPairHigh<Register>(),
1544 first.AsRegisterPairHigh<Register>(),
1545 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001546 break;
Calin Juravle11351682014-10-23 15:38:15 +01001547 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001548
Calin Juravle11351682014-10-23 15:38:15 +01001549 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001550 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001551 break;
Calin Juravle11351682014-10-23 15:38:15 +01001552 }
1553
1554 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001555 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1556 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1557 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001558 break;
1559 }
1560
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001561
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001562 default:
Calin Juravle11351682014-10-23 15:38:15 +01001563 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001564 }
1565}
1566
Calin Juravle34bacdf2014-10-07 20:23:36 +01001567void LocationsBuilderARM::VisitMul(HMul* mul) {
1568 LocationSummary* locations =
1569 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1570 switch (mul->GetResultType()) {
1571 case Primitive::kPrimInt:
1572 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001573 locations->SetInAt(0, Location::RequiresRegister());
1574 locations->SetInAt(1, Location::RequiresRegister());
1575 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001576 break;
1577 }
1578
Calin Juravleb5bfa962014-10-21 18:02:24 +01001579 case Primitive::kPrimFloat:
1580 case Primitive::kPrimDouble: {
1581 locations->SetInAt(0, Location::RequiresFpuRegister());
1582 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001583 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001584 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001585 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001586
1587 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001588 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001589 }
1590}
1591
1592void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1593 LocationSummary* locations = mul->GetLocations();
1594 Location out = locations->Out();
1595 Location first = locations->InAt(0);
1596 Location second = locations->InAt(1);
1597 switch (mul->GetResultType()) {
1598 case Primitive::kPrimInt: {
1599 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1600 break;
1601 }
1602 case Primitive::kPrimLong: {
1603 Register out_hi = out.AsRegisterPairHigh<Register>();
1604 Register out_lo = out.AsRegisterPairLow<Register>();
1605 Register in1_hi = first.AsRegisterPairHigh<Register>();
1606 Register in1_lo = first.AsRegisterPairLow<Register>();
1607 Register in2_hi = second.AsRegisterPairHigh<Register>();
1608 Register in2_lo = second.AsRegisterPairLow<Register>();
1609
1610 // Extra checks to protect caused by the existence of R1_R2.
1611 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1612 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1613 DCHECK_NE(out_hi, in1_lo);
1614 DCHECK_NE(out_hi, in2_lo);
1615
1616 // input: in1 - 64 bits, in2 - 64 bits
1617 // output: out
1618 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1619 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1620 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1621
1622 // IP <- in1.lo * in2.hi
1623 __ mul(IP, in1_lo, in2_hi);
1624 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1625 __ mla(out_hi, in1_hi, in2_lo, IP);
1626 // out.lo <- (in1.lo * in2.lo)[31:0];
1627 __ umull(out_lo, IP, in1_lo, in2_lo);
1628 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1629 __ add(out_hi, out_hi, ShifterOperand(IP));
1630 break;
1631 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001632
1633 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001634 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001635 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001636 }
1637
1638 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001639 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1640 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1641 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001642 break;
1643 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001644
1645 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001646 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001647 }
1648}
1649
Calin Juravle7c4954d2014-10-28 16:57:40 +00001650void LocationsBuilderARM::VisitDiv(HDiv* div) {
1651 LocationSummary* locations =
1652 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1653 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001654 case Primitive::kPrimInt: {
1655 locations->SetInAt(0, Location::RequiresRegister());
1656 locations->SetInAt(1, Location::RequiresRegister());
1657 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1658 break;
1659 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001660 case Primitive::kPrimLong: {
1661 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1662 break;
1663 }
1664 case Primitive::kPrimFloat:
1665 case Primitive::kPrimDouble: {
1666 locations->SetInAt(0, Location::RequiresFpuRegister());
1667 locations->SetInAt(1, Location::RequiresFpuRegister());
1668 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1669 break;
1670 }
1671
1672 default:
1673 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1674 }
1675}
1676
1677void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1678 LocationSummary* locations = div->GetLocations();
1679 Location out = locations->Out();
1680 Location first = locations->InAt(0);
1681 Location second = locations->InAt(1);
1682
1683 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001684 case Primitive::kPrimInt: {
1685 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>());
1686 break;
1687 }
1688
Calin Juravle7c4954d2014-10-28 16:57:40 +00001689 case Primitive::kPrimLong: {
1690 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1691 break;
1692 }
1693
1694 case Primitive::kPrimFloat: {
1695 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1696 break;
1697 }
1698
1699 case Primitive::kPrimDouble: {
1700 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1701 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1702 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1703 break;
1704 }
1705
1706 default:
1707 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1708 }
1709}
1710
Calin Juravled0d48522014-11-04 16:40:20 +00001711void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1712 LocationSummary* locations =
1713 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1714 locations->SetInAt(0, Location::RequiresRegister());
1715 if (instruction->HasUses()) {
1716 locations->SetOut(Location::SameAsFirstInput());
1717 }
1718}
1719
1720void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1721 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
1722 codegen_->AddSlowPath(slow_path);
1723
1724 LocationSummary* locations = instruction->GetLocations();
1725 Location value = locations->InAt(0);
1726
1727 DCHECK(value.IsRegister()) << value;
1728 __ cmp(value.As<Register>(), ShifterOperand(0));
1729 __ b(slow_path->GetEntryLabel(), EQ);
1730}
1731
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001732void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001733 LocationSummary* locations =
1734 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001735 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001736 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1737 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1738 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001739}
1740
1741void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1742 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001743 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001744 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001745 codegen_->InvokeRuntime(
1746 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001747}
1748
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001749void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1750 LocationSummary* locations =
1751 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1752 InvokeRuntimeCallingConvention calling_convention;
1753 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1754 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1755 locations->SetOut(Location::RegisterLocation(R0));
1756 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1757}
1758
1759void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1760 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001761 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001762 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001763 codegen_->InvokeRuntime(
1764 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001765}
1766
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001767void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001768 LocationSummary* locations =
1769 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001770 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1771 if (location.IsStackSlot()) {
1772 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1773 } else if (location.IsDoubleStackSlot()) {
1774 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001775 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001776 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001777}
1778
1779void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001780 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001781 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001782}
1783
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001784void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001785 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001786 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001787 locations->SetInAt(0, Location::RequiresRegister());
1788 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001789}
1790
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001791void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1792 LocationSummary* locations = not_->GetLocations();
1793 Location out = locations->Out();
1794 Location in = locations->InAt(0);
1795 switch (not_->InputAt(0)->GetType()) {
1796 case Primitive::kPrimBoolean:
1797 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1798 break;
1799
1800 case Primitive::kPrimInt:
1801 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1802 break;
1803
1804 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001805 __ mvn(out.AsRegisterPairLow<Register>(),
1806 ShifterOperand(in.AsRegisterPairLow<Register>()));
1807 __ mvn(out.AsRegisterPairHigh<Register>(),
1808 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001809 break;
1810
1811 default:
1812 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1813 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001814}
1815
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001816void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001817 LocationSummary* locations =
1818 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001819 locations->SetInAt(0, Location::RequiresRegister());
1820 locations->SetInAt(1, Location::RequiresRegister());
1821 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001822}
1823
1824void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001825 LocationSummary* locations = compare->GetLocations();
1826 switch (compare->InputAt(0)->GetType()) {
1827 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001828 Register output = locations->Out().As<Register>();
1829 Location left = locations->InAt(0);
1830 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001831 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001832 __ cmp(left.AsRegisterPairHigh<Register>(),
1833 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001834 __ b(&less, LT);
1835 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001836 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1837 // the status flags.
1838 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001839 __ cmp(left.AsRegisterPairLow<Register>(),
1840 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001841 __ b(&done, EQ);
1842 __ b(&less, CC);
1843
1844 __ Bind(&greater);
1845 __ LoadImmediate(output, 1);
1846 __ b(&done);
1847
1848 __ Bind(&less);
1849 __ LoadImmediate(output, -1);
1850
1851 __ Bind(&done);
1852 break;
1853 }
1854 default:
1855 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1856 }
1857}
1858
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001859void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001860 LocationSummary* locations =
1861 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001862 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1863 locations->SetInAt(i, Location::Any());
1864 }
1865 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001866}
1867
1868void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001869 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001870 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001871}
1872
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001873void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001874 LocationSummary* locations =
1875 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001876 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001877 locations->SetInAt(0, Location::RequiresRegister());
1878 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001879 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001880 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001881 locations->AddTemp(Location::RequiresRegister());
1882 locations->AddTemp(Location::RequiresRegister());
1883 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001884}
1885
1886void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1887 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001888 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001889 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001890 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001891
1892 switch (field_type) {
1893 case Primitive::kPrimBoolean:
1894 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001895 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001896 __ StoreToOffset(kStoreByte, value, obj, offset);
1897 break;
1898 }
1899
1900 case Primitive::kPrimShort:
1901 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001902 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001903 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1904 break;
1905 }
1906
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001907 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001908 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001909 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001910 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001911 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001912 Register temp = locations->GetTemp(0).As<Register>();
1913 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001914 codegen_->MarkGCCard(temp, card, obj, value);
1915 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001916 break;
1917 }
1918
1919 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001920 Location value = locations->InAt(1);
1921 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001922 break;
1923 }
1924
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00001925 case Primitive::kPrimFloat: {
1926 SRegister value = locations->InAt(1).As<SRegister>();
1927 __ StoreSToOffset(value, obj, offset);
1928 break;
1929 }
1930
1931 case Primitive::kPrimDouble: {
1932 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
1933 __ StoreDToOffset(value, obj, offset);
1934 break;
1935 }
1936
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001937 case Primitive::kPrimVoid:
1938 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001939 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001940 }
1941}
1942
1943void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001944 LocationSummary* locations =
1945 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001946 locations->SetInAt(0, Location::RequiresRegister());
1947 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001948}
1949
1950void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1951 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001952 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001953 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1954
1955 switch (instruction->GetType()) {
1956 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001957 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001958 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1959 break;
1960 }
1961
1962 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001963 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001964 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1965 break;
1966 }
1967
1968 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001969 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001970 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1971 break;
1972 }
1973
1974 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001975 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001976 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1977 break;
1978 }
1979
1980 case Primitive::kPrimInt:
1981 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001982 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001983 __ LoadFromOffset(kLoadWord, out, obj, offset);
1984 break;
1985 }
1986
1987 case Primitive::kPrimLong: {
1988 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001989 Location out = locations->Out();
1990 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001991 break;
1992 }
1993
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00001994 case Primitive::kPrimFloat: {
1995 SRegister out = locations->Out().As<SRegister>();
1996 __ LoadSFromOffset(out, obj, offset);
1997 break;
1998 }
1999
2000 case Primitive::kPrimDouble: {
2001 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2002 __ LoadDFromOffset(out, obj, offset);
2003 break;
2004 }
2005
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002006 case Primitive::kPrimVoid:
2007 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002008 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002009 }
2010}
2011
2012void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002013 LocationSummary* locations =
2014 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002015 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002016 if (instruction->HasUses()) {
2017 locations->SetOut(Location::SameAsFirstInput());
2018 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002019}
2020
2021void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002022 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002023 codegen_->AddSlowPath(slow_path);
2024
2025 LocationSummary* locations = instruction->GetLocations();
2026 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002027
2028 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002029 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002030 __ b(slow_path->GetEntryLabel(), EQ);
2031 } else {
2032 DCHECK(obj.IsConstant()) << obj;
2033 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2034 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002035 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002036}
2037
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002038void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002039 LocationSummary* locations =
2040 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002041 locations->SetInAt(0, Location::RequiresRegister());
2042 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2043 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002044}
2045
2046void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2047 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002048 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002049 Location index = locations->InAt(1);
2050
2051 switch (instruction->GetType()) {
2052 case Primitive::kPrimBoolean: {
2053 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002054 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002055 if (index.IsConstant()) {
2056 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2057 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2058 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002059 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002060 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2061 }
2062 break;
2063 }
2064
2065 case Primitive::kPrimByte: {
2066 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002067 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002068 if (index.IsConstant()) {
2069 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2070 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2071 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002072 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002073 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2074 }
2075 break;
2076 }
2077
2078 case Primitive::kPrimShort: {
2079 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002080 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002081 if (index.IsConstant()) {
2082 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2083 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2084 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002085 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002086 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2087 }
2088 break;
2089 }
2090
2091 case Primitive::kPrimChar: {
2092 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002093 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002094 if (index.IsConstant()) {
2095 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2096 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2097 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002098 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002099 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2100 }
2101 break;
2102 }
2103
2104 case Primitive::kPrimInt:
2105 case Primitive::kPrimNot: {
2106 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2107 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002108 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002109 if (index.IsConstant()) {
2110 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2111 __ LoadFromOffset(kLoadWord, out, obj, offset);
2112 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002113 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002114 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2115 }
2116 break;
2117 }
2118
2119 case Primitive::kPrimLong: {
2120 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002121 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002122 if (index.IsConstant()) {
2123 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002124 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002125 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002126 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2127 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002128 }
2129 break;
2130 }
2131
2132 case Primitive::kPrimFloat:
2133 case Primitive::kPrimDouble:
2134 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002135 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002136 case Primitive::kPrimVoid:
2137 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002138 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002139 }
2140}
2141
2142void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002143 Primitive::Type value_type = instruction->GetComponentType();
2144 bool is_object = value_type == Primitive::kPrimNot;
2145 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2146 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
2147 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002148 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002149 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2150 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2151 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002152 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002153 locations->SetInAt(0, Location::RequiresRegister());
2154 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2155 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002156 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002157}
2158
2159void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2160 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002161 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002162 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002163 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002164
2165 switch (value_type) {
2166 case Primitive::kPrimBoolean:
2167 case Primitive::kPrimByte: {
2168 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002169 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002170 if (index.IsConstant()) {
2171 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2172 __ StoreToOffset(kStoreByte, value, obj, offset);
2173 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002174 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002175 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2176 }
2177 break;
2178 }
2179
2180 case Primitive::kPrimShort:
2181 case Primitive::kPrimChar: {
2182 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002183 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002184 if (index.IsConstant()) {
2185 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2186 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2187 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002188 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002189 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2190 }
2191 break;
2192 }
2193
2194 case Primitive::kPrimInt: {
2195 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002196 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002197 if (index.IsConstant()) {
2198 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2199 __ StoreToOffset(kStoreWord, value, obj, offset);
2200 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002201 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002202 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2203 }
2204 break;
2205 }
2206
2207 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002208 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002209 break;
2210 }
2211
2212 case Primitive::kPrimLong: {
2213 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002214 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002215 if (index.IsConstant()) {
2216 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002217 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002218 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002219 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2220 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002221 }
2222 break;
2223 }
2224
2225 case Primitive::kPrimFloat:
2226 case Primitive::kPrimDouble:
2227 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002228 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002229 case Primitive::kPrimVoid:
2230 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002231 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002232 }
2233}
2234
2235void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002236 LocationSummary* locations =
2237 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002238 locations->SetInAt(0, Location::RequiresRegister());
2239 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002240}
2241
2242void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2243 LocationSummary* locations = instruction->GetLocations();
2244 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002245 Register obj = locations->InAt(0).As<Register>();
2246 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002247 __ LoadFromOffset(kLoadWord, out, obj, offset);
2248}
2249
2250void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002251 LocationSummary* locations =
2252 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002253 locations->SetInAt(0, Location::RequiresRegister());
2254 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002255 if (instruction->HasUses()) {
2256 locations->SetOut(Location::SameAsFirstInput());
2257 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002258}
2259
2260void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2261 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002262 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002263 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002264 codegen_->AddSlowPath(slow_path);
2265
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002266 Register index = locations->InAt(0).As<Register>();
2267 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002268
2269 __ cmp(index, ShifterOperand(length));
2270 __ b(slow_path->GetEntryLabel(), CS);
2271}
2272
2273void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2274 Label is_null;
2275 __ CompareAndBranchIfZero(value, &is_null);
2276 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2277 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2278 __ strb(card, Address(card, temp));
2279 __ Bind(&is_null);
2280}
2281
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002282void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2283 temp->SetLocations(nullptr);
2284}
2285
2286void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2287 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002288 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002289}
2290
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002291void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002292 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002293 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002294}
2295
2296void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002297 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2298}
2299
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002300void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2301 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2302}
2303
2304void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002305 HBasicBlock* block = instruction->GetBlock();
2306 if (block->GetLoopInformation() != nullptr) {
2307 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2308 // The back edge will generate the suspend check.
2309 return;
2310 }
2311 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2312 // The goto will generate the suspend check.
2313 return;
2314 }
2315 GenerateSuspendCheck(instruction, nullptr);
2316}
2317
2318void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2319 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002320 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002321 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002322 codegen_->AddSlowPath(slow_path);
2323
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002324 __ LoadFromOffset(
2325 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2326 __ cmp(IP, ShifterOperand(0));
2327 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002328 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002329 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002330 __ Bind(slow_path->GetReturnLabel());
2331 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002332 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002333 __ b(slow_path->GetEntryLabel());
2334 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002335}
2336
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002337ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2338 return codegen_->GetAssembler();
2339}
2340
2341void ParallelMoveResolverARM::EmitMove(size_t index) {
2342 MoveOperands* move = moves_.Get(index);
2343 Location source = move->GetSource();
2344 Location destination = move->GetDestination();
2345
2346 if (source.IsRegister()) {
2347 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002348 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002349 } else {
2350 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002351 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002352 SP, destination.GetStackIndex());
2353 }
2354 } else if (source.IsStackSlot()) {
2355 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002356 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002357 SP, source.GetStackIndex());
2358 } else {
2359 DCHECK(destination.IsStackSlot());
2360 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2361 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2362 }
2363 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002364 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002365 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002366 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2367 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002368 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002369 } else {
2370 DCHECK(destination.IsStackSlot());
2371 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002372 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002373 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002374 }
2375}
2376
2377void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2378 __ Mov(IP, reg);
2379 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2380 __ StoreToOffset(kStoreWord, IP, SP, mem);
2381}
2382
2383void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2384 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2385 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2386 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2387 SP, mem1 + stack_offset);
2388 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2389 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2390 SP, mem2 + stack_offset);
2391 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2392}
2393
2394void ParallelMoveResolverARM::EmitSwap(size_t index) {
2395 MoveOperands* move = moves_.Get(index);
2396 Location source = move->GetSource();
2397 Location destination = move->GetDestination();
2398
2399 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002400 DCHECK_NE(source.As<Register>(), IP);
2401 DCHECK_NE(destination.As<Register>(), IP);
2402 __ Mov(IP, source.As<Register>());
2403 __ Mov(source.As<Register>(), destination.As<Register>());
2404 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002405 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002406 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002407 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002408 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002409 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2410 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2411 } else {
2412 LOG(FATAL) << "Unimplemented";
2413 }
2414}
2415
2416void ParallelMoveResolverARM::SpillScratch(int reg) {
2417 __ Push(static_cast<Register>(reg));
2418}
2419
2420void ParallelMoveResolverARM::RestoreScratch(int reg) {
2421 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002422}
2423
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002424void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002425 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2426 ? LocationSummary::kCallOnSlowPath
2427 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002428 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002429 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002430 locations->SetOut(Location::RequiresRegister());
2431}
2432
2433void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2434 Register out = cls->GetLocations()->Out().As<Register>();
2435 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002436 DCHECK(!cls->CanCallRuntime());
2437 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002438 codegen_->LoadCurrentMethod(out);
2439 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2440 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002441 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002442 codegen_->LoadCurrentMethod(out);
2443 __ LoadFromOffset(
2444 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2445 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002446
2447 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2448 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2449 codegen_->AddSlowPath(slow_path);
2450 __ cmp(out, ShifterOperand(0));
2451 __ b(slow_path->GetEntryLabel(), EQ);
2452 if (cls->MustGenerateClinitCheck()) {
2453 GenerateClassInitializationCheck(slow_path, out);
2454 } else {
2455 __ Bind(slow_path->GetExitLabel());
2456 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002457 }
2458}
2459
2460void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2461 LocationSummary* locations =
2462 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2463 locations->SetInAt(0, Location::RequiresRegister());
2464 if (check->HasUses()) {
2465 locations->SetOut(Location::SameAsFirstInput());
2466 }
2467}
2468
2469void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002470 // We assume the class is not null.
2471 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2472 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002473 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002474 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2475}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002476
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002477void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2478 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002479 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2480 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2481 __ b(slow_path->GetEntryLabel(), LT);
2482 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2483 // properly. Therefore, we do a memory fence.
2484 __ dmb(ISH);
2485 __ Bind(slow_path->GetExitLabel());
2486}
2487
2488void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2489 LocationSummary* locations =
2490 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2491 locations->SetInAt(0, Location::RequiresRegister());
2492 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2493}
2494
2495void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2496 LocationSummary* locations = instruction->GetLocations();
2497 Register cls = locations->InAt(0).As<Register>();
2498 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2499
2500 switch (instruction->GetType()) {
2501 case Primitive::kPrimBoolean: {
2502 Register out = locations->Out().As<Register>();
2503 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2504 break;
2505 }
2506
2507 case Primitive::kPrimByte: {
2508 Register out = locations->Out().As<Register>();
2509 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2510 break;
2511 }
2512
2513 case Primitive::kPrimShort: {
2514 Register out = locations->Out().As<Register>();
2515 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2516 break;
2517 }
2518
2519 case Primitive::kPrimChar: {
2520 Register out = locations->Out().As<Register>();
2521 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2522 break;
2523 }
2524
2525 case Primitive::kPrimInt:
2526 case Primitive::kPrimNot: {
2527 Register out = locations->Out().As<Register>();
2528 __ LoadFromOffset(kLoadWord, out, cls, offset);
2529 break;
2530 }
2531
2532 case Primitive::kPrimLong: {
2533 // TODO: support volatile.
2534 Location out = locations->Out();
2535 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2536 break;
2537 }
2538
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002539 case Primitive::kPrimFloat: {
2540 SRegister out = locations->Out().As<SRegister>();
2541 __ LoadSFromOffset(out, cls, offset);
2542 break;
2543 }
2544
2545 case Primitive::kPrimDouble: {
2546 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2547 __ LoadDFromOffset(out, cls, offset);
2548 break;
2549 }
2550
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002551 case Primitive::kPrimVoid:
2552 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2553 UNREACHABLE();
2554 }
2555}
2556
2557void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2558 LocationSummary* locations =
2559 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2560 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2561 locations->SetInAt(0, Location::RequiresRegister());
2562 locations->SetInAt(1, Location::RequiresRegister());
2563 // Temporary registers for the write barrier.
2564 if (is_object_type) {
2565 locations->AddTemp(Location::RequiresRegister());
2566 locations->AddTemp(Location::RequiresRegister());
2567 }
2568}
2569
2570void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2571 LocationSummary* locations = instruction->GetLocations();
2572 Register cls = locations->InAt(0).As<Register>();
2573 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2574 Primitive::Type field_type = instruction->GetFieldType();
2575
2576 switch (field_type) {
2577 case Primitive::kPrimBoolean:
2578 case Primitive::kPrimByte: {
2579 Register value = locations->InAt(1).As<Register>();
2580 __ StoreToOffset(kStoreByte, value, cls, offset);
2581 break;
2582 }
2583
2584 case Primitive::kPrimShort:
2585 case Primitive::kPrimChar: {
2586 Register value = locations->InAt(1).As<Register>();
2587 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2588 break;
2589 }
2590
2591 case Primitive::kPrimInt:
2592 case Primitive::kPrimNot: {
2593 Register value = locations->InAt(1).As<Register>();
2594 __ StoreToOffset(kStoreWord, value, cls, offset);
2595 if (field_type == Primitive::kPrimNot) {
2596 Register temp = locations->GetTemp(0).As<Register>();
2597 Register card = locations->GetTemp(1).As<Register>();
2598 codegen_->MarkGCCard(temp, card, cls, value);
2599 }
2600 break;
2601 }
2602
2603 case Primitive::kPrimLong: {
2604 Location value = locations->InAt(1);
2605 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2606 break;
2607 }
2608
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002609 case Primitive::kPrimFloat: {
2610 SRegister value = locations->InAt(1).As<SRegister>();
2611 __ StoreSToOffset(value, cls, offset);
2612 break;
2613 }
2614
2615 case Primitive::kPrimDouble: {
2616 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2617 __ StoreDToOffset(value, cls, offset);
2618 break;
2619 }
2620
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002621 case Primitive::kPrimVoid:
2622 LOG(FATAL) << "Unreachable type " << field_type;
2623 UNREACHABLE();
2624 }
2625}
2626
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002627void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2628 LocationSummary* locations =
2629 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2630 locations->SetOut(Location::RequiresRegister());
2631}
2632
2633void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2634 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2635 codegen_->AddSlowPath(slow_path);
2636
2637 Register out = load->GetLocations()->Out().As<Register>();
2638 codegen_->LoadCurrentMethod(out);
2639 __ LoadFromOffset(
2640 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2641 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2642 __ cmp(out, ShifterOperand(0));
2643 __ b(slow_path->GetEntryLabel(), EQ);
2644 __ Bind(slow_path->GetExitLabel());
2645}
2646
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002647void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
2648 LocationSummary* locations =
2649 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2650 locations->SetOut(Location::RequiresRegister());
2651}
2652
2653void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
2654 Register out = load->GetLocations()->Out().As<Register>();
2655 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
2656 __ LoadFromOffset(kLoadWord, out, TR, offset);
2657 __ LoadImmediate(IP, 0);
2658 __ StoreToOffset(kStoreWord, IP, TR, offset);
2659}
2660
2661void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
2662 LocationSummary* locations =
2663 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2664 InvokeRuntimeCallingConvention calling_convention;
2665 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2666}
2667
2668void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
2669 codegen_->InvokeRuntime(
2670 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
2671}
2672
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002673void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002674 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
2675 ? LocationSummary::kNoCall
2676 : LocationSummary::kCallOnSlowPath;
2677 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2678 locations->SetInAt(0, Location::RequiresRegister());
2679 locations->SetInAt(1, Location::RequiresRegister());
2680 locations->SetOut(Location::RequiresRegister());
2681}
2682
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002683void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002684 LocationSummary* locations = instruction->GetLocations();
2685 Register obj = locations->InAt(0).As<Register>();
2686 Register cls = locations->InAt(1).As<Register>();
2687 Register out = locations->Out().As<Register>();
2688 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2689 Label done, zero;
2690 SlowPathCodeARM* slow_path = nullptr;
2691
2692 // Return 0 if `obj` is null.
2693 // TODO: avoid this check if we know obj is not null.
2694 __ cmp(obj, ShifterOperand(0));
2695 __ b(&zero, EQ);
2696 // Compare the class of `obj` with `cls`.
2697 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
2698 __ cmp(out, ShifterOperand(cls));
2699 if (instruction->IsClassFinal()) {
2700 // Classes must be equal for the instanceof to succeed.
2701 __ b(&zero, NE);
2702 __ LoadImmediate(out, 1);
2703 __ b(&done);
2704 } else {
2705 // If the classes are not equal, we go into a slow path.
2706 DCHECK(locations->OnlyCallsOnSlowPath());
2707 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002708 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002709 codegen_->AddSlowPath(slow_path);
2710 __ b(slow_path->GetEntryLabel(), NE);
2711 __ LoadImmediate(out, 1);
2712 __ b(&done);
2713 }
2714 __ Bind(&zero);
2715 __ LoadImmediate(out, 0);
2716 if (slow_path != nullptr) {
2717 __ Bind(slow_path->GetExitLabel());
2718 }
2719 __ Bind(&done);
2720}
2721
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002722void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
2723 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2724 instruction, LocationSummary::kCallOnSlowPath);
2725 locations->SetInAt(0, Location::RequiresRegister());
2726 locations->SetInAt(1, Location::RequiresRegister());
2727 locations->AddTemp(Location::RequiresRegister());
2728}
2729
2730void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
2731 LocationSummary* locations = instruction->GetLocations();
2732 Register obj = locations->InAt(0).As<Register>();
2733 Register cls = locations->InAt(1).As<Register>();
2734 Register temp = locations->GetTemp(0).As<Register>();
2735 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2736
2737 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
2738 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
2739 codegen_->AddSlowPath(slow_path);
2740
2741 // TODO: avoid this check if we know obj is not null.
2742 __ cmp(obj, ShifterOperand(0));
2743 __ b(slow_path->GetExitLabel(), EQ);
2744 // Compare the class of `obj` with `cls`.
2745 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
2746 __ cmp(temp, ShifterOperand(cls));
2747 __ b(slow_path->GetEntryLabel(), NE);
2748 __ Bind(slow_path->GetExitLabel());
2749}
2750
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002751} // namespace arm
2752} // namespace art