blob: 0f14436539cd7384466f52d3eea3104194894253 [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 Geoffray0a6c4592014-10-30 16:37:57 +0000449 return Location::QuickParameter(index, 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()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000564 uint16_t register_index = source.GetQuickParameterRegisterIndex();
565 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100566 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100567 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000568 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100569 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000570 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100571 } else {
572 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100573 if (destination.AsRegisterPairLow<Register>() == R1) {
574 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100575 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
576 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100577 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100578 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100579 SP, source.GetStackIndex());
580 }
581 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000582 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100583 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000584 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
585 SP,
586 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100587 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000588 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100589 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100590 } else if (destination.IsQuickParameter()) {
591 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000592 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
593 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100594 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000595 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100596 source.AsRegisterPairLow<Register>());
597 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000598 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100599 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000600 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100601 } else {
602 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000603 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000604 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100605 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000606 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100607 }
608 } else {
609 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100610 if (source.IsRegisterPair()) {
611 if (source.AsRegisterPairLow<Register>() == R1) {
612 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100613 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
614 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100615 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100616 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100617 SP, destination.GetStackIndex());
618 }
619 } else if (source.IsQuickParameter()) {
620 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000621 uint16_t register_index = source.GetQuickParameterRegisterIndex();
622 uint16_t stack_index = source.GetQuickParameterStackIndex();
623 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100624 SP, destination.GetStackIndex());
625 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000626 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100627 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000628 } else if (source.IsFpuRegisterPair()) {
629 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
630 SP,
631 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100632 } else {
633 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100634 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
635 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
636 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
637 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100638 }
639 }
640}
641
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100642void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100643 LocationSummary* locations = instruction->GetLocations();
644 if (locations != nullptr && locations->Out().Equals(location)) {
645 return;
646 }
647
Roland Levillain476df552014-10-09 17:51:36 +0100648 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100649 int32_t value = instruction->AsIntConstant()->GetValue();
650 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100651 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100652 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100653 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100654 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100655 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100656 }
Roland Levillain476df552014-10-09 17:51:36 +0100657 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100658 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100659 if (location.IsRegisterPair()) {
660 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
661 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100662 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100663 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100664 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100665 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100666 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100667 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100668 }
Roland Levillain476df552014-10-09 17:51:36 +0100669 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100670 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
671 switch (instruction->GetType()) {
672 case Primitive::kPrimBoolean:
673 case Primitive::kPrimByte:
674 case Primitive::kPrimChar:
675 case Primitive::kPrimShort:
676 case Primitive::kPrimInt:
677 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100678 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100679 Move32(location, Location::StackSlot(stack_slot));
680 break;
681
682 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100683 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100684 Move64(location, Location::DoubleStackSlot(stack_slot));
685 break;
686
687 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100688 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000690 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100691 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100692 switch (instruction->GetType()) {
693 case Primitive::kPrimBoolean:
694 case Primitive::kPrimByte:
695 case Primitive::kPrimChar:
696 case Primitive::kPrimShort:
697 case Primitive::kPrimNot:
698 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100699 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100700 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100701 break;
702
703 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100704 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100705 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 break;
707
708 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100709 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000711 }
712}
713
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100714void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
715 HInstruction* instruction,
716 uint32_t dex_pc) {
717 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
718 __ blx(LR);
719 RecordPcInfo(instruction, dex_pc);
720 DCHECK(instruction->IsSuspendCheck()
721 || instruction->IsBoundsCheck()
722 || instruction->IsNullCheck()
723 || !IsLeafMethod());
724}
725
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000726void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000727 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000728}
729
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000730void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000731 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100732 DCHECK(!successor->IsExitBlock());
733
734 HBasicBlock* block = got->GetBlock();
735 HInstruction* previous = got->GetPrevious();
736
737 HLoopInformation* info = block->GetLoopInformation();
738 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
739 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
740 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
741 return;
742 }
743
744 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
745 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
746 }
747 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000748 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000749 }
750}
751
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000752void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000753 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000754}
755
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000756void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000757 if (kIsDebugBuild) {
758 __ Comment("Unreachable");
759 __ bkpt(0);
760 }
761}
762
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000763void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100764 LocationSummary* locations =
765 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100766 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100767 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100768 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100769 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000770}
771
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000772void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700773 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100774 if (cond->IsIntConstant()) {
775 // Constant condition, statically compared against 1.
776 int32_t cond_value = cond->AsIntConstant()->GetValue();
777 if (cond_value == 1) {
778 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
779 if_instr->IfTrueSuccessor())) {
780 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100781 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100782 return;
783 } else {
784 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100785 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100786 } else {
787 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
788 // Condition has been materialized, compare the output to 0
789 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
790 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
791 ShifterOperand(0));
792 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
793 } else {
794 // Condition has not been materialized, use its inputs as the
795 // comparison and its condition as the branch condition.
796 LocationSummary* locations = cond->GetLocations();
797 if (locations->InAt(1).IsRegister()) {
798 __ cmp(locations->InAt(0).As<Register>(),
799 ShifterOperand(locations->InAt(1).As<Register>()));
800 } else {
801 DCHECK(locations->InAt(1).IsConstant());
802 int32_t value =
803 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
804 ShifterOperand operand;
805 if (ShifterOperand::CanHoldArm(value, &operand)) {
806 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
807 } else {
808 Register temp = IP;
809 __ LoadImmediate(temp, value);
810 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
811 }
812 }
813 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
814 ARMCondition(cond->AsCondition()->GetCondition()));
815 }
Dave Allison20dfc792014-06-16 20:44:29 -0700816 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100817 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
818 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700819 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000820 }
821}
822
Dave Allison20dfc792014-06-16 20:44:29 -0700823
824void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100825 LocationSummary* locations =
826 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100827 locations->SetInAt(0, Location::RequiresRegister());
828 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100829 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100830 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100831 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000832}
833
Dave Allison20dfc792014-06-16 20:44:29 -0700834void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100835 if (!comp->NeedsMaterialization()) return;
836
837 LocationSummary* locations = comp->GetLocations();
838 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100839 __ cmp(locations->InAt(0).As<Register>(),
840 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100841 } else {
842 DCHECK(locations->InAt(1).IsConstant());
843 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
844 ShifterOperand operand;
845 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100846 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100847 } else {
848 Register temp = IP;
849 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100850 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100851 }
Dave Allison20dfc792014-06-16 20:44:29 -0700852 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100853 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100854 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100855 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100856 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100857 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700858}
859
860void LocationsBuilderARM::VisitEqual(HEqual* comp) {
861 VisitCondition(comp);
862}
863
864void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
865 VisitCondition(comp);
866}
867
868void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
869 VisitCondition(comp);
870}
871
872void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
873 VisitCondition(comp);
874}
875
876void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
877 VisitCondition(comp);
878}
879
880void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
881 VisitCondition(comp);
882}
883
884void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
885 VisitCondition(comp);
886}
887
888void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
889 VisitCondition(comp);
890}
891
892void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
893 VisitCondition(comp);
894}
895
896void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
897 VisitCondition(comp);
898}
899
900void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
901 VisitCondition(comp);
902}
903
904void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
905 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000906}
907
908void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000909 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000910}
911
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000912void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
913 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000914}
915
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000916void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100917 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000918}
919
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000920void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100921 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000922}
923
924void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100925 LocationSummary* locations =
926 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100927 switch (store->InputAt(1)->GetType()) {
928 case Primitive::kPrimBoolean:
929 case Primitive::kPrimByte:
930 case Primitive::kPrimChar:
931 case Primitive::kPrimShort:
932 case Primitive::kPrimInt:
933 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100934 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100935 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
936 break;
937
938 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100939 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100940 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
941 break;
942
943 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100944 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100945 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000946}
947
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000948void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000949}
950
951void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100952 LocationSummary* locations =
953 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100954 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000955}
956
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000957void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100958 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000959}
960
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100961void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100962 LocationSummary* locations =
963 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100964 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100965}
966
967void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
968 // Will be generated at use site.
969}
970
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100971void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
972 LocationSummary* locations =
973 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
974 locations->SetOut(Location::ConstantLocation(constant));
975}
976
977void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
978 // Will be generated at use site.
979}
980
981void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
982 LocationSummary* locations =
983 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
984 locations->SetOut(Location::ConstantLocation(constant));
985}
986
987void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
988 // Will be generated at use site.
989}
990
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000991void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000992 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000993}
994
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000995void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
996 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000997}
998
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000999void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001000 LocationSummary* locations =
1001 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001002 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001003}
1004
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001005void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001006 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001007}
1008
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001009void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001010 HandleInvoke(invoke);
1011}
1012
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001013void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001014 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001015}
1016
1017void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001018 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001019
1020 // TODO: Implement all kinds of calls:
1021 // 1) boot -> boot
1022 // 2) app -> boot
1023 // 3) app -> app
1024 //
1025 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1026
1027 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001028 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001029 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001030 __ LoadFromOffset(
1031 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001032 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001033 __ LoadFromOffset(
1034 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001035 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001036 __ LoadFromOffset(kLoadWord, LR, temp,
1037 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001038 // LR()
1039 __ blx(LR);
1040
1041 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1042 DCHECK(!codegen_->IsLeafMethod());
1043}
1044
1045void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1046 HandleInvoke(invoke);
1047}
1048
1049void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001050 LocationSummary* locations =
1051 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001052 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001053
1054 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001055 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001056 HInstruction* input = invoke->InputAt(i);
1057 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1058 }
1059
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001060 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001061}
1062
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001063
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001064void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001065 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001066 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1067 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1068 LocationSummary* locations = invoke->GetLocations();
1069 Location receiver = locations->InAt(0);
1070 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1071 // temp = object->GetClass();
1072 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001073 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1074 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001075 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001076 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001077 }
1078 // temp = temp->GetMethodAt(method_offset);
1079 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001080 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001081 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001082 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001083 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001084 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001085 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001086 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001087}
1088
Roland Levillain88cb1752014-10-20 16:36:47 +01001089void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1090 LocationSummary* locations =
1091 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1092 switch (neg->GetResultType()) {
1093 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001094 case Primitive::kPrimLong: {
1095 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001096 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001097 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001098 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001099 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001100
Roland Levillain88cb1752014-10-20 16:36:47 +01001101 case Primitive::kPrimFloat:
1102 case Primitive::kPrimDouble:
1103 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1104 break;
1105
1106 default:
1107 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1108 }
1109}
1110
1111void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1112 LocationSummary* locations = neg->GetLocations();
1113 Location out = locations->Out();
1114 Location in = locations->InAt(0);
1115 switch (neg->GetResultType()) {
1116 case Primitive::kPrimInt:
1117 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001118 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001119 break;
1120
1121 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001122 DCHECK(in.IsRegisterPair());
1123 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1124 __ rsbs(out.AsRegisterPairLow<Register>(),
1125 in.AsRegisterPairLow<Register>(),
1126 ShifterOperand(0));
1127 // We cannot emit an RSC (Reverse Subtract with Carry)
1128 // instruction here, as it does not exist in the Thumb-2
1129 // instruction set. We use the following approach
1130 // using SBC and SUB instead.
1131 //
1132 // out.hi = -C
1133 __ sbc(out.AsRegisterPairHigh<Register>(),
1134 out.AsRegisterPairHigh<Register>(),
1135 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1136 // out.hi = out.hi - in.hi
1137 __ sub(out.AsRegisterPairHigh<Register>(),
1138 out.AsRegisterPairHigh<Register>(),
1139 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1140 break;
1141
Roland Levillain88cb1752014-10-20 16:36:47 +01001142 case Primitive::kPrimFloat:
1143 case Primitive::kPrimDouble:
1144 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1145 break;
1146
1147 default:
1148 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1149 }
1150}
1151
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001152void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001153 LocationSummary* locations =
1154 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001155 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001156 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001157 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001158 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1159 locations->SetInAt(0, Location::RequiresRegister());
1160 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1161 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001162 break;
1163 }
1164
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001165 case Primitive::kPrimFloat:
1166 case Primitive::kPrimDouble: {
1167 locations->SetInAt(0, Location::RequiresFpuRegister());
1168 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001169 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001170 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001171 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001172
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001173 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001174 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001175 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001176}
1177
1178void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1179 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001180 Location out = locations->Out();
1181 Location first = locations->InAt(0);
1182 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001183 switch (add->GetResultType()) {
1184 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001185 if (second.IsRegister()) {
1186 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001187 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001188 __ AddConstant(out.As<Register>(),
1189 first.As<Register>(),
1190 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001191 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001192 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001193
1194 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001195 __ adds(out.AsRegisterPairLow<Register>(),
1196 first.AsRegisterPairLow<Register>(),
1197 ShifterOperand(second.AsRegisterPairLow<Register>()));
1198 __ adc(out.AsRegisterPairHigh<Register>(),
1199 first.AsRegisterPairHigh<Register>(),
1200 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001201 break;
1202
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001203 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001204 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001205 break;
1206
1207 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001208 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1209 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1210 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001211 break;
1212
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001213 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001214 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001215 }
1216}
1217
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001218void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001219 LocationSummary* locations =
1220 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001221 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001222 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001223 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001224 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1225 locations->SetInAt(0, Location::RequiresRegister());
1226 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1227 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001228 break;
1229 }
Calin Juravle11351682014-10-23 15:38:15 +01001230 case Primitive::kPrimFloat:
1231 case Primitive::kPrimDouble: {
1232 locations->SetInAt(0, Location::RequiresFpuRegister());
1233 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001234 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001235 break;
Calin Juravle11351682014-10-23 15:38:15 +01001236 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001237 default:
Calin Juravle11351682014-10-23 15:38:15 +01001238 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001239 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001240}
1241
1242void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1243 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001244 Location out = locations->Out();
1245 Location first = locations->InAt(0);
1246 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001247 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001248 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001249 if (second.IsRegister()) {
1250 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001251 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001252 __ AddConstant(out.As<Register>(),
1253 first.As<Register>(),
1254 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001255 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001256 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001257 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001258
Calin Juravle11351682014-10-23 15:38:15 +01001259 case Primitive::kPrimLong: {
1260 __ subs(out.AsRegisterPairLow<Register>(),
1261 first.AsRegisterPairLow<Register>(),
1262 ShifterOperand(second.AsRegisterPairLow<Register>()));
1263 __ sbc(out.AsRegisterPairHigh<Register>(),
1264 first.AsRegisterPairHigh<Register>(),
1265 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001266 break;
Calin Juravle11351682014-10-23 15:38:15 +01001267 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001268
Calin Juravle11351682014-10-23 15:38:15 +01001269 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001270 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001271 break;
Calin Juravle11351682014-10-23 15:38:15 +01001272 }
1273
1274 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001275 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1276 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1277 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001278 break;
1279 }
1280
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001281
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001282 default:
Calin Juravle11351682014-10-23 15:38:15 +01001283 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001284 }
1285}
1286
Calin Juravle34bacdf2014-10-07 20:23:36 +01001287void LocationsBuilderARM::VisitMul(HMul* mul) {
1288 LocationSummary* locations =
1289 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1290 switch (mul->GetResultType()) {
1291 case Primitive::kPrimInt:
1292 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001293 locations->SetInAt(0, Location::RequiresRegister());
1294 locations->SetInAt(1, Location::RequiresRegister());
1295 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001296 break;
1297 }
1298
Calin Juravleb5bfa962014-10-21 18:02:24 +01001299 case Primitive::kPrimFloat:
1300 case Primitive::kPrimDouble: {
1301 locations->SetInAt(0, Location::RequiresFpuRegister());
1302 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001303 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001304 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001305 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001306
1307 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001308 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001309 }
1310}
1311
1312void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1313 LocationSummary* locations = mul->GetLocations();
1314 Location out = locations->Out();
1315 Location first = locations->InAt(0);
1316 Location second = locations->InAt(1);
1317 switch (mul->GetResultType()) {
1318 case Primitive::kPrimInt: {
1319 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1320 break;
1321 }
1322 case Primitive::kPrimLong: {
1323 Register out_hi = out.AsRegisterPairHigh<Register>();
1324 Register out_lo = out.AsRegisterPairLow<Register>();
1325 Register in1_hi = first.AsRegisterPairHigh<Register>();
1326 Register in1_lo = first.AsRegisterPairLow<Register>();
1327 Register in2_hi = second.AsRegisterPairHigh<Register>();
1328 Register in2_lo = second.AsRegisterPairLow<Register>();
1329
1330 // Extra checks to protect caused by the existence of R1_R2.
1331 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1332 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1333 DCHECK_NE(out_hi, in1_lo);
1334 DCHECK_NE(out_hi, in2_lo);
1335
1336 // input: in1 - 64 bits, in2 - 64 bits
1337 // output: out
1338 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1339 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1340 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1341
1342 // IP <- in1.lo * in2.hi
1343 __ mul(IP, in1_lo, in2_hi);
1344 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1345 __ mla(out_hi, in1_hi, in2_lo, IP);
1346 // out.lo <- (in1.lo * in2.lo)[31:0];
1347 __ umull(out_lo, IP, in1_lo, in2_lo);
1348 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1349 __ add(out_hi, out_hi, ShifterOperand(IP));
1350 break;
1351 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001352
1353 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001354 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001355 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001356 }
1357
1358 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001359 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1360 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1361 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001362 break;
1363 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001364
1365 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001366 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001367 }
1368}
1369
Calin Juravle7c4954d2014-10-28 16:57:40 +00001370void LocationsBuilderARM::VisitDiv(HDiv* div) {
1371 LocationSummary* locations =
1372 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1373 switch (div->GetResultType()) {
1374 case Primitive::kPrimInt:
1375 case Primitive::kPrimLong: {
1376 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1377 break;
1378 }
1379 case Primitive::kPrimFloat:
1380 case Primitive::kPrimDouble: {
1381 locations->SetInAt(0, Location::RequiresFpuRegister());
1382 locations->SetInAt(1, Location::RequiresFpuRegister());
1383 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1384 break;
1385 }
1386
1387 default:
1388 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1389 }
1390}
1391
1392void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1393 LocationSummary* locations = div->GetLocations();
1394 Location out = locations->Out();
1395 Location first = locations->InAt(0);
1396 Location second = locations->InAt(1);
1397
1398 switch (div->GetResultType()) {
1399 case Primitive::kPrimInt:
1400 case Primitive::kPrimLong: {
1401 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1402 break;
1403 }
1404
1405 case Primitive::kPrimFloat: {
1406 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1407 break;
1408 }
1409
1410 case Primitive::kPrimDouble: {
1411 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1412 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1413 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1414 break;
1415 }
1416
1417 default:
1418 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1419 }
1420}
1421
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001422void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001423 LocationSummary* locations =
1424 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001425 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001426 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1427 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1428 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001429}
1430
1431void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1432 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001433 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001434 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001435 codegen_->InvokeRuntime(
1436 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001437}
1438
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001439void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1440 LocationSummary* locations =
1441 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1442 InvokeRuntimeCallingConvention calling_convention;
1443 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1444 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1445 locations->SetOut(Location::RegisterLocation(R0));
1446 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1447}
1448
1449void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1450 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001451 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001452 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001453 codegen_->InvokeRuntime(
1454 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001455}
1456
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001457void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001458 LocationSummary* locations =
1459 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001460 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1461 if (location.IsStackSlot()) {
1462 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1463 } else if (location.IsDoubleStackSlot()) {
1464 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001465 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001466 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001467}
1468
1469void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001470 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001471}
1472
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001473void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001474 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001475 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001476 locations->SetInAt(0, Location::RequiresRegister());
1477 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001478}
1479
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001480void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1481 LocationSummary* locations = not_->GetLocations();
1482 Location out = locations->Out();
1483 Location in = locations->InAt(0);
1484 switch (not_->InputAt(0)->GetType()) {
1485 case Primitive::kPrimBoolean:
1486 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1487 break;
1488
1489 case Primitive::kPrimInt:
1490 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1491 break;
1492
1493 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001494 __ mvn(out.AsRegisterPairLow<Register>(),
1495 ShifterOperand(in.AsRegisterPairLow<Register>()));
1496 __ mvn(out.AsRegisterPairHigh<Register>(),
1497 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001498 break;
1499
1500 default:
1501 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1502 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001503}
1504
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001505void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001506 LocationSummary* locations =
1507 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001508 locations->SetInAt(0, Location::RequiresRegister());
1509 locations->SetInAt(1, Location::RequiresRegister());
1510 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001511}
1512
1513void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1514 Label greater, done;
1515 LocationSummary* locations = compare->GetLocations();
1516 switch (compare->InputAt(0)->GetType()) {
1517 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001518 Register output = locations->Out().As<Register>();
1519 Location left = locations->InAt(0);
1520 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001521 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001522 __ cmp(left.AsRegisterPairHigh<Register>(),
1523 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001524 __ b(&less, LT);
1525 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001526 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1527 // the status flags.
1528 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001529 __ cmp(left.AsRegisterPairLow<Register>(),
1530 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001531 __ b(&done, EQ);
1532 __ b(&less, CC);
1533
1534 __ Bind(&greater);
1535 __ LoadImmediate(output, 1);
1536 __ b(&done);
1537
1538 __ Bind(&less);
1539 __ LoadImmediate(output, -1);
1540
1541 __ Bind(&done);
1542 break;
1543 }
1544 default:
1545 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1546 }
1547}
1548
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001549void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001550 LocationSummary* locations =
1551 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001552 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1553 locations->SetInAt(i, Location::Any());
1554 }
1555 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001556}
1557
1558void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001559 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001560}
1561
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001562void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001563 LocationSummary* locations =
1564 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001565 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001566 locations->SetInAt(0, Location::RequiresRegister());
1567 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001568 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001569 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001570 locations->AddTemp(Location::RequiresRegister());
1571 locations->AddTemp(Location::RequiresRegister());
1572 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001573}
1574
1575void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1576 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001577 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001578 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001579 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001580
1581 switch (field_type) {
1582 case Primitive::kPrimBoolean:
1583 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001584 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001585 __ StoreToOffset(kStoreByte, value, obj, offset);
1586 break;
1587 }
1588
1589 case Primitive::kPrimShort:
1590 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001591 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001592 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1593 break;
1594 }
1595
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001596 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001597 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001598 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001599 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001600 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001601 Register temp = locations->GetTemp(0).As<Register>();
1602 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001603 codegen_->MarkGCCard(temp, card, obj, value);
1604 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001605 break;
1606 }
1607
1608 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001609 Location value = locations->InAt(1);
1610 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001611 break;
1612 }
1613
1614 case Primitive::kPrimFloat:
1615 case Primitive::kPrimDouble:
1616 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001617 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001618 case Primitive::kPrimVoid:
1619 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001620 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001621 }
1622}
1623
1624void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001625 LocationSummary* locations =
1626 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001627 locations->SetInAt(0, Location::RequiresRegister());
1628 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001629}
1630
1631void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1632 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001633 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001634 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1635
1636 switch (instruction->GetType()) {
1637 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001638 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001639 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1640 break;
1641 }
1642
1643 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001644 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001645 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1646 break;
1647 }
1648
1649 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001650 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001651 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1652 break;
1653 }
1654
1655 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001656 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001657 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1658 break;
1659 }
1660
1661 case Primitive::kPrimInt:
1662 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001663 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001664 __ LoadFromOffset(kLoadWord, out, obj, offset);
1665 break;
1666 }
1667
1668 case Primitive::kPrimLong: {
1669 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001670 Location out = locations->Out();
1671 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001672 break;
1673 }
1674
1675 case Primitive::kPrimFloat:
1676 case Primitive::kPrimDouble:
1677 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001678 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001679 case Primitive::kPrimVoid:
1680 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001681 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001682 }
1683}
1684
1685void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001686 LocationSummary* locations =
1687 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001688 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001689 if (instruction->HasUses()) {
1690 locations->SetOut(Location::SameAsFirstInput());
1691 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001692}
1693
1694void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001695 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001696 codegen_->AddSlowPath(slow_path);
1697
1698 LocationSummary* locations = instruction->GetLocations();
1699 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001700
1701 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001702 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001703 __ b(slow_path->GetEntryLabel(), EQ);
1704 } else {
1705 DCHECK(obj.IsConstant()) << obj;
1706 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1707 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001708 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001709}
1710
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001711void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001712 LocationSummary* locations =
1713 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001714 locations->SetInAt(0, Location::RequiresRegister());
1715 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1716 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001717}
1718
1719void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1720 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001721 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001722 Location index = locations->InAt(1);
1723
1724 switch (instruction->GetType()) {
1725 case Primitive::kPrimBoolean: {
1726 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001727 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001728 if (index.IsConstant()) {
1729 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1730 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1731 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001732 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001733 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1734 }
1735 break;
1736 }
1737
1738 case Primitive::kPrimByte: {
1739 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001740 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001741 if (index.IsConstant()) {
1742 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1743 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1744 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001745 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001746 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1747 }
1748 break;
1749 }
1750
1751 case Primitive::kPrimShort: {
1752 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001753 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001754 if (index.IsConstant()) {
1755 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1756 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1757 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001758 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001759 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1760 }
1761 break;
1762 }
1763
1764 case Primitive::kPrimChar: {
1765 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001766 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001767 if (index.IsConstant()) {
1768 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1769 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1770 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001771 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001772 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1773 }
1774 break;
1775 }
1776
1777 case Primitive::kPrimInt:
1778 case Primitive::kPrimNot: {
1779 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1780 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001781 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001782 if (index.IsConstant()) {
1783 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1784 __ LoadFromOffset(kLoadWord, out, obj, offset);
1785 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001786 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001787 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1788 }
1789 break;
1790 }
1791
1792 case Primitive::kPrimLong: {
1793 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001794 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001795 if (index.IsConstant()) {
1796 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001797 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001798 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001799 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1800 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001801 }
1802 break;
1803 }
1804
1805 case Primitive::kPrimFloat:
1806 case Primitive::kPrimDouble:
1807 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001808 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001809 case Primitive::kPrimVoid:
1810 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001811 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001812 }
1813}
1814
1815void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001816 Primitive::Type value_type = instruction->GetComponentType();
1817 bool is_object = value_type == Primitive::kPrimNot;
1818 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1819 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1820 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001821 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001822 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1823 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1824 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001825 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001826 locations->SetInAt(0, Location::RequiresRegister());
1827 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1828 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001829 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001830}
1831
1832void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1833 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001834 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001835 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001836 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001837
1838 switch (value_type) {
1839 case Primitive::kPrimBoolean:
1840 case Primitive::kPrimByte: {
1841 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001842 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001843 if (index.IsConstant()) {
1844 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1845 __ StoreToOffset(kStoreByte, value, obj, offset);
1846 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001847 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001848 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1849 }
1850 break;
1851 }
1852
1853 case Primitive::kPrimShort:
1854 case Primitive::kPrimChar: {
1855 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001856 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001857 if (index.IsConstant()) {
1858 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1859 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1860 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001861 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001862 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1863 }
1864 break;
1865 }
1866
1867 case Primitive::kPrimInt: {
1868 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001869 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001870 if (index.IsConstant()) {
1871 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1872 __ StoreToOffset(kStoreWord, value, obj, offset);
1873 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001874 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001875 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1876 }
1877 break;
1878 }
1879
1880 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001881 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001882 break;
1883 }
1884
1885 case Primitive::kPrimLong: {
1886 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001887 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001888 if (index.IsConstant()) {
1889 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001890 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001891 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001892 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1893 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001894 }
1895 break;
1896 }
1897
1898 case Primitive::kPrimFloat:
1899 case Primitive::kPrimDouble:
1900 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001901 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001902 case Primitive::kPrimVoid:
1903 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001904 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001905 }
1906}
1907
1908void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001909 LocationSummary* locations =
1910 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001911 locations->SetInAt(0, Location::RequiresRegister());
1912 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001913}
1914
1915void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1916 LocationSummary* locations = instruction->GetLocations();
1917 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001918 Register obj = locations->InAt(0).As<Register>();
1919 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001920 __ LoadFromOffset(kLoadWord, out, obj, offset);
1921}
1922
1923void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001924 LocationSummary* locations =
1925 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001926 locations->SetInAt(0, Location::RequiresRegister());
1927 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001928 if (instruction->HasUses()) {
1929 locations->SetOut(Location::SameAsFirstInput());
1930 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001931}
1932
1933void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1934 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001935 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001936 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001937 codegen_->AddSlowPath(slow_path);
1938
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001939 Register index = locations->InAt(0).As<Register>();
1940 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001941
1942 __ cmp(index, ShifterOperand(length));
1943 __ b(slow_path->GetEntryLabel(), CS);
1944}
1945
1946void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1947 Label is_null;
1948 __ CompareAndBranchIfZero(value, &is_null);
1949 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1950 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1951 __ strb(card, Address(card, temp));
1952 __ Bind(&is_null);
1953}
1954
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001955void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1956 temp->SetLocations(nullptr);
1957}
1958
1959void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1960 // Nothing to do, this is driven by the code generator.
1961}
1962
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001963void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001964 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001965}
1966
1967void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001968 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1969}
1970
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001971void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
1972 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1973}
1974
1975void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001976 HBasicBlock* block = instruction->GetBlock();
1977 if (block->GetLoopInformation() != nullptr) {
1978 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1979 // The back edge will generate the suspend check.
1980 return;
1981 }
1982 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1983 // The goto will generate the suspend check.
1984 return;
1985 }
1986 GenerateSuspendCheck(instruction, nullptr);
1987}
1988
1989void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
1990 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001991 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001992 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001993 codegen_->AddSlowPath(slow_path);
1994
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001995 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001996 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001997 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001998 __ Bind(slow_path->GetReturnLabel());
1999 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002000 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002001 __ b(slow_path->GetEntryLabel());
2002 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002003}
2004
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002005ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2006 return codegen_->GetAssembler();
2007}
2008
2009void ParallelMoveResolverARM::EmitMove(size_t index) {
2010 MoveOperands* move = moves_.Get(index);
2011 Location source = move->GetSource();
2012 Location destination = move->GetDestination();
2013
2014 if (source.IsRegister()) {
2015 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002016 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002017 } else {
2018 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002019 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002020 SP, destination.GetStackIndex());
2021 }
2022 } else if (source.IsStackSlot()) {
2023 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002024 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002025 SP, source.GetStackIndex());
2026 } else {
2027 DCHECK(destination.IsStackSlot());
2028 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2029 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2030 }
2031 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002032 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002033 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002034 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2035 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002036 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002037 } else {
2038 DCHECK(destination.IsStackSlot());
2039 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002040 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002041 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002042 }
2043}
2044
2045void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2046 __ Mov(IP, reg);
2047 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2048 __ StoreToOffset(kStoreWord, IP, SP, mem);
2049}
2050
2051void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2052 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2053 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2054 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2055 SP, mem1 + stack_offset);
2056 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2057 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2058 SP, mem2 + stack_offset);
2059 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2060}
2061
2062void ParallelMoveResolverARM::EmitSwap(size_t index) {
2063 MoveOperands* move = moves_.Get(index);
2064 Location source = move->GetSource();
2065 Location destination = move->GetDestination();
2066
2067 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002068 DCHECK_NE(source.As<Register>(), IP);
2069 DCHECK_NE(destination.As<Register>(), IP);
2070 __ Mov(IP, source.As<Register>());
2071 __ Mov(source.As<Register>(), destination.As<Register>());
2072 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002073 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002074 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002075 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002076 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002077 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2078 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2079 } else {
2080 LOG(FATAL) << "Unimplemented";
2081 }
2082}
2083
2084void ParallelMoveResolverARM::SpillScratch(int reg) {
2085 __ Push(static_cast<Register>(reg));
2086}
2087
2088void ParallelMoveResolverARM::RestoreScratch(int reg) {
2089 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002090}
2091
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002092void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
2093 LocationSummary* locations =
2094 new (GetGraph()->GetArena()) LocationSummary(cls, LocationSummary::kNoCall);
2095 locations->SetOut(Location::RequiresRegister());
2096}
2097
2098void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2099 Register out = cls->GetLocations()->Out().As<Register>();
2100 if (cls->IsReferrersClass()) {
2101 codegen_->LoadCurrentMethod(out);
2102 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2103 } else {
2104 codegen_->LoadCurrentMethod(out);
2105 __ LoadFromOffset(
2106 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2107 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
2108 }
2109}
2110
2111void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2112 LocationSummary* locations =
2113 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2114 locations->SetInAt(0, Location::RequiresRegister());
2115 if (check->HasUses()) {
2116 locations->SetOut(Location::SameAsFirstInput());
2117 }
2118}
2119
2120void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
2121 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ClinitCheckSlowPathARM(check);
2122 codegen_->AddSlowPath(slow_path);
2123
2124 LocationSummary* locations = check->GetLocations();
2125 // We remove the class as a live register, we know it's null or unused in the slow path.
2126 RegisterSet* register_set = locations->GetLiveRegisters();
2127 register_set->Remove(locations->InAt(0));
2128
2129 Register class_reg = locations->InAt(0).As<Register>();
2130 __ cmp(class_reg, ShifterOperand(0));
2131 __ b(slow_path->GetEntryLabel(), EQ);
2132 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2133 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2134 __ b(slow_path->GetEntryLabel(), LT);
2135 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2136 // properly. Therefore, we do a memory fence.
2137 __ dmb(ISH);
2138 __ Bind(slow_path->GetExitLabel());
2139}
2140
2141void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2142 LocationSummary* locations =
2143 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2144 locations->SetInAt(0, Location::RequiresRegister());
2145 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2146}
2147
2148void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2149 LocationSummary* locations = instruction->GetLocations();
2150 Register cls = locations->InAt(0).As<Register>();
2151 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2152
2153 switch (instruction->GetType()) {
2154 case Primitive::kPrimBoolean: {
2155 Register out = locations->Out().As<Register>();
2156 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2157 break;
2158 }
2159
2160 case Primitive::kPrimByte: {
2161 Register out = locations->Out().As<Register>();
2162 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2163 break;
2164 }
2165
2166 case Primitive::kPrimShort: {
2167 Register out = locations->Out().As<Register>();
2168 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2169 break;
2170 }
2171
2172 case Primitive::kPrimChar: {
2173 Register out = locations->Out().As<Register>();
2174 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2175 break;
2176 }
2177
2178 case Primitive::kPrimInt:
2179 case Primitive::kPrimNot: {
2180 Register out = locations->Out().As<Register>();
2181 __ LoadFromOffset(kLoadWord, out, cls, offset);
2182 break;
2183 }
2184
2185 case Primitive::kPrimLong: {
2186 // TODO: support volatile.
2187 Location out = locations->Out();
2188 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2189 break;
2190 }
2191
2192 case Primitive::kPrimFloat:
2193 case Primitive::kPrimDouble:
2194 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2195 UNREACHABLE();
2196 case Primitive::kPrimVoid:
2197 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2198 UNREACHABLE();
2199 }
2200}
2201
2202void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2203 LocationSummary* locations =
2204 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2205 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2206 locations->SetInAt(0, Location::RequiresRegister());
2207 locations->SetInAt(1, Location::RequiresRegister());
2208 // Temporary registers for the write barrier.
2209 if (is_object_type) {
2210 locations->AddTemp(Location::RequiresRegister());
2211 locations->AddTemp(Location::RequiresRegister());
2212 }
2213}
2214
2215void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2216 LocationSummary* locations = instruction->GetLocations();
2217 Register cls = locations->InAt(0).As<Register>();
2218 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2219 Primitive::Type field_type = instruction->GetFieldType();
2220
2221 switch (field_type) {
2222 case Primitive::kPrimBoolean:
2223 case Primitive::kPrimByte: {
2224 Register value = locations->InAt(1).As<Register>();
2225 __ StoreToOffset(kStoreByte, value, cls, offset);
2226 break;
2227 }
2228
2229 case Primitive::kPrimShort:
2230 case Primitive::kPrimChar: {
2231 Register value = locations->InAt(1).As<Register>();
2232 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2233 break;
2234 }
2235
2236 case Primitive::kPrimInt:
2237 case Primitive::kPrimNot: {
2238 Register value = locations->InAt(1).As<Register>();
2239 __ StoreToOffset(kStoreWord, value, cls, offset);
2240 if (field_type == Primitive::kPrimNot) {
2241 Register temp = locations->GetTemp(0).As<Register>();
2242 Register card = locations->GetTemp(1).As<Register>();
2243 codegen_->MarkGCCard(temp, card, cls, value);
2244 }
2245 break;
2246 }
2247
2248 case Primitive::kPrimLong: {
2249 Location value = locations->InAt(1);
2250 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2251 break;
2252 }
2253
2254 case Primitive::kPrimFloat:
2255 case Primitive::kPrimDouble:
2256 LOG(FATAL) << "Unimplemented register type " << field_type;
2257 UNREACHABLE();
2258 case Primitive::kPrimVoid:
2259 LOG(FATAL) << "Unreachable type " << field_type;
2260 UNREACHABLE();
2261 }
2262}
2263
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002264} // namespace arm
2265} // namespace art