blob: 56546c290197b484d766ad7df5b53d2dabffb9db [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"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010025#include "utils/arm/assembler_arm.h"
26#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000027#include "utils/assembler.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) {
Roland Levillain946e1432014-11-11 17:35:19 +00001348 case Primitive::kPrimInt:
1349 switch (input_type) {
1350 case Primitive::kPrimLong:
1351 // long-to-int conversion.
1352 locations->SetInAt(0, Location::Any());
1353 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1354 break;
1355
1356 case Primitive::kPrimFloat:
1357 case Primitive::kPrimDouble:
1358 LOG(FATAL) << "Type conversion from " << input_type
1359 << " to " << result_type << " not yet implemented";
1360 break;
1361
1362 default:
1363 LOG(FATAL) << "Unexpected type conversion from " << input_type
1364 << " to " << result_type;
1365 }
1366 break;
1367
Roland Levillaindff1f282014-11-05 14:15:05 +00001368 case Primitive::kPrimLong:
1369 switch (input_type) {
1370 case Primitive::kPrimByte:
1371 case Primitive::kPrimShort:
1372 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001373 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001374 // int-to-long conversion.
1375 locations->SetInAt(0, Location::RequiresRegister());
1376 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1377 break;
1378
1379 case Primitive::kPrimFloat:
1380 case Primitive::kPrimDouble:
1381 LOG(FATAL) << "Type conversion from " << input_type << " to "
1382 << result_type << " not yet implemented";
1383 break;
1384
1385 default:
1386 LOG(FATAL) << "Unexpected type conversion from " << input_type
1387 << " to " << result_type;
1388 }
1389 break;
1390
Roland Levillaindff1f282014-11-05 14:15:05 +00001391 case Primitive::kPrimFloat:
1392 case Primitive::kPrimDouble:
1393 LOG(FATAL) << "Type conversion from " << input_type
1394 << " to " << result_type << " not yet implemented";
1395 break;
1396
1397 default:
1398 LOG(FATAL) << "Unexpected type conversion from " << input_type
1399 << " to " << result_type;
1400 }
1401}
1402
1403void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1404 LocationSummary* locations = conversion->GetLocations();
1405 Location out = locations->Out();
1406 Location in = locations->InAt(0);
1407 Primitive::Type result_type = conversion->GetResultType();
1408 Primitive::Type input_type = conversion->GetInputType();
1409 switch (result_type) {
Roland Levillain946e1432014-11-11 17:35:19 +00001410 case Primitive::kPrimInt:
1411 switch (input_type) {
1412 case Primitive::kPrimLong:
1413 // long-to-int conversion.
1414 DCHECK(out.IsRegister());
1415 if (in.IsRegisterPair()) {
1416 __ Mov(out.As<Register>(), in.AsRegisterPairLow<Register>());
1417 } else if (in.IsDoubleStackSlot()) {
1418 __ LoadFromOffset(kLoadWord, out.As<Register>(), SP, in.GetStackIndex());
1419 } else {
1420 DCHECK(in.IsConstant());
1421 DCHECK(in.GetConstant()->IsLongConstant());
1422 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
1423 __ LoadImmediate(out.As<Register>(), static_cast<int32_t>(value));
1424 }
1425 break;
1426
1427 case Primitive::kPrimFloat:
1428 case Primitive::kPrimDouble:
1429 LOG(FATAL) << "Type conversion from " << input_type
1430 << " to " << result_type << " not yet implemented";
1431 break;
1432
1433 default:
1434 LOG(FATAL) << "Unexpected type conversion from " << input_type
1435 << " to " << result_type;
1436 }
1437 break;
1438
Roland Levillaindff1f282014-11-05 14:15:05 +00001439 case Primitive::kPrimLong:
1440 switch (input_type) {
1441 case Primitive::kPrimByte:
1442 case Primitive::kPrimShort:
1443 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001444 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001445 // int-to-long conversion.
1446 DCHECK(out.IsRegisterPair());
1447 DCHECK(in.IsRegister());
1448 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1449 // Sign extension.
1450 __ Asr(out.AsRegisterPairHigh<Register>(),
1451 out.AsRegisterPairLow<Register>(),
1452 31);
1453 break;
1454
1455 case Primitive::kPrimFloat:
1456 case Primitive::kPrimDouble:
1457 LOG(FATAL) << "Type conversion from " << input_type << " to "
1458 << result_type << " not yet implemented";
1459 break;
1460
1461 default:
1462 LOG(FATAL) << "Unexpected type conversion from " << input_type
1463 << " to " << result_type;
1464 }
1465 break;
1466
Roland Levillaindff1f282014-11-05 14:15:05 +00001467 case Primitive::kPrimFloat:
1468 case Primitive::kPrimDouble:
1469 LOG(FATAL) << "Type conversion from " << input_type
1470 << " to " << result_type << " not yet implemented";
1471 break;
1472
1473 default:
1474 LOG(FATAL) << "Unexpected type conversion from " << input_type
1475 << " to " << result_type;
1476 }
1477}
1478
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001479void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001480 LocationSummary* locations =
1481 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001482 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001483 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001484 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001485 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1486 locations->SetInAt(0, Location::RequiresRegister());
1487 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1488 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001489 break;
1490 }
1491
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001492 case Primitive::kPrimFloat:
1493 case Primitive::kPrimDouble: {
1494 locations->SetInAt(0, Location::RequiresFpuRegister());
1495 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001496 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001497 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001498 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001499
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001500 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001501 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001502 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001503}
1504
1505void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1506 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001507 Location out = locations->Out();
1508 Location first = locations->InAt(0);
1509 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001510 switch (add->GetResultType()) {
1511 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001512 if (second.IsRegister()) {
1513 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001514 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001515 __ AddConstant(out.As<Register>(),
1516 first.As<Register>(),
1517 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001518 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001519 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001520
1521 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001522 __ adds(out.AsRegisterPairLow<Register>(),
1523 first.AsRegisterPairLow<Register>(),
1524 ShifterOperand(second.AsRegisterPairLow<Register>()));
1525 __ adc(out.AsRegisterPairHigh<Register>(),
1526 first.AsRegisterPairHigh<Register>(),
1527 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001528 break;
1529
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001530 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001531 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001532 break;
1533
1534 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001535 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1536 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1537 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001538 break;
1539
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001540 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001541 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001542 }
1543}
1544
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001545void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001546 LocationSummary* locations =
1547 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001548 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001549 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001550 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001551 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1552 locations->SetInAt(0, Location::RequiresRegister());
1553 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1554 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001555 break;
1556 }
Calin Juravle11351682014-10-23 15:38:15 +01001557 case Primitive::kPrimFloat:
1558 case Primitive::kPrimDouble: {
1559 locations->SetInAt(0, Location::RequiresFpuRegister());
1560 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001561 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001562 break;
Calin Juravle11351682014-10-23 15:38:15 +01001563 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001564 default:
Calin Juravle11351682014-10-23 15:38:15 +01001565 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001566 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001567}
1568
1569void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1570 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001571 Location out = locations->Out();
1572 Location first = locations->InAt(0);
1573 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001574 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001575 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001576 if (second.IsRegister()) {
1577 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001578 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001579 __ AddConstant(out.As<Register>(),
1580 first.As<Register>(),
1581 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001582 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001583 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001584 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001585
Calin Juravle11351682014-10-23 15:38:15 +01001586 case Primitive::kPrimLong: {
1587 __ subs(out.AsRegisterPairLow<Register>(),
1588 first.AsRegisterPairLow<Register>(),
1589 ShifterOperand(second.AsRegisterPairLow<Register>()));
1590 __ sbc(out.AsRegisterPairHigh<Register>(),
1591 first.AsRegisterPairHigh<Register>(),
1592 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001593 break;
Calin Juravle11351682014-10-23 15:38:15 +01001594 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001595
Calin Juravle11351682014-10-23 15:38:15 +01001596 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001597 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001598 break;
Calin Juravle11351682014-10-23 15:38:15 +01001599 }
1600
1601 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001602 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1603 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1604 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001605 break;
1606 }
1607
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001608
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001609 default:
Calin Juravle11351682014-10-23 15:38:15 +01001610 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001611 }
1612}
1613
Calin Juravle34bacdf2014-10-07 20:23:36 +01001614void LocationsBuilderARM::VisitMul(HMul* mul) {
1615 LocationSummary* locations =
1616 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1617 switch (mul->GetResultType()) {
1618 case Primitive::kPrimInt:
1619 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001620 locations->SetInAt(0, Location::RequiresRegister());
1621 locations->SetInAt(1, Location::RequiresRegister());
1622 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001623 break;
1624 }
1625
Calin Juravleb5bfa962014-10-21 18:02:24 +01001626 case Primitive::kPrimFloat:
1627 case Primitive::kPrimDouble: {
1628 locations->SetInAt(0, Location::RequiresFpuRegister());
1629 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001630 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001631 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001632 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001633
1634 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001635 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001636 }
1637}
1638
1639void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1640 LocationSummary* locations = mul->GetLocations();
1641 Location out = locations->Out();
1642 Location first = locations->InAt(0);
1643 Location second = locations->InAt(1);
1644 switch (mul->GetResultType()) {
1645 case Primitive::kPrimInt: {
1646 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1647 break;
1648 }
1649 case Primitive::kPrimLong: {
1650 Register out_hi = out.AsRegisterPairHigh<Register>();
1651 Register out_lo = out.AsRegisterPairLow<Register>();
1652 Register in1_hi = first.AsRegisterPairHigh<Register>();
1653 Register in1_lo = first.AsRegisterPairLow<Register>();
1654 Register in2_hi = second.AsRegisterPairHigh<Register>();
1655 Register in2_lo = second.AsRegisterPairLow<Register>();
1656
1657 // Extra checks to protect caused by the existence of R1_R2.
1658 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1659 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1660 DCHECK_NE(out_hi, in1_lo);
1661 DCHECK_NE(out_hi, in2_lo);
1662
1663 // input: in1 - 64 bits, in2 - 64 bits
1664 // output: out
1665 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1666 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1667 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1668
1669 // IP <- in1.lo * in2.hi
1670 __ mul(IP, in1_lo, in2_hi);
1671 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1672 __ mla(out_hi, in1_hi, in2_lo, IP);
1673 // out.lo <- (in1.lo * in2.lo)[31:0];
1674 __ umull(out_lo, IP, in1_lo, in2_lo);
1675 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1676 __ add(out_hi, out_hi, ShifterOperand(IP));
1677 break;
1678 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001679
1680 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001681 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001682 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001683 }
1684
1685 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001686 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1687 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1688 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001689 break;
1690 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001691
1692 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001693 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001694 }
1695}
1696
Calin Juravle7c4954d2014-10-28 16:57:40 +00001697void LocationsBuilderARM::VisitDiv(HDiv* div) {
1698 LocationSummary* locations =
1699 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1700 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001701 case Primitive::kPrimInt: {
1702 locations->SetInAt(0, Location::RequiresRegister());
1703 locations->SetInAt(1, Location::RequiresRegister());
1704 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1705 break;
1706 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001707 case Primitive::kPrimLong: {
1708 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1709 break;
1710 }
1711 case Primitive::kPrimFloat:
1712 case Primitive::kPrimDouble: {
1713 locations->SetInAt(0, Location::RequiresFpuRegister());
1714 locations->SetInAt(1, Location::RequiresFpuRegister());
1715 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1716 break;
1717 }
1718
1719 default:
1720 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1721 }
1722}
1723
1724void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1725 LocationSummary* locations = div->GetLocations();
1726 Location out = locations->Out();
1727 Location first = locations->InAt(0);
1728 Location second = locations->InAt(1);
1729
1730 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001731 case Primitive::kPrimInt: {
1732 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>());
1733 break;
1734 }
1735
Calin Juravle7c4954d2014-10-28 16:57:40 +00001736 case Primitive::kPrimLong: {
1737 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1738 break;
1739 }
1740
1741 case Primitive::kPrimFloat: {
1742 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1743 break;
1744 }
1745
1746 case Primitive::kPrimDouble: {
1747 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1748 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1749 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1750 break;
1751 }
1752
1753 default:
1754 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1755 }
1756}
1757
Calin Juravled0d48522014-11-04 16:40:20 +00001758void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1759 LocationSummary* locations =
1760 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1761 locations->SetInAt(0, Location::RequiresRegister());
1762 if (instruction->HasUses()) {
1763 locations->SetOut(Location::SameAsFirstInput());
1764 }
1765}
1766
1767void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1768 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
1769 codegen_->AddSlowPath(slow_path);
1770
1771 LocationSummary* locations = instruction->GetLocations();
1772 Location value = locations->InAt(0);
1773
1774 DCHECK(value.IsRegister()) << value;
1775 __ cmp(value.As<Register>(), ShifterOperand(0));
1776 __ b(slow_path->GetEntryLabel(), EQ);
1777}
1778
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001779void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001780 LocationSummary* locations =
1781 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001782 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001783 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1784 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1785 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001786}
1787
1788void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1789 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001790 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001791 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001792 codegen_->InvokeRuntime(
1793 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001794}
1795
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001796void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1797 LocationSummary* locations =
1798 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1799 InvokeRuntimeCallingConvention calling_convention;
1800 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1801 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1802 locations->SetOut(Location::RegisterLocation(R0));
1803 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1804}
1805
1806void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1807 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001808 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001809 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001810 codegen_->InvokeRuntime(
1811 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001812}
1813
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001814void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001815 LocationSummary* locations =
1816 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001817 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1818 if (location.IsStackSlot()) {
1819 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1820 } else if (location.IsDoubleStackSlot()) {
1821 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001822 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001823 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001824}
1825
1826void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001827 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001828 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001829}
1830
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001831void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001832 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001833 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001834 locations->SetInAt(0, Location::RequiresRegister());
1835 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001836}
1837
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001838void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1839 LocationSummary* locations = not_->GetLocations();
1840 Location out = locations->Out();
1841 Location in = locations->InAt(0);
1842 switch (not_->InputAt(0)->GetType()) {
1843 case Primitive::kPrimBoolean:
1844 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1845 break;
1846
1847 case Primitive::kPrimInt:
1848 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1849 break;
1850
1851 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001852 __ mvn(out.AsRegisterPairLow<Register>(),
1853 ShifterOperand(in.AsRegisterPairLow<Register>()));
1854 __ mvn(out.AsRegisterPairHigh<Register>(),
1855 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001856 break;
1857
1858 default:
1859 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1860 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001861}
1862
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001863void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001864 LocationSummary* locations =
1865 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001866 locations->SetInAt(0, Location::RequiresRegister());
1867 locations->SetInAt(1, Location::RequiresRegister());
1868 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001869}
1870
1871void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001872 LocationSummary* locations = compare->GetLocations();
1873 switch (compare->InputAt(0)->GetType()) {
1874 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001875 Register output = locations->Out().As<Register>();
1876 Location left = locations->InAt(0);
1877 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001878 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001879 __ cmp(left.AsRegisterPairHigh<Register>(),
1880 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001881 __ b(&less, LT);
1882 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001883 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1884 // the status flags.
1885 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001886 __ cmp(left.AsRegisterPairLow<Register>(),
1887 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001888 __ b(&done, EQ);
1889 __ b(&less, CC);
1890
1891 __ Bind(&greater);
1892 __ LoadImmediate(output, 1);
1893 __ b(&done);
1894
1895 __ Bind(&less);
1896 __ LoadImmediate(output, -1);
1897
1898 __ Bind(&done);
1899 break;
1900 }
1901 default:
1902 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1903 }
1904}
1905
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001906void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001907 LocationSummary* locations =
1908 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001909 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1910 locations->SetInAt(i, Location::Any());
1911 }
1912 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001913}
1914
1915void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001916 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001917 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001918}
1919
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001920void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001921 LocationSummary* locations =
1922 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001923 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001924 locations->SetInAt(0, Location::RequiresRegister());
1925 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001926 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001927 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001928 locations->AddTemp(Location::RequiresRegister());
1929 locations->AddTemp(Location::RequiresRegister());
1930 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001931}
1932
1933void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1934 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001935 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001936 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001937 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001938
1939 switch (field_type) {
1940 case Primitive::kPrimBoolean:
1941 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001942 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001943 __ StoreToOffset(kStoreByte, value, obj, offset);
1944 break;
1945 }
1946
1947 case Primitive::kPrimShort:
1948 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001949 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001950 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1951 break;
1952 }
1953
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001954 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001955 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001956 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001957 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001958 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001959 Register temp = locations->GetTemp(0).As<Register>();
1960 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001961 codegen_->MarkGCCard(temp, card, obj, value);
1962 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001963 break;
1964 }
1965
1966 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001967 Location value = locations->InAt(1);
1968 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001969 break;
1970 }
1971
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00001972 case Primitive::kPrimFloat: {
1973 SRegister value = locations->InAt(1).As<SRegister>();
1974 __ StoreSToOffset(value, obj, offset);
1975 break;
1976 }
1977
1978 case Primitive::kPrimDouble: {
1979 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
1980 __ StoreDToOffset(value, obj, offset);
1981 break;
1982 }
1983
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001984 case Primitive::kPrimVoid:
1985 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001986 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001987 }
1988}
1989
1990void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001991 LocationSummary* locations =
1992 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001993 locations->SetInAt(0, Location::RequiresRegister());
1994 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001995}
1996
1997void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1998 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001999 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002000 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2001
2002 switch (instruction->GetType()) {
2003 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002004 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002005 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2006 break;
2007 }
2008
2009 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002010 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002011 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2012 break;
2013 }
2014
2015 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002016 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002017 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2018 break;
2019 }
2020
2021 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002022 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002023 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2024 break;
2025 }
2026
2027 case Primitive::kPrimInt:
2028 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002029 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002030 __ LoadFromOffset(kLoadWord, out, obj, offset);
2031 break;
2032 }
2033
2034 case Primitive::kPrimLong: {
2035 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002036 Location out = locations->Out();
2037 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002038 break;
2039 }
2040
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002041 case Primitive::kPrimFloat: {
2042 SRegister out = locations->Out().As<SRegister>();
2043 __ LoadSFromOffset(out, obj, offset);
2044 break;
2045 }
2046
2047 case Primitive::kPrimDouble: {
2048 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2049 __ LoadDFromOffset(out, obj, offset);
2050 break;
2051 }
2052
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002053 case Primitive::kPrimVoid:
2054 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002055 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002056 }
2057}
2058
2059void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002060 LocationSummary* locations =
2061 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002062 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002063 if (instruction->HasUses()) {
2064 locations->SetOut(Location::SameAsFirstInput());
2065 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002066}
2067
2068void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002069 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002070 codegen_->AddSlowPath(slow_path);
2071
2072 LocationSummary* locations = instruction->GetLocations();
2073 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002074
2075 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002076 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002077 __ b(slow_path->GetEntryLabel(), EQ);
2078 } else {
2079 DCHECK(obj.IsConstant()) << obj;
2080 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2081 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002082 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002083}
2084
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002085void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002086 LocationSummary* locations =
2087 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002088 locations->SetInAt(0, Location::RequiresRegister());
2089 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2090 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002091}
2092
2093void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2094 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002095 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002096 Location index = locations->InAt(1);
2097
2098 switch (instruction->GetType()) {
2099 case Primitive::kPrimBoolean: {
2100 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002101 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002102 if (index.IsConstant()) {
2103 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2104 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2105 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002106 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002107 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2108 }
2109 break;
2110 }
2111
2112 case Primitive::kPrimByte: {
2113 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002114 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002115 if (index.IsConstant()) {
2116 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2117 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2118 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002119 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002120 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2121 }
2122 break;
2123 }
2124
2125 case Primitive::kPrimShort: {
2126 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002127 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002128 if (index.IsConstant()) {
2129 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2130 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2131 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002132 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002133 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2134 }
2135 break;
2136 }
2137
2138 case Primitive::kPrimChar: {
2139 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002140 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002141 if (index.IsConstant()) {
2142 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2143 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2144 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002145 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002146 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2147 }
2148 break;
2149 }
2150
2151 case Primitive::kPrimInt:
2152 case Primitive::kPrimNot: {
2153 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2154 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002155 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002156 if (index.IsConstant()) {
2157 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2158 __ LoadFromOffset(kLoadWord, out, obj, offset);
2159 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002160 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002161 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2162 }
2163 break;
2164 }
2165
2166 case Primitive::kPrimLong: {
2167 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002168 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002169 if (index.IsConstant()) {
2170 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002171 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002172 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002173 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2174 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002175 }
2176 break;
2177 }
2178
2179 case Primitive::kPrimFloat:
2180 case Primitive::kPrimDouble:
2181 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002182 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002183 case Primitive::kPrimVoid:
2184 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002185 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002186 }
2187}
2188
2189void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002190 Primitive::Type value_type = instruction->GetComponentType();
2191 bool is_object = value_type == Primitive::kPrimNot;
2192 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2193 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
2194 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002195 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002196 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2197 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2198 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002199 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002200 locations->SetInAt(0, Location::RequiresRegister());
2201 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2202 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002203 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002204}
2205
2206void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2207 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002208 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002209 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002210 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002211
2212 switch (value_type) {
2213 case Primitive::kPrimBoolean:
2214 case Primitive::kPrimByte: {
2215 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002216 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002217 if (index.IsConstant()) {
2218 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2219 __ StoreToOffset(kStoreByte, value, obj, offset);
2220 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002221 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002222 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2223 }
2224 break;
2225 }
2226
2227 case Primitive::kPrimShort:
2228 case Primitive::kPrimChar: {
2229 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002230 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002231 if (index.IsConstant()) {
2232 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2233 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2234 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002235 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002236 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2237 }
2238 break;
2239 }
2240
2241 case Primitive::kPrimInt: {
2242 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002243 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002244 if (index.IsConstant()) {
2245 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2246 __ StoreToOffset(kStoreWord, value, obj, offset);
2247 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002248 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002249 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2250 }
2251 break;
2252 }
2253
2254 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002255 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002256 break;
2257 }
2258
2259 case Primitive::kPrimLong: {
2260 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002261 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002262 if (index.IsConstant()) {
2263 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002264 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002265 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002266 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2267 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002268 }
2269 break;
2270 }
2271
2272 case Primitive::kPrimFloat:
2273 case Primitive::kPrimDouble:
2274 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002275 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002276 case Primitive::kPrimVoid:
2277 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002278 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002279 }
2280}
2281
2282void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002283 LocationSummary* locations =
2284 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002285 locations->SetInAt(0, Location::RequiresRegister());
2286 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002287}
2288
2289void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2290 LocationSummary* locations = instruction->GetLocations();
2291 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002292 Register obj = locations->InAt(0).As<Register>();
2293 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002294 __ LoadFromOffset(kLoadWord, out, obj, offset);
2295}
2296
2297void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002298 LocationSummary* locations =
2299 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002300 locations->SetInAt(0, Location::RequiresRegister());
2301 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002302 if (instruction->HasUses()) {
2303 locations->SetOut(Location::SameAsFirstInput());
2304 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002305}
2306
2307void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2308 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002309 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002310 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002311 codegen_->AddSlowPath(slow_path);
2312
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002313 Register index = locations->InAt(0).As<Register>();
2314 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002315
2316 __ cmp(index, ShifterOperand(length));
2317 __ b(slow_path->GetEntryLabel(), CS);
2318}
2319
2320void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2321 Label is_null;
2322 __ CompareAndBranchIfZero(value, &is_null);
2323 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2324 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2325 __ strb(card, Address(card, temp));
2326 __ Bind(&is_null);
2327}
2328
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002329void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2330 temp->SetLocations(nullptr);
2331}
2332
2333void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2334 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002335 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002336}
2337
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002338void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002339 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002340 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002341}
2342
2343void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002344 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2345}
2346
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002347void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2348 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2349}
2350
2351void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002352 HBasicBlock* block = instruction->GetBlock();
2353 if (block->GetLoopInformation() != nullptr) {
2354 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2355 // The back edge will generate the suspend check.
2356 return;
2357 }
2358 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2359 // The goto will generate the suspend check.
2360 return;
2361 }
2362 GenerateSuspendCheck(instruction, nullptr);
2363}
2364
2365void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2366 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002367 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002368 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002369 codegen_->AddSlowPath(slow_path);
2370
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002371 __ LoadFromOffset(
2372 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2373 __ cmp(IP, ShifterOperand(0));
2374 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002375 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002376 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002377 __ Bind(slow_path->GetReturnLabel());
2378 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002379 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002380 __ b(slow_path->GetEntryLabel());
2381 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002382}
2383
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002384ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2385 return codegen_->GetAssembler();
2386}
2387
2388void ParallelMoveResolverARM::EmitMove(size_t index) {
2389 MoveOperands* move = moves_.Get(index);
2390 Location source = move->GetSource();
2391 Location destination = move->GetDestination();
2392
2393 if (source.IsRegister()) {
2394 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002395 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002396 } else {
2397 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002398 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002399 SP, destination.GetStackIndex());
2400 }
2401 } else if (source.IsStackSlot()) {
2402 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002403 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002404 SP, source.GetStackIndex());
2405 } else {
2406 DCHECK(destination.IsStackSlot());
2407 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2408 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2409 }
2410 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002411 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002412 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002413 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2414 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002415 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002416 } else {
2417 DCHECK(destination.IsStackSlot());
2418 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002419 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002420 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002421 }
2422}
2423
2424void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2425 __ Mov(IP, reg);
2426 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2427 __ StoreToOffset(kStoreWord, IP, SP, mem);
2428}
2429
2430void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2431 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2432 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2433 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2434 SP, mem1 + stack_offset);
2435 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2436 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2437 SP, mem2 + stack_offset);
2438 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2439}
2440
2441void ParallelMoveResolverARM::EmitSwap(size_t index) {
2442 MoveOperands* move = moves_.Get(index);
2443 Location source = move->GetSource();
2444 Location destination = move->GetDestination();
2445
2446 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002447 DCHECK_NE(source.As<Register>(), IP);
2448 DCHECK_NE(destination.As<Register>(), IP);
2449 __ Mov(IP, source.As<Register>());
2450 __ Mov(source.As<Register>(), destination.As<Register>());
2451 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002452 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002453 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002454 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002455 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002456 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2457 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2458 } else {
2459 LOG(FATAL) << "Unimplemented";
2460 }
2461}
2462
2463void ParallelMoveResolverARM::SpillScratch(int reg) {
2464 __ Push(static_cast<Register>(reg));
2465}
2466
2467void ParallelMoveResolverARM::RestoreScratch(int reg) {
2468 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002469}
2470
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002471void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002472 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2473 ? LocationSummary::kCallOnSlowPath
2474 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002475 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002476 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002477 locations->SetOut(Location::RequiresRegister());
2478}
2479
2480void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2481 Register out = cls->GetLocations()->Out().As<Register>();
2482 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002483 DCHECK(!cls->CanCallRuntime());
2484 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002485 codegen_->LoadCurrentMethod(out);
2486 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2487 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002488 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002489 codegen_->LoadCurrentMethod(out);
2490 __ LoadFromOffset(
2491 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2492 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002493
2494 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2495 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2496 codegen_->AddSlowPath(slow_path);
2497 __ cmp(out, ShifterOperand(0));
2498 __ b(slow_path->GetEntryLabel(), EQ);
2499 if (cls->MustGenerateClinitCheck()) {
2500 GenerateClassInitializationCheck(slow_path, out);
2501 } else {
2502 __ Bind(slow_path->GetExitLabel());
2503 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002504 }
2505}
2506
2507void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2508 LocationSummary* locations =
2509 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2510 locations->SetInAt(0, Location::RequiresRegister());
2511 if (check->HasUses()) {
2512 locations->SetOut(Location::SameAsFirstInput());
2513 }
2514}
2515
2516void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002517 // We assume the class is not null.
2518 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2519 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002520 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002521 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2522}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002523
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002524void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2525 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002526 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2527 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2528 __ b(slow_path->GetEntryLabel(), LT);
2529 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2530 // properly. Therefore, we do a memory fence.
2531 __ dmb(ISH);
2532 __ Bind(slow_path->GetExitLabel());
2533}
2534
2535void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2536 LocationSummary* locations =
2537 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2538 locations->SetInAt(0, Location::RequiresRegister());
2539 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2540}
2541
2542void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2543 LocationSummary* locations = instruction->GetLocations();
2544 Register cls = locations->InAt(0).As<Register>();
2545 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2546
2547 switch (instruction->GetType()) {
2548 case Primitive::kPrimBoolean: {
2549 Register out = locations->Out().As<Register>();
2550 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2551 break;
2552 }
2553
2554 case Primitive::kPrimByte: {
2555 Register out = locations->Out().As<Register>();
2556 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2557 break;
2558 }
2559
2560 case Primitive::kPrimShort: {
2561 Register out = locations->Out().As<Register>();
2562 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2563 break;
2564 }
2565
2566 case Primitive::kPrimChar: {
2567 Register out = locations->Out().As<Register>();
2568 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2569 break;
2570 }
2571
2572 case Primitive::kPrimInt:
2573 case Primitive::kPrimNot: {
2574 Register out = locations->Out().As<Register>();
2575 __ LoadFromOffset(kLoadWord, out, cls, offset);
2576 break;
2577 }
2578
2579 case Primitive::kPrimLong: {
2580 // TODO: support volatile.
2581 Location out = locations->Out();
2582 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2583 break;
2584 }
2585
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002586 case Primitive::kPrimFloat: {
2587 SRegister out = locations->Out().As<SRegister>();
2588 __ LoadSFromOffset(out, cls, offset);
2589 break;
2590 }
2591
2592 case Primitive::kPrimDouble: {
2593 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2594 __ LoadDFromOffset(out, cls, offset);
2595 break;
2596 }
2597
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002598 case Primitive::kPrimVoid:
2599 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2600 UNREACHABLE();
2601 }
2602}
2603
2604void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2605 LocationSummary* locations =
2606 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2607 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2608 locations->SetInAt(0, Location::RequiresRegister());
2609 locations->SetInAt(1, Location::RequiresRegister());
2610 // Temporary registers for the write barrier.
2611 if (is_object_type) {
2612 locations->AddTemp(Location::RequiresRegister());
2613 locations->AddTemp(Location::RequiresRegister());
2614 }
2615}
2616
2617void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2618 LocationSummary* locations = instruction->GetLocations();
2619 Register cls = locations->InAt(0).As<Register>();
2620 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2621 Primitive::Type field_type = instruction->GetFieldType();
2622
2623 switch (field_type) {
2624 case Primitive::kPrimBoolean:
2625 case Primitive::kPrimByte: {
2626 Register value = locations->InAt(1).As<Register>();
2627 __ StoreToOffset(kStoreByte, value, cls, offset);
2628 break;
2629 }
2630
2631 case Primitive::kPrimShort:
2632 case Primitive::kPrimChar: {
2633 Register value = locations->InAt(1).As<Register>();
2634 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2635 break;
2636 }
2637
2638 case Primitive::kPrimInt:
2639 case Primitive::kPrimNot: {
2640 Register value = locations->InAt(1).As<Register>();
2641 __ StoreToOffset(kStoreWord, value, cls, offset);
2642 if (field_type == Primitive::kPrimNot) {
2643 Register temp = locations->GetTemp(0).As<Register>();
2644 Register card = locations->GetTemp(1).As<Register>();
2645 codegen_->MarkGCCard(temp, card, cls, value);
2646 }
2647 break;
2648 }
2649
2650 case Primitive::kPrimLong: {
2651 Location value = locations->InAt(1);
2652 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2653 break;
2654 }
2655
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002656 case Primitive::kPrimFloat: {
2657 SRegister value = locations->InAt(1).As<SRegister>();
2658 __ StoreSToOffset(value, cls, offset);
2659 break;
2660 }
2661
2662 case Primitive::kPrimDouble: {
2663 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2664 __ StoreDToOffset(value, cls, offset);
2665 break;
2666 }
2667
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002668 case Primitive::kPrimVoid:
2669 LOG(FATAL) << "Unreachable type " << field_type;
2670 UNREACHABLE();
2671 }
2672}
2673
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002674void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2675 LocationSummary* locations =
2676 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2677 locations->SetOut(Location::RequiresRegister());
2678}
2679
2680void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2681 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2682 codegen_->AddSlowPath(slow_path);
2683
2684 Register out = load->GetLocations()->Out().As<Register>();
2685 codegen_->LoadCurrentMethod(out);
2686 __ LoadFromOffset(
2687 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2688 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2689 __ cmp(out, ShifterOperand(0));
2690 __ b(slow_path->GetEntryLabel(), EQ);
2691 __ Bind(slow_path->GetExitLabel());
2692}
2693
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002694void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
2695 LocationSummary* locations =
2696 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2697 locations->SetOut(Location::RequiresRegister());
2698}
2699
2700void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
2701 Register out = load->GetLocations()->Out().As<Register>();
2702 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
2703 __ LoadFromOffset(kLoadWord, out, TR, offset);
2704 __ LoadImmediate(IP, 0);
2705 __ StoreToOffset(kStoreWord, IP, TR, offset);
2706}
2707
2708void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
2709 LocationSummary* locations =
2710 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2711 InvokeRuntimeCallingConvention calling_convention;
2712 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2713}
2714
2715void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
2716 codegen_->InvokeRuntime(
2717 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
2718}
2719
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002720void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002721 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
2722 ? LocationSummary::kNoCall
2723 : LocationSummary::kCallOnSlowPath;
2724 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2725 locations->SetInAt(0, Location::RequiresRegister());
2726 locations->SetInAt(1, Location::RequiresRegister());
2727 locations->SetOut(Location::RequiresRegister());
2728}
2729
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002730void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002731 LocationSummary* locations = instruction->GetLocations();
2732 Register obj = locations->InAt(0).As<Register>();
2733 Register cls = locations->InAt(1).As<Register>();
2734 Register out = locations->Out().As<Register>();
2735 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2736 Label done, zero;
2737 SlowPathCodeARM* slow_path = nullptr;
2738
2739 // Return 0 if `obj` is null.
2740 // TODO: avoid this check if we know obj is not null.
2741 __ cmp(obj, ShifterOperand(0));
2742 __ b(&zero, EQ);
2743 // Compare the class of `obj` with `cls`.
2744 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
2745 __ cmp(out, ShifterOperand(cls));
2746 if (instruction->IsClassFinal()) {
2747 // Classes must be equal for the instanceof to succeed.
2748 __ b(&zero, NE);
2749 __ LoadImmediate(out, 1);
2750 __ b(&done);
2751 } else {
2752 // If the classes are not equal, we go into a slow path.
2753 DCHECK(locations->OnlyCallsOnSlowPath());
2754 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002755 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002756 codegen_->AddSlowPath(slow_path);
2757 __ b(slow_path->GetEntryLabel(), NE);
2758 __ LoadImmediate(out, 1);
2759 __ b(&done);
2760 }
2761 __ Bind(&zero);
2762 __ LoadImmediate(out, 0);
2763 if (slow_path != nullptr) {
2764 __ Bind(slow_path->GetExitLabel());
2765 }
2766 __ Bind(&done);
2767}
2768
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002769void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
2770 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2771 instruction, LocationSummary::kCallOnSlowPath);
2772 locations->SetInAt(0, Location::RequiresRegister());
2773 locations->SetInAt(1, Location::RequiresRegister());
2774 locations->AddTemp(Location::RequiresRegister());
2775}
2776
2777void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
2778 LocationSummary* locations = instruction->GetLocations();
2779 Register obj = locations->InAt(0).As<Register>();
2780 Register cls = locations->InAt(1).As<Register>();
2781 Register temp = locations->GetTemp(0).As<Register>();
2782 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2783
2784 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
2785 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
2786 codegen_->AddSlowPath(slow_path);
2787
2788 // TODO: avoid this check if we know obj is not null.
2789 __ cmp(obj, ShifterOperand(0));
2790 __ b(slow_path->GetExitLabel(), EQ);
2791 // Compare the class of `obj` with `cls`.
2792 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
2793 __ cmp(temp, ShifterOperand(cls));
2794 __ b(slow_path->GetEntryLabel(), NE);
2795 __ Bind(slow_path->GetExitLabel());
2796}
2797
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002798void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
2799 LocationSummary* locations =
2800 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2801 InvokeRuntimeCallingConvention calling_convention;
2802 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2803}
2804
2805void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
2806 codegen_->InvokeRuntime(instruction->IsEnter()
2807 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2808 instruction,
2809 instruction->GetDexPc());
2810}
2811
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002812void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
2813void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
2814void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
2815
2816void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
2817 LocationSummary* locations =
2818 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2819 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
2820 || instruction->GetResultType() == Primitive::kPrimLong);
2821 locations->SetInAt(0, Location::RequiresRegister());
2822 locations->SetInAt(1, Location::RequiresRegister());
2823 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
2824 locations->SetOut(Location::RequiresRegister(), output_overlaps);
2825}
2826
2827void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
2828 HandleBitwiseOperation(instruction);
2829}
2830
2831void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
2832 HandleBitwiseOperation(instruction);
2833}
2834
2835void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
2836 HandleBitwiseOperation(instruction);
2837}
2838
2839void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
2840 LocationSummary* locations = instruction->GetLocations();
2841
2842 if (instruction->GetResultType() == Primitive::kPrimInt) {
2843 Register first = locations->InAt(0).As<Register>();
2844 Register second = locations->InAt(1).As<Register>();
2845 Register out = locations->Out().As<Register>();
2846 if (instruction->IsAnd()) {
2847 __ and_(out, first, ShifterOperand(second));
2848 } else if (instruction->IsOr()) {
2849 __ orr(out, first, ShifterOperand(second));
2850 } else {
2851 DCHECK(instruction->IsXor());
2852 __ eor(out, first, ShifterOperand(second));
2853 }
2854 } else {
2855 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
2856 Location first = locations->InAt(0);
2857 Location second = locations->InAt(1);
2858 Location out = locations->Out();
2859 if (instruction->IsAnd()) {
2860 __ and_(out.AsRegisterPairLow<Register>(),
2861 first.AsRegisterPairLow<Register>(),
2862 ShifterOperand(second.AsRegisterPairLow<Register>()));
2863 __ and_(out.AsRegisterPairHigh<Register>(),
2864 first.AsRegisterPairHigh<Register>(),
2865 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2866 } else if (instruction->IsOr()) {
2867 __ orr(out.AsRegisterPairLow<Register>(),
2868 first.AsRegisterPairLow<Register>(),
2869 ShifterOperand(second.AsRegisterPairLow<Register>()));
2870 __ orr(out.AsRegisterPairHigh<Register>(),
2871 first.AsRegisterPairHigh<Register>(),
2872 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2873 } else {
2874 DCHECK(instruction->IsXor());
2875 __ eor(out.AsRegisterPairLow<Register>(),
2876 first.AsRegisterPairLow<Register>(),
2877 ShifterOperand(second.AsRegisterPairLow<Register>()));
2878 __ eor(out.AsRegisterPairHigh<Register>(),
2879 first.AsRegisterPairHigh<Register>(),
2880 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2881 }
2882 }
2883}
2884
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002885} // namespace arm
2886} // namespace art