blob: a2cf670b0f48d731c355d1271a6918595edba3b2 [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
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001019void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001020 LocationSummary* locations =
1021 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001022 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001023 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001024 case Primitive::kPrimLong: {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001025 bool dies_at_entry = add->GetResultType() != Primitive::kPrimLong;
1026 locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry);
1027 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)), dies_at_entry);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001028 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001029 break;
1030 }
1031
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001032 case Primitive::kPrimFloat:
1033 case Primitive::kPrimDouble: {
1034 locations->SetInAt(0, Location::RequiresFpuRegister());
1035 locations->SetInAt(1, Location::RequiresFpuRegister());
1036 locations->SetOut(Location::RequiresFpuRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001037 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001038 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001039
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001040 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001041 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001042 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001043}
1044
1045void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1046 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001047 Location out = locations->Out();
1048 Location first = locations->InAt(0);
1049 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001050 switch (add->GetResultType()) {
1051 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001052 if (second.IsRegister()) {
1053 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001054 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001055 __ AddConstant(out.As<Register>(),
1056 first.As<Register>(),
1057 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001058 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001059 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001060
1061 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001062 __ adds(out.AsRegisterPairLow<Register>(),
1063 first.AsRegisterPairLow<Register>(),
1064 ShifterOperand(second.AsRegisterPairLow<Register>()));
1065 __ adc(out.AsRegisterPairHigh<Register>(),
1066 first.AsRegisterPairHigh<Register>(),
1067 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001068 break;
1069
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001070 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001071 __ vadds(FromDToLowS(out.As<DRegister>()),
1072 FromDToLowS(first.As<DRegister>()),
1073 FromDToLowS(second.As<DRegister>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001074 break;
1075
1076 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001077 __ vaddd(out.As<DRegister>(), first.As<DRegister>(), second.As<DRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001078 break;
1079
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001080 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001081 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001082 }
1083}
1084
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001085void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001086 LocationSummary* locations =
1087 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001088 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001089 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001090 case Primitive::kPrimLong: {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001091 bool dies_at_entry = sub->GetResultType() != Primitive::kPrimLong;
1092 locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry);
1093 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)), dies_at_entry);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001094 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001095 break;
1096 }
1097
1098 case Primitive::kPrimBoolean:
1099 case Primitive::kPrimByte:
1100 case Primitive::kPrimChar:
1101 case Primitive::kPrimShort:
1102 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1103 break;
1104
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001105 default:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001106 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001107 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001108}
1109
1110void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1111 LocationSummary* locations = sub->GetLocations();
1112 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001113 case Primitive::kPrimInt: {
1114 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001115 __ sub(locations->Out().As<Register>(),
1116 locations->InAt(0).As<Register>(),
1117 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001118 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001119 __ AddConstant(locations->Out().As<Register>(),
1120 locations->InAt(0).As<Register>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001121 -locations->InAt(1).GetConstant()->AsIntConstant()->GetValue());
1122 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001123 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001124 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001125
1126 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001127 __ subs(locations->Out().AsRegisterPairLow<Register>(),
1128 locations->InAt(0).AsRegisterPairLow<Register>(),
1129 ShifterOperand(locations->InAt(1).AsRegisterPairLow<Register>()));
1130 __ sbc(locations->Out().AsRegisterPairHigh<Register>(),
1131 locations->InAt(0).AsRegisterPairHigh<Register>(),
1132 ShifterOperand(locations->InAt(1).AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001133 break;
1134
1135 case Primitive::kPrimBoolean:
1136 case Primitive::kPrimByte:
1137 case Primitive::kPrimChar:
1138 case Primitive::kPrimShort:
1139 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1140 break;
1141
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001142 default:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001143 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001144 }
1145}
1146
Calin Juravle34bacdf2014-10-07 20:23:36 +01001147void LocationsBuilderARM::VisitMul(HMul* mul) {
1148 LocationSummary* locations =
1149 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1150 switch (mul->GetResultType()) {
1151 case Primitive::kPrimInt:
1152 case Primitive::kPrimLong: {
1153 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1154 locations->SetInAt(1, Location::RequiresRegister(), Location::kDiesAtEntry);
1155 locations->SetOut(Location::RequiresRegister());
1156 break;
1157 }
1158
1159 case Primitive::kPrimBoolean:
1160 case Primitive::kPrimByte:
1161 case Primitive::kPrimChar:
1162 case Primitive::kPrimShort:
1163 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1164 break;
1165
1166 default:
1167 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1168 }
1169}
1170
1171void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1172 LocationSummary* locations = mul->GetLocations();
1173 Location out = locations->Out();
1174 Location first = locations->InAt(0);
1175 Location second = locations->InAt(1);
1176 switch (mul->GetResultType()) {
1177 case Primitive::kPrimInt: {
1178 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1179 break;
1180 }
1181 case Primitive::kPrimLong: {
1182 Register out_hi = out.AsRegisterPairHigh<Register>();
1183 Register out_lo = out.AsRegisterPairLow<Register>();
1184 Register in1_hi = first.AsRegisterPairHigh<Register>();
1185 Register in1_lo = first.AsRegisterPairLow<Register>();
1186 Register in2_hi = second.AsRegisterPairHigh<Register>();
1187 Register in2_lo = second.AsRegisterPairLow<Register>();
1188
1189 // Extra checks to protect caused by the existence of R1_R2.
1190 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1191 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1192 DCHECK_NE(out_hi, in1_lo);
1193 DCHECK_NE(out_hi, in2_lo);
1194
1195 // input: in1 - 64 bits, in2 - 64 bits
1196 // output: out
1197 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1198 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1199 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1200
1201 // IP <- in1.lo * in2.hi
1202 __ mul(IP, in1_lo, in2_hi);
1203 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1204 __ mla(out_hi, in1_hi, in2_lo, IP);
1205 // out.lo <- (in1.lo * in2.lo)[31:0];
1206 __ umull(out_lo, IP, in1_lo, in2_lo);
1207 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1208 __ add(out_hi, out_hi, ShifterOperand(IP));
1209 break;
1210 }
1211 case Primitive::kPrimBoolean:
1212 case Primitive::kPrimByte:
1213 case Primitive::kPrimChar:
1214 case Primitive::kPrimShort:
1215 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1216 break;
1217
1218 default:
1219 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1220 }
1221}
1222
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001223void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001224 LocationSummary* locations =
1225 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001226 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001227 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1228 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1229 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001230}
1231
1232void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1233 InvokeRuntimeCallingConvention calling_convention;
1234 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1235 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1236
Nicolas Geoffray707c8092014-04-04 10:50:14 +01001237 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocObjectWithAccessCheck).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001238 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001239 __ blx(LR);
1240
Nicolas Geoffray39468442014-09-02 15:17:15 +01001241 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001242 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001243}
1244
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001245void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001246 LocationSummary* locations =
1247 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001248 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1249 if (location.IsStackSlot()) {
1250 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1251 } else if (location.IsDoubleStackSlot()) {
1252 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001253 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001254 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001255}
1256
1257void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001258 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001259}
1260
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001261void LocationsBuilderARM::VisitNot(HNot* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001262 LocationSummary* locations =
1263 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001264 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001265 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001266}
1267
1268void InstructionCodeGeneratorARM::VisitNot(HNot* instruction) {
1269 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001270 __ eor(locations->Out().As<Register>(),
1271 locations->InAt(0).As<Register>(), ShifterOperand(1));
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001272}
1273
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001274void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001275 LocationSummary* locations =
1276 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001277 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1278 locations->SetInAt(1, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001279 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001280}
1281
1282void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1283 Label greater, done;
1284 LocationSummary* locations = compare->GetLocations();
1285 switch (compare->InputAt(0)->GetType()) {
1286 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001287 Register output = locations->Out().As<Register>();
1288 Location left = locations->InAt(0);
1289 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001290 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001291 __ cmp(left.AsRegisterPairHigh<Register>(),
1292 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001293 __ b(&less, LT);
1294 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001295 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1296 // the status flags.
1297 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001298 __ cmp(left.AsRegisterPairLow<Register>(),
1299 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001300 __ b(&done, EQ);
1301 __ b(&less, CC);
1302
1303 __ Bind(&greater);
1304 __ LoadImmediate(output, 1);
1305 __ b(&done);
1306
1307 __ Bind(&less);
1308 __ LoadImmediate(output, -1);
1309
1310 __ Bind(&done);
1311 break;
1312 }
1313 default:
1314 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1315 }
1316}
1317
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001318void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001319 LocationSummary* locations =
1320 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001321 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1322 locations->SetInAt(i, Location::Any());
1323 }
1324 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001325}
1326
1327void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001328 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001329}
1330
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001331void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001332 LocationSummary* locations =
1333 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001334 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
1335 bool dies_at_entry = !is_object_type;
1336 locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry);
1337 locations->SetInAt(1, Location::RequiresRegister(), dies_at_entry);
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001338 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001339 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001340 locations->AddTemp(Location::RequiresRegister());
1341 locations->AddTemp(Location::RequiresRegister());
1342 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001343}
1344
1345void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1346 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001347 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001348 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001349 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001350
1351 switch (field_type) {
1352 case Primitive::kPrimBoolean:
1353 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001354 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001355 __ StoreToOffset(kStoreByte, value, obj, offset);
1356 break;
1357 }
1358
1359 case Primitive::kPrimShort:
1360 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001361 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001362 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1363 break;
1364 }
1365
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001366 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001367 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001368 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001369 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001370 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001371 Register temp = locations->GetTemp(0).As<Register>();
1372 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001373 codegen_->MarkGCCard(temp, card, obj, value);
1374 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001375 break;
1376 }
1377
1378 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001379 Location value = locations->InAt(1);
1380 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001381 break;
1382 }
1383
1384 case Primitive::kPrimFloat:
1385 case Primitive::kPrimDouble:
1386 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001387 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001388 case Primitive::kPrimVoid:
1389 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001390 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001391 }
1392}
1393
1394void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001395 LocationSummary* locations =
1396 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001397 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001398 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001399}
1400
1401void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1402 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001403 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001404 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1405
1406 switch (instruction->GetType()) {
1407 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001408 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001409 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1410 break;
1411 }
1412
1413 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001414 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001415 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1416 break;
1417 }
1418
1419 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001420 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001421 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1422 break;
1423 }
1424
1425 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001426 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001427 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1428 break;
1429 }
1430
1431 case Primitive::kPrimInt:
1432 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001433 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001434 __ LoadFromOffset(kLoadWord, out, obj, offset);
1435 break;
1436 }
1437
1438 case Primitive::kPrimLong: {
1439 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001440 Location out = locations->Out();
1441 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001442 break;
1443 }
1444
1445 case Primitive::kPrimFloat:
1446 case Primitive::kPrimDouble:
1447 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001448 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001449 case Primitive::kPrimVoid:
1450 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001451 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001452 }
1453}
1454
1455void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001456 LocationSummary* locations =
1457 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001458 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001459 if (instruction->HasUses()) {
1460 locations->SetOut(Location::SameAsFirstInput());
1461 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001462}
1463
1464void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001465 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001466 codegen_->AddSlowPath(slow_path);
1467
1468 LocationSummary* locations = instruction->GetLocations();
1469 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001470
1471 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001472 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001473 __ b(slow_path->GetEntryLabel(), EQ);
1474 } else {
1475 DCHECK(obj.IsConstant()) << obj;
1476 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1477 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001478 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001479}
1480
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001481void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001482 LocationSummary* locations =
1483 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001484 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1485 locations->SetInAt(
1486 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001487 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001488}
1489
1490void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1491 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001492 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001493 Location index = locations->InAt(1);
1494
1495 switch (instruction->GetType()) {
1496 case Primitive::kPrimBoolean: {
1497 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001498 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001499 if (index.IsConstant()) {
1500 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1501 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1502 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001503 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001504 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1505 }
1506 break;
1507 }
1508
1509 case Primitive::kPrimByte: {
1510 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001511 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001512 if (index.IsConstant()) {
1513 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1514 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1515 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001516 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001517 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1518 }
1519 break;
1520 }
1521
1522 case Primitive::kPrimShort: {
1523 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001524 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001525 if (index.IsConstant()) {
1526 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1527 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1528 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001529 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001530 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1531 }
1532 break;
1533 }
1534
1535 case Primitive::kPrimChar: {
1536 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001537 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001538 if (index.IsConstant()) {
1539 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1540 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1541 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001542 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001543 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1544 }
1545 break;
1546 }
1547
1548 case Primitive::kPrimInt:
1549 case Primitive::kPrimNot: {
1550 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1551 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_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_4) + data_offset;
1555 __ LoadFromOffset(kLoadWord, out, obj, offset);
1556 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001557 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001558 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1559 }
1560 break;
1561 }
1562
1563 case Primitive::kPrimLong: {
1564 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001565 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001566 if (index.IsConstant()) {
1567 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001568 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001569 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001570 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1571 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001572 }
1573 break;
1574 }
1575
1576 case Primitive::kPrimFloat:
1577 case Primitive::kPrimDouble:
1578 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001579 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001580 case Primitive::kPrimVoid:
1581 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001582 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001583 }
1584}
1585
1586void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001587 Primitive::Type value_type = instruction->GetComponentType();
1588 bool is_object = value_type == Primitive::kPrimNot;
1589 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1590 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1591 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001592 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001593 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1594 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1595 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001596 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001597 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
1598 locations->SetInAt(
1599 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry);
1600 locations->SetInAt(2, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001601 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001602}
1603
1604void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1605 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001606 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001607 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001608 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001609
1610 switch (value_type) {
1611 case Primitive::kPrimBoolean:
1612 case Primitive::kPrimByte: {
1613 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001614 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001615 if (index.IsConstant()) {
1616 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1617 __ StoreToOffset(kStoreByte, value, obj, offset);
1618 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001619 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001620 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1621 }
1622 break;
1623 }
1624
1625 case Primitive::kPrimShort:
1626 case Primitive::kPrimChar: {
1627 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001628 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001629 if (index.IsConstant()) {
1630 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1631 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1632 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001633 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001634 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1635 }
1636 break;
1637 }
1638
1639 case Primitive::kPrimInt: {
1640 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001641 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001642 if (index.IsConstant()) {
1643 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1644 __ StoreToOffset(kStoreWord, value, obj, offset);
1645 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001646 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001647 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1648 }
1649 break;
1650 }
1651
1652 case Primitive::kPrimNot: {
1653 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAputObject).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001654 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001655 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001656 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001657 DCHECK(!codegen_->IsLeafMethod());
1658 break;
1659 }
1660
1661 case Primitive::kPrimLong: {
1662 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001663 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001664 if (index.IsConstant()) {
1665 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001666 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001667 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001668 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1669 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001670 }
1671 break;
1672 }
1673
1674 case Primitive::kPrimFloat:
1675 case Primitive::kPrimDouble:
1676 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001677 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001678 case Primitive::kPrimVoid:
1679 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001680 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001681 }
1682}
1683
1684void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001685 LocationSummary* locations =
1686 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001687 locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001688 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001689}
1690
1691void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1692 LocationSummary* locations = instruction->GetLocations();
1693 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001694 Register obj = locations->InAt(0).As<Register>();
1695 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001696 __ LoadFromOffset(kLoadWord, out, obj, offset);
1697}
1698
1699void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001700 LocationSummary* locations =
1701 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001702 locations->SetInAt(0, Location::RequiresRegister());
1703 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001704 if (instruction->HasUses()) {
1705 locations->SetOut(Location::SameAsFirstInput());
1706 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001707}
1708
1709void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1710 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001711 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001712 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001713 codegen_->AddSlowPath(slow_path);
1714
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001715 Register index = locations->InAt(0).As<Register>();
1716 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001717
1718 __ cmp(index, ShifterOperand(length));
1719 __ b(slow_path->GetEntryLabel(), CS);
1720}
1721
1722void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1723 Label is_null;
1724 __ CompareAndBranchIfZero(value, &is_null);
1725 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1726 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1727 __ strb(card, Address(card, temp));
1728 __ Bind(&is_null);
1729}
1730
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001731void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1732 temp->SetLocations(nullptr);
1733}
1734
1735void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1736 // Nothing to do, this is driven by the code generator.
1737}
1738
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001739void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001740 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001741}
1742
1743void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001744 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1745}
1746
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001747void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
1748 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1749}
1750
1751void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001752 HBasicBlock* block = instruction->GetBlock();
1753 if (block->GetLoopInformation() != nullptr) {
1754 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1755 // The back edge will generate the suspend check.
1756 return;
1757 }
1758 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1759 // The goto will generate the suspend check.
1760 return;
1761 }
1762 GenerateSuspendCheck(instruction, nullptr);
1763}
1764
1765void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
1766 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001767 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001768 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001769 codegen_->AddSlowPath(slow_path);
1770
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001771 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001772 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001773 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001774 __ Bind(slow_path->GetReturnLabel());
1775 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001776 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001777 __ b(slow_path->GetEntryLabel());
1778 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001779}
1780
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001781ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
1782 return codegen_->GetAssembler();
1783}
1784
1785void ParallelMoveResolverARM::EmitMove(size_t index) {
1786 MoveOperands* move = moves_.Get(index);
1787 Location source = move->GetSource();
1788 Location destination = move->GetDestination();
1789
1790 if (source.IsRegister()) {
1791 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001792 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001793 } else {
1794 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001795 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001796 SP, destination.GetStackIndex());
1797 }
1798 } else if (source.IsStackSlot()) {
1799 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001800 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001801 SP, source.GetStackIndex());
1802 } else {
1803 DCHECK(destination.IsStackSlot());
1804 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1805 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
1806 }
1807 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001808 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01001809 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001810 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
1811 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001812 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001813 } else {
1814 DCHECK(destination.IsStackSlot());
1815 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001816 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001817 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001818 }
1819}
1820
1821void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
1822 __ Mov(IP, reg);
1823 __ LoadFromOffset(kLoadWord, reg, SP, mem);
1824 __ StoreToOffset(kStoreWord, IP, SP, mem);
1825}
1826
1827void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
1828 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
1829 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
1830 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
1831 SP, mem1 + stack_offset);
1832 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
1833 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
1834 SP, mem2 + stack_offset);
1835 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
1836}
1837
1838void ParallelMoveResolverARM::EmitSwap(size_t index) {
1839 MoveOperands* move = moves_.Get(index);
1840 Location source = move->GetSource();
1841 Location destination = move->GetDestination();
1842
1843 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001844 DCHECK_NE(source.As<Register>(), IP);
1845 DCHECK_NE(destination.As<Register>(), IP);
1846 __ Mov(IP, source.As<Register>());
1847 __ Mov(source.As<Register>(), destination.As<Register>());
1848 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001849 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001850 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001851 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001852 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001853 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
1854 Exchange(source.GetStackIndex(), destination.GetStackIndex());
1855 } else {
1856 LOG(FATAL) << "Unimplemented";
1857 }
1858}
1859
1860void ParallelMoveResolverARM::SpillScratch(int reg) {
1861 __ Push(static_cast<Register>(reg));
1862}
1863
1864void ParallelMoveResolverARM::RestoreScratch(int reg) {
1865 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001866}
1867
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001868} // namespace arm
1869} // namespace art