blob: a06860a5b619314146777d25130d88b50d86d0af [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/assembler.h"
26#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010028#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000029
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000030namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010031
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032namespace arm {
33
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000034static DRegister FromLowSToD(SRegister reg) {
35 DCHECK_EQ(reg % 2, 0);
36 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010037}
38
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010039static constexpr bool kExplicitStackOverflowCheck = false;
40
41static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
42static constexpr int kCurrentMethodStackOffset = 0;
43
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2 };
45static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { };
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010048static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010049
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000050class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051 public:
52 InvokeRuntimeCallingConvention()
53 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 kRuntimeParameterCoreRegistersLength,
55 kRuntimeParameterFpuRegisters,
56 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010057
58 private:
59 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
60};
61
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010063#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010065class SlowPathCodeARM : public SlowPathCode {
66 public:
67 SlowPathCodeARM() : entry_label_(), exit_label_() {}
68
69 Label* GetEntryLabel() { return &entry_label_; }
70 Label* GetExitLabel() { return &exit_label_; }
71
72 private:
73 Label entry_label_;
74 Label exit_label_;
75
76 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
77};
78
79class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010081 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082
83 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010086 arm_codegen->InvokeRuntime(
87 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 }
89
90 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010091 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010092 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
93};
94
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010095class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010096 public:
97 StackOverflowCheckSlowPathARM() {}
98
99 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
100 __ Bind(GetEntryLabel());
101 __ LoadFromOffset(kLoadWord, PC, TR,
102 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
103 }
104
105 private:
106 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
107};
108
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100109class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000110 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100111 explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
112 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000113
114 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100117 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100118 arm_codegen->InvokeRuntime(
119 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100120 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121 if (successor_ == nullptr) {
122 __ b(GetReturnLabel());
123 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100124 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 }
127
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100128 Label* GetReturnLabel() {
129 DCHECK(successor_ == nullptr);
130 return &return_label_;
131 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132
133 private:
134 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100135 // If not null, the block to branch to after the suspend check.
136 HBasicBlock* const successor_;
137
138 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000139 Label return_label_;
140
141 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
142};
143
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100144class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100145 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100146 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
147 Location index_location,
148 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100149 : instruction_(instruction),
150 index_location_(index_location),
151 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152
153 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100154 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155 __ Bind(GetEntryLabel());
156 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100157 arm_codegen->Move32(
158 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
159 arm_codegen->Move32(
160 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
161 arm_codegen->InvokeRuntime(
162 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 }
164
165 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100166 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100167 const Location index_location_;
168 const Location length_location_;
169
170 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
171};
172
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100173class ClinitCheckSlowPathARM : public SlowPathCodeARM {
174 public:
175 explicit ClinitCheckSlowPathARM(HClinitCheck* instruction) : instruction_(instruction) {}
176
177 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
178 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
179 __ Bind(GetEntryLabel());
180 codegen->SaveLiveRegisters(instruction_->GetLocations());
181
182 HLoadClass* cls = instruction_->GetLoadClass();
183 InvokeRuntimeCallingConvention calling_convention;
184 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls->GetTypeIndex());
185 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
186 arm_codegen->InvokeRuntime(
187 QUICK_ENTRY_POINT(pInitializeStaticStorage), instruction_, instruction_->GetDexPc());
188 arm_codegen->Move32(instruction_->GetLocations()->InAt(0), Location::RegisterLocation(R0));
189 codegen->RestoreLiveRegisters(instruction_->GetLocations());
190 __ b(GetExitLabel());
191 }
192
193 private:
194 HClinitCheck* const instruction_;
195
196 DISALLOW_COPY_AND_ASSIGN(ClinitCheckSlowPathARM);
197};
198
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100199#undef __
200#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700201
202inline Condition ARMCondition(IfCondition cond) {
203 switch (cond) {
204 case kCondEQ: return EQ;
205 case kCondNE: return NE;
206 case kCondLT: return LT;
207 case kCondLE: return LE;
208 case kCondGT: return GT;
209 case kCondGE: return GE;
210 default:
211 LOG(FATAL) << "Unknown if condition";
212 }
213 return EQ; // Unreachable.
214}
215
216inline Condition ARMOppositeCondition(IfCondition cond) {
217 switch (cond) {
218 case kCondEQ: return NE;
219 case kCondNE: return EQ;
220 case kCondLT: return GE;
221 case kCondLE: return GT;
222 case kCondGT: return LE;
223 case kCondGE: return LT;
224 default:
225 LOG(FATAL) << "Unknown if condition";
226 }
227 return EQ; // Unreachable.
228}
229
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100230void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
231 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
232}
233
234void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000235 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100236}
237
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100238size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
239 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
240 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100241}
242
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100243size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
244 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
245 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100246}
247
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100248CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000249 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100250 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100251 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100252 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100253 move_resolver_(graph->GetArena(), this),
254 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100255
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100256size_t CodeGeneratorARM::FrameEntrySpillSize() const {
257 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
258}
259
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100260Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100261 switch (type) {
262 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100263 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100264 ArmManagedRegister pair =
265 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100266 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
267 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
268
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100269 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
270 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100271 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100272 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100273 }
274
275 case Primitive::kPrimByte:
276 case Primitive::kPrimBoolean:
277 case Primitive::kPrimChar:
278 case Primitive::kPrimShort:
279 case Primitive::kPrimInt:
280 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100281 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100282 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100283 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
284 ArmManagedRegister current =
285 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
286 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100287 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100288 }
289 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100290 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100291 }
292
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000293 case Primitive::kPrimFloat: {
294 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100295 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100296 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100297
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000298 case Primitive::kPrimDouble: {
299 int reg = FindTwoFreeConsecutiveEntries(blocked_fpu_registers_, kNumberOfSRegisters);
300 return Location::FpuRegisterPairLocation(reg, reg + 1);
301 }
302
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100303 case Primitive::kPrimVoid:
304 LOG(FATAL) << "Unreachable type " << type;
305 }
306
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100307 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100308}
309
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100310void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100311 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100312 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100313
314 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100315 blocked_core_registers_[SP] = true;
316 blocked_core_registers_[LR] = true;
317 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100318
319 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100320 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100321
322 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100323 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100324
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100325 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100326 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100327
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100328 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100329 // We always save and restore R6 and R7 to make sure we can use three
330 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100331 blocked_core_registers_[R5] = true;
332 blocked_core_registers_[R8] = true;
333 blocked_core_registers_[R10] = true;
334 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100335
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000336 blocked_fpu_registers_[S16] = true;
337 blocked_fpu_registers_[S17] = true;
338 blocked_fpu_registers_[S18] = true;
339 blocked_fpu_registers_[S19] = true;
340 blocked_fpu_registers_[S20] = true;
341 blocked_fpu_registers_[S21] = true;
342 blocked_fpu_registers_[S22] = true;
343 blocked_fpu_registers_[S23] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100344
345 UpdateBlockedPairRegisters();
346}
347
348void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
349 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
350 ArmManagedRegister current =
351 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
352 if (blocked_core_registers_[current.AsRegisterPairLow()]
353 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
354 blocked_register_pairs_[i] = true;
355 }
356 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100357}
358
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100359InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
360 : HGraphVisitor(graph),
361 assembler_(codegen->GetAssembler()),
362 codegen_(codegen) {}
363
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000364void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700365 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100366 if (!skip_overflow_check) {
367 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100368 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100369 AddSlowPath(slow_path);
370
371 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
372 __ cmp(SP, ShifterOperand(IP));
373 __ b(slow_path->GetEntryLabel(), CC);
374 } else {
375 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100376 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100377 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100378 }
379 }
380
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100381 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
382 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000383
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100384 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100385 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100386 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000387}
388
389void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100390 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100391 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000392}
393
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100394void CodeGeneratorARM::Bind(HBasicBlock* block) {
395 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000396}
397
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100398Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
399 switch (load->GetType()) {
400 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100401 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100402 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
403 break;
404
405 case Primitive::kPrimInt:
406 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100407 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100408 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100409
410 case Primitive::kPrimBoolean:
411 case Primitive::kPrimByte:
412 case Primitive::kPrimChar:
413 case Primitive::kPrimShort:
414 case Primitive::kPrimVoid:
415 LOG(FATAL) << "Unexpected type " << load->GetType();
416 }
417
418 LOG(FATAL) << "Unreachable";
419 return Location();
420}
421
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100422Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
423 switch (type) {
424 case Primitive::kPrimBoolean:
425 case Primitive::kPrimByte:
426 case Primitive::kPrimChar:
427 case Primitive::kPrimShort:
428 case Primitive::kPrimInt:
429 case Primitive::kPrimNot: {
430 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000431 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100432 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100433 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100434 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000435 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100436 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100437 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100438
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000439 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100440 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000441 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100442 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000443 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100444 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100445 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
446 calling_convention.GetRegisterPairAt(index));
447 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100448 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000449 return Location::QuickParameter(stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100450 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000451 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
452 }
453 }
454
455 case Primitive::kPrimFloat: {
456 uint32_t stack_index = stack_index_++;
457 if (float_index_ % 2 == 0) {
458 float_index_ = std::max(double_index_, float_index_);
459 }
460 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
461 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
462 } else {
463 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
464 }
465 }
466
467 case Primitive::kPrimDouble: {
468 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
469 uint32_t stack_index = stack_index_;
470 stack_index_ += 2;
471 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
472 uint32_t index = double_index_;
473 double_index_ += 2;
474 return Location::FpuRegisterPairLocation(
475 calling_convention.GetFpuRegisterAt(index),
476 calling_convention.GetFpuRegisterAt(index + 1));
477 } else {
478 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100479 }
480 }
481
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100482 case Primitive::kPrimVoid:
483 LOG(FATAL) << "Unexpected parameter type " << type;
484 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100485 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100486 return Location();
487}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100488
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000489Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
490 switch (type) {
491 case Primitive::kPrimBoolean:
492 case Primitive::kPrimByte:
493 case Primitive::kPrimChar:
494 case Primitive::kPrimShort:
495 case Primitive::kPrimInt:
496 case Primitive::kPrimNot: {
497 return Location::RegisterLocation(R0);
498 }
499
500 case Primitive::kPrimFloat: {
501 return Location::FpuRegisterLocation(S0);
502 }
503
504 case Primitive::kPrimLong: {
505 return Location::RegisterPairLocation(R0, R1);
506 }
507
508 case Primitive::kPrimDouble: {
509 return Location::FpuRegisterPairLocation(S0, S1);
510 }
511
512 case Primitive::kPrimVoid:
513 return Location();
514 }
515 UNREACHABLE();
516 return Location();
517}
518
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100519void CodeGeneratorARM::Move32(Location destination, Location source) {
520 if (source.Equals(destination)) {
521 return;
522 }
523 if (destination.IsRegister()) {
524 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100525 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100526 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000527 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100528 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100529 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100530 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100531 } else if (destination.IsFpuRegister()) {
532 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000533 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100534 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000535 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100536 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000537 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100538 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100539 } else {
540 DCHECK(destination.IsStackSlot());
541 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100542 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100543 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000544 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100545 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100546 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100547 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
548 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100549 }
550 }
551}
552
553void CodeGeneratorARM::Move64(Location destination, Location source) {
554 if (source.Equals(destination)) {
555 return;
556 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100557 if (destination.IsRegisterPair()) {
558 if (source.IsRegisterPair()) {
559 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
560 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100561 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000562 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100563 } else if (source.IsQuickParameter()) {
564 uint32_t argument_index = source.GetQuickParameterIndex();
565 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100566 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100567 calling_convention.GetRegisterAt(argument_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100568 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
569 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100570 } else {
571 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100572 if (destination.AsRegisterPairLow<Register>() == R1) {
573 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100574 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
575 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100576 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100577 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100578 SP, source.GetStackIndex());
579 }
580 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000581 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100582 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000583 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
584 SP,
585 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100586 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000587 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100588 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100589 } else if (destination.IsQuickParameter()) {
590 InvokeDexCallingConvention calling_convention;
591 uint32_t argument_index = destination.GetQuickParameterIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100592 if (source.IsRegisterPair()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100593 __ Mov(calling_convention.GetRegisterAt(argument_index),
594 source.AsRegisterPairLow<Register>());
595 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
596 SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100597 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000598 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100599 } else {
600 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000601 __ LoadFromOffset(
602 kLoadWord, calling_convention.GetRegisterAt(argument_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100603 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
604 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100605 }
606 } else {
607 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100608 if (source.IsRegisterPair()) {
609 if (source.AsRegisterPairLow<Register>() == R1) {
610 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100611 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
612 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100613 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100614 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100615 SP, destination.GetStackIndex());
616 }
617 } else if (source.IsQuickParameter()) {
618 InvokeDexCallingConvention calling_convention;
619 uint32_t argument_index = source.GetQuickParameterIndex();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100620 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(argument_index),
621 SP, destination.GetStackIndex());
622 __ LoadFromOffset(kLoadWord, R0,
623 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
624 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000625 } else if (source.IsFpuRegisterPair()) {
626 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
627 SP,
628 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100629 } else {
630 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100631 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
632 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
633 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
634 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100635 }
636 }
637}
638
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100639void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100640 LocationSummary* locations = instruction->GetLocations();
641 if (locations != nullptr && locations->Out().Equals(location)) {
642 return;
643 }
644
Roland Levillain476df552014-10-09 17:51:36 +0100645 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100646 int32_t value = instruction->AsIntConstant()->GetValue();
647 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100648 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100649 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100650 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100651 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100652 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100653 }
Roland Levillain476df552014-10-09 17:51:36 +0100654 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100655 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100656 if (location.IsRegisterPair()) {
657 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
658 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100659 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100660 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100661 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100662 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100663 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100664 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100665 }
Roland Levillain476df552014-10-09 17:51:36 +0100666 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100667 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
668 switch (instruction->GetType()) {
669 case Primitive::kPrimBoolean:
670 case Primitive::kPrimByte:
671 case Primitive::kPrimChar:
672 case Primitive::kPrimShort:
673 case Primitive::kPrimInt:
674 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100675 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100676 Move32(location, Location::StackSlot(stack_slot));
677 break;
678
679 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100680 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100681 Move64(location, Location::DoubleStackSlot(stack_slot));
682 break;
683
684 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100685 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100686 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000687 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100688 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 switch (instruction->GetType()) {
690 case Primitive::kPrimBoolean:
691 case Primitive::kPrimByte:
692 case Primitive::kPrimChar:
693 case Primitive::kPrimShort:
694 case Primitive::kPrimNot:
695 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100696 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100697 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100698 break;
699
700 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100701 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100702 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100703 break;
704
705 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100706 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100707 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000708 }
709}
710
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100711void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
712 HInstruction* instruction,
713 uint32_t dex_pc) {
714 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
715 __ blx(LR);
716 RecordPcInfo(instruction, dex_pc);
717 DCHECK(instruction->IsSuspendCheck()
718 || instruction->IsBoundsCheck()
719 || instruction->IsNullCheck()
720 || !IsLeafMethod());
721}
722
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000723void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000724 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000725}
726
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000727void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000728 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100729 DCHECK(!successor->IsExitBlock());
730
731 HBasicBlock* block = got->GetBlock();
732 HInstruction* previous = got->GetPrevious();
733
734 HLoopInformation* info = block->GetLoopInformation();
735 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
736 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
737 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
738 return;
739 }
740
741 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
742 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
743 }
744 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000745 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000746 }
747}
748
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000749void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000750 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000751}
752
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000753void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000754 if (kIsDebugBuild) {
755 __ Comment("Unreachable");
756 __ bkpt(0);
757 }
758}
759
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000760void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100761 LocationSummary* locations =
762 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100763 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100764 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100765 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100766 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000767}
768
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000769void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700770 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100771 if (cond->IsIntConstant()) {
772 // Constant condition, statically compared against 1.
773 int32_t cond_value = cond->AsIntConstant()->GetValue();
774 if (cond_value == 1) {
775 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
776 if_instr->IfTrueSuccessor())) {
777 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100778 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100779 return;
780 } else {
781 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100782 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100783 } else {
784 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
785 // Condition has been materialized, compare the output to 0
786 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
787 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
788 ShifterOperand(0));
789 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
790 } else {
791 // Condition has not been materialized, use its inputs as the
792 // comparison and its condition as the branch condition.
793 LocationSummary* locations = cond->GetLocations();
794 if (locations->InAt(1).IsRegister()) {
795 __ cmp(locations->InAt(0).As<Register>(),
796 ShifterOperand(locations->InAt(1).As<Register>()));
797 } else {
798 DCHECK(locations->InAt(1).IsConstant());
799 int32_t value =
800 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
801 ShifterOperand operand;
802 if (ShifterOperand::CanHoldArm(value, &operand)) {
803 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
804 } else {
805 Register temp = IP;
806 __ LoadImmediate(temp, value);
807 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
808 }
809 }
810 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
811 ARMCondition(cond->AsCondition()->GetCondition()));
812 }
Dave Allison20dfc792014-06-16 20:44:29 -0700813 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100814 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
815 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700816 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000817 }
818}
819
Dave Allison20dfc792014-06-16 20:44:29 -0700820
821void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100822 LocationSummary* locations =
823 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100824 locations->SetInAt(0, Location::RequiresRegister());
825 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100826 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100827 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100828 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000829}
830
Dave Allison20dfc792014-06-16 20:44:29 -0700831void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100832 if (!comp->NeedsMaterialization()) return;
833
834 LocationSummary* locations = comp->GetLocations();
835 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100836 __ cmp(locations->InAt(0).As<Register>(),
837 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100838 } else {
839 DCHECK(locations->InAt(1).IsConstant());
840 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
841 ShifterOperand operand;
842 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100843 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100844 } else {
845 Register temp = IP;
846 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100847 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100848 }
Dave Allison20dfc792014-06-16 20:44:29 -0700849 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100850 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100851 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100852 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100853 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100854 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700855}
856
857void LocationsBuilderARM::VisitEqual(HEqual* comp) {
858 VisitCondition(comp);
859}
860
861void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
862 VisitCondition(comp);
863}
864
865void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
866 VisitCondition(comp);
867}
868
869void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
870 VisitCondition(comp);
871}
872
873void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
874 VisitCondition(comp);
875}
876
877void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
878 VisitCondition(comp);
879}
880
881void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
882 VisitCondition(comp);
883}
884
885void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
886 VisitCondition(comp);
887}
888
889void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
890 VisitCondition(comp);
891}
892
893void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
894 VisitCondition(comp);
895}
896
897void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
898 VisitCondition(comp);
899}
900
901void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
902 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000903}
904
905void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000906 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000907}
908
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000909void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
910 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000911}
912
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000913void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100914 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000915}
916
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000917void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100918 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000919}
920
921void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100922 LocationSummary* locations =
923 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100924 switch (store->InputAt(1)->GetType()) {
925 case Primitive::kPrimBoolean:
926 case Primitive::kPrimByte:
927 case Primitive::kPrimChar:
928 case Primitive::kPrimShort:
929 case Primitive::kPrimInt:
930 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100931 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100932 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
933 break;
934
935 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100936 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100937 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
938 break;
939
940 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100941 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100942 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000943}
944
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000945void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000946}
947
948void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100949 LocationSummary* locations =
950 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100951 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000952}
953
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000954void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100955 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000956}
957
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100958void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100959 LocationSummary* locations =
960 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100961 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100962}
963
964void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
965 // Will be generated at use site.
966}
967
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100968void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
969 LocationSummary* locations =
970 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
971 locations->SetOut(Location::ConstantLocation(constant));
972}
973
974void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
975 // Will be generated at use site.
976}
977
978void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
979 LocationSummary* locations =
980 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
981 locations->SetOut(Location::ConstantLocation(constant));
982}
983
984void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
985 // Will be generated at use site.
986}
987
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000988void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000989 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000990}
991
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000992void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
993 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000994}
995
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000996void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100997 LocationSummary* locations =
998 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000999 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001000}
1001
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001002void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001003 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001004}
1005
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001006void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001007 HandleInvoke(invoke);
1008}
1009
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001010void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001011 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001012}
1013
1014void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001015 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001016
1017 // TODO: Implement all kinds of calls:
1018 // 1) boot -> boot
1019 // 2) app -> boot
1020 // 3) app -> app
1021 //
1022 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1023
1024 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001025 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001026 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001027 __ LoadFromOffset(
1028 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001029 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001030 __ LoadFromOffset(
1031 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001032 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001033 __ LoadFromOffset(kLoadWord, LR, temp,
1034 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001035 // LR()
1036 __ blx(LR);
1037
1038 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1039 DCHECK(!codegen_->IsLeafMethod());
1040}
1041
1042void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1043 HandleInvoke(invoke);
1044}
1045
1046void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001047 LocationSummary* locations =
1048 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001049 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001050
1051 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001052 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001053 HInstruction* input = invoke->InputAt(i);
1054 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1055 }
1056
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001057 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001058}
1059
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001060
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001061void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001062 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001063 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1064 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1065 LocationSummary* locations = invoke->GetLocations();
1066 Location receiver = locations->InAt(0);
1067 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1068 // temp = object->GetClass();
1069 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001070 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1071 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001072 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001073 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001074 }
1075 // temp = temp->GetMethodAt(method_offset);
1076 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001077 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001078 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001079 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001080 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001081 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001082 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001083 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001084}
1085
Roland Levillain88cb1752014-10-20 16:36:47 +01001086void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1087 LocationSummary* locations =
1088 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1089 switch (neg->GetResultType()) {
1090 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001091 case Primitive::kPrimLong: {
1092 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001093 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001094 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001095 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001096 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001097
Roland Levillain88cb1752014-10-20 16:36:47 +01001098 case Primitive::kPrimFloat:
1099 case Primitive::kPrimDouble:
1100 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1101 break;
1102
1103 default:
1104 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1105 }
1106}
1107
1108void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1109 LocationSummary* locations = neg->GetLocations();
1110 Location out = locations->Out();
1111 Location in = locations->InAt(0);
1112 switch (neg->GetResultType()) {
1113 case Primitive::kPrimInt:
1114 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001115 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001116 break;
1117
1118 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001119 DCHECK(in.IsRegisterPair());
1120 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1121 __ rsbs(out.AsRegisterPairLow<Register>(),
1122 in.AsRegisterPairLow<Register>(),
1123 ShifterOperand(0));
1124 // We cannot emit an RSC (Reverse Subtract with Carry)
1125 // instruction here, as it does not exist in the Thumb-2
1126 // instruction set. We use the following approach
1127 // using SBC and SUB instead.
1128 //
1129 // out.hi = -C
1130 __ sbc(out.AsRegisterPairHigh<Register>(),
1131 out.AsRegisterPairHigh<Register>(),
1132 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1133 // out.hi = out.hi - in.hi
1134 __ sub(out.AsRegisterPairHigh<Register>(),
1135 out.AsRegisterPairHigh<Register>(),
1136 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1137 break;
1138
Roland Levillain88cb1752014-10-20 16:36:47 +01001139 case Primitive::kPrimFloat:
1140 case Primitive::kPrimDouble:
1141 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1142 break;
1143
1144 default:
1145 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1146 }
1147}
1148
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001149void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001150 LocationSummary* locations =
1151 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001152 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001153 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001154 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001155 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1156 locations->SetInAt(0, Location::RequiresRegister());
1157 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1158 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001159 break;
1160 }
1161
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001162 case Primitive::kPrimFloat:
1163 case Primitive::kPrimDouble: {
1164 locations->SetInAt(0, Location::RequiresFpuRegister());
1165 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001166 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001167 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001168 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001169
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001170 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001171 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001172 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001173}
1174
1175void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1176 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001177 Location out = locations->Out();
1178 Location first = locations->InAt(0);
1179 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001180 switch (add->GetResultType()) {
1181 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001182 if (second.IsRegister()) {
1183 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001184 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001185 __ AddConstant(out.As<Register>(),
1186 first.As<Register>(),
1187 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001188 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001189 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001190
1191 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001192 __ adds(out.AsRegisterPairLow<Register>(),
1193 first.AsRegisterPairLow<Register>(),
1194 ShifterOperand(second.AsRegisterPairLow<Register>()));
1195 __ adc(out.AsRegisterPairHigh<Register>(),
1196 first.AsRegisterPairHigh<Register>(),
1197 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001198 break;
1199
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001200 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001201 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001202 break;
1203
1204 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001205 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1206 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1207 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001208 break;
1209
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001210 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001211 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001212 }
1213}
1214
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001215void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001216 LocationSummary* locations =
1217 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001218 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001219 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001220 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001221 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1222 locations->SetInAt(0, Location::RequiresRegister());
1223 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1224 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001225 break;
1226 }
Calin Juravle11351682014-10-23 15:38:15 +01001227 case Primitive::kPrimFloat:
1228 case Primitive::kPrimDouble: {
1229 locations->SetInAt(0, Location::RequiresFpuRegister());
1230 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001231 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001232 break;
Calin Juravle11351682014-10-23 15:38:15 +01001233 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001234 default:
Calin Juravle11351682014-10-23 15:38:15 +01001235 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001236 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001237}
1238
1239void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1240 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001241 Location out = locations->Out();
1242 Location first = locations->InAt(0);
1243 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001244 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001245 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001246 if (second.IsRegister()) {
1247 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001248 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001249 __ AddConstant(out.As<Register>(),
1250 first.As<Register>(),
1251 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001252 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001253 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001254 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001255
Calin Juravle11351682014-10-23 15:38:15 +01001256 case Primitive::kPrimLong: {
1257 __ subs(out.AsRegisterPairLow<Register>(),
1258 first.AsRegisterPairLow<Register>(),
1259 ShifterOperand(second.AsRegisterPairLow<Register>()));
1260 __ sbc(out.AsRegisterPairHigh<Register>(),
1261 first.AsRegisterPairHigh<Register>(),
1262 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001263 break;
Calin Juravle11351682014-10-23 15:38:15 +01001264 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001265
Calin Juravle11351682014-10-23 15:38:15 +01001266 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001267 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001268 break;
Calin Juravle11351682014-10-23 15:38:15 +01001269 }
1270
1271 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001272 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1273 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1274 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001275 break;
1276 }
1277
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001278
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001279 default:
Calin Juravle11351682014-10-23 15:38:15 +01001280 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001281 }
1282}
1283
Calin Juravle34bacdf2014-10-07 20:23:36 +01001284void LocationsBuilderARM::VisitMul(HMul* mul) {
1285 LocationSummary* locations =
1286 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1287 switch (mul->GetResultType()) {
1288 case Primitive::kPrimInt:
1289 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001290 locations->SetInAt(0, Location::RequiresRegister());
1291 locations->SetInAt(1, Location::RequiresRegister());
1292 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001293 break;
1294 }
1295
Calin Juravleb5bfa962014-10-21 18:02:24 +01001296 case Primitive::kPrimFloat:
1297 case Primitive::kPrimDouble: {
1298 locations->SetInAt(0, Location::RequiresFpuRegister());
1299 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001300 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001301 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001302 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001303
1304 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001305 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001306 }
1307}
1308
1309void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1310 LocationSummary* locations = mul->GetLocations();
1311 Location out = locations->Out();
1312 Location first = locations->InAt(0);
1313 Location second = locations->InAt(1);
1314 switch (mul->GetResultType()) {
1315 case Primitive::kPrimInt: {
1316 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1317 break;
1318 }
1319 case Primitive::kPrimLong: {
1320 Register out_hi = out.AsRegisterPairHigh<Register>();
1321 Register out_lo = out.AsRegisterPairLow<Register>();
1322 Register in1_hi = first.AsRegisterPairHigh<Register>();
1323 Register in1_lo = first.AsRegisterPairLow<Register>();
1324 Register in2_hi = second.AsRegisterPairHigh<Register>();
1325 Register in2_lo = second.AsRegisterPairLow<Register>();
1326
1327 // Extra checks to protect caused by the existence of R1_R2.
1328 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1329 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1330 DCHECK_NE(out_hi, in1_lo);
1331 DCHECK_NE(out_hi, in2_lo);
1332
1333 // input: in1 - 64 bits, in2 - 64 bits
1334 // output: out
1335 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1336 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1337 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1338
1339 // IP <- in1.lo * in2.hi
1340 __ mul(IP, in1_lo, in2_hi);
1341 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1342 __ mla(out_hi, in1_hi, in2_lo, IP);
1343 // out.lo <- (in1.lo * in2.lo)[31:0];
1344 __ umull(out_lo, IP, in1_lo, in2_lo);
1345 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1346 __ add(out_hi, out_hi, ShifterOperand(IP));
1347 break;
1348 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001349
1350 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001351 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001352 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001353 }
1354
1355 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001356 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1357 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1358 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001359 break;
1360 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001361
1362 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001363 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001364 }
1365}
1366
Calin Juravle7c4954d2014-10-28 16:57:40 +00001367void LocationsBuilderARM::VisitDiv(HDiv* div) {
1368 LocationSummary* locations =
1369 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1370 switch (div->GetResultType()) {
1371 case Primitive::kPrimInt:
1372 case Primitive::kPrimLong: {
1373 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1374 break;
1375 }
1376 case Primitive::kPrimFloat:
1377 case Primitive::kPrimDouble: {
1378 locations->SetInAt(0, Location::RequiresFpuRegister());
1379 locations->SetInAt(1, Location::RequiresFpuRegister());
1380 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1381 break;
1382 }
1383
1384 default:
1385 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1386 }
1387}
1388
1389void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1390 LocationSummary* locations = div->GetLocations();
1391 Location out = locations->Out();
1392 Location first = locations->InAt(0);
1393 Location second = locations->InAt(1);
1394
1395 switch (div->GetResultType()) {
1396 case Primitive::kPrimInt:
1397 case Primitive::kPrimLong: {
1398 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1399 break;
1400 }
1401
1402 case Primitive::kPrimFloat: {
1403 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1404 break;
1405 }
1406
1407 case Primitive::kPrimDouble: {
1408 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1409 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1410 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1411 break;
1412 }
1413
1414 default:
1415 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1416 }
1417}
1418
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001419void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001420 LocationSummary* locations =
1421 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001422 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001423 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1424 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1425 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001426}
1427
1428void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1429 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001430 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001431 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001432 codegen_->InvokeRuntime(
1433 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001434}
1435
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001436void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1437 LocationSummary* locations =
1438 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1439 InvokeRuntimeCallingConvention calling_convention;
1440 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1441 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1442 locations->SetOut(Location::RegisterLocation(R0));
1443 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1444}
1445
1446void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1447 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001448 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001449 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001450 codegen_->InvokeRuntime(
1451 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001452}
1453
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001454void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001455 LocationSummary* locations =
1456 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001457 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1458 if (location.IsStackSlot()) {
1459 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1460 } else if (location.IsDoubleStackSlot()) {
1461 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001462 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001463 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001464}
1465
1466void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001467 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001468}
1469
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001470void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001471 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001472 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001473 locations->SetInAt(0, Location::RequiresRegister());
1474 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001475}
1476
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001477void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1478 LocationSummary* locations = not_->GetLocations();
1479 Location out = locations->Out();
1480 Location in = locations->InAt(0);
1481 switch (not_->InputAt(0)->GetType()) {
1482 case Primitive::kPrimBoolean:
1483 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1484 break;
1485
1486 case Primitive::kPrimInt:
1487 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1488 break;
1489
1490 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001491 __ mvn(out.AsRegisterPairLow<Register>(),
1492 ShifterOperand(in.AsRegisterPairLow<Register>()));
1493 __ mvn(out.AsRegisterPairHigh<Register>(),
1494 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001495 break;
1496
1497 default:
1498 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1499 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001500}
1501
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001502void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001503 LocationSummary* locations =
1504 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001505 locations->SetInAt(0, Location::RequiresRegister());
1506 locations->SetInAt(1, Location::RequiresRegister());
1507 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001508}
1509
1510void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1511 Label greater, done;
1512 LocationSummary* locations = compare->GetLocations();
1513 switch (compare->InputAt(0)->GetType()) {
1514 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001515 Register output = locations->Out().As<Register>();
1516 Location left = locations->InAt(0);
1517 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001518 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001519 __ cmp(left.AsRegisterPairHigh<Register>(),
1520 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001521 __ b(&less, LT);
1522 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001523 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1524 // the status flags.
1525 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001526 __ cmp(left.AsRegisterPairLow<Register>(),
1527 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001528 __ b(&done, EQ);
1529 __ b(&less, CC);
1530
1531 __ Bind(&greater);
1532 __ LoadImmediate(output, 1);
1533 __ b(&done);
1534
1535 __ Bind(&less);
1536 __ LoadImmediate(output, -1);
1537
1538 __ Bind(&done);
1539 break;
1540 }
1541 default:
1542 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1543 }
1544}
1545
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001546void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001547 LocationSummary* locations =
1548 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001549 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1550 locations->SetInAt(i, Location::Any());
1551 }
1552 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001553}
1554
1555void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001556 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001557}
1558
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001559void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001560 LocationSummary* locations =
1561 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001562 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001563 locations->SetInAt(0, Location::RequiresRegister());
1564 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001565 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001566 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001567 locations->AddTemp(Location::RequiresRegister());
1568 locations->AddTemp(Location::RequiresRegister());
1569 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001570}
1571
1572void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1573 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001574 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001575 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001576 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001577
1578 switch (field_type) {
1579 case Primitive::kPrimBoolean:
1580 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001581 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001582 __ StoreToOffset(kStoreByte, value, obj, offset);
1583 break;
1584 }
1585
1586 case Primitive::kPrimShort:
1587 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001588 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001589 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1590 break;
1591 }
1592
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001593 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001594 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001595 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001596 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001597 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001598 Register temp = locations->GetTemp(0).As<Register>();
1599 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001600 codegen_->MarkGCCard(temp, card, obj, value);
1601 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001602 break;
1603 }
1604
1605 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001606 Location value = locations->InAt(1);
1607 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001608 break;
1609 }
1610
1611 case Primitive::kPrimFloat:
1612 case Primitive::kPrimDouble:
1613 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001614 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001615 case Primitive::kPrimVoid:
1616 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001617 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001618 }
1619}
1620
1621void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001622 LocationSummary* locations =
1623 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001624 locations->SetInAt(0, Location::RequiresRegister());
1625 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001626}
1627
1628void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1629 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001630 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001631 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1632
1633 switch (instruction->GetType()) {
1634 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001635 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001636 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1637 break;
1638 }
1639
1640 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001641 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001642 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1643 break;
1644 }
1645
1646 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001647 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001648 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1649 break;
1650 }
1651
1652 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001653 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001654 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1655 break;
1656 }
1657
1658 case Primitive::kPrimInt:
1659 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001660 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001661 __ LoadFromOffset(kLoadWord, out, obj, offset);
1662 break;
1663 }
1664
1665 case Primitive::kPrimLong: {
1666 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001667 Location out = locations->Out();
1668 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001669 break;
1670 }
1671
1672 case Primitive::kPrimFloat:
1673 case Primitive::kPrimDouble:
1674 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001675 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001676 case Primitive::kPrimVoid:
1677 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001678 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001679 }
1680}
1681
1682void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001683 LocationSummary* locations =
1684 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001685 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001686 if (instruction->HasUses()) {
1687 locations->SetOut(Location::SameAsFirstInput());
1688 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001689}
1690
1691void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001692 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001693 codegen_->AddSlowPath(slow_path);
1694
1695 LocationSummary* locations = instruction->GetLocations();
1696 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001697
1698 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001699 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001700 __ b(slow_path->GetEntryLabel(), EQ);
1701 } else {
1702 DCHECK(obj.IsConstant()) << obj;
1703 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1704 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001705 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001706}
1707
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001708void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001709 LocationSummary* locations =
1710 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001711 locations->SetInAt(0, Location::RequiresRegister());
1712 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1713 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001714}
1715
1716void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1717 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001718 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001719 Location index = locations->InAt(1);
1720
1721 switch (instruction->GetType()) {
1722 case Primitive::kPrimBoolean: {
1723 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001724 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001725 if (index.IsConstant()) {
1726 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1727 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1728 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001729 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001730 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1731 }
1732 break;
1733 }
1734
1735 case Primitive::kPrimByte: {
1736 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001737 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001738 if (index.IsConstant()) {
1739 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1740 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1741 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001742 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001743 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1744 }
1745 break;
1746 }
1747
1748 case Primitive::kPrimShort: {
1749 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001750 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001751 if (index.IsConstant()) {
1752 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1753 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1754 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001755 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001756 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1757 }
1758 break;
1759 }
1760
1761 case Primitive::kPrimChar: {
1762 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001763 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001764 if (index.IsConstant()) {
1765 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1766 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1767 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001768 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001769 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1770 }
1771 break;
1772 }
1773
1774 case Primitive::kPrimInt:
1775 case Primitive::kPrimNot: {
1776 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1777 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001778 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001779 if (index.IsConstant()) {
1780 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1781 __ LoadFromOffset(kLoadWord, out, obj, offset);
1782 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001783 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001784 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1785 }
1786 break;
1787 }
1788
1789 case Primitive::kPrimLong: {
1790 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001791 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001792 if (index.IsConstant()) {
1793 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001794 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001795 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001796 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1797 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001798 }
1799 break;
1800 }
1801
1802 case Primitive::kPrimFloat:
1803 case Primitive::kPrimDouble:
1804 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001805 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001806 case Primitive::kPrimVoid:
1807 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001808 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001809 }
1810}
1811
1812void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001813 Primitive::Type value_type = instruction->GetComponentType();
1814 bool is_object = value_type == Primitive::kPrimNot;
1815 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1816 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1817 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001818 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001819 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1820 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1821 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001822 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001823 locations->SetInAt(0, Location::RequiresRegister());
1824 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1825 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001826 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001827}
1828
1829void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1830 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001831 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001832 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001833 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001834
1835 switch (value_type) {
1836 case Primitive::kPrimBoolean:
1837 case Primitive::kPrimByte: {
1838 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001839 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001840 if (index.IsConstant()) {
1841 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1842 __ StoreToOffset(kStoreByte, value, obj, offset);
1843 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001844 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001845 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1846 }
1847 break;
1848 }
1849
1850 case Primitive::kPrimShort:
1851 case Primitive::kPrimChar: {
1852 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001853 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001854 if (index.IsConstant()) {
1855 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1856 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1857 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001858 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001859 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1860 }
1861 break;
1862 }
1863
1864 case Primitive::kPrimInt: {
1865 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001866 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001867 if (index.IsConstant()) {
1868 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1869 __ StoreToOffset(kStoreWord, value, obj, offset);
1870 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001871 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001872 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1873 }
1874 break;
1875 }
1876
1877 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001878 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001879 break;
1880 }
1881
1882 case Primitive::kPrimLong: {
1883 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001884 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001885 if (index.IsConstant()) {
1886 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001887 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001888 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001889 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1890 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001891 }
1892 break;
1893 }
1894
1895 case Primitive::kPrimFloat:
1896 case Primitive::kPrimDouble:
1897 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001898 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001899 case Primitive::kPrimVoid:
1900 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001901 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001902 }
1903}
1904
1905void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001906 LocationSummary* locations =
1907 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001908 locations->SetInAt(0, Location::RequiresRegister());
1909 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001910}
1911
1912void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1913 LocationSummary* locations = instruction->GetLocations();
1914 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001915 Register obj = locations->InAt(0).As<Register>();
1916 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001917 __ LoadFromOffset(kLoadWord, out, obj, offset);
1918}
1919
1920void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001921 LocationSummary* locations =
1922 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001923 locations->SetInAt(0, Location::RequiresRegister());
1924 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001925 if (instruction->HasUses()) {
1926 locations->SetOut(Location::SameAsFirstInput());
1927 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001928}
1929
1930void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1931 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001932 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001933 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001934 codegen_->AddSlowPath(slow_path);
1935
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001936 Register index = locations->InAt(0).As<Register>();
1937 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001938
1939 __ cmp(index, ShifterOperand(length));
1940 __ b(slow_path->GetEntryLabel(), CS);
1941}
1942
1943void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1944 Label is_null;
1945 __ CompareAndBranchIfZero(value, &is_null);
1946 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1947 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1948 __ strb(card, Address(card, temp));
1949 __ Bind(&is_null);
1950}
1951
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001952void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1953 temp->SetLocations(nullptr);
1954}
1955
1956void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1957 // Nothing to do, this is driven by the code generator.
1958}
1959
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001960void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001961 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001962}
1963
1964void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001965 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1966}
1967
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001968void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
1969 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1970}
1971
1972void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001973 HBasicBlock* block = instruction->GetBlock();
1974 if (block->GetLoopInformation() != nullptr) {
1975 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1976 // The back edge will generate the suspend check.
1977 return;
1978 }
1979 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1980 // The goto will generate the suspend check.
1981 return;
1982 }
1983 GenerateSuspendCheck(instruction, nullptr);
1984}
1985
1986void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
1987 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001988 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001989 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001990 codegen_->AddSlowPath(slow_path);
1991
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001992 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001993 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001994 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001995 __ Bind(slow_path->GetReturnLabel());
1996 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001997 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001998 __ b(slow_path->GetEntryLabel());
1999 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002000}
2001
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002002ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2003 return codegen_->GetAssembler();
2004}
2005
2006void ParallelMoveResolverARM::EmitMove(size_t index) {
2007 MoveOperands* move = moves_.Get(index);
2008 Location source = move->GetSource();
2009 Location destination = move->GetDestination();
2010
2011 if (source.IsRegister()) {
2012 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002013 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002014 } else {
2015 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002016 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002017 SP, destination.GetStackIndex());
2018 }
2019 } else if (source.IsStackSlot()) {
2020 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002021 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002022 SP, source.GetStackIndex());
2023 } else {
2024 DCHECK(destination.IsStackSlot());
2025 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2026 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2027 }
2028 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002029 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002030 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002031 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2032 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002033 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002034 } else {
2035 DCHECK(destination.IsStackSlot());
2036 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002037 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002038 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002039 }
2040}
2041
2042void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2043 __ Mov(IP, reg);
2044 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2045 __ StoreToOffset(kStoreWord, IP, SP, mem);
2046}
2047
2048void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2049 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2050 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2051 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2052 SP, mem1 + stack_offset);
2053 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2054 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2055 SP, mem2 + stack_offset);
2056 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2057}
2058
2059void ParallelMoveResolverARM::EmitSwap(size_t index) {
2060 MoveOperands* move = moves_.Get(index);
2061 Location source = move->GetSource();
2062 Location destination = move->GetDestination();
2063
2064 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002065 DCHECK_NE(source.As<Register>(), IP);
2066 DCHECK_NE(destination.As<Register>(), IP);
2067 __ Mov(IP, source.As<Register>());
2068 __ Mov(source.As<Register>(), destination.As<Register>());
2069 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002070 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002071 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002072 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002073 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002074 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2075 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2076 } else {
2077 LOG(FATAL) << "Unimplemented";
2078 }
2079}
2080
2081void ParallelMoveResolverARM::SpillScratch(int reg) {
2082 __ Push(static_cast<Register>(reg));
2083}
2084
2085void ParallelMoveResolverARM::RestoreScratch(int reg) {
2086 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002087}
2088
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002089void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
2090 LocationSummary* locations =
2091 new (GetGraph()->GetArena()) LocationSummary(cls, LocationSummary::kNoCall);
2092 locations->SetOut(Location::RequiresRegister());
2093}
2094
2095void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2096 Register out = cls->GetLocations()->Out().As<Register>();
2097 if (cls->IsReferrersClass()) {
2098 codegen_->LoadCurrentMethod(out);
2099 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2100 } else {
2101 codegen_->LoadCurrentMethod(out);
2102 __ LoadFromOffset(
2103 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2104 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
2105 }
2106}
2107
2108void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2109 LocationSummary* locations =
2110 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2111 locations->SetInAt(0, Location::RequiresRegister());
2112 if (check->HasUses()) {
2113 locations->SetOut(Location::SameAsFirstInput());
2114 }
2115}
2116
2117void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
2118 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ClinitCheckSlowPathARM(check);
2119 codegen_->AddSlowPath(slow_path);
2120
2121 LocationSummary* locations = check->GetLocations();
2122 // We remove the class as a live register, we know it's null or unused in the slow path.
2123 RegisterSet* register_set = locations->GetLiveRegisters();
2124 register_set->Remove(locations->InAt(0));
2125
2126 Register class_reg = locations->InAt(0).As<Register>();
2127 __ cmp(class_reg, ShifterOperand(0));
2128 __ b(slow_path->GetEntryLabel(), EQ);
2129 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2130 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2131 __ b(slow_path->GetEntryLabel(), LT);
2132 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2133 // properly. Therefore, we do a memory fence.
2134 __ dmb(ISH);
2135 __ Bind(slow_path->GetExitLabel());
2136}
2137
2138void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2139 LocationSummary* locations =
2140 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2141 locations->SetInAt(0, Location::RequiresRegister());
2142 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2143}
2144
2145void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2146 LocationSummary* locations = instruction->GetLocations();
2147 Register cls = locations->InAt(0).As<Register>();
2148 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2149
2150 switch (instruction->GetType()) {
2151 case Primitive::kPrimBoolean: {
2152 Register out = locations->Out().As<Register>();
2153 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2154 break;
2155 }
2156
2157 case Primitive::kPrimByte: {
2158 Register out = locations->Out().As<Register>();
2159 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2160 break;
2161 }
2162
2163 case Primitive::kPrimShort: {
2164 Register out = locations->Out().As<Register>();
2165 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2166 break;
2167 }
2168
2169 case Primitive::kPrimChar: {
2170 Register out = locations->Out().As<Register>();
2171 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2172 break;
2173 }
2174
2175 case Primitive::kPrimInt:
2176 case Primitive::kPrimNot: {
2177 Register out = locations->Out().As<Register>();
2178 __ LoadFromOffset(kLoadWord, out, cls, offset);
2179 break;
2180 }
2181
2182 case Primitive::kPrimLong: {
2183 // TODO: support volatile.
2184 Location out = locations->Out();
2185 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2186 break;
2187 }
2188
2189 case Primitive::kPrimFloat:
2190 case Primitive::kPrimDouble:
2191 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2192 UNREACHABLE();
2193 case Primitive::kPrimVoid:
2194 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2195 UNREACHABLE();
2196 }
2197}
2198
2199void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2200 LocationSummary* locations =
2201 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2202 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2203 locations->SetInAt(0, Location::RequiresRegister());
2204 locations->SetInAt(1, Location::RequiresRegister());
2205 // Temporary registers for the write barrier.
2206 if (is_object_type) {
2207 locations->AddTemp(Location::RequiresRegister());
2208 locations->AddTemp(Location::RequiresRegister());
2209 }
2210}
2211
2212void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2213 LocationSummary* locations = instruction->GetLocations();
2214 Register cls = locations->InAt(0).As<Register>();
2215 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2216 Primitive::Type field_type = instruction->GetFieldType();
2217
2218 switch (field_type) {
2219 case Primitive::kPrimBoolean:
2220 case Primitive::kPrimByte: {
2221 Register value = locations->InAt(1).As<Register>();
2222 __ StoreToOffset(kStoreByte, value, cls, offset);
2223 break;
2224 }
2225
2226 case Primitive::kPrimShort:
2227 case Primitive::kPrimChar: {
2228 Register value = locations->InAt(1).As<Register>();
2229 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2230 break;
2231 }
2232
2233 case Primitive::kPrimInt:
2234 case Primitive::kPrimNot: {
2235 Register value = locations->InAt(1).As<Register>();
2236 __ StoreToOffset(kStoreWord, value, cls, offset);
2237 if (field_type == Primitive::kPrimNot) {
2238 Register temp = locations->GetTemp(0).As<Register>();
2239 Register card = locations->GetTemp(1).As<Register>();
2240 codegen_->MarkGCCard(temp, card, cls, value);
2241 }
2242 break;
2243 }
2244
2245 case Primitive::kPrimLong: {
2246 Location value = locations->InAt(1);
2247 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2248 break;
2249 }
2250
2251 case Primitive::kPrimFloat:
2252 case Primitive::kPrimDouble:
2253 LOG(FATAL) << "Unimplemented register type " << field_type;
2254 UNREACHABLE();
2255 case Primitive::kPrimVoid:
2256 LOG(FATAL) << "Unreachable type " << field_type;
2257 UNREACHABLE();
2258 }
2259}
2260
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002261} // namespace arm
2262} // namespace art