blob: 7ed802ec7b0cf9f75e089d0becb35da5bb93c70f [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 Geoffray102cbed2014-10-15 18:31:05 +0100213size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
214 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
215 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100216}
217
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100218size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
219 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
220 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100221}
222
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100223CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100224 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfDRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100225 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100226 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100227 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100228 move_resolver_(graph->GetArena(), this),
229 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100230
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100231size_t CodeGeneratorARM::FrameEntrySpillSize() const {
232 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
233}
234
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100235Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100236 switch (type) {
237 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100238 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100239 ArmManagedRegister pair =
240 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100241 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
242 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
243
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100244 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
245 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100246 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100247 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100248 }
249
250 case Primitive::kPrimByte:
251 case Primitive::kPrimBoolean:
252 case Primitive::kPrimChar:
253 case Primitive::kPrimShort:
254 case Primitive::kPrimInt:
255 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100256 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100257 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100258 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
259 ArmManagedRegister current =
260 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
261 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100262 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100263 }
264 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100265 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100266 }
267
268 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100269 case Primitive::kPrimDouble: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100270 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfDRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100271 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100272 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100273
274 case Primitive::kPrimVoid:
275 LOG(FATAL) << "Unreachable type " << type;
276 }
277
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100278 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100279}
280
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100281void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100282 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100283 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100284
285 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100286 blocked_core_registers_[SP] = true;
287 blocked_core_registers_[LR] = true;
288 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100289
290 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100291 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100292
293 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100294 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100295
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100296 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100297 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100298
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100299 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100300 // We always save and restore R6 and R7 to make sure we can use three
301 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100302 blocked_core_registers_[R5] = true;
303 blocked_core_registers_[R8] = true;
304 blocked_core_registers_[R10] = true;
305 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100306
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100307 blocked_fpu_registers_[D8] = true;
308 blocked_fpu_registers_[D9] = true;
309 blocked_fpu_registers_[D10] = true;
310 blocked_fpu_registers_[D11] = true;
311 blocked_fpu_registers_[D12] = true;
312 blocked_fpu_registers_[D13] = true;
313 blocked_fpu_registers_[D14] = true;
314 blocked_fpu_registers_[D15] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100315
316 UpdateBlockedPairRegisters();
317}
318
319void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
320 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
321 ArmManagedRegister current =
322 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
323 if (blocked_core_registers_[current.AsRegisterPairLow()]
324 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
325 blocked_register_pairs_[i] = true;
326 }
327 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100328}
329
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100330InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
331 : HGraphVisitor(graph),
332 assembler_(codegen->GetAssembler()),
333 codegen_(codegen) {}
334
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000335void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700336 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100337 if (!skip_overflow_check) {
338 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100339 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100340 AddSlowPath(slow_path);
341
342 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
343 __ cmp(SP, ShifterOperand(IP));
344 __ b(slow_path->GetEntryLabel(), CC);
345 } else {
346 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100347 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100348 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100349 }
350 }
351
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100352 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
353 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000354
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100355 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100356 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100357 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000358}
359
360void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100361 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100362 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000363}
364
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100365void CodeGeneratorARM::Bind(HBasicBlock* block) {
366 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000367}
368
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100369Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
370 switch (load->GetType()) {
371 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100372 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100373 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
374 break;
375
376 case Primitive::kPrimInt:
377 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100378 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100379 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100380
381 case Primitive::kPrimBoolean:
382 case Primitive::kPrimByte:
383 case Primitive::kPrimChar:
384 case Primitive::kPrimShort:
385 case Primitive::kPrimVoid:
386 LOG(FATAL) << "Unexpected type " << load->GetType();
387 }
388
389 LOG(FATAL) << "Unreachable";
390 return Location();
391}
392
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100393Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
394 switch (type) {
395 case Primitive::kPrimBoolean:
396 case Primitive::kPrimByte:
397 case Primitive::kPrimChar:
398 case Primitive::kPrimShort:
399 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100400 case Primitive::kPrimFloat:
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100401 case Primitive::kPrimNot: {
402 uint32_t index = gp_index_++;
403 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100404 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100405 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100406 return Location::StackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100407 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100408 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100409
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100410 case Primitive::kPrimLong:
411 case Primitive::kPrimDouble: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100412 uint32_t index = gp_index_;
413 gp_index_ += 2;
414 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100415 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
416 calling_convention.GetRegisterPairAt(index));
417 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100418 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
419 return Location::QuickParameter(index);
420 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100421 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100422 }
423 }
424
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100425 case Primitive::kPrimVoid:
426 LOG(FATAL) << "Unexpected parameter type " << type;
427 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100428 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100429 return Location();
430}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100431
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100432void CodeGeneratorARM::Move32(Location destination, Location source) {
433 if (source.Equals(destination)) {
434 return;
435 }
436 if (destination.IsRegister()) {
437 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100438 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100439 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100440 __ vmovrs(destination.As<Register>(), FromDToLowS(source.As<DRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100441 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100442 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100443 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100444 } else if (destination.IsFpuRegister()) {
445 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100446 __ vmovsr(FromDToLowS(destination.As<DRegister>()), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100447 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100448 __ vmovs(FromDToLowS(destination.As<DRegister>()), FromDToLowS(source.As<DRegister>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100449 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100450 __ vldrs(FromDToLowS(destination.As<DRegister>()), Address(SP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100451 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100452 } else {
453 DCHECK(destination.IsStackSlot());
454 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100455 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100456 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100457 __ vstrs(FromDToLowS(source.As<DRegister>()), Address(SP, destination.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100458 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100459 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100460 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
461 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100462 }
463 }
464}
465
466void CodeGeneratorARM::Move64(Location destination, Location source) {
467 if (source.Equals(destination)) {
468 return;
469 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100470 if (destination.IsRegisterPair()) {
471 if (source.IsRegisterPair()) {
472 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
473 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100474 } else if (source.IsFpuRegister()) {
475 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100476 } else if (source.IsQuickParameter()) {
477 uint32_t argument_index = source.GetQuickParameterIndex();
478 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100479 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100480 calling_convention.GetRegisterAt(argument_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100481 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
482 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100483 } else {
484 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100485 if (destination.AsRegisterPairLow<Register>() == R1) {
486 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100487 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
488 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100489 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100490 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100491 SP, source.GetStackIndex());
492 }
493 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100494 } else if (destination.IsFpuRegister()) {
495 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100496 __ vldrd(destination.As<DRegister>(), Address(SP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100497 } else {
498 LOG(FATAL) << "Unimplemented";
499 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100500 } else if (destination.IsQuickParameter()) {
501 InvokeDexCallingConvention calling_convention;
502 uint32_t argument_index = destination.GetQuickParameterIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100503 if (source.IsRegisterPair()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100504 __ Mov(calling_convention.GetRegisterAt(argument_index),
505 source.AsRegisterPairLow<Register>());
506 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
507 SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100508 } else if (source.IsFpuRegister()) {
509 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100510 } else {
511 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100512 __ LoadFromOffset(kLoadWord, calling_convention.GetRegisterAt(argument_index), SP, source.GetStackIndex());
513 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
514 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100515 }
516 } else {
517 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100518 if (source.IsRegisterPair()) {
519 if (source.AsRegisterPairLow<Register>() == R1) {
520 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100521 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
522 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100523 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100524 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100525 SP, destination.GetStackIndex());
526 }
527 } else if (source.IsQuickParameter()) {
528 InvokeDexCallingConvention calling_convention;
529 uint32_t argument_index = source.GetQuickParameterIndex();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100530 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(argument_index),
531 SP, destination.GetStackIndex());
532 __ LoadFromOffset(kLoadWord, R0,
533 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
534 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100535 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100536 __ vstrd(source.As<DRegister>(), Address(SP, destination.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100537 } else {
538 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100539 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
540 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
541 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
542 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100543 }
544 }
545}
546
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100547void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100548 LocationSummary* locations = instruction->GetLocations();
549 if (locations != nullptr && locations->Out().Equals(location)) {
550 return;
551 }
552
Roland Levillain476df552014-10-09 17:51:36 +0100553 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100554 int32_t value = instruction->AsIntConstant()->GetValue();
555 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100556 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100557 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100558 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100559 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100560 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100561 }
Roland Levillain476df552014-10-09 17:51:36 +0100562 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100563 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100564 if (location.IsRegisterPair()) {
565 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
566 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100567 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100568 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100569 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100570 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100571 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100572 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100573 }
Roland Levillain476df552014-10-09 17:51:36 +0100574 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100575 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
576 switch (instruction->GetType()) {
577 case Primitive::kPrimBoolean:
578 case Primitive::kPrimByte:
579 case Primitive::kPrimChar:
580 case Primitive::kPrimShort:
581 case Primitive::kPrimInt:
582 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100583 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100584 Move32(location, Location::StackSlot(stack_slot));
585 break;
586
587 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100588 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100589 Move64(location, Location::DoubleStackSlot(stack_slot));
590 break;
591
592 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100593 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100594 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000595 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100596 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100597 switch (instruction->GetType()) {
598 case Primitive::kPrimBoolean:
599 case Primitive::kPrimByte:
600 case Primitive::kPrimChar:
601 case Primitive::kPrimShort:
602 case Primitive::kPrimNot:
603 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100604 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100605 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100606 break;
607
608 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100609 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100610 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100611 break;
612
613 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100614 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100615 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000616 }
617}
618
619void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000620 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000621}
622
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000623void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000624 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100625 DCHECK(!successor->IsExitBlock());
626
627 HBasicBlock* block = got->GetBlock();
628 HInstruction* previous = got->GetPrevious();
629
630 HLoopInformation* info = block->GetLoopInformation();
631 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
632 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
633 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
634 return;
635 }
636
637 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
638 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
639 }
640 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000641 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000642 }
643}
644
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000645void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000646 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000647}
648
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000649void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000650 if (kIsDebugBuild) {
651 __ Comment("Unreachable");
652 __ bkpt(0);
653 }
654}
655
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000656void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100657 LocationSummary* locations =
658 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100659 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100660 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100661 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100662 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000663}
664
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000665void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700666 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100667 if (cond->IsIntConstant()) {
668 // Constant condition, statically compared against 1.
669 int32_t cond_value = cond->AsIntConstant()->GetValue();
670 if (cond_value == 1) {
671 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
672 if_instr->IfTrueSuccessor())) {
673 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100674 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100675 return;
676 } else {
677 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100678 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100679 } else {
680 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
681 // Condition has been materialized, compare the output to 0
682 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
683 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
684 ShifterOperand(0));
685 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
686 } else {
687 // Condition has not been materialized, use its inputs as the
688 // comparison and its condition as the branch condition.
689 LocationSummary* locations = cond->GetLocations();
690 if (locations->InAt(1).IsRegister()) {
691 __ cmp(locations->InAt(0).As<Register>(),
692 ShifterOperand(locations->InAt(1).As<Register>()));
693 } else {
694 DCHECK(locations->InAt(1).IsConstant());
695 int32_t value =
696 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
697 ShifterOperand operand;
698 if (ShifterOperand::CanHoldArm(value, &operand)) {
699 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
700 } else {
701 Register temp = IP;
702 __ LoadImmediate(temp, value);
703 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
704 }
705 }
706 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
707 ARMCondition(cond->AsCondition()->GetCondition()));
708 }
Dave Allison20dfc792014-06-16 20:44:29 -0700709 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100710 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
711 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700712 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000713 }
714}
715
Dave Allison20dfc792014-06-16 20:44:29 -0700716
717void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100718 LocationSummary* locations =
719 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100720 locations->SetInAt(0, Location::RequiresRegister());
721 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100722 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100723 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100724 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000725}
726
Dave Allison20dfc792014-06-16 20:44:29 -0700727void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100728 if (!comp->NeedsMaterialization()) return;
729
730 LocationSummary* locations = comp->GetLocations();
731 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100732 __ cmp(locations->InAt(0).As<Register>(),
733 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100734 } else {
735 DCHECK(locations->InAt(1).IsConstant());
736 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
737 ShifterOperand operand;
738 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100739 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100740 } else {
741 Register temp = IP;
742 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100743 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100744 }
Dave Allison20dfc792014-06-16 20:44:29 -0700745 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100746 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100747 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100748 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100749 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100750 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700751}
752
753void LocationsBuilderARM::VisitEqual(HEqual* comp) {
754 VisitCondition(comp);
755}
756
757void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
758 VisitCondition(comp);
759}
760
761void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
762 VisitCondition(comp);
763}
764
765void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
766 VisitCondition(comp);
767}
768
769void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
770 VisitCondition(comp);
771}
772
773void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
774 VisitCondition(comp);
775}
776
777void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
778 VisitCondition(comp);
779}
780
781void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
782 VisitCondition(comp);
783}
784
785void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
786 VisitCondition(comp);
787}
788
789void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
790 VisitCondition(comp);
791}
792
793void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
794 VisitCondition(comp);
795}
796
797void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
798 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000799}
800
801void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000802 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000803}
804
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000805void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
806 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000807}
808
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000809void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100810 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000811}
812
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000813void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100814 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000815}
816
817void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100818 LocationSummary* locations =
819 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100820 switch (store->InputAt(1)->GetType()) {
821 case Primitive::kPrimBoolean:
822 case Primitive::kPrimByte:
823 case Primitive::kPrimChar:
824 case Primitive::kPrimShort:
825 case Primitive::kPrimInt:
826 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100827 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100828 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
829 break;
830
831 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100832 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100833 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
834 break;
835
836 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100837 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100838 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000839}
840
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000841void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000842}
843
844void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100845 LocationSummary* locations =
846 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100847 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000848}
849
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000850void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100851 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000852}
853
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100854void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100855 LocationSummary* locations =
856 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100857 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100858}
859
860void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
861 // Will be generated at use site.
862}
863
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100864void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
865 LocationSummary* locations =
866 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
867 locations->SetOut(Location::ConstantLocation(constant));
868}
869
870void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
871 // Will be generated at use site.
872}
873
874void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
875 LocationSummary* locations =
876 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
877 locations->SetOut(Location::ConstantLocation(constant));
878}
879
880void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
881 // Will be generated at use site.
882}
883
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000884void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000885 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000886}
887
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000888void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
889 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000890}
891
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000892void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100893 LocationSummary* locations =
894 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100895 switch (ret->InputAt(0)->GetType()) {
896 case Primitive::kPrimBoolean:
897 case Primitive::kPrimByte:
898 case Primitive::kPrimChar:
899 case Primitive::kPrimShort:
900 case Primitive::kPrimInt:
901 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100902 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100903 locations->SetInAt(0, Location::RegisterLocation(R0));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100904 break;
905
906 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100907 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100908 locations->SetInAt(0, Location::RegisterPairLocation(R0, R1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100909 break;
910
911 default:
912 LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType();
913 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000914}
915
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000916void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100917 if (kIsDebugBuild) {
918 switch (ret->InputAt(0)->GetType()) {
919 case Primitive::kPrimBoolean:
920 case Primitive::kPrimByte:
921 case Primitive::kPrimChar:
922 case Primitive::kPrimShort:
923 case Primitive::kPrimInt:
924 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100925 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100926 DCHECK_EQ(ret->GetLocations()->InAt(0).As<Register>(), R0);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100927 break;
928
929 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100930 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100931 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), R0);
932 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), R1);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100933 break;
934
935 default:
936 LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType();
937 }
938 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000939 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000940}
941
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000942void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100943 HandleInvoke(invoke);
944}
945
946void InstructionCodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100947 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100948}
949
950void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100951 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100952 uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>);
953 size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).Int32Value() +
954 invoke->GetIndexInDexCache() * kArmWordSize;
955
956 // TODO: Implement all kinds of calls:
957 // 1) boot -> boot
958 // 2) app -> boot
959 // 3) app -> app
960 //
961 // Currently we implement the app -> app logic, which looks up in the resolve cache.
962
963 // temp = method;
964 LoadCurrentMethod(temp);
965 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100966 __ LoadFromOffset(kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100967 // temp = temp[index_in_cache]
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100968 __ LoadFromOffset(kLoadWord, temp, temp, index_in_cache);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100969 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100970 __ LoadFromOffset(kLoadWord, LR, temp,
971 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100972 // LR()
973 __ blx(LR);
974
975 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
976 DCHECK(!codegen_->IsLeafMethod());
977}
978
979void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
980 HandleInvoke(invoke);
981}
982
983void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100984 LocationSummary* locations =
985 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100986 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100987
988 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100989 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100990 HInstruction* input = invoke->InputAt(i);
991 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
992 }
993
994 switch (invoke->GetType()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100995 case Primitive::kPrimBoolean:
996 case Primitive::kPrimByte:
997 case Primitive::kPrimChar:
998 case Primitive::kPrimShort:
999 case Primitive::kPrimInt:
1000 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001001 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001002 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001003 break;
1004
1005 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001006 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001007 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001008 break;
1009
1010 case Primitive::kPrimVoid:
1011 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001012 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001013}
1014
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001015
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001016void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001017 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001018 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1019 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1020 LocationSummary* locations = invoke->GetLocations();
1021 Location receiver = locations->InAt(0);
1022 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1023 // temp = object->GetClass();
1024 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001025 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1026 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001027 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001028 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001029 }
1030 // temp = temp->GetMethodAt(method_offset);
1031 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001032 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001033 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001034 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001035 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001036 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001037 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001038 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001039}
1040
Roland Levillain88cb1752014-10-20 16:36:47 +01001041void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1042 LocationSummary* locations =
1043 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1044 switch (neg->GetResultType()) {
1045 case Primitive::kPrimInt:
1046 locations->SetInAt(0, Location::RequiresRegister());
1047 locations->SetOut(Location::RequiresRegister());
1048 break;
1049
1050 case Primitive::kPrimLong:
1051 case Primitive::kPrimFloat:
1052 case Primitive::kPrimDouble:
1053 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1054 break;
1055
1056 default:
1057 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1058 }
1059}
1060
1061void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1062 LocationSummary* locations = neg->GetLocations();
1063 Location out = locations->Out();
1064 Location in = locations->InAt(0);
1065 switch (neg->GetResultType()) {
1066 case Primitive::kPrimInt:
1067 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001068 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001069 break;
1070
1071 case Primitive::kPrimLong:
1072 case Primitive::kPrimFloat:
1073 case Primitive::kPrimDouble:
1074 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1075 break;
1076
1077 default:
1078 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1079 }
1080}
1081
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001082void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001083 LocationSummary* locations =
1084 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001085 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001086 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001087 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001088 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1089 locations->SetInAt(0, Location::RequiresRegister());
1090 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1091 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001092 break;
1093 }
1094
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001095 case Primitive::kPrimFloat:
1096 case Primitive::kPrimDouble: {
1097 locations->SetInAt(0, Location::RequiresFpuRegister());
1098 locations->SetInAt(1, Location::RequiresFpuRegister());
1099 locations->SetOut(Location::RequiresFpuRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001100 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001101 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001102
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001103 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001104 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001105 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001106}
1107
1108void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1109 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001110 Location out = locations->Out();
1111 Location first = locations->InAt(0);
1112 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001113 switch (add->GetResultType()) {
1114 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001115 if (second.IsRegister()) {
1116 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001117 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001118 __ AddConstant(out.As<Register>(),
1119 first.As<Register>(),
1120 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001121 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001122 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001123
1124 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001125 __ adds(out.AsRegisterPairLow<Register>(),
1126 first.AsRegisterPairLow<Register>(),
1127 ShifterOperand(second.AsRegisterPairLow<Register>()));
1128 __ adc(out.AsRegisterPairHigh<Register>(),
1129 first.AsRegisterPairHigh<Register>(),
1130 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001131 break;
1132
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001133 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001134 __ vadds(FromDToLowS(out.As<DRegister>()),
1135 FromDToLowS(first.As<DRegister>()),
1136 FromDToLowS(second.As<DRegister>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001137 break;
1138
1139 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001140 __ vaddd(out.As<DRegister>(), first.As<DRegister>(), second.As<DRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001141 break;
1142
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001143 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001144 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001145 }
1146}
1147
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001148void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001149 LocationSummary* locations =
1150 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001151 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001152 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001153 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001154 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1155 locations->SetInAt(0, Location::RequiresRegister());
1156 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1157 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001158 break;
1159 }
1160
1161 case Primitive::kPrimBoolean:
1162 case Primitive::kPrimByte:
1163 case Primitive::kPrimChar:
1164 case Primitive::kPrimShort:
1165 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1166 break;
1167
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001168 default:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001169 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001170 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001171}
1172
1173void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1174 LocationSummary* locations = sub->GetLocations();
1175 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001176 case Primitive::kPrimInt: {
1177 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001178 __ sub(locations->Out().As<Register>(),
1179 locations->InAt(0).As<Register>(),
1180 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001181 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001182 __ AddConstant(locations->Out().As<Register>(),
1183 locations->InAt(0).As<Register>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001184 -locations->InAt(1).GetConstant()->AsIntConstant()->GetValue());
1185 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001186 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001187 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001188
1189 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001190 __ subs(locations->Out().AsRegisterPairLow<Register>(),
1191 locations->InAt(0).AsRegisterPairLow<Register>(),
1192 ShifterOperand(locations->InAt(1).AsRegisterPairLow<Register>()));
1193 __ sbc(locations->Out().AsRegisterPairHigh<Register>(),
1194 locations->InAt(0).AsRegisterPairHigh<Register>(),
1195 ShifterOperand(locations->InAt(1).AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001196 break;
1197
1198 case Primitive::kPrimBoolean:
1199 case Primitive::kPrimByte:
1200 case Primitive::kPrimChar:
1201 case Primitive::kPrimShort:
1202 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1203 break;
1204
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001205 default:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001206 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001207 }
1208}
1209
Calin Juravle34bacdf2014-10-07 20:23:36 +01001210void LocationsBuilderARM::VisitMul(HMul* mul) {
1211 LocationSummary* locations =
1212 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1213 switch (mul->GetResultType()) {
1214 case Primitive::kPrimInt:
1215 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001216 locations->SetInAt(0, Location::RequiresRegister());
1217 locations->SetInAt(1, Location::RequiresRegister());
1218 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001219 break;
1220 }
1221
Calin Juravleb5bfa962014-10-21 18:02:24 +01001222 case Primitive::kPrimFloat:
1223 case Primitive::kPrimDouble: {
1224 locations->SetInAt(0, Location::RequiresFpuRegister());
1225 locations->SetInAt(1, Location::RequiresFpuRegister());
1226 locations->SetOut(Location::RequiresFpuRegister());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001227 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001228 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001229
1230 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001231 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001232 }
1233}
1234
1235void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1236 LocationSummary* locations = mul->GetLocations();
1237 Location out = locations->Out();
1238 Location first = locations->InAt(0);
1239 Location second = locations->InAt(1);
1240 switch (mul->GetResultType()) {
1241 case Primitive::kPrimInt: {
1242 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1243 break;
1244 }
1245 case Primitive::kPrimLong: {
1246 Register out_hi = out.AsRegisterPairHigh<Register>();
1247 Register out_lo = out.AsRegisterPairLow<Register>();
1248 Register in1_hi = first.AsRegisterPairHigh<Register>();
1249 Register in1_lo = first.AsRegisterPairLow<Register>();
1250 Register in2_hi = second.AsRegisterPairHigh<Register>();
1251 Register in2_lo = second.AsRegisterPairLow<Register>();
1252
1253 // Extra checks to protect caused by the existence of R1_R2.
1254 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1255 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1256 DCHECK_NE(out_hi, in1_lo);
1257 DCHECK_NE(out_hi, in2_lo);
1258
1259 // input: in1 - 64 bits, in2 - 64 bits
1260 // output: out
1261 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1262 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1263 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1264
1265 // IP <- in1.lo * in2.hi
1266 __ mul(IP, in1_lo, in2_hi);
1267 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1268 __ mla(out_hi, in1_hi, in2_lo, IP);
1269 // out.lo <- (in1.lo * in2.lo)[31:0];
1270 __ umull(out_lo, IP, in1_lo, in2_lo);
1271 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1272 __ add(out_hi, out_hi, ShifterOperand(IP));
1273 break;
1274 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001275
1276 case Primitive::kPrimFloat: {
1277 __ vmuls(FromDToLowS(out.As<DRegister>()),
1278 FromDToLowS(first.As<DRegister>()),
1279 FromDToLowS(second.As<DRegister>()));
Calin Juravle34bacdf2014-10-07 20:23:36 +01001280 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001281 }
1282
1283 case Primitive::kPrimDouble: {
1284 __ vmuld(out.As<DRegister>(), first.As<DRegister>(), second.As<DRegister>());
1285 break;
1286 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001287
1288 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001289 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001290 }
1291}
1292
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001293void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001294 LocationSummary* locations =
1295 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001296 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001297 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1298 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1299 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001300}
1301
1302void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1303 InvokeRuntimeCallingConvention calling_convention;
1304 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1305 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1306
Nicolas Geoffray707c8092014-04-04 10:50:14 +01001307 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocObjectWithAccessCheck).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001308 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001309 __ blx(LR);
1310
Nicolas Geoffray39468442014-09-02 15:17:15 +01001311 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001312 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001313}
1314
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001315void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1316 LocationSummary* locations =
1317 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1318 InvokeRuntimeCallingConvention calling_convention;
1319 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1320 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1321 locations->SetOut(Location::RegisterLocation(R0));
1322 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1323}
1324
1325void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1326 InvokeRuntimeCallingConvention calling_convention;
1327 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1328 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1329
1330 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocArrayWithAccessCheck).Int32Value();
1331 __ LoadFromOffset(kLoadWord, LR, TR, offset);
1332 __ blx(LR);
1333
1334 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
1335 DCHECK(!codegen_->IsLeafMethod());
1336}
1337
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001338void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001339 LocationSummary* locations =
1340 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001341 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1342 if (location.IsStackSlot()) {
1343 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1344 } else if (location.IsDoubleStackSlot()) {
1345 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001346 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001347 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001348}
1349
1350void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001351 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001352}
1353
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001354void LocationsBuilderARM::VisitNot(HNot* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001355 LocationSummary* locations =
1356 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001357 locations->SetInAt(0, Location::RequiresRegister());
1358 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001359}
1360
1361void InstructionCodeGeneratorARM::VisitNot(HNot* instruction) {
1362 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001363 __ eor(locations->Out().As<Register>(),
1364 locations->InAt(0).As<Register>(), ShifterOperand(1));
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001365}
1366
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001367void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001368 LocationSummary* locations =
1369 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001370 locations->SetInAt(0, Location::RequiresRegister());
1371 locations->SetInAt(1, Location::RequiresRegister());
1372 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001373}
1374
1375void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1376 Label greater, done;
1377 LocationSummary* locations = compare->GetLocations();
1378 switch (compare->InputAt(0)->GetType()) {
1379 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001380 Register output = locations->Out().As<Register>();
1381 Location left = locations->InAt(0);
1382 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001383 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001384 __ cmp(left.AsRegisterPairHigh<Register>(),
1385 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001386 __ b(&less, LT);
1387 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001388 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1389 // the status flags.
1390 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001391 __ cmp(left.AsRegisterPairLow<Register>(),
1392 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001393 __ b(&done, EQ);
1394 __ b(&less, CC);
1395
1396 __ Bind(&greater);
1397 __ LoadImmediate(output, 1);
1398 __ b(&done);
1399
1400 __ Bind(&less);
1401 __ LoadImmediate(output, -1);
1402
1403 __ Bind(&done);
1404 break;
1405 }
1406 default:
1407 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1408 }
1409}
1410
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001411void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001412 LocationSummary* locations =
1413 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001414 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1415 locations->SetInAt(i, Location::Any());
1416 }
1417 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001418}
1419
1420void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001421 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001422}
1423
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001424void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001425 LocationSummary* locations =
1426 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001427 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001428 locations->SetInAt(0, Location::RequiresRegister());
1429 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001430 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001431 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001432 locations->AddTemp(Location::RequiresRegister());
1433 locations->AddTemp(Location::RequiresRegister());
1434 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001435}
1436
1437void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1438 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001439 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001440 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001441 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001442
1443 switch (field_type) {
1444 case Primitive::kPrimBoolean:
1445 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001446 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001447 __ StoreToOffset(kStoreByte, value, obj, offset);
1448 break;
1449 }
1450
1451 case Primitive::kPrimShort:
1452 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001453 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001454 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1455 break;
1456 }
1457
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001458 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001459 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001460 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001461 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001462 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001463 Register temp = locations->GetTemp(0).As<Register>();
1464 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001465 codegen_->MarkGCCard(temp, card, obj, value);
1466 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001467 break;
1468 }
1469
1470 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001471 Location value = locations->InAt(1);
1472 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001473 break;
1474 }
1475
1476 case Primitive::kPrimFloat:
1477 case Primitive::kPrimDouble:
1478 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001479 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001480 case Primitive::kPrimVoid:
1481 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001482 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001483 }
1484}
1485
1486void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001487 LocationSummary* locations =
1488 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001489 locations->SetInAt(0, Location::RequiresRegister());
1490 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001491}
1492
1493void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1494 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001495 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001496 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1497
1498 switch (instruction->GetType()) {
1499 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001500 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001501 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1502 break;
1503 }
1504
1505 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001506 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001507 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1508 break;
1509 }
1510
1511 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001512 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001513 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1514 break;
1515 }
1516
1517 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001518 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001519 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1520 break;
1521 }
1522
1523 case Primitive::kPrimInt:
1524 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001525 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001526 __ LoadFromOffset(kLoadWord, out, obj, offset);
1527 break;
1528 }
1529
1530 case Primitive::kPrimLong: {
1531 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001532 Location out = locations->Out();
1533 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001534 break;
1535 }
1536
1537 case Primitive::kPrimFloat:
1538 case Primitive::kPrimDouble:
1539 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001540 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001541 case Primitive::kPrimVoid:
1542 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001543 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001544 }
1545}
1546
1547void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001548 LocationSummary* locations =
1549 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001550 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001551 if (instruction->HasUses()) {
1552 locations->SetOut(Location::SameAsFirstInput());
1553 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001554}
1555
1556void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001557 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001558 codegen_->AddSlowPath(slow_path);
1559
1560 LocationSummary* locations = instruction->GetLocations();
1561 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001562
1563 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001564 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001565 __ b(slow_path->GetEntryLabel(), EQ);
1566 } else {
1567 DCHECK(obj.IsConstant()) << obj;
1568 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1569 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001570 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001571}
1572
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001573void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001574 LocationSummary* locations =
1575 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001576 locations->SetInAt(0, Location::RequiresRegister());
1577 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1578 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001579}
1580
1581void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1582 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001583 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001584 Location index = locations->InAt(1);
1585
1586 switch (instruction->GetType()) {
1587 case Primitive::kPrimBoolean: {
1588 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001589 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001590 if (index.IsConstant()) {
1591 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1592 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1593 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001594 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001595 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1596 }
1597 break;
1598 }
1599
1600 case Primitive::kPrimByte: {
1601 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001602 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001603 if (index.IsConstant()) {
1604 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1605 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1606 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001607 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001608 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1609 }
1610 break;
1611 }
1612
1613 case Primitive::kPrimShort: {
1614 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001615 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001616 if (index.IsConstant()) {
1617 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1618 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1619 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001620 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001621 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1622 }
1623 break;
1624 }
1625
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 out = locations->Out().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 __ LoadFromOffset(kLoadUnsignedHalfword, out, 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 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1635 }
1636 break;
1637 }
1638
1639 case Primitive::kPrimInt:
1640 case Primitive::kPrimNot: {
1641 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1642 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001643 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001644 if (index.IsConstant()) {
1645 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1646 __ LoadFromOffset(kLoadWord, out, obj, offset);
1647 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001648 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001649 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1650 }
1651 break;
1652 }
1653
1654 case Primitive::kPrimLong: {
1655 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001656 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001657 if (index.IsConstant()) {
1658 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001659 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001660 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001661 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1662 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001663 }
1664 break;
1665 }
1666
1667 case Primitive::kPrimFloat:
1668 case Primitive::kPrimDouble:
1669 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001670 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001671 case Primitive::kPrimVoid:
1672 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001673 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001674 }
1675}
1676
1677void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001678 Primitive::Type value_type = instruction->GetComponentType();
1679 bool is_object = value_type == Primitive::kPrimNot;
1680 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1681 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1682 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001683 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001684 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1685 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1686 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001687 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001688 locations->SetInAt(0, Location::RequiresRegister());
1689 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1690 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001691 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001692}
1693
1694void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1695 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001696 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001697 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001698 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001699
1700 switch (value_type) {
1701 case Primitive::kPrimBoolean:
1702 case Primitive::kPrimByte: {
1703 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001704 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001705 if (index.IsConstant()) {
1706 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1707 __ StoreToOffset(kStoreByte, value, obj, offset);
1708 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001709 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001710 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1711 }
1712 break;
1713 }
1714
1715 case Primitive::kPrimShort:
1716 case Primitive::kPrimChar: {
1717 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001718 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001719 if (index.IsConstant()) {
1720 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1721 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1722 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001723 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001724 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1725 }
1726 break;
1727 }
1728
1729 case Primitive::kPrimInt: {
1730 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001731 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001732 if (index.IsConstant()) {
1733 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1734 __ StoreToOffset(kStoreWord, value, obj, offset);
1735 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001736 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001737 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1738 }
1739 break;
1740 }
1741
1742 case Primitive::kPrimNot: {
1743 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAputObject).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001744 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001745 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001746 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001747 DCHECK(!codegen_->IsLeafMethod());
1748 break;
1749 }
1750
1751 case Primitive::kPrimLong: {
1752 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001753 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001754 if (index.IsConstant()) {
1755 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001756 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001757 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001758 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1759 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001760 }
1761 break;
1762 }
1763
1764 case Primitive::kPrimFloat:
1765 case Primitive::kPrimDouble:
1766 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001767 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001768 case Primitive::kPrimVoid:
1769 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001770 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001771 }
1772}
1773
1774void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001775 LocationSummary* locations =
1776 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001777 locations->SetInAt(0, Location::RequiresRegister());
1778 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001779}
1780
1781void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1782 LocationSummary* locations = instruction->GetLocations();
1783 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001784 Register obj = locations->InAt(0).As<Register>();
1785 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001786 __ LoadFromOffset(kLoadWord, out, obj, offset);
1787}
1788
1789void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001790 LocationSummary* locations =
1791 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001792 locations->SetInAt(0, Location::RequiresRegister());
1793 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001794 if (instruction->HasUses()) {
1795 locations->SetOut(Location::SameAsFirstInput());
1796 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001797}
1798
1799void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1800 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001801 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001802 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001803 codegen_->AddSlowPath(slow_path);
1804
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001805 Register index = locations->InAt(0).As<Register>();
1806 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001807
1808 __ cmp(index, ShifterOperand(length));
1809 __ b(slow_path->GetEntryLabel(), CS);
1810}
1811
1812void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1813 Label is_null;
1814 __ CompareAndBranchIfZero(value, &is_null);
1815 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1816 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1817 __ strb(card, Address(card, temp));
1818 __ Bind(&is_null);
1819}
1820
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001821void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1822 temp->SetLocations(nullptr);
1823}
1824
1825void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1826 // Nothing to do, this is driven by the code generator.
1827}
1828
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001829void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001830 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001831}
1832
1833void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001834 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1835}
1836
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001837void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
1838 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1839}
1840
1841void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001842 HBasicBlock* block = instruction->GetBlock();
1843 if (block->GetLoopInformation() != nullptr) {
1844 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1845 // The back edge will generate the suspend check.
1846 return;
1847 }
1848 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1849 // The goto will generate the suspend check.
1850 return;
1851 }
1852 GenerateSuspendCheck(instruction, nullptr);
1853}
1854
1855void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
1856 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001857 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001858 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001859 codegen_->AddSlowPath(slow_path);
1860
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001861 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001862 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001863 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001864 __ Bind(slow_path->GetReturnLabel());
1865 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001866 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001867 __ b(slow_path->GetEntryLabel());
1868 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001869}
1870
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001871ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
1872 return codegen_->GetAssembler();
1873}
1874
1875void ParallelMoveResolverARM::EmitMove(size_t index) {
1876 MoveOperands* move = moves_.Get(index);
1877 Location source = move->GetSource();
1878 Location destination = move->GetDestination();
1879
1880 if (source.IsRegister()) {
1881 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001882 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001883 } else {
1884 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001885 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001886 SP, destination.GetStackIndex());
1887 }
1888 } else if (source.IsStackSlot()) {
1889 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001890 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001891 SP, source.GetStackIndex());
1892 } else {
1893 DCHECK(destination.IsStackSlot());
1894 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1895 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
1896 }
1897 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001898 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01001899 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001900 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
1901 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001902 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001903 } else {
1904 DCHECK(destination.IsStackSlot());
1905 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001906 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001907 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001908 }
1909}
1910
1911void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
1912 __ Mov(IP, reg);
1913 __ LoadFromOffset(kLoadWord, reg, SP, mem);
1914 __ StoreToOffset(kStoreWord, IP, SP, mem);
1915}
1916
1917void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
1918 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
1919 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
1920 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
1921 SP, mem1 + stack_offset);
1922 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
1923 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
1924 SP, mem2 + stack_offset);
1925 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
1926}
1927
1928void ParallelMoveResolverARM::EmitSwap(size_t index) {
1929 MoveOperands* move = moves_.Get(index);
1930 Location source = move->GetSource();
1931 Location destination = move->GetDestination();
1932
1933 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001934 DCHECK_NE(source.As<Register>(), IP);
1935 DCHECK_NE(destination.As<Register>(), IP);
1936 __ Mov(IP, source.As<Register>());
1937 __ Mov(source.As<Register>(), destination.As<Register>());
1938 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001939 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001940 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001941 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001942 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001943 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
1944 Exchange(source.GetStackIndex(), destination.GetStackIndex());
1945 } else {
1946 LOG(FATAL) << "Unimplemented";
1947 }
1948}
1949
1950void ParallelMoveResolverARM::SpillScratch(int reg) {
1951 __ Push(static_cast<Register>(reg));
1952}
1953
1954void ParallelMoveResolverARM::RestoreScratch(int reg) {
1955 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001956}
1957
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001958} // namespace arm
1959} // namespace art