blob: 87955ebae56104d040e4ada0ea8d52f2819e5c72 [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());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000827 if (temp_location.IsStackSlot()) {
828 Move32(location, temp_location);
829 } else {
830 DCHECK(temp_location.IsDoubleStackSlot());
831 Move64(location, temp_location);
832 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000833 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100834 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 switch (instruction->GetType()) {
836 case Primitive::kPrimBoolean:
837 case Primitive::kPrimByte:
838 case Primitive::kPrimChar:
839 case Primitive::kPrimShort:
840 case Primitive::kPrimNot:
841 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100842 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100843 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100844 break;
845
846 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100847 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100848 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 break;
850
851 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100852 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100853 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000854 }
855}
856
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100857void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
858 HInstruction* instruction,
859 uint32_t dex_pc) {
860 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
861 __ blx(LR);
862 RecordPcInfo(instruction, dex_pc);
863 DCHECK(instruction->IsSuspendCheck()
864 || instruction->IsBoundsCheck()
865 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000866 || instruction->IsDivZeroCheck()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100867 || !IsLeafMethod());
868}
869
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000870void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000871 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000872}
873
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000874void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000875 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100876 DCHECK(!successor->IsExitBlock());
877
878 HBasicBlock* block = got->GetBlock();
879 HInstruction* previous = got->GetPrevious();
880
881 HLoopInformation* info = block->GetLoopInformation();
882 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
883 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
884 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
885 return;
886 }
887
888 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
889 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
890 }
891 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000892 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000893 }
894}
895
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000896void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000897 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000898}
899
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000900void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700901 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000902 if (kIsDebugBuild) {
903 __ Comment("Unreachable");
904 __ bkpt(0);
905 }
906}
907
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000908void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100909 LocationSummary* locations =
910 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100911 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100912 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100913 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100914 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000915}
916
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000917void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700918 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100919 if (cond->IsIntConstant()) {
920 // Constant condition, statically compared against 1.
921 int32_t cond_value = cond->AsIntConstant()->GetValue();
922 if (cond_value == 1) {
923 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
924 if_instr->IfTrueSuccessor())) {
925 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100926 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100927 return;
928 } else {
929 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100930 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100931 } else {
932 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
933 // Condition has been materialized, compare the output to 0
934 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
935 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
936 ShifterOperand(0));
937 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
938 } else {
939 // Condition has not been materialized, use its inputs as the
940 // comparison and its condition as the branch condition.
941 LocationSummary* locations = cond->GetLocations();
942 if (locations->InAt(1).IsRegister()) {
943 __ cmp(locations->InAt(0).As<Register>(),
944 ShifterOperand(locations->InAt(1).As<Register>()));
945 } else {
946 DCHECK(locations->InAt(1).IsConstant());
947 int32_t value =
948 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
949 ShifterOperand operand;
950 if (ShifterOperand::CanHoldArm(value, &operand)) {
951 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
952 } else {
953 Register temp = IP;
954 __ LoadImmediate(temp, value);
955 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
956 }
957 }
958 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
959 ARMCondition(cond->AsCondition()->GetCondition()));
960 }
Dave Allison20dfc792014-06-16 20:44:29 -0700961 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100962 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
963 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700964 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000965 }
966}
967
Dave Allison20dfc792014-06-16 20:44:29 -0700968
969void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100970 LocationSummary* locations =
971 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100972 locations->SetInAt(0, Location::RequiresRegister());
973 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100974 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100975 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100976 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000977}
978
Dave Allison20dfc792014-06-16 20:44:29 -0700979void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100980 if (!comp->NeedsMaterialization()) return;
981
982 LocationSummary* locations = comp->GetLocations();
983 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100984 __ cmp(locations->InAt(0).As<Register>(),
985 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100986 } else {
987 DCHECK(locations->InAt(1).IsConstant());
988 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
989 ShifterOperand operand;
990 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100991 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100992 } else {
993 Register temp = IP;
994 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100995 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 }
Dave Allison20dfc792014-06-16 20:44:29 -0700997 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100998 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100999 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001001 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001002 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001003}
1004
1005void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1006 VisitCondition(comp);
1007}
1008
1009void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1010 VisitCondition(comp);
1011}
1012
1013void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1014 VisitCondition(comp);
1015}
1016
1017void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1018 VisitCondition(comp);
1019}
1020
1021void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1022 VisitCondition(comp);
1023}
1024
1025void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1026 VisitCondition(comp);
1027}
1028
1029void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1030 VisitCondition(comp);
1031}
1032
1033void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1034 VisitCondition(comp);
1035}
1036
1037void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1038 VisitCondition(comp);
1039}
1040
1041void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1042 VisitCondition(comp);
1043}
1044
1045void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1046 VisitCondition(comp);
1047}
1048
1049void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1050 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001051}
1052
1053void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001054 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001055}
1056
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001057void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1058 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001059}
1060
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001061void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001062 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001063}
1064
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001065void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001066 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001067 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001068}
1069
1070void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001071 LocationSummary* locations =
1072 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001073 switch (store->InputAt(1)->GetType()) {
1074 case Primitive::kPrimBoolean:
1075 case Primitive::kPrimByte:
1076 case Primitive::kPrimChar:
1077 case Primitive::kPrimShort:
1078 case Primitive::kPrimInt:
1079 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001080 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001081 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1082 break;
1083
1084 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001085 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001086 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1087 break;
1088
1089 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001090 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001091 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001092}
1093
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001094void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001095 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001096}
1097
1098void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001099 LocationSummary* locations =
1100 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001101 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001102}
1103
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001104void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001105 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001106 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001107}
1108
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001109void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001110 LocationSummary* locations =
1111 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001112 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001113}
1114
1115void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1116 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001117 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001118}
1119
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001120void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1121 LocationSummary* locations =
1122 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1123 locations->SetOut(Location::ConstantLocation(constant));
1124}
1125
1126void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1127 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001128 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001129}
1130
1131void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1132 LocationSummary* locations =
1133 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1134 locations->SetOut(Location::ConstantLocation(constant));
1135}
1136
1137void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1138 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001139 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001140}
1141
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001142void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001143 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001144}
1145
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001146void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001147 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001148 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001149}
1150
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001151void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001152 LocationSummary* locations =
1153 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001154 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155}
1156
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001158 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001159 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001160}
1161
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001162void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001163 HandleInvoke(invoke);
1164}
1165
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001166void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001167 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001168}
1169
1170void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001171 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001172
1173 // TODO: Implement all kinds of calls:
1174 // 1) boot -> boot
1175 // 2) app -> boot
1176 // 3) app -> app
1177 //
1178 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1179
1180 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001181 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001182 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001183 __ LoadFromOffset(
1184 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001185 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001186 __ LoadFromOffset(
1187 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001188 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001189 __ LoadFromOffset(kLoadWord, LR, temp,
1190 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001191 // LR()
1192 __ blx(LR);
1193
1194 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1195 DCHECK(!codegen_->IsLeafMethod());
1196}
1197
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001198void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001199 LocationSummary* locations =
1200 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001201 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001202
1203 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001204 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001205 HInstruction* input = invoke->InputAt(i);
1206 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1207 }
1208
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001209 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001210}
1211
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001212void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1213 HandleInvoke(invoke);
1214}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001215
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001216void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001217 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001218 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1219 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1220 LocationSummary* locations = invoke->GetLocations();
1221 Location receiver = locations->InAt(0);
1222 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1223 // temp = object->GetClass();
1224 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001225 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1226 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001227 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001228 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001229 }
1230 // temp = temp->GetMethodAt(method_offset);
1231 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001232 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001233 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001234 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001235 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001236 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001237 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001238 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001239}
1240
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001241void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1242 HandleInvoke(invoke);
1243 // Add the hidden argument.
1244 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1245}
1246
1247void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1248 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1249 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
1250 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1251 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1252 LocationSummary* locations = invoke->GetLocations();
1253 Location receiver = locations->InAt(0);
1254 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1255
1256 // Set the hidden argument.
1257 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex());
1258
1259 // temp = object->GetClass();
1260 if (receiver.IsStackSlot()) {
1261 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1262 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1263 } else {
1264 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
1265 }
1266 // temp = temp->GetImtEntryAt(method_offset);
1267 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
1268 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1269 // LR = temp->GetEntryPoint();
1270 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1271 // LR();
1272 __ blx(LR);
1273 DCHECK(!codegen_->IsLeafMethod());
1274 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1275}
1276
Roland Levillain88cb1752014-10-20 16:36:47 +01001277void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1278 LocationSummary* locations =
1279 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1280 switch (neg->GetResultType()) {
1281 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001282 case Primitive::kPrimLong: {
1283 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001284 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001285 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001286 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001287 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001288
Roland Levillain88cb1752014-10-20 16:36:47 +01001289 case Primitive::kPrimFloat:
1290 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001291 locations->SetInAt(0, Location::RequiresFpuRegister());
1292 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001293 break;
1294
1295 default:
1296 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1297 }
1298}
1299
1300void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1301 LocationSummary* locations = neg->GetLocations();
1302 Location out = locations->Out();
1303 Location in = locations->InAt(0);
1304 switch (neg->GetResultType()) {
1305 case Primitive::kPrimInt:
1306 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001307 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001308 break;
1309
1310 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001311 DCHECK(in.IsRegisterPair());
1312 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1313 __ rsbs(out.AsRegisterPairLow<Register>(),
1314 in.AsRegisterPairLow<Register>(),
1315 ShifterOperand(0));
1316 // We cannot emit an RSC (Reverse Subtract with Carry)
1317 // instruction here, as it does not exist in the Thumb-2
1318 // instruction set. We use the following approach
1319 // using SBC and SUB instead.
1320 //
1321 // out.hi = -C
1322 __ sbc(out.AsRegisterPairHigh<Register>(),
1323 out.AsRegisterPairHigh<Register>(),
1324 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1325 // out.hi = out.hi - in.hi
1326 __ sub(out.AsRegisterPairHigh<Register>(),
1327 out.AsRegisterPairHigh<Register>(),
1328 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1329 break;
1330
Roland Levillain88cb1752014-10-20 16:36:47 +01001331 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001332 DCHECK(in.IsFpuRegister());
1333 __ vnegs(out.As<SRegister>(), in.As<SRegister>());
1334 break;
1335
Roland Levillain88cb1752014-10-20 16:36:47 +01001336 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001337 DCHECK(in.IsFpuRegisterPair());
1338 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1339 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001340 break;
1341
1342 default:
1343 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1344 }
1345}
1346
Roland Levillaindff1f282014-11-05 14:15:05 +00001347void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1348 LocationSummary* locations =
1349 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1350 Primitive::Type result_type = conversion->GetResultType();
1351 Primitive::Type input_type = conversion->GetInputType();
1352 switch (result_type) {
Roland Levillain946e1432014-11-11 17:35:19 +00001353 case Primitive::kPrimInt:
1354 switch (input_type) {
1355 case Primitive::kPrimLong:
1356 // long-to-int conversion.
1357 locations->SetInAt(0, Location::Any());
1358 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1359 break;
1360
1361 case Primitive::kPrimFloat:
1362 case Primitive::kPrimDouble:
1363 LOG(FATAL) << "Type conversion from " << input_type
1364 << " to " << result_type << " not yet implemented";
1365 break;
1366
1367 default:
1368 LOG(FATAL) << "Unexpected type conversion from " << input_type
1369 << " to " << result_type;
1370 }
1371 break;
1372
Roland Levillaindff1f282014-11-05 14:15:05 +00001373 case Primitive::kPrimLong:
1374 switch (input_type) {
1375 case Primitive::kPrimByte:
1376 case Primitive::kPrimShort:
1377 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001378 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001379 // int-to-long conversion.
1380 locations->SetInAt(0, Location::RequiresRegister());
1381 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1382 break;
1383
1384 case Primitive::kPrimFloat:
1385 case Primitive::kPrimDouble:
1386 LOG(FATAL) << "Type conversion from " << input_type << " to "
1387 << result_type << " not yet implemented";
1388 break;
1389
1390 default:
1391 LOG(FATAL) << "Unexpected type conversion from " << input_type
1392 << " to " << result_type;
1393 }
1394 break;
1395
Roland Levillaindff1f282014-11-05 14:15:05 +00001396 case Primitive::kPrimFloat:
1397 case Primitive::kPrimDouble:
1398 LOG(FATAL) << "Type conversion from " << input_type
1399 << " to " << result_type << " not yet implemented";
1400 break;
1401
1402 default:
1403 LOG(FATAL) << "Unexpected type conversion from " << input_type
1404 << " to " << result_type;
1405 }
1406}
1407
1408void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1409 LocationSummary* locations = conversion->GetLocations();
1410 Location out = locations->Out();
1411 Location in = locations->InAt(0);
1412 Primitive::Type result_type = conversion->GetResultType();
1413 Primitive::Type input_type = conversion->GetInputType();
1414 switch (result_type) {
Roland Levillain946e1432014-11-11 17:35:19 +00001415 case Primitive::kPrimInt:
1416 switch (input_type) {
1417 case Primitive::kPrimLong:
1418 // long-to-int conversion.
1419 DCHECK(out.IsRegister());
1420 if (in.IsRegisterPair()) {
1421 __ Mov(out.As<Register>(), in.AsRegisterPairLow<Register>());
1422 } else if (in.IsDoubleStackSlot()) {
1423 __ LoadFromOffset(kLoadWord, out.As<Register>(), SP, in.GetStackIndex());
1424 } else {
1425 DCHECK(in.IsConstant());
1426 DCHECK(in.GetConstant()->IsLongConstant());
1427 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
1428 __ LoadImmediate(out.As<Register>(), static_cast<int32_t>(value));
1429 }
1430 break;
1431
1432 case Primitive::kPrimFloat:
1433 case Primitive::kPrimDouble:
1434 LOG(FATAL) << "Type conversion from " << input_type
1435 << " to " << result_type << " not yet implemented";
1436 break;
1437
1438 default:
1439 LOG(FATAL) << "Unexpected type conversion from " << input_type
1440 << " to " << result_type;
1441 }
1442 break;
1443
Roland Levillaindff1f282014-11-05 14:15:05 +00001444 case Primitive::kPrimLong:
1445 switch (input_type) {
1446 case Primitive::kPrimByte:
1447 case Primitive::kPrimShort:
1448 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001449 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001450 // int-to-long conversion.
1451 DCHECK(out.IsRegisterPair());
1452 DCHECK(in.IsRegister());
1453 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1454 // Sign extension.
1455 __ Asr(out.AsRegisterPairHigh<Register>(),
1456 out.AsRegisterPairLow<Register>(),
1457 31);
1458 break;
1459
1460 case Primitive::kPrimFloat:
1461 case Primitive::kPrimDouble:
1462 LOG(FATAL) << "Type conversion from " << input_type << " to "
1463 << result_type << " not yet implemented";
1464 break;
1465
1466 default:
1467 LOG(FATAL) << "Unexpected type conversion from " << input_type
1468 << " to " << result_type;
1469 }
1470 break;
1471
Roland Levillaindff1f282014-11-05 14:15:05 +00001472 case Primitive::kPrimFloat:
1473 case Primitive::kPrimDouble:
1474 LOG(FATAL) << "Type conversion from " << input_type
1475 << " to " << result_type << " not yet implemented";
1476 break;
1477
1478 default:
1479 LOG(FATAL) << "Unexpected type conversion from " << input_type
1480 << " to " << result_type;
1481 }
1482}
1483
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001484void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001485 LocationSummary* locations =
1486 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001487 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001488 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001489 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001490 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1491 locations->SetInAt(0, Location::RequiresRegister());
1492 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1493 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001494 break;
1495 }
1496
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001497 case Primitive::kPrimFloat:
1498 case Primitive::kPrimDouble: {
1499 locations->SetInAt(0, Location::RequiresFpuRegister());
1500 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001501 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001502 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001503 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001504
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001505 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001506 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001507 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001508}
1509
1510void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1511 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001512 Location out = locations->Out();
1513 Location first = locations->InAt(0);
1514 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001515 switch (add->GetResultType()) {
1516 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001517 if (second.IsRegister()) {
1518 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001519 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001520 __ AddConstant(out.As<Register>(),
1521 first.As<Register>(),
1522 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001523 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001524 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001525
1526 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001527 __ adds(out.AsRegisterPairLow<Register>(),
1528 first.AsRegisterPairLow<Register>(),
1529 ShifterOperand(second.AsRegisterPairLow<Register>()));
1530 __ adc(out.AsRegisterPairHigh<Register>(),
1531 first.AsRegisterPairHigh<Register>(),
1532 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001533 break;
1534
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001535 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001536 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001537 break;
1538
1539 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001540 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1541 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1542 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001543 break;
1544
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001545 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001546 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001547 }
1548}
1549
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001550void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001551 LocationSummary* locations =
1552 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001553 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001554 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001555 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001556 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1557 locations->SetInAt(0, Location::RequiresRegister());
1558 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1559 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001560 break;
1561 }
Calin Juravle11351682014-10-23 15:38:15 +01001562 case Primitive::kPrimFloat:
1563 case Primitive::kPrimDouble: {
1564 locations->SetInAt(0, Location::RequiresFpuRegister());
1565 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001566 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001567 break;
Calin Juravle11351682014-10-23 15:38:15 +01001568 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001569 default:
Calin Juravle11351682014-10-23 15:38:15 +01001570 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001571 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001572}
1573
1574void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1575 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001576 Location out = locations->Out();
1577 Location first = locations->InAt(0);
1578 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001579 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001580 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001581 if (second.IsRegister()) {
1582 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001583 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001584 __ AddConstant(out.As<Register>(),
1585 first.As<Register>(),
1586 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001587 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001588 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001589 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001590
Calin Juravle11351682014-10-23 15:38:15 +01001591 case Primitive::kPrimLong: {
1592 __ subs(out.AsRegisterPairLow<Register>(),
1593 first.AsRegisterPairLow<Register>(),
1594 ShifterOperand(second.AsRegisterPairLow<Register>()));
1595 __ sbc(out.AsRegisterPairHigh<Register>(),
1596 first.AsRegisterPairHigh<Register>(),
1597 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001598 break;
Calin Juravle11351682014-10-23 15:38:15 +01001599 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001600
Calin Juravle11351682014-10-23 15:38:15 +01001601 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001602 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001603 break;
Calin Juravle11351682014-10-23 15:38:15 +01001604 }
1605
1606 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001607 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1608 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1609 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001610 break;
1611 }
1612
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001613
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001614 default:
Calin Juravle11351682014-10-23 15:38:15 +01001615 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001616 }
1617}
1618
Calin Juravle34bacdf2014-10-07 20:23:36 +01001619void LocationsBuilderARM::VisitMul(HMul* mul) {
1620 LocationSummary* locations =
1621 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1622 switch (mul->GetResultType()) {
1623 case Primitive::kPrimInt:
1624 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001625 locations->SetInAt(0, Location::RequiresRegister());
1626 locations->SetInAt(1, Location::RequiresRegister());
1627 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001628 break;
1629 }
1630
Calin Juravleb5bfa962014-10-21 18:02:24 +01001631 case Primitive::kPrimFloat:
1632 case Primitive::kPrimDouble: {
1633 locations->SetInAt(0, Location::RequiresFpuRegister());
1634 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001635 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001636 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001637 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001638
1639 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001640 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001641 }
1642}
1643
1644void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1645 LocationSummary* locations = mul->GetLocations();
1646 Location out = locations->Out();
1647 Location first = locations->InAt(0);
1648 Location second = locations->InAt(1);
1649 switch (mul->GetResultType()) {
1650 case Primitive::kPrimInt: {
1651 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1652 break;
1653 }
1654 case Primitive::kPrimLong: {
1655 Register out_hi = out.AsRegisterPairHigh<Register>();
1656 Register out_lo = out.AsRegisterPairLow<Register>();
1657 Register in1_hi = first.AsRegisterPairHigh<Register>();
1658 Register in1_lo = first.AsRegisterPairLow<Register>();
1659 Register in2_hi = second.AsRegisterPairHigh<Register>();
1660 Register in2_lo = second.AsRegisterPairLow<Register>();
1661
1662 // Extra checks to protect caused by the existence of R1_R2.
1663 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1664 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1665 DCHECK_NE(out_hi, in1_lo);
1666 DCHECK_NE(out_hi, in2_lo);
1667
1668 // input: in1 - 64 bits, in2 - 64 bits
1669 // output: out
1670 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1671 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1672 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1673
1674 // IP <- in1.lo * in2.hi
1675 __ mul(IP, in1_lo, in2_hi);
1676 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1677 __ mla(out_hi, in1_hi, in2_lo, IP);
1678 // out.lo <- (in1.lo * in2.lo)[31:0];
1679 __ umull(out_lo, IP, in1_lo, in2_lo);
1680 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1681 __ add(out_hi, out_hi, ShifterOperand(IP));
1682 break;
1683 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001684
1685 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001686 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001687 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001688 }
1689
1690 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001691 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1692 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1693 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001694 break;
1695 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001696
1697 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001698 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001699 }
1700}
1701
Calin Juravle7c4954d2014-10-28 16:57:40 +00001702void LocationsBuilderARM::VisitDiv(HDiv* div) {
1703 LocationSummary* locations =
1704 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1705 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001706 case Primitive::kPrimInt: {
1707 locations->SetInAt(0, Location::RequiresRegister());
1708 locations->SetInAt(1, Location::RequiresRegister());
1709 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1710 break;
1711 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001712 case Primitive::kPrimLong: {
1713 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1714 break;
1715 }
1716 case Primitive::kPrimFloat:
1717 case Primitive::kPrimDouble: {
1718 locations->SetInAt(0, Location::RequiresFpuRegister());
1719 locations->SetInAt(1, Location::RequiresFpuRegister());
1720 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1721 break;
1722 }
1723
1724 default:
1725 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1726 }
1727}
1728
1729void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1730 LocationSummary* locations = div->GetLocations();
1731 Location out = locations->Out();
1732 Location first = locations->InAt(0);
1733 Location second = locations->InAt(1);
1734
1735 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001736 case Primitive::kPrimInt: {
1737 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>());
1738 break;
1739 }
1740
Calin Juravle7c4954d2014-10-28 16:57:40 +00001741 case Primitive::kPrimLong: {
1742 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1743 break;
1744 }
1745
1746 case Primitive::kPrimFloat: {
1747 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1748 break;
1749 }
1750
1751 case Primitive::kPrimDouble: {
1752 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1753 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1754 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1755 break;
1756 }
1757
1758 default:
1759 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1760 }
1761}
1762
Calin Juravled0d48522014-11-04 16:40:20 +00001763void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1764 LocationSummary* locations =
1765 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1766 locations->SetInAt(0, Location::RequiresRegister());
1767 if (instruction->HasUses()) {
1768 locations->SetOut(Location::SameAsFirstInput());
1769 }
1770}
1771
1772void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1773 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
1774 codegen_->AddSlowPath(slow_path);
1775
1776 LocationSummary* locations = instruction->GetLocations();
1777 Location value = locations->InAt(0);
1778
1779 DCHECK(value.IsRegister()) << value;
1780 __ cmp(value.As<Register>(), ShifterOperand(0));
1781 __ b(slow_path->GetEntryLabel(), EQ);
1782}
1783
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001784void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001785 LocationSummary* locations =
1786 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001787 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001788 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1789 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1790 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001791}
1792
1793void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1794 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001795 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001796 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001797 codegen_->InvokeRuntime(
1798 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001799}
1800
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001801void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1802 LocationSummary* locations =
1803 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1804 InvokeRuntimeCallingConvention calling_convention;
1805 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1806 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1807 locations->SetOut(Location::RegisterLocation(R0));
1808 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1809}
1810
1811void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1812 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001813 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001814 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001815 codegen_->InvokeRuntime(
1816 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001817}
1818
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001819void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001820 LocationSummary* locations =
1821 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001822 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1823 if (location.IsStackSlot()) {
1824 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1825 } else if (location.IsDoubleStackSlot()) {
1826 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001827 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001828 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001829}
1830
1831void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001832 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001833 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001834}
1835
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001836void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001837 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001838 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001839 locations->SetInAt(0, Location::RequiresRegister());
1840 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001841}
1842
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001843void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1844 LocationSummary* locations = not_->GetLocations();
1845 Location out = locations->Out();
1846 Location in = locations->InAt(0);
1847 switch (not_->InputAt(0)->GetType()) {
1848 case Primitive::kPrimBoolean:
1849 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1850 break;
1851
1852 case Primitive::kPrimInt:
1853 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1854 break;
1855
1856 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001857 __ mvn(out.AsRegisterPairLow<Register>(),
1858 ShifterOperand(in.AsRegisterPairLow<Register>()));
1859 __ mvn(out.AsRegisterPairHigh<Register>(),
1860 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001861 break;
1862
1863 default:
1864 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1865 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001866}
1867
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001868void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001869 LocationSummary* locations =
1870 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001871 locations->SetInAt(0, Location::RequiresRegister());
1872 locations->SetInAt(1, Location::RequiresRegister());
1873 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001874}
1875
1876void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001877 LocationSummary* locations = compare->GetLocations();
1878 switch (compare->InputAt(0)->GetType()) {
1879 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001880 Register output = locations->Out().As<Register>();
1881 Location left = locations->InAt(0);
1882 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001883 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001884 __ cmp(left.AsRegisterPairHigh<Register>(),
1885 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001886 __ b(&less, LT);
1887 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001888 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1889 // the status flags.
1890 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001891 __ cmp(left.AsRegisterPairLow<Register>(),
1892 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001893 __ b(&done, EQ);
1894 __ b(&less, CC);
1895
1896 __ Bind(&greater);
1897 __ LoadImmediate(output, 1);
1898 __ b(&done);
1899
1900 __ Bind(&less);
1901 __ LoadImmediate(output, -1);
1902
1903 __ Bind(&done);
1904 break;
1905 }
1906 default:
1907 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1908 }
1909}
1910
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001911void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001912 LocationSummary* locations =
1913 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001914 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1915 locations->SetInAt(i, Location::Any());
1916 }
1917 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001918}
1919
1920void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001921 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001922 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001923}
1924
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001925void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001926 LocationSummary* locations =
1927 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001928 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001929 locations->SetInAt(0, Location::RequiresRegister());
1930 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001931 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001932 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001933 locations->AddTemp(Location::RequiresRegister());
1934 locations->AddTemp(Location::RequiresRegister());
1935 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001936}
1937
1938void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1939 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001940 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001941 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001942 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001943
1944 switch (field_type) {
1945 case Primitive::kPrimBoolean:
1946 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001947 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001948 __ StoreToOffset(kStoreByte, value, obj, offset);
1949 break;
1950 }
1951
1952 case Primitive::kPrimShort:
1953 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001954 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001955 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1956 break;
1957 }
1958
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001959 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001960 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001961 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001962 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001963 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001964 Register temp = locations->GetTemp(0).As<Register>();
1965 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001966 codegen_->MarkGCCard(temp, card, obj, value);
1967 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001968 break;
1969 }
1970
1971 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001972 Location value = locations->InAt(1);
1973 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001974 break;
1975 }
1976
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00001977 case Primitive::kPrimFloat: {
1978 SRegister value = locations->InAt(1).As<SRegister>();
1979 __ StoreSToOffset(value, obj, offset);
1980 break;
1981 }
1982
1983 case Primitive::kPrimDouble: {
1984 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
1985 __ StoreDToOffset(value, obj, offset);
1986 break;
1987 }
1988
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001989 case Primitive::kPrimVoid:
1990 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001991 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001992 }
1993}
1994
1995void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001996 LocationSummary* locations =
1997 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001998 locations->SetInAt(0, Location::RequiresRegister());
1999 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002000}
2001
2002void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2003 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002004 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002005 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2006
2007 switch (instruction->GetType()) {
2008 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002009 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002010 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2011 break;
2012 }
2013
2014 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002015 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002016 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2017 break;
2018 }
2019
2020 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002021 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002022 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2023 break;
2024 }
2025
2026 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002027 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002028 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2029 break;
2030 }
2031
2032 case Primitive::kPrimInt:
2033 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002034 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002035 __ LoadFromOffset(kLoadWord, out, obj, offset);
2036 break;
2037 }
2038
2039 case Primitive::kPrimLong: {
2040 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002041 Location out = locations->Out();
2042 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002043 break;
2044 }
2045
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002046 case Primitive::kPrimFloat: {
2047 SRegister out = locations->Out().As<SRegister>();
2048 __ LoadSFromOffset(out, obj, offset);
2049 break;
2050 }
2051
2052 case Primitive::kPrimDouble: {
2053 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2054 __ LoadDFromOffset(out, obj, offset);
2055 break;
2056 }
2057
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002058 case Primitive::kPrimVoid:
2059 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002060 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002061 }
2062}
2063
2064void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002065 LocationSummary* locations =
2066 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002067 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002068 if (instruction->HasUses()) {
2069 locations->SetOut(Location::SameAsFirstInput());
2070 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002071}
2072
2073void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002074 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002075 codegen_->AddSlowPath(slow_path);
2076
2077 LocationSummary* locations = instruction->GetLocations();
2078 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002079
2080 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002081 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002082 __ b(slow_path->GetEntryLabel(), EQ);
2083 } else {
2084 DCHECK(obj.IsConstant()) << obj;
2085 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2086 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002087 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002088}
2089
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002090void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002091 LocationSummary* locations =
2092 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002093 locations->SetInAt(0, Location::RequiresRegister());
2094 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2095 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002096}
2097
2098void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2099 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002100 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002101 Location index = locations->InAt(1);
2102
2103 switch (instruction->GetType()) {
2104 case Primitive::kPrimBoolean: {
2105 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002106 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002107 if (index.IsConstant()) {
2108 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2109 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2110 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002111 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002112 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2113 }
2114 break;
2115 }
2116
2117 case Primitive::kPrimByte: {
2118 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002119 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002120 if (index.IsConstant()) {
2121 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2122 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2123 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002124 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002125 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2126 }
2127 break;
2128 }
2129
2130 case Primitive::kPrimShort: {
2131 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002132 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002133 if (index.IsConstant()) {
2134 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2135 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2136 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002137 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002138 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2139 }
2140 break;
2141 }
2142
2143 case Primitive::kPrimChar: {
2144 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002145 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002146 if (index.IsConstant()) {
2147 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2148 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2149 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002150 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002151 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2152 }
2153 break;
2154 }
2155
2156 case Primitive::kPrimInt:
2157 case Primitive::kPrimNot: {
2158 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2159 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002160 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002161 if (index.IsConstant()) {
2162 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2163 __ LoadFromOffset(kLoadWord, out, obj, offset);
2164 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002165 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002166 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2167 }
2168 break;
2169 }
2170
2171 case Primitive::kPrimLong: {
2172 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002173 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002174 if (index.IsConstant()) {
2175 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002176 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002177 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002178 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2179 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002180 }
2181 break;
2182 }
2183
2184 case Primitive::kPrimFloat:
2185 case Primitive::kPrimDouble:
2186 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002187 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002188 case Primitive::kPrimVoid:
2189 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002190 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002191 }
2192}
2193
2194void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002195 Primitive::Type value_type = instruction->GetComponentType();
2196 bool is_object = value_type == Primitive::kPrimNot;
2197 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2198 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
2199 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002200 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002201 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2202 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2203 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002204 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002205 locations->SetInAt(0, Location::RequiresRegister());
2206 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2207 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002208 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002209}
2210
2211void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2212 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002213 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002214 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002215 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002216
2217 switch (value_type) {
2218 case Primitive::kPrimBoolean:
2219 case Primitive::kPrimByte: {
2220 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002221 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002222 if (index.IsConstant()) {
2223 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2224 __ StoreToOffset(kStoreByte, value, obj, offset);
2225 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002226 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002227 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2228 }
2229 break;
2230 }
2231
2232 case Primitive::kPrimShort:
2233 case Primitive::kPrimChar: {
2234 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002235 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002236 if (index.IsConstant()) {
2237 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2238 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2239 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002240 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002241 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2242 }
2243 break;
2244 }
2245
2246 case Primitive::kPrimInt: {
2247 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002248 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002249 if (index.IsConstant()) {
2250 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2251 __ StoreToOffset(kStoreWord, value, obj, offset);
2252 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002253 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002254 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2255 }
2256 break;
2257 }
2258
2259 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002260 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002261 break;
2262 }
2263
2264 case Primitive::kPrimLong: {
2265 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002266 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002267 if (index.IsConstant()) {
2268 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002269 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002270 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002271 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2272 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002273 }
2274 break;
2275 }
2276
2277 case Primitive::kPrimFloat:
2278 case Primitive::kPrimDouble:
2279 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002280 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002281 case Primitive::kPrimVoid:
2282 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002283 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002284 }
2285}
2286
2287void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002288 LocationSummary* locations =
2289 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002290 locations->SetInAt(0, Location::RequiresRegister());
2291 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002292}
2293
2294void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2295 LocationSummary* locations = instruction->GetLocations();
2296 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002297 Register obj = locations->InAt(0).As<Register>();
2298 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002299 __ LoadFromOffset(kLoadWord, out, obj, offset);
2300}
2301
2302void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002303 LocationSummary* locations =
2304 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002305 locations->SetInAt(0, Location::RequiresRegister());
2306 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002307 if (instruction->HasUses()) {
2308 locations->SetOut(Location::SameAsFirstInput());
2309 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002310}
2311
2312void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2313 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002314 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002315 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002316 codegen_->AddSlowPath(slow_path);
2317
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002318 Register index = locations->InAt(0).As<Register>();
2319 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002320
2321 __ cmp(index, ShifterOperand(length));
2322 __ b(slow_path->GetEntryLabel(), CS);
2323}
2324
2325void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2326 Label is_null;
2327 __ CompareAndBranchIfZero(value, &is_null);
2328 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2329 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2330 __ strb(card, Address(card, temp));
2331 __ Bind(&is_null);
2332}
2333
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002334void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2335 temp->SetLocations(nullptr);
2336}
2337
2338void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2339 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002340 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002341}
2342
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002343void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002344 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002345 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002346}
2347
2348void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002349 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2350}
2351
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002352void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2353 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2354}
2355
2356void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002357 HBasicBlock* block = instruction->GetBlock();
2358 if (block->GetLoopInformation() != nullptr) {
2359 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2360 // The back edge will generate the suspend check.
2361 return;
2362 }
2363 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2364 // The goto will generate the suspend check.
2365 return;
2366 }
2367 GenerateSuspendCheck(instruction, nullptr);
2368}
2369
2370void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2371 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002372 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002373 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002374 codegen_->AddSlowPath(slow_path);
2375
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002376 __ LoadFromOffset(
2377 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2378 __ cmp(IP, ShifterOperand(0));
2379 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002380 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002381 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002382 __ Bind(slow_path->GetReturnLabel());
2383 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002384 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002385 __ b(slow_path->GetEntryLabel());
2386 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002387}
2388
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002389ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2390 return codegen_->GetAssembler();
2391}
2392
2393void ParallelMoveResolverARM::EmitMove(size_t index) {
2394 MoveOperands* move = moves_.Get(index);
2395 Location source = move->GetSource();
2396 Location destination = move->GetDestination();
2397
2398 if (source.IsRegister()) {
2399 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002400 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002401 } else {
2402 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002403 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002404 SP, destination.GetStackIndex());
2405 }
2406 } else if (source.IsStackSlot()) {
2407 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002408 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002409 SP, source.GetStackIndex());
2410 } else {
2411 DCHECK(destination.IsStackSlot());
2412 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2413 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2414 }
2415 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002416 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002417 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002418 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2419 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002420 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002421 } else {
2422 DCHECK(destination.IsStackSlot());
2423 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002424 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002425 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002426 }
2427}
2428
2429void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2430 __ Mov(IP, reg);
2431 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2432 __ StoreToOffset(kStoreWord, IP, SP, mem);
2433}
2434
2435void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2436 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2437 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2438 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2439 SP, mem1 + stack_offset);
2440 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2441 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2442 SP, mem2 + stack_offset);
2443 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2444}
2445
2446void ParallelMoveResolverARM::EmitSwap(size_t index) {
2447 MoveOperands* move = moves_.Get(index);
2448 Location source = move->GetSource();
2449 Location destination = move->GetDestination();
2450
2451 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002452 DCHECK_NE(source.As<Register>(), IP);
2453 DCHECK_NE(destination.As<Register>(), IP);
2454 __ Mov(IP, source.As<Register>());
2455 __ Mov(source.As<Register>(), destination.As<Register>());
2456 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002457 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002458 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002459 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002460 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002461 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2462 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2463 } else {
2464 LOG(FATAL) << "Unimplemented";
2465 }
2466}
2467
2468void ParallelMoveResolverARM::SpillScratch(int reg) {
2469 __ Push(static_cast<Register>(reg));
2470}
2471
2472void ParallelMoveResolverARM::RestoreScratch(int reg) {
2473 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002474}
2475
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002476void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002477 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2478 ? LocationSummary::kCallOnSlowPath
2479 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002480 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002481 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002482 locations->SetOut(Location::RequiresRegister());
2483}
2484
2485void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2486 Register out = cls->GetLocations()->Out().As<Register>();
2487 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002488 DCHECK(!cls->CanCallRuntime());
2489 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002490 codegen_->LoadCurrentMethod(out);
2491 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2492 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002493 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002494 codegen_->LoadCurrentMethod(out);
2495 __ LoadFromOffset(
2496 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2497 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002498
2499 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2500 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2501 codegen_->AddSlowPath(slow_path);
2502 __ cmp(out, ShifterOperand(0));
2503 __ b(slow_path->GetEntryLabel(), EQ);
2504 if (cls->MustGenerateClinitCheck()) {
2505 GenerateClassInitializationCheck(slow_path, out);
2506 } else {
2507 __ Bind(slow_path->GetExitLabel());
2508 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002509 }
2510}
2511
2512void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2513 LocationSummary* locations =
2514 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2515 locations->SetInAt(0, Location::RequiresRegister());
2516 if (check->HasUses()) {
2517 locations->SetOut(Location::SameAsFirstInput());
2518 }
2519}
2520
2521void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002522 // We assume the class is not null.
2523 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2524 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002525 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002526 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2527}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002528
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002529void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2530 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002531 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2532 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2533 __ b(slow_path->GetEntryLabel(), LT);
2534 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2535 // properly. Therefore, we do a memory fence.
2536 __ dmb(ISH);
2537 __ Bind(slow_path->GetExitLabel());
2538}
2539
2540void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2541 LocationSummary* locations =
2542 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2543 locations->SetInAt(0, Location::RequiresRegister());
2544 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2545}
2546
2547void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2548 LocationSummary* locations = instruction->GetLocations();
2549 Register cls = locations->InAt(0).As<Register>();
2550 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2551
2552 switch (instruction->GetType()) {
2553 case Primitive::kPrimBoolean: {
2554 Register out = locations->Out().As<Register>();
2555 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2556 break;
2557 }
2558
2559 case Primitive::kPrimByte: {
2560 Register out = locations->Out().As<Register>();
2561 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2562 break;
2563 }
2564
2565 case Primitive::kPrimShort: {
2566 Register out = locations->Out().As<Register>();
2567 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2568 break;
2569 }
2570
2571 case Primitive::kPrimChar: {
2572 Register out = locations->Out().As<Register>();
2573 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2574 break;
2575 }
2576
2577 case Primitive::kPrimInt:
2578 case Primitive::kPrimNot: {
2579 Register out = locations->Out().As<Register>();
2580 __ LoadFromOffset(kLoadWord, out, cls, offset);
2581 break;
2582 }
2583
2584 case Primitive::kPrimLong: {
2585 // TODO: support volatile.
2586 Location out = locations->Out();
2587 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2588 break;
2589 }
2590
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002591 case Primitive::kPrimFloat: {
2592 SRegister out = locations->Out().As<SRegister>();
2593 __ LoadSFromOffset(out, cls, offset);
2594 break;
2595 }
2596
2597 case Primitive::kPrimDouble: {
2598 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2599 __ LoadDFromOffset(out, cls, offset);
2600 break;
2601 }
2602
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002603 case Primitive::kPrimVoid:
2604 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2605 UNREACHABLE();
2606 }
2607}
2608
2609void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2610 LocationSummary* locations =
2611 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2612 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2613 locations->SetInAt(0, Location::RequiresRegister());
2614 locations->SetInAt(1, Location::RequiresRegister());
2615 // Temporary registers for the write barrier.
2616 if (is_object_type) {
2617 locations->AddTemp(Location::RequiresRegister());
2618 locations->AddTemp(Location::RequiresRegister());
2619 }
2620}
2621
2622void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2623 LocationSummary* locations = instruction->GetLocations();
2624 Register cls = locations->InAt(0).As<Register>();
2625 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2626 Primitive::Type field_type = instruction->GetFieldType();
2627
2628 switch (field_type) {
2629 case Primitive::kPrimBoolean:
2630 case Primitive::kPrimByte: {
2631 Register value = locations->InAt(1).As<Register>();
2632 __ StoreToOffset(kStoreByte, value, cls, offset);
2633 break;
2634 }
2635
2636 case Primitive::kPrimShort:
2637 case Primitive::kPrimChar: {
2638 Register value = locations->InAt(1).As<Register>();
2639 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2640 break;
2641 }
2642
2643 case Primitive::kPrimInt:
2644 case Primitive::kPrimNot: {
2645 Register value = locations->InAt(1).As<Register>();
2646 __ StoreToOffset(kStoreWord, value, cls, offset);
2647 if (field_type == Primitive::kPrimNot) {
2648 Register temp = locations->GetTemp(0).As<Register>();
2649 Register card = locations->GetTemp(1).As<Register>();
2650 codegen_->MarkGCCard(temp, card, cls, value);
2651 }
2652 break;
2653 }
2654
2655 case Primitive::kPrimLong: {
2656 Location value = locations->InAt(1);
2657 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2658 break;
2659 }
2660
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002661 case Primitive::kPrimFloat: {
2662 SRegister value = locations->InAt(1).As<SRegister>();
2663 __ StoreSToOffset(value, cls, offset);
2664 break;
2665 }
2666
2667 case Primitive::kPrimDouble: {
2668 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2669 __ StoreDToOffset(value, cls, offset);
2670 break;
2671 }
2672
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002673 case Primitive::kPrimVoid:
2674 LOG(FATAL) << "Unreachable type " << field_type;
2675 UNREACHABLE();
2676 }
2677}
2678
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002679void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2680 LocationSummary* locations =
2681 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2682 locations->SetOut(Location::RequiresRegister());
2683}
2684
2685void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2686 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2687 codegen_->AddSlowPath(slow_path);
2688
2689 Register out = load->GetLocations()->Out().As<Register>();
2690 codegen_->LoadCurrentMethod(out);
2691 __ LoadFromOffset(
2692 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2693 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2694 __ cmp(out, ShifterOperand(0));
2695 __ b(slow_path->GetEntryLabel(), EQ);
2696 __ Bind(slow_path->GetExitLabel());
2697}
2698
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002699void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
2700 LocationSummary* locations =
2701 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2702 locations->SetOut(Location::RequiresRegister());
2703}
2704
2705void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
2706 Register out = load->GetLocations()->Out().As<Register>();
2707 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
2708 __ LoadFromOffset(kLoadWord, out, TR, offset);
2709 __ LoadImmediate(IP, 0);
2710 __ StoreToOffset(kStoreWord, IP, TR, offset);
2711}
2712
2713void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
2714 LocationSummary* locations =
2715 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2716 InvokeRuntimeCallingConvention calling_convention;
2717 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2718}
2719
2720void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
2721 codegen_->InvokeRuntime(
2722 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
2723}
2724
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002725void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002726 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
2727 ? LocationSummary::kNoCall
2728 : LocationSummary::kCallOnSlowPath;
2729 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2730 locations->SetInAt(0, Location::RequiresRegister());
2731 locations->SetInAt(1, Location::RequiresRegister());
2732 locations->SetOut(Location::RequiresRegister());
2733}
2734
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002735void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002736 LocationSummary* locations = instruction->GetLocations();
2737 Register obj = locations->InAt(0).As<Register>();
2738 Register cls = locations->InAt(1).As<Register>();
2739 Register out = locations->Out().As<Register>();
2740 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2741 Label done, zero;
2742 SlowPathCodeARM* slow_path = nullptr;
2743
2744 // Return 0 if `obj` is null.
2745 // TODO: avoid this check if we know obj is not null.
2746 __ cmp(obj, ShifterOperand(0));
2747 __ b(&zero, EQ);
2748 // Compare the class of `obj` with `cls`.
2749 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
2750 __ cmp(out, ShifterOperand(cls));
2751 if (instruction->IsClassFinal()) {
2752 // Classes must be equal for the instanceof to succeed.
2753 __ b(&zero, NE);
2754 __ LoadImmediate(out, 1);
2755 __ b(&done);
2756 } else {
2757 // If the classes are not equal, we go into a slow path.
2758 DCHECK(locations->OnlyCallsOnSlowPath());
2759 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002760 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002761 codegen_->AddSlowPath(slow_path);
2762 __ b(slow_path->GetEntryLabel(), NE);
2763 __ LoadImmediate(out, 1);
2764 __ b(&done);
2765 }
2766 __ Bind(&zero);
2767 __ LoadImmediate(out, 0);
2768 if (slow_path != nullptr) {
2769 __ Bind(slow_path->GetExitLabel());
2770 }
2771 __ Bind(&done);
2772}
2773
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002774void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
2775 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2776 instruction, LocationSummary::kCallOnSlowPath);
2777 locations->SetInAt(0, Location::RequiresRegister());
2778 locations->SetInAt(1, Location::RequiresRegister());
2779 locations->AddTemp(Location::RequiresRegister());
2780}
2781
2782void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
2783 LocationSummary* locations = instruction->GetLocations();
2784 Register obj = locations->InAt(0).As<Register>();
2785 Register cls = locations->InAt(1).As<Register>();
2786 Register temp = locations->GetTemp(0).As<Register>();
2787 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2788
2789 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
2790 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
2791 codegen_->AddSlowPath(slow_path);
2792
2793 // TODO: avoid this check if we know obj is not null.
2794 __ cmp(obj, ShifterOperand(0));
2795 __ b(slow_path->GetExitLabel(), EQ);
2796 // Compare the class of `obj` with `cls`.
2797 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
2798 __ cmp(temp, ShifterOperand(cls));
2799 __ b(slow_path->GetEntryLabel(), NE);
2800 __ Bind(slow_path->GetExitLabel());
2801}
2802
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002803void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
2804 LocationSummary* locations =
2805 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2806 InvokeRuntimeCallingConvention calling_convention;
2807 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2808}
2809
2810void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
2811 codegen_->InvokeRuntime(instruction->IsEnter()
2812 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2813 instruction,
2814 instruction->GetDexPc());
2815}
2816
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002817void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
2818void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
2819void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
2820
2821void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
2822 LocationSummary* locations =
2823 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2824 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
2825 || instruction->GetResultType() == Primitive::kPrimLong);
2826 locations->SetInAt(0, Location::RequiresRegister());
2827 locations->SetInAt(1, Location::RequiresRegister());
2828 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
2829 locations->SetOut(Location::RequiresRegister(), output_overlaps);
2830}
2831
2832void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
2833 HandleBitwiseOperation(instruction);
2834}
2835
2836void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
2837 HandleBitwiseOperation(instruction);
2838}
2839
2840void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
2841 HandleBitwiseOperation(instruction);
2842}
2843
2844void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
2845 LocationSummary* locations = instruction->GetLocations();
2846
2847 if (instruction->GetResultType() == Primitive::kPrimInt) {
2848 Register first = locations->InAt(0).As<Register>();
2849 Register second = locations->InAt(1).As<Register>();
2850 Register out = locations->Out().As<Register>();
2851 if (instruction->IsAnd()) {
2852 __ and_(out, first, ShifterOperand(second));
2853 } else if (instruction->IsOr()) {
2854 __ orr(out, first, ShifterOperand(second));
2855 } else {
2856 DCHECK(instruction->IsXor());
2857 __ eor(out, first, ShifterOperand(second));
2858 }
2859 } else {
2860 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
2861 Location first = locations->InAt(0);
2862 Location second = locations->InAt(1);
2863 Location out = locations->Out();
2864 if (instruction->IsAnd()) {
2865 __ and_(out.AsRegisterPairLow<Register>(),
2866 first.AsRegisterPairLow<Register>(),
2867 ShifterOperand(second.AsRegisterPairLow<Register>()));
2868 __ and_(out.AsRegisterPairHigh<Register>(),
2869 first.AsRegisterPairHigh<Register>(),
2870 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2871 } else if (instruction->IsOr()) {
2872 __ orr(out.AsRegisterPairLow<Register>(),
2873 first.AsRegisterPairLow<Register>(),
2874 ShifterOperand(second.AsRegisterPairLow<Register>()));
2875 __ orr(out.AsRegisterPairHigh<Register>(),
2876 first.AsRegisterPairHigh<Register>(),
2877 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2878 } else {
2879 DCHECK(instruction->IsXor());
2880 __ eor(out.AsRegisterPairLow<Register>(),
2881 first.AsRegisterPairLow<Register>(),
2882 ShifterOperand(second.AsRegisterPairLow<Register>()));
2883 __ eor(out.AsRegisterPairHigh<Register>(),
2884 first.AsRegisterPairHigh<Register>(),
2885 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2886 }
2887 }
2888}
2889
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002890} // namespace arm
2891} // namespace art