blob: bfada27d2c750b2832d8a03de4df56e18948d222 [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 Geoffray56b9ee62014-10-09 11:47:51 +010034static SRegister FromDToLowS(DRegister reg) {
35 return static_cast<SRegister>(reg * 2);
36}
37
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010038static constexpr bool kExplicitStackOverflowCheck = false;
39
40static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
41static constexpr int kCurrentMethodStackOffset = 0;
42
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010043static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2 };
44static constexpr size_t kRuntimeParameterCoreRegistersLength =
45 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010046static constexpr DRegister kRuntimeParameterFpuRegisters[] = { };
47static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010048
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010049class InvokeRuntimeCallingConvention : public CallingConvention<Register, DRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010050 public:
51 InvokeRuntimeCallingConvention()
52 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010053 kRuntimeParameterCoreRegistersLength,
54 kRuntimeParameterFpuRegisters,
55 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010056
57 private:
58 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
59};
60
Nicolas Geoffraye5038322014-07-04 09:41:32 +010061#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
62
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010063class SlowPathCodeARM : public SlowPathCode {
64 public:
65 SlowPathCodeARM() : entry_label_(), exit_label_() {}
66
67 Label* GetEntryLabel() { return &entry_label_; }
68 Label* GetExitLabel() { return &exit_label_; }
69
70 private:
71 Label entry_label_;
72 Label exit_label_;
73
74 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
75};
76
77class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010078 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010079 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080
81 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
82 __ Bind(GetEntryLabel());
83 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowNullPointer).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +010084 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +010086 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010087 }
88
89 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010090 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010091 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
92};
93
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010094class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010095 public:
96 StackOverflowCheckSlowPathARM() {}
97
98 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
99 __ Bind(GetEntryLabel());
100 __ LoadFromOffset(kLoadWord, PC, TR,
101 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
102 }
103
104 private:
105 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
106};
107
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100108class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000109 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100110 explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
111 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000112
113 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100114 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000115 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100116 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000117 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pTestSuspend).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100118 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000119 __ blx(LR);
120 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100121 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100122 if (successor_ == nullptr) {
123 __ b(GetReturnLabel());
124 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100125 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100126 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 }
128
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 Label* GetReturnLabel() {
130 DCHECK(successor_ == nullptr);
131 return &return_label_;
132 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000133
134 private:
135 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100136 // If not null, the block to branch to after the suspend check.
137 HBasicBlock* const successor_;
138
139 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000140 Label return_label_;
141
142 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
143};
144
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100145class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100146 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100147 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
148 Location index_location,
149 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100150 : instruction_(instruction),
151 index_location_(index_location),
152 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100153
154 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100155 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100156 __ Bind(GetEntryLabel());
157 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100158 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
159 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100160 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowArrayBounds).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100161 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100163 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100164 }
165
166 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100167 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168 const Location index_location_;
169 const Location length_location_;
170
171 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
172};
173
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100174#undef __
175#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700176
177inline Condition ARMCondition(IfCondition cond) {
178 switch (cond) {
179 case kCondEQ: return EQ;
180 case kCondNE: return NE;
181 case kCondLT: return LT;
182 case kCondLE: return LE;
183 case kCondGT: return GT;
184 case kCondGE: return GE;
185 default:
186 LOG(FATAL) << "Unknown if condition";
187 }
188 return EQ; // Unreachable.
189}
190
191inline Condition ARMOppositeCondition(IfCondition cond) {
192 switch (cond) {
193 case kCondEQ: return NE;
194 case kCondNE: return EQ;
195 case kCondLT: return GE;
196 case kCondLE: return GT;
197 case kCondGT: return LE;
198 case kCondGE: return LT;
199 default:
200 LOG(FATAL) << "Unknown if condition";
201 }
202 return EQ; // Unreachable.
203}
204
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100205void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
206 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
207}
208
209void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
210 stream << ArmManagedRegister::FromDRegister(DRegister(reg));
211}
212
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100213void CodeGeneratorARM::SaveCoreRegister(Location stack_location, uint32_t reg_id) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100214 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_location.GetStackIndex());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100215}
216
217void CodeGeneratorARM::RestoreCoreRegister(Location stack_location, uint32_t reg_id) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100218 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_location.GetStackIndex());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100219}
220
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100221CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100222 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfDRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100223 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100224 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100225 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100226 move_resolver_(graph->GetArena(), this),
227 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100228
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100229size_t CodeGeneratorARM::FrameEntrySpillSize() const {
230 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
231}
232
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100233Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100234 switch (type) {
235 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100236 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100237 ArmManagedRegister pair =
238 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100239 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
240 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
241
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100242 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
243 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100244 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100245 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100246 }
247
248 case Primitive::kPrimByte:
249 case Primitive::kPrimBoolean:
250 case Primitive::kPrimChar:
251 case Primitive::kPrimShort:
252 case Primitive::kPrimInt:
253 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100254 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100255 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100256 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
257 ArmManagedRegister current =
258 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
259 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100260 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100261 }
262 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100263 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100264 }
265
266 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100267 case Primitive::kPrimDouble: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100268 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfDRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100269 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100270 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100271
272 case Primitive::kPrimVoid:
273 LOG(FATAL) << "Unreachable type " << type;
274 }
275
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100276 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100277}
278
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100279void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100280 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100281 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100282
283 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100284 blocked_core_registers_[SP] = true;
285 blocked_core_registers_[LR] = true;
286 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100287
288 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100289 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100290
291 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100292 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100293
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100294 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100295 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100296
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100297 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100298 // We always save and restore R6 and R7 to make sure we can use three
299 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100300 blocked_core_registers_[R5] = true;
301 blocked_core_registers_[R8] = true;
302 blocked_core_registers_[R10] = true;
303 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100304
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100305 blocked_fpu_registers_[D8] = true;
306 blocked_fpu_registers_[D9] = true;
307 blocked_fpu_registers_[D10] = true;
308 blocked_fpu_registers_[D11] = true;
309 blocked_fpu_registers_[D12] = true;
310 blocked_fpu_registers_[D13] = true;
311 blocked_fpu_registers_[D14] = true;
312 blocked_fpu_registers_[D15] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100313
314 UpdateBlockedPairRegisters();
315}
316
317void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
318 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
319 ArmManagedRegister current =
320 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
321 if (blocked_core_registers_[current.AsRegisterPairLow()]
322 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
323 blocked_register_pairs_[i] = true;
324 }
325 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100326}
327
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100328InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
329 : HGraphVisitor(graph),
330 assembler_(codegen->GetAssembler()),
331 codegen_(codegen) {}
332
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000333void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700334 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100335 if (!skip_overflow_check) {
336 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100337 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100338 AddSlowPath(slow_path);
339
340 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
341 __ cmp(SP, ShifterOperand(IP));
342 __ b(slow_path->GetEntryLabel(), CC);
343 } else {
344 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100345 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100346 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100347 }
348 }
349
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100350 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
351 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000352
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100353 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100354 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100355 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000356}
357
358void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100359 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100360 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000361}
362
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100363void CodeGeneratorARM::Bind(HBasicBlock* block) {
364 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000365}
366
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100367Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
368 switch (load->GetType()) {
369 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100370 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100371 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
372 break;
373
374 case Primitive::kPrimInt:
375 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100376 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100377 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100378
379 case Primitive::kPrimBoolean:
380 case Primitive::kPrimByte:
381 case Primitive::kPrimChar:
382 case Primitive::kPrimShort:
383 case Primitive::kPrimVoid:
384 LOG(FATAL) << "Unexpected type " << load->GetType();
385 }
386
387 LOG(FATAL) << "Unreachable";
388 return Location();
389}
390
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100391Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
392 switch (type) {
393 case Primitive::kPrimBoolean:
394 case Primitive::kPrimByte:
395 case Primitive::kPrimChar:
396 case Primitive::kPrimShort:
397 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100398 case Primitive::kPrimFloat:
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100399 case Primitive::kPrimNot: {
400 uint32_t index = gp_index_++;
401 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100402 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100403 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100404 return Location::StackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100405 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100406 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100407
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100408 case Primitive::kPrimLong:
409 case Primitive::kPrimDouble: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100410 uint32_t index = gp_index_;
411 gp_index_ += 2;
412 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100413 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
414 calling_convention.GetRegisterPairAt(index));
415 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100416 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
417 return Location::QuickParameter(index);
418 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100419 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100420 }
421 }
422
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100423 case Primitive::kPrimVoid:
424 LOG(FATAL) << "Unexpected parameter type " << type;
425 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100426 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100427 return Location();
428}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100429
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100430void CodeGeneratorARM::Move32(Location destination, Location source) {
431 if (source.Equals(destination)) {
432 return;
433 }
434 if (destination.IsRegister()) {
435 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100436 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100437 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100438 __ vmovrs(destination.As<Register>(), FromDToLowS(source.As<DRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100439 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100440 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100441 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100442 } else if (destination.IsFpuRegister()) {
443 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100444 __ vmovsr(FromDToLowS(destination.As<DRegister>()), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100445 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100446 __ vmovs(FromDToLowS(destination.As<DRegister>()), FromDToLowS(source.As<DRegister>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100447 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100448 __ vldrs(FromDToLowS(destination.As<DRegister>()), Address(SP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100449 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100450 } else {
451 DCHECK(destination.IsStackSlot());
452 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100453 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100454 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100455 __ vstrs(FromDToLowS(source.As<DRegister>()), Address(SP, destination.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100456 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100457 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100458 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
459 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100460 }
461 }
462}
463
464void CodeGeneratorARM::Move64(Location destination, Location source) {
465 if (source.Equals(destination)) {
466 return;
467 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100468 if (destination.IsRegisterPair()) {
469 if (source.IsRegisterPair()) {
470 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
471 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100472 } else if (source.IsFpuRegister()) {
473 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100474 } else if (source.IsQuickParameter()) {
475 uint32_t argument_index = source.GetQuickParameterIndex();
476 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100477 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100478 calling_convention.GetRegisterAt(argument_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100479 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
480 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100481 } else {
482 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100483 if (destination.AsRegisterPairLow<Register>() == R1) {
484 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100485 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
486 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100487 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100488 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100489 SP, source.GetStackIndex());
490 }
491 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100492 } else if (destination.IsFpuRegister()) {
493 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100494 __ vldrd(destination.As<DRegister>(), Address(SP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100495 } else {
496 LOG(FATAL) << "Unimplemented";
497 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100498 } else if (destination.IsQuickParameter()) {
499 InvokeDexCallingConvention calling_convention;
500 uint32_t argument_index = destination.GetQuickParameterIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100501 if (source.IsRegisterPair()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100502 __ Mov(calling_convention.GetRegisterAt(argument_index),
503 source.AsRegisterPairLow<Register>());
504 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
505 SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100506 } else if (source.IsFpuRegister()) {
507 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100508 } else {
509 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100510 __ LoadFromOffset(kLoadWord, calling_convention.GetRegisterAt(argument_index), SP, source.GetStackIndex());
511 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
512 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100513 }
514 } else {
515 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100516 if (source.IsRegisterPair()) {
517 if (source.AsRegisterPairLow<Register>() == R1) {
518 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100519 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
520 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100521 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100522 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100523 SP, destination.GetStackIndex());
524 }
525 } else if (source.IsQuickParameter()) {
526 InvokeDexCallingConvention calling_convention;
527 uint32_t argument_index = source.GetQuickParameterIndex();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100528 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(argument_index),
529 SP, destination.GetStackIndex());
530 __ LoadFromOffset(kLoadWord, R0,
531 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
532 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100533 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100534 __ vstrd(source.As<DRegister>(), Address(SP, destination.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100535 } else {
536 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100537 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
538 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
539 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
540 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100541 }
542 }
543}
544
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100545void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100546 LocationSummary* locations = instruction->GetLocations();
547 if (locations != nullptr && locations->Out().Equals(location)) {
548 return;
549 }
550
Roland Levillain476df552014-10-09 17:51:36 +0100551 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100552 int32_t value = instruction->AsIntConstant()->GetValue();
553 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100554 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100555 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100556 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100557 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100558 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100559 }
Roland Levillain476df552014-10-09 17:51:36 +0100560 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100561 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100562 if (location.IsRegisterPair()) {
563 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
564 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100565 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100566 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100567 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100568 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100569 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100570 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100571 }
Roland Levillain476df552014-10-09 17:51:36 +0100572 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100573 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
574 switch (instruction->GetType()) {
575 case Primitive::kPrimBoolean:
576 case Primitive::kPrimByte:
577 case Primitive::kPrimChar:
578 case Primitive::kPrimShort:
579 case Primitive::kPrimInt:
580 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100581 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100582 Move32(location, Location::StackSlot(stack_slot));
583 break;
584
585 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100586 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100587 Move64(location, Location::DoubleStackSlot(stack_slot));
588 break;
589
590 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100591 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100592 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000593 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100594 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100595 switch (instruction->GetType()) {
596 case Primitive::kPrimBoolean:
597 case Primitive::kPrimByte:
598 case Primitive::kPrimChar:
599 case Primitive::kPrimShort:
600 case Primitive::kPrimNot:
601 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100602 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100603 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100604 break;
605
606 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100607 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100608 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100609 break;
610
611 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100612 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100613 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000614 }
615}
616
617void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000618 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000619}
620
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000621void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000622 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100623 DCHECK(!successor->IsExitBlock());
624
625 HBasicBlock* block = got->GetBlock();
626 HInstruction* previous = got->GetPrevious();
627
628 HLoopInformation* info = block->GetLoopInformation();
629 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
630 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
631 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
632 return;
633 }
634
635 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
636 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
637 }
638 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000639 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000640 }
641}
642
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000643void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000644 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000645}
646
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000647void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000648 if (kIsDebugBuild) {
649 __ Comment("Unreachable");
650 __ bkpt(0);
651 }
652}
653
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000654void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100655 LocationSummary* locations =
656 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100657 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100658 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +0100659 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100660 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000661}
662
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000663void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700664 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100665 if (cond->IsIntConstant()) {
666 // Constant condition, statically compared against 1.
667 int32_t cond_value = cond->AsIntConstant()->GetValue();
668 if (cond_value == 1) {
669 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
670 if_instr->IfTrueSuccessor())) {
671 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100672 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100673 return;
674 } else {
675 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100676 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100677 } else {
678 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
679 // Condition has been materialized, compare the output to 0
680 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
681 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
682 ShifterOperand(0));
683 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
684 } else {
685 // Condition has not been materialized, use its inputs as the
686 // comparison and its condition as the branch condition.
687 LocationSummary* locations = cond->GetLocations();
688 if (locations->InAt(1).IsRegister()) {
689 __ cmp(locations->InAt(0).As<Register>(),
690 ShifterOperand(locations->InAt(1).As<Register>()));
691 } else {
692 DCHECK(locations->InAt(1).IsConstant());
693 int32_t value =
694 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
695 ShifterOperand operand;
696 if (ShifterOperand::CanHoldArm(value, &operand)) {
697 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
698 } else {
699 Register temp = IP;
700 __ LoadImmediate(temp, value);
701 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
702 }
703 }
704 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
705 ARMCondition(cond->AsCondition()->GetCondition()));
706 }
Dave Allison20dfc792014-06-16 20:44:29 -0700707 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100708 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
709 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700710 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000711 }
712}
713
Dave Allison20dfc792014-06-16 20:44:29 -0700714
715void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100716 LocationSummary* locations =
717 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +0100718 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
719 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)), Location::kDiesAtEntry);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100720 if (comp->NeedsMaterialization()) {
721 locations->SetOut(Location::RequiresRegister());
722 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000723}
724
Dave Allison20dfc792014-06-16 20:44:29 -0700725void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100726 if (!comp->NeedsMaterialization()) return;
727
728 LocationSummary* locations = comp->GetLocations();
729 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100730 __ cmp(locations->InAt(0).As<Register>(),
731 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100732 } else {
733 DCHECK(locations->InAt(1).IsConstant());
734 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
735 ShifterOperand operand;
736 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100737 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100738 } else {
739 Register temp = IP;
740 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100741 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100742 }
Dave Allison20dfc792014-06-16 20:44:29 -0700743 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100744 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100745 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100746 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100747 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100748 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700749}
750
751void LocationsBuilderARM::VisitEqual(HEqual* comp) {
752 VisitCondition(comp);
753}
754
755void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
756 VisitCondition(comp);
757}
758
759void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
760 VisitCondition(comp);
761}
762
763void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
764 VisitCondition(comp);
765}
766
767void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
768 VisitCondition(comp);
769}
770
771void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
772 VisitCondition(comp);
773}
774
775void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
776 VisitCondition(comp);
777}
778
779void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
780 VisitCondition(comp);
781}
782
783void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
784 VisitCondition(comp);
785}
786
787void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
788 VisitCondition(comp);
789}
790
791void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
792 VisitCondition(comp);
793}
794
795void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
796 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000797}
798
799void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000800 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000801}
802
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000803void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
804 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000805}
806
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000807void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100808 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000809}
810
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000811void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100812 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000813}
814
815void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100816 LocationSummary* locations =
817 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100818 switch (store->InputAt(1)->GetType()) {
819 case Primitive::kPrimBoolean:
820 case Primitive::kPrimByte:
821 case Primitive::kPrimChar:
822 case Primitive::kPrimShort:
823 case Primitive::kPrimInt:
824 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100825 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100826 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
827 break;
828
829 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100830 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100831 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
832 break;
833
834 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100835 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100836 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000837}
838
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000839void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000840}
841
842void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100843 LocationSummary* locations =
844 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100845 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000846}
847
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000848void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100849 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000850}
851
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100852void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100853 LocationSummary* locations =
854 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100855 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100856}
857
858void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
859 // Will be generated at use site.
860}
861
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000862void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000863 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000864}
865
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000866void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
867 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000868}
869
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000870void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100871 LocationSummary* locations =
872 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100873 switch (ret->InputAt(0)->GetType()) {
874 case Primitive::kPrimBoolean:
875 case Primitive::kPrimByte:
876 case Primitive::kPrimChar:
877 case Primitive::kPrimShort:
878 case Primitive::kPrimInt:
879 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100880 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100881 locations->SetInAt(0, Location::RegisterLocation(R0));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100882 break;
883
884 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100885 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100886 locations->SetInAt(0, Location::RegisterPairLocation(R0, R1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100887 break;
888
889 default:
890 LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType();
891 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000892}
893
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000894void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100895 if (kIsDebugBuild) {
896 switch (ret->InputAt(0)->GetType()) {
897 case Primitive::kPrimBoolean:
898 case Primitive::kPrimByte:
899 case Primitive::kPrimChar:
900 case Primitive::kPrimShort:
901 case Primitive::kPrimInt:
902 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100903 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100904 DCHECK_EQ(ret->GetLocations()->InAt(0).As<Register>(), R0);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100905 break;
906
907 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100908 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100909 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), R0);
910 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), R1);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100911 break;
912
913 default:
914 LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType();
915 }
916 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000917 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000918}
919
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000920void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100921 HandleInvoke(invoke);
922}
923
924void InstructionCodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100925 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100926}
927
928void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100929 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100930 uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>);
931 size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).Int32Value() +
932 invoke->GetIndexInDexCache() * kArmWordSize;
933
934 // TODO: Implement all kinds of calls:
935 // 1) boot -> boot
936 // 2) app -> boot
937 // 3) app -> app
938 //
939 // Currently we implement the app -> app logic, which looks up in the resolve cache.
940
941 // temp = method;
942 LoadCurrentMethod(temp);
943 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100944 __ LoadFromOffset(kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100945 // temp = temp[index_in_cache]
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100946 __ LoadFromOffset(kLoadWord, temp, temp, index_in_cache);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100947 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100948 __ LoadFromOffset(kLoadWord, LR, temp,
949 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100950 // LR()
951 __ blx(LR);
952
953 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
954 DCHECK(!codegen_->IsLeafMethod());
955}
956
957void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
958 HandleInvoke(invoke);
959}
960
961void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100962 LocationSummary* locations =
963 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100964 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100965
966 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100967 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100968 HInstruction* input = invoke->InputAt(i);
969 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
970 }
971
972 switch (invoke->GetType()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100973 case Primitive::kPrimBoolean:
974 case Primitive::kPrimByte:
975 case Primitive::kPrimChar:
976 case Primitive::kPrimShort:
977 case Primitive::kPrimInt:
978 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100979 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100980 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100981 break;
982
983 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100984 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100985 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100986 break;
987
988 case Primitive::kPrimVoid:
989 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100990 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000991}
992
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000993
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100994void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100995 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100996 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
997 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
998 LocationSummary* locations = invoke->GetLocations();
999 Location receiver = locations->InAt(0);
1000 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1001 // temp = object->GetClass();
1002 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001003 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1004 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001005 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001006 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001007 }
1008 // temp = temp->GetMethodAt(method_offset);
1009 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001010 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001011 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001012 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001013 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001014 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001015 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001016 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001017}
1018
Roland Levillain88cb1752014-10-20 16:36:47 +01001019void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1020 LocationSummary* locations =
1021 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1022 switch (neg->GetResultType()) {
1023 case Primitive::kPrimInt:
1024 locations->SetInAt(0, Location::RequiresRegister());
1025 locations->SetOut(Location::RequiresRegister());
1026 break;
1027
1028 case Primitive::kPrimLong:
1029 case Primitive::kPrimFloat:
1030 case Primitive::kPrimDouble:
1031 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1032 break;
1033
1034 default:
1035 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1036 }
1037}
1038
1039void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1040 LocationSummary* locations = neg->GetLocations();
1041 Location out = locations->Out();
1042 Location in = locations->InAt(0);
1043 switch (neg->GetResultType()) {
1044 case Primitive::kPrimInt:
1045 DCHECK(in.IsRegister());
1046 __ rsbs(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
1047 break;
1048
1049 case Primitive::kPrimLong:
1050 case Primitive::kPrimFloat:
1051 case Primitive::kPrimDouble:
1052 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1053 break;
1054
1055 default:
1056 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1057 }
1058}
1059
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001060void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001061 LocationSummary* locations =
1062 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001063 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001064 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001065 case Primitive::kPrimLong: {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001066 bool dies_at_entry = add->GetResultType() != Primitive::kPrimLong;
1067 locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry);
1068 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)), dies_at_entry);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001069 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001070 break;
1071 }
1072
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001073 case Primitive::kPrimFloat:
1074 case Primitive::kPrimDouble: {
1075 locations->SetInAt(0, Location::RequiresFpuRegister());
1076 locations->SetInAt(1, Location::RequiresFpuRegister());
1077 locations->SetOut(Location::RequiresFpuRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001078 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001079 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001080
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001081 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001082 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001083 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001084}
1085
1086void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1087 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001088 Location out = locations->Out();
1089 Location first = locations->InAt(0);
1090 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001091 switch (add->GetResultType()) {
1092 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001093 if (second.IsRegister()) {
1094 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001095 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001096 __ AddConstant(out.As<Register>(),
1097 first.As<Register>(),
1098 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001099 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001100 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001101
1102 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001103 __ adds(out.AsRegisterPairLow<Register>(),
1104 first.AsRegisterPairLow<Register>(),
1105 ShifterOperand(second.AsRegisterPairLow<Register>()));
1106 __ adc(out.AsRegisterPairHigh<Register>(),
1107 first.AsRegisterPairHigh<Register>(),
1108 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001109 break;
1110
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001111 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001112 __ vadds(FromDToLowS(out.As<DRegister>()),
1113 FromDToLowS(first.As<DRegister>()),
1114 FromDToLowS(second.As<DRegister>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001115 break;
1116
1117 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001118 __ vaddd(out.As<DRegister>(), first.As<DRegister>(), second.As<DRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001119 break;
1120
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001121 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001122 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001123 }
1124}
1125
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001126void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001127 LocationSummary* locations =
1128 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001129 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001130 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001131 case Primitive::kPrimLong: {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001132 bool dies_at_entry = sub->GetResultType() != Primitive::kPrimLong;
1133 locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry);
1134 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)), dies_at_entry);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001135 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001136 break;
1137 }
1138
1139 case Primitive::kPrimBoolean:
1140 case Primitive::kPrimByte:
1141 case Primitive::kPrimChar:
1142 case Primitive::kPrimShort:
1143 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1144 break;
1145
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001146 default:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001147 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001148 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001149}
1150
1151void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1152 LocationSummary* locations = sub->GetLocations();
1153 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001154 case Primitive::kPrimInt: {
1155 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001156 __ sub(locations->Out().As<Register>(),
1157 locations->InAt(0).As<Register>(),
1158 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001159 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001160 __ AddConstant(locations->Out().As<Register>(),
1161 locations->InAt(0).As<Register>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001162 -locations->InAt(1).GetConstant()->AsIntConstant()->GetValue());
1163 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001164 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001165 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001166
1167 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001168 __ subs(locations->Out().AsRegisterPairLow<Register>(),
1169 locations->InAt(0).AsRegisterPairLow<Register>(),
1170 ShifterOperand(locations->InAt(1).AsRegisterPairLow<Register>()));
1171 __ sbc(locations->Out().AsRegisterPairHigh<Register>(),
1172 locations->InAt(0).AsRegisterPairHigh<Register>(),
1173 ShifterOperand(locations->InAt(1).AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001174 break;
1175
1176 case Primitive::kPrimBoolean:
1177 case Primitive::kPrimByte:
1178 case Primitive::kPrimChar:
1179 case Primitive::kPrimShort:
1180 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1181 break;
1182
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001183 default:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001184 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001185 }
1186}
1187
Calin Juravle34bacdf2014-10-07 20:23:36 +01001188void LocationsBuilderARM::VisitMul(HMul* mul) {
1189 LocationSummary* locations =
1190 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1191 switch (mul->GetResultType()) {
1192 case Primitive::kPrimInt:
1193 case Primitive::kPrimLong: {
1194 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1195 locations->SetInAt(1, Location::RequiresRegister(), Location::kDiesAtEntry);
1196 locations->SetOut(Location::RequiresRegister());
1197 break;
1198 }
1199
1200 case Primitive::kPrimBoolean:
1201 case Primitive::kPrimByte:
1202 case Primitive::kPrimChar:
1203 case Primitive::kPrimShort:
1204 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1205 break;
1206
1207 default:
1208 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1209 }
1210}
1211
1212void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1213 LocationSummary* locations = mul->GetLocations();
1214 Location out = locations->Out();
1215 Location first = locations->InAt(0);
1216 Location second = locations->InAt(1);
1217 switch (mul->GetResultType()) {
1218 case Primitive::kPrimInt: {
1219 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1220 break;
1221 }
1222 case Primitive::kPrimLong: {
1223 Register out_hi = out.AsRegisterPairHigh<Register>();
1224 Register out_lo = out.AsRegisterPairLow<Register>();
1225 Register in1_hi = first.AsRegisterPairHigh<Register>();
1226 Register in1_lo = first.AsRegisterPairLow<Register>();
1227 Register in2_hi = second.AsRegisterPairHigh<Register>();
1228 Register in2_lo = second.AsRegisterPairLow<Register>();
1229
1230 // Extra checks to protect caused by the existence of R1_R2.
1231 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1232 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1233 DCHECK_NE(out_hi, in1_lo);
1234 DCHECK_NE(out_hi, in2_lo);
1235
1236 // input: in1 - 64 bits, in2 - 64 bits
1237 // output: out
1238 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1239 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1240 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1241
1242 // IP <- in1.lo * in2.hi
1243 __ mul(IP, in1_lo, in2_hi);
1244 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1245 __ mla(out_hi, in1_hi, in2_lo, IP);
1246 // out.lo <- (in1.lo * in2.lo)[31:0];
1247 __ umull(out_lo, IP, in1_lo, in2_lo);
1248 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1249 __ add(out_hi, out_hi, ShifterOperand(IP));
1250 break;
1251 }
1252 case Primitive::kPrimBoolean:
1253 case Primitive::kPrimByte:
1254 case Primitive::kPrimChar:
1255 case Primitive::kPrimShort:
1256 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1257 break;
1258
1259 default:
1260 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1261 }
1262}
1263
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001264void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001265 LocationSummary* locations =
1266 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001267 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001268 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1269 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1270 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001271}
1272
1273void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1274 InvokeRuntimeCallingConvention calling_convention;
1275 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1276 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1277
Nicolas Geoffray707c8092014-04-04 10:50:14 +01001278 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocObjectWithAccessCheck).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001279 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001280 __ blx(LR);
1281
Nicolas Geoffray39468442014-09-02 15:17:15 +01001282 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001283 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001284}
1285
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001286void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001287 LocationSummary* locations =
1288 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001289 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1290 if (location.IsStackSlot()) {
1291 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1292 } else if (location.IsDoubleStackSlot()) {
1293 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001294 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001295 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001296}
1297
1298void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001299 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001300}
1301
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001302void LocationsBuilderARM::VisitNot(HNot* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001303 LocationSummary* locations =
1304 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001305 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001306 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001307}
1308
1309void InstructionCodeGeneratorARM::VisitNot(HNot* instruction) {
1310 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001311 __ eor(locations->Out().As<Register>(),
1312 locations->InAt(0).As<Register>(), ShifterOperand(1));
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001313}
1314
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001315void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001316 LocationSummary* locations =
1317 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001318 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1319 locations->SetInAt(1, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001320 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001321}
1322
1323void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1324 Label greater, done;
1325 LocationSummary* locations = compare->GetLocations();
1326 switch (compare->InputAt(0)->GetType()) {
1327 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001328 Register output = locations->Out().As<Register>();
1329 Location left = locations->InAt(0);
1330 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001331 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001332 __ cmp(left.AsRegisterPairHigh<Register>(),
1333 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001334 __ b(&less, LT);
1335 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001336 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1337 // the status flags.
1338 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001339 __ cmp(left.AsRegisterPairLow<Register>(),
1340 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001341 __ b(&done, EQ);
1342 __ b(&less, CC);
1343
1344 __ Bind(&greater);
1345 __ LoadImmediate(output, 1);
1346 __ b(&done);
1347
1348 __ Bind(&less);
1349 __ LoadImmediate(output, -1);
1350
1351 __ Bind(&done);
1352 break;
1353 }
1354 default:
1355 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1356 }
1357}
1358
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001359void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001360 LocationSummary* locations =
1361 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001362 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1363 locations->SetInAt(i, Location::Any());
1364 }
1365 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001366}
1367
1368void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001369 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001370}
1371
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001372void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001373 LocationSummary* locations =
1374 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001375 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
1376 bool dies_at_entry = !is_object_type;
1377 locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry);
1378 locations->SetInAt(1, Location::RequiresRegister(), dies_at_entry);
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001379 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001380 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001381 locations->AddTemp(Location::RequiresRegister());
1382 locations->AddTemp(Location::RequiresRegister());
1383 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001384}
1385
1386void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1387 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001388 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001389 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001390 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001391
1392 switch (field_type) {
1393 case Primitive::kPrimBoolean:
1394 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001395 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001396 __ StoreToOffset(kStoreByte, value, obj, offset);
1397 break;
1398 }
1399
1400 case Primitive::kPrimShort:
1401 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001402 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001403 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1404 break;
1405 }
1406
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001407 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001408 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001409 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001410 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001411 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001412 Register temp = locations->GetTemp(0).As<Register>();
1413 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001414 codegen_->MarkGCCard(temp, card, obj, value);
1415 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001416 break;
1417 }
1418
1419 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001420 Location value = locations->InAt(1);
1421 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001422 break;
1423 }
1424
1425 case Primitive::kPrimFloat:
1426 case Primitive::kPrimDouble:
1427 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001428 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001429 case Primitive::kPrimVoid:
1430 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001431 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001432 }
1433}
1434
1435void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001436 LocationSummary* locations =
1437 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001438 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001439 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001440}
1441
1442void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1443 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001444 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001445 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1446
1447 switch (instruction->GetType()) {
1448 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001449 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001450 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1451 break;
1452 }
1453
1454 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001455 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001456 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1457 break;
1458 }
1459
1460 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001461 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001462 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1463 break;
1464 }
1465
1466 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001467 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001468 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1469 break;
1470 }
1471
1472 case Primitive::kPrimInt:
1473 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001474 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001475 __ LoadFromOffset(kLoadWord, out, obj, offset);
1476 break;
1477 }
1478
1479 case Primitive::kPrimLong: {
1480 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001481 Location out = locations->Out();
1482 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001483 break;
1484 }
1485
1486 case Primitive::kPrimFloat:
1487 case Primitive::kPrimDouble:
1488 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001489 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001490 case Primitive::kPrimVoid:
1491 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001492 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001493 }
1494}
1495
1496void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001497 LocationSummary* locations =
1498 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001499 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001500 if (instruction->HasUses()) {
1501 locations->SetOut(Location::SameAsFirstInput());
1502 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001503}
1504
1505void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001506 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001507 codegen_->AddSlowPath(slow_path);
1508
1509 LocationSummary* locations = instruction->GetLocations();
1510 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001511
1512 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001513 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001514 __ b(slow_path->GetEntryLabel(), EQ);
1515 } else {
1516 DCHECK(obj.IsConstant()) << obj;
1517 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1518 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001519 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001520}
1521
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001522void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001523 LocationSummary* locations =
1524 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001525 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1526 locations->SetInAt(
1527 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001528 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001529}
1530
1531void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1532 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001533 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001534 Location index = locations->InAt(1);
1535
1536 switch (instruction->GetType()) {
1537 case Primitive::kPrimBoolean: {
1538 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001539 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001540 if (index.IsConstant()) {
1541 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1542 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1543 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001544 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001545 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1546 }
1547 break;
1548 }
1549
1550 case Primitive::kPrimByte: {
1551 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001552 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001553 if (index.IsConstant()) {
1554 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1555 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1556 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001557 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001558 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1559 }
1560 break;
1561 }
1562
1563 case Primitive::kPrimShort: {
1564 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001565 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001566 if (index.IsConstant()) {
1567 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1568 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1569 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001570 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001571 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1572 }
1573 break;
1574 }
1575
1576 case Primitive::kPrimChar: {
1577 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001578 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001579 if (index.IsConstant()) {
1580 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1581 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1582 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001583 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001584 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1585 }
1586 break;
1587 }
1588
1589 case Primitive::kPrimInt:
1590 case Primitive::kPrimNot: {
1591 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1592 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001593 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001594 if (index.IsConstant()) {
1595 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1596 __ LoadFromOffset(kLoadWord, out, obj, offset);
1597 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001598 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001599 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1600 }
1601 break;
1602 }
1603
1604 case Primitive::kPrimLong: {
1605 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001606 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001607 if (index.IsConstant()) {
1608 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001609 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001610 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001611 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1612 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001613 }
1614 break;
1615 }
1616
1617 case Primitive::kPrimFloat:
1618 case Primitive::kPrimDouble:
1619 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001620 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001621 case Primitive::kPrimVoid:
1622 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001623 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001624 }
1625}
1626
1627void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001628 Primitive::Type value_type = instruction->GetComponentType();
1629 bool is_object = value_type == Primitive::kPrimNot;
1630 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1631 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1632 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001633 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001634 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1635 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1636 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001637 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001638 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1639 locations->SetInAt(
1640 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry);
1641 locations->SetInAt(2, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001642 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001643}
1644
1645void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1646 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001647 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001648 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001649 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001650
1651 switch (value_type) {
1652 case Primitive::kPrimBoolean:
1653 case Primitive::kPrimByte: {
1654 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001655 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001656 if (index.IsConstant()) {
1657 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1658 __ StoreToOffset(kStoreByte, value, obj, offset);
1659 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001660 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001661 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1662 }
1663 break;
1664 }
1665
1666 case Primitive::kPrimShort:
1667 case Primitive::kPrimChar: {
1668 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001669 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001670 if (index.IsConstant()) {
1671 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1672 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1673 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001674 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001675 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1676 }
1677 break;
1678 }
1679
1680 case Primitive::kPrimInt: {
1681 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001682 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001683 if (index.IsConstant()) {
1684 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1685 __ StoreToOffset(kStoreWord, value, obj, offset);
1686 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001687 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001688 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1689 }
1690 break;
1691 }
1692
1693 case Primitive::kPrimNot: {
1694 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAputObject).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001695 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001696 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001697 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001698 DCHECK(!codegen_->IsLeafMethod());
1699 break;
1700 }
1701
1702 case Primitive::kPrimLong: {
1703 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001704 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001705 if (index.IsConstant()) {
1706 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001707 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001708 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001709 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1710 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001711 }
1712 break;
1713 }
1714
1715 case Primitive::kPrimFloat:
1716 case Primitive::kPrimDouble:
1717 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001718 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001719 case Primitive::kPrimVoid:
1720 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001721 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001722 }
1723}
1724
1725void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001726 LocationSummary* locations =
1727 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001728 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001729 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001730}
1731
1732void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1733 LocationSummary* locations = instruction->GetLocations();
1734 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001735 Register obj = locations->InAt(0).As<Register>();
1736 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001737 __ LoadFromOffset(kLoadWord, out, obj, offset);
1738}
1739
1740void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001741 LocationSummary* locations =
1742 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001743 locations->SetInAt(0, Location::RequiresRegister());
1744 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001745 if (instruction->HasUses()) {
1746 locations->SetOut(Location::SameAsFirstInput());
1747 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001748}
1749
1750void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1751 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001752 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001753 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001754 codegen_->AddSlowPath(slow_path);
1755
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001756 Register index = locations->InAt(0).As<Register>();
1757 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001758
1759 __ cmp(index, ShifterOperand(length));
1760 __ b(slow_path->GetEntryLabel(), CS);
1761}
1762
1763void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1764 Label is_null;
1765 __ CompareAndBranchIfZero(value, &is_null);
1766 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1767 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1768 __ strb(card, Address(card, temp));
1769 __ Bind(&is_null);
1770}
1771
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001772void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1773 temp->SetLocations(nullptr);
1774}
1775
1776void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1777 // Nothing to do, this is driven by the code generator.
1778}
1779
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001780void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001781 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001782}
1783
1784void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001785 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1786}
1787
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001788void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
1789 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1790}
1791
1792void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001793 HBasicBlock* block = instruction->GetBlock();
1794 if (block->GetLoopInformation() != nullptr) {
1795 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1796 // The back edge will generate the suspend check.
1797 return;
1798 }
1799 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1800 // The goto will generate the suspend check.
1801 return;
1802 }
1803 GenerateSuspendCheck(instruction, nullptr);
1804}
1805
1806void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
1807 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001808 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001809 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001810 codegen_->AddSlowPath(slow_path);
1811
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001812 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001813 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001814 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001815 __ Bind(slow_path->GetReturnLabel());
1816 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001817 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001818 __ b(slow_path->GetEntryLabel());
1819 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001820}
1821
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001822ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
1823 return codegen_->GetAssembler();
1824}
1825
1826void ParallelMoveResolverARM::EmitMove(size_t index) {
1827 MoveOperands* move = moves_.Get(index);
1828 Location source = move->GetSource();
1829 Location destination = move->GetDestination();
1830
1831 if (source.IsRegister()) {
1832 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001833 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001834 } else {
1835 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001836 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001837 SP, destination.GetStackIndex());
1838 }
1839 } else if (source.IsStackSlot()) {
1840 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001841 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001842 SP, source.GetStackIndex());
1843 } else {
1844 DCHECK(destination.IsStackSlot());
1845 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1846 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
1847 }
1848 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001849 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01001850 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001851 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
1852 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001853 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001854 } else {
1855 DCHECK(destination.IsStackSlot());
1856 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001857 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001858 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001859 }
1860}
1861
1862void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
1863 __ Mov(IP, reg);
1864 __ LoadFromOffset(kLoadWord, reg, SP, mem);
1865 __ StoreToOffset(kStoreWord, IP, SP, mem);
1866}
1867
1868void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
1869 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
1870 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
1871 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
1872 SP, mem1 + stack_offset);
1873 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
1874 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
1875 SP, mem2 + stack_offset);
1876 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
1877}
1878
1879void ParallelMoveResolverARM::EmitSwap(size_t index) {
1880 MoveOperands* move = moves_.Get(index);
1881 Location source = move->GetSource();
1882 Location destination = move->GetDestination();
1883
1884 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001885 DCHECK_NE(source.As<Register>(), IP);
1886 DCHECK_NE(destination.As<Register>(), IP);
1887 __ Mov(IP, source.As<Register>());
1888 __ Mov(source.As<Register>(), destination.As<Register>());
1889 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001890 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001891 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001892 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001893 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001894 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
1895 Exchange(source.GetStackIndex(), destination.GetStackIndex());
1896 } else {
1897 LOG(FATAL) << "Unimplemented";
1898 }
1899}
1900
1901void ParallelMoveResolverARM::SpillScratch(int reg) {
1902 __ Push(static_cast<Register>(reg));
1903}
1904
1905void ParallelMoveResolverARM::RestoreScratch(int reg) {
1906 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001907}
1908
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001909} // namespace arm
1910} // namespace art