blob: 4733432ce8a0bcb1c5ba6dc05b40c8be5da494f5 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070019#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010020#include "gc/accounting/card_table.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070021#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000022#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010023#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070024#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010025#include "utils/assembler.h"
26#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010028#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000029
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000030namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010031
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032namespace arm {
33
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000034static DRegister FromLowSToD(SRegister reg) {
35 DCHECK_EQ(reg % 2, 0);
36 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010037}
38
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010039static constexpr bool kExplicitStackOverflowCheck = false;
40
41static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
42static constexpr int kCurrentMethodStackOffset = 0;
43
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2 };
45static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { };
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010048static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010049
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000050class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051 public:
52 InvokeRuntimeCallingConvention()
53 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 kRuntimeParameterCoreRegistersLength,
55 kRuntimeParameterFpuRegisters,
56 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010057
58 private:
59 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
60};
61
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
63
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010064class SlowPathCodeARM : public SlowPathCode {
65 public:
66 SlowPathCodeARM() : entry_label_(), exit_label_() {}
67
68 Label* GetEntryLabel() { return &entry_label_; }
69 Label* GetExitLabel() { return &exit_label_; }
70
71 private:
72 Label entry_label_;
73 Label exit_label_;
74
75 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
76};
77
78class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010079 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010080 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010081
82 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
83 __ Bind(GetEntryLabel());
84 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowNullPointer).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +010085 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +010087 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 }
89
90 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010091 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010092 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
93};
94
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010095class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010096 public:
97 StackOverflowCheckSlowPathARM() {}
98
99 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
100 __ Bind(GetEntryLabel());
101 __ LoadFromOffset(kLoadWord, PC, TR,
102 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
103 }
104
105 private:
106 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
107};
108
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100109class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000110 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100111 explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
112 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000113
114 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100117 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000118 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pTestSuspend).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100119 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000120 __ blx(LR);
121 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100122 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100123 if (successor_ == nullptr) {
124 __ b(GetReturnLabel());
125 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100126 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100127 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000128 }
129
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100130 Label* GetReturnLabel() {
131 DCHECK(successor_ == nullptr);
132 return &return_label_;
133 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000134
135 private:
136 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100137 // If not null, the block to branch to after the suspend check.
138 HBasicBlock* const successor_;
139
140 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000141 Label return_label_;
142
143 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
144};
145
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100146class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100147 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100148 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
149 Location index_location,
150 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100151 : instruction_(instruction),
152 index_location_(index_location),
153 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100154
155 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100156 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100157 __ Bind(GetEntryLabel());
158 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100159 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
160 arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100161 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowArrayBounds).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100162 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100164 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100165 }
166
167 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100168 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100169 const Location index_location_;
170 const Location length_location_;
171
172 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
173};
174
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100175#undef __
176#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700177
178inline Condition ARMCondition(IfCondition cond) {
179 switch (cond) {
180 case kCondEQ: return EQ;
181 case kCondNE: return NE;
182 case kCondLT: return LT;
183 case kCondLE: return LE;
184 case kCondGT: return GT;
185 case kCondGE: return GE;
186 default:
187 LOG(FATAL) << "Unknown if condition";
188 }
189 return EQ; // Unreachable.
190}
191
192inline Condition ARMOppositeCondition(IfCondition cond) {
193 switch (cond) {
194 case kCondEQ: return NE;
195 case kCondNE: return EQ;
196 case kCondLT: return GE;
197 case kCondLE: return GT;
198 case kCondGT: return LE;
199 case kCondGE: return LT;
200 default:
201 LOG(FATAL) << "Unknown if condition";
202 }
203 return EQ; // Unreachable.
204}
205
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100206void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
207 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
208}
209
210void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000211 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100212}
213
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100214size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
215 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
216 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100217}
218
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100219size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
220 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
221 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100222}
223
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100224CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000225 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100226 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100227 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100228 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100229 move_resolver_(graph->GetArena(), this),
230 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100231
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100232size_t CodeGeneratorARM::FrameEntrySpillSize() const {
233 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
234}
235
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100236Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100237 switch (type) {
238 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100239 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100240 ArmManagedRegister pair =
241 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100242 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
243 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
244
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100245 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
246 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100247 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100248 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100249 }
250
251 case Primitive::kPrimByte:
252 case Primitive::kPrimBoolean:
253 case Primitive::kPrimChar:
254 case Primitive::kPrimShort:
255 case Primitive::kPrimInt:
256 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100257 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100258 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100259 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
260 ArmManagedRegister current =
261 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
262 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100263 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100264 }
265 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100266 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100267 }
268
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000269 case Primitive::kPrimFloat: {
270 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
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
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000274 case Primitive::kPrimDouble: {
275 int reg = FindTwoFreeConsecutiveEntries(blocked_fpu_registers_, kNumberOfSRegisters);
276 return Location::FpuRegisterPairLocation(reg, reg + 1);
277 }
278
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100279 case Primitive::kPrimVoid:
280 LOG(FATAL) << "Unreachable type " << type;
281 }
282
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100283 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100284}
285
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100286void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100287 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100288 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100289
290 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100291 blocked_core_registers_[SP] = true;
292 blocked_core_registers_[LR] = true;
293 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100294
295 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100296 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100297
298 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100299 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100300
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100301 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100302 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100303
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100304 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100305 // We always save and restore R6 and R7 to make sure we can use three
306 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100307 blocked_core_registers_[R5] = true;
308 blocked_core_registers_[R8] = true;
309 blocked_core_registers_[R10] = true;
310 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100311
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000312 blocked_fpu_registers_[S16] = true;
313 blocked_fpu_registers_[S17] = true;
314 blocked_fpu_registers_[S18] = true;
315 blocked_fpu_registers_[S19] = true;
316 blocked_fpu_registers_[S20] = true;
317 blocked_fpu_registers_[S21] = true;
318 blocked_fpu_registers_[S22] = true;
319 blocked_fpu_registers_[S23] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100320
321 UpdateBlockedPairRegisters();
322}
323
324void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
325 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
326 ArmManagedRegister current =
327 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
328 if (blocked_core_registers_[current.AsRegisterPairLow()]
329 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
330 blocked_register_pairs_[i] = true;
331 }
332 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100333}
334
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100335InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
336 : HGraphVisitor(graph),
337 assembler_(codegen->GetAssembler()),
338 codegen_(codegen) {}
339
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000340void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700341 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100342 if (!skip_overflow_check) {
343 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100344 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100345 AddSlowPath(slow_path);
346
347 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
348 __ cmp(SP, ShifterOperand(IP));
349 __ b(slow_path->GetEntryLabel(), CC);
350 } else {
351 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100352 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100353 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100354 }
355 }
356
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100357 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
358 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000359
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100360 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100361 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100362 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000363}
364
365void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100366 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100367 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000368}
369
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100370void CodeGeneratorARM::Bind(HBasicBlock* block) {
371 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000372}
373
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100374Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
375 switch (load->GetType()) {
376 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100377 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100378 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
379 break;
380
381 case Primitive::kPrimInt:
382 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100383 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100384 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100385
386 case Primitive::kPrimBoolean:
387 case Primitive::kPrimByte:
388 case Primitive::kPrimChar:
389 case Primitive::kPrimShort:
390 case Primitive::kPrimVoid:
391 LOG(FATAL) << "Unexpected type " << load->GetType();
392 }
393
394 LOG(FATAL) << "Unreachable";
395 return Location();
396}
397
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100398Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
399 switch (type) {
400 case Primitive::kPrimBoolean:
401 case Primitive::kPrimByte:
402 case Primitive::kPrimChar:
403 case Primitive::kPrimShort:
404 case Primitive::kPrimInt:
405 case Primitive::kPrimNot: {
406 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000407 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100408 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100409 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100410 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000411 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100412 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100413 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100414
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000415 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100416 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000417 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100418 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000419 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100420 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100421 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
422 calling_convention.GetRegisterPairAt(index));
423 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100424 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000425 return Location::QuickParameter(stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100426 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000427 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
428 }
429 }
430
431 case Primitive::kPrimFloat: {
432 uint32_t stack_index = stack_index_++;
433 if (float_index_ % 2 == 0) {
434 float_index_ = std::max(double_index_, float_index_);
435 }
436 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
437 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
438 } else {
439 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
440 }
441 }
442
443 case Primitive::kPrimDouble: {
444 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
445 uint32_t stack_index = stack_index_;
446 stack_index_ += 2;
447 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
448 uint32_t index = double_index_;
449 double_index_ += 2;
450 return Location::FpuRegisterPairLocation(
451 calling_convention.GetFpuRegisterAt(index),
452 calling_convention.GetFpuRegisterAt(index + 1));
453 } else {
454 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100455 }
456 }
457
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100458 case Primitive::kPrimVoid:
459 LOG(FATAL) << "Unexpected parameter type " << type;
460 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100461 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100462 return Location();
463}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100464
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000465Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
466 switch (type) {
467 case Primitive::kPrimBoolean:
468 case Primitive::kPrimByte:
469 case Primitive::kPrimChar:
470 case Primitive::kPrimShort:
471 case Primitive::kPrimInt:
472 case Primitive::kPrimNot: {
473 return Location::RegisterLocation(R0);
474 }
475
476 case Primitive::kPrimFloat: {
477 return Location::FpuRegisterLocation(S0);
478 }
479
480 case Primitive::kPrimLong: {
481 return Location::RegisterPairLocation(R0, R1);
482 }
483
484 case Primitive::kPrimDouble: {
485 return Location::FpuRegisterPairLocation(S0, S1);
486 }
487
488 case Primitive::kPrimVoid:
489 return Location();
490 }
491 UNREACHABLE();
492 return Location();
493}
494
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100495void CodeGeneratorARM::Move32(Location destination, Location source) {
496 if (source.Equals(destination)) {
497 return;
498 }
499 if (destination.IsRegister()) {
500 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100501 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100502 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000503 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100504 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100505 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100506 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100507 } else if (destination.IsFpuRegister()) {
508 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000509 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100510 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000511 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100512 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000513 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100514 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100515 } else {
516 DCHECK(destination.IsStackSlot());
517 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100518 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100519 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000520 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100521 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100522 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100523 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
524 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100525 }
526 }
527}
528
529void CodeGeneratorARM::Move64(Location destination, Location source) {
530 if (source.Equals(destination)) {
531 return;
532 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100533 if (destination.IsRegisterPair()) {
534 if (source.IsRegisterPair()) {
535 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
536 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100537 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000538 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100539 } else if (source.IsQuickParameter()) {
540 uint32_t argument_index = source.GetQuickParameterIndex();
541 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100542 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100543 calling_convention.GetRegisterAt(argument_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100544 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
545 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100546 } else {
547 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100548 if (destination.AsRegisterPairLow<Register>() == R1) {
549 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100550 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
551 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100552 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100553 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100554 SP, source.GetStackIndex());
555 }
556 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000557 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100558 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000559 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
560 SP,
561 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100562 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000563 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100564 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100565 } else if (destination.IsQuickParameter()) {
566 InvokeDexCallingConvention calling_convention;
567 uint32_t argument_index = destination.GetQuickParameterIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100568 if (source.IsRegisterPair()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100569 __ Mov(calling_convention.GetRegisterAt(argument_index),
570 source.AsRegisterPairLow<Register>());
571 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
572 SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100573 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000574 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100575 } else {
576 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000577 __ LoadFromOffset(
578 kLoadWord, calling_convention.GetRegisterAt(argument_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100579 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
580 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100581 }
582 } else {
583 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100584 if (source.IsRegisterPair()) {
585 if (source.AsRegisterPairLow<Register>() == R1) {
586 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100587 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
588 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100589 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100590 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100591 SP, destination.GetStackIndex());
592 }
593 } else if (source.IsQuickParameter()) {
594 InvokeDexCallingConvention calling_convention;
595 uint32_t argument_index = source.GetQuickParameterIndex();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100596 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(argument_index),
597 SP, destination.GetStackIndex());
598 __ LoadFromOffset(kLoadWord, R0,
599 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
600 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000601 } else if (source.IsFpuRegisterPair()) {
602 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
603 SP,
604 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100605 } else {
606 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100607 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
608 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
609 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
610 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100611 }
612 }
613}
614
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100615void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100616 LocationSummary* locations = instruction->GetLocations();
617 if (locations != nullptr && locations->Out().Equals(location)) {
618 return;
619 }
620
Roland Levillain476df552014-10-09 17:51:36 +0100621 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100622 int32_t value = instruction->AsIntConstant()->GetValue();
623 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100624 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100625 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100626 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100627 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100628 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100629 }
Roland Levillain476df552014-10-09 17:51:36 +0100630 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100631 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100632 if (location.IsRegisterPair()) {
633 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
634 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100635 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100636 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100637 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100638 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100639 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100640 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100641 }
Roland Levillain476df552014-10-09 17:51:36 +0100642 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100643 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
644 switch (instruction->GetType()) {
645 case Primitive::kPrimBoolean:
646 case Primitive::kPrimByte:
647 case Primitive::kPrimChar:
648 case Primitive::kPrimShort:
649 case Primitive::kPrimInt:
650 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100651 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100652 Move32(location, Location::StackSlot(stack_slot));
653 break;
654
655 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100656 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100657 Move64(location, Location::DoubleStackSlot(stack_slot));
658 break;
659
660 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100661 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100662 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000663 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100664 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100665 switch (instruction->GetType()) {
666 case Primitive::kPrimBoolean:
667 case Primitive::kPrimByte:
668 case Primitive::kPrimChar:
669 case Primitive::kPrimShort:
670 case Primitive::kPrimNot:
671 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100672 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100673 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100674 break;
675
676 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100677 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100678 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100679 break;
680
681 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100682 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100683 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000684 }
685}
686
687void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000688 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000689}
690
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000691void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000692 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100693 DCHECK(!successor->IsExitBlock());
694
695 HBasicBlock* block = got->GetBlock();
696 HInstruction* previous = got->GetPrevious();
697
698 HLoopInformation* info = block->GetLoopInformation();
699 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
700 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
701 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
702 return;
703 }
704
705 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
706 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
707 }
708 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000709 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000710 }
711}
712
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000713void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000714 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000715}
716
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000717void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000718 if (kIsDebugBuild) {
719 __ Comment("Unreachable");
720 __ bkpt(0);
721 }
722}
723
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000724void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100725 LocationSummary* locations =
726 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100727 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100728 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100729 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100730 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000731}
732
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000733void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700734 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100735 if (cond->IsIntConstant()) {
736 // Constant condition, statically compared against 1.
737 int32_t cond_value = cond->AsIntConstant()->GetValue();
738 if (cond_value == 1) {
739 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
740 if_instr->IfTrueSuccessor())) {
741 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100742 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100743 return;
744 } else {
745 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100746 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100747 } else {
748 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
749 // Condition has been materialized, compare the output to 0
750 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
751 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
752 ShifterOperand(0));
753 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
754 } else {
755 // Condition has not been materialized, use its inputs as the
756 // comparison and its condition as the branch condition.
757 LocationSummary* locations = cond->GetLocations();
758 if (locations->InAt(1).IsRegister()) {
759 __ cmp(locations->InAt(0).As<Register>(),
760 ShifterOperand(locations->InAt(1).As<Register>()));
761 } else {
762 DCHECK(locations->InAt(1).IsConstant());
763 int32_t value =
764 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
765 ShifterOperand operand;
766 if (ShifterOperand::CanHoldArm(value, &operand)) {
767 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
768 } else {
769 Register temp = IP;
770 __ LoadImmediate(temp, value);
771 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
772 }
773 }
774 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
775 ARMCondition(cond->AsCondition()->GetCondition()));
776 }
Dave Allison20dfc792014-06-16 20:44:29 -0700777 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100778 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
779 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700780 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000781 }
782}
783
Dave Allison20dfc792014-06-16 20:44:29 -0700784
785void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100786 LocationSummary* locations =
787 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100788 locations->SetInAt(0, Location::RequiresRegister());
789 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100790 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100791 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100792 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000793}
794
Dave Allison20dfc792014-06-16 20:44:29 -0700795void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100796 if (!comp->NeedsMaterialization()) return;
797
798 LocationSummary* locations = comp->GetLocations();
799 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100800 __ cmp(locations->InAt(0).As<Register>(),
801 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100802 } else {
803 DCHECK(locations->InAt(1).IsConstant());
804 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
805 ShifterOperand operand;
806 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100807 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100808 } else {
809 Register temp = IP;
810 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100811 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100812 }
Dave Allison20dfc792014-06-16 20:44:29 -0700813 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100814 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100815 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100816 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100817 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100818 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700819}
820
821void LocationsBuilderARM::VisitEqual(HEqual* comp) {
822 VisitCondition(comp);
823}
824
825void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
826 VisitCondition(comp);
827}
828
829void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
830 VisitCondition(comp);
831}
832
833void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
834 VisitCondition(comp);
835}
836
837void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
838 VisitCondition(comp);
839}
840
841void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
842 VisitCondition(comp);
843}
844
845void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
846 VisitCondition(comp);
847}
848
849void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
850 VisitCondition(comp);
851}
852
853void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
854 VisitCondition(comp);
855}
856
857void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
858 VisitCondition(comp);
859}
860
861void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
862 VisitCondition(comp);
863}
864
865void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
866 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000867}
868
869void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000870 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000871}
872
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000873void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
874 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000875}
876
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000877void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100878 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000879}
880
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000881void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100882 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000883}
884
885void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100886 LocationSummary* locations =
887 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100888 switch (store->InputAt(1)->GetType()) {
889 case Primitive::kPrimBoolean:
890 case Primitive::kPrimByte:
891 case Primitive::kPrimChar:
892 case Primitive::kPrimShort:
893 case Primitive::kPrimInt:
894 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100895 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100896 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
897 break;
898
899 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100900 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100901 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
902 break;
903
904 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100905 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100906 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000907}
908
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000909void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000910}
911
912void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100913 LocationSummary* locations =
914 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100915 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000916}
917
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000918void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100919 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000920}
921
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100922void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100923 LocationSummary* locations =
924 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100925 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100926}
927
928void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
929 // Will be generated at use site.
930}
931
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100932void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
933 LocationSummary* locations =
934 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
935 locations->SetOut(Location::ConstantLocation(constant));
936}
937
938void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
939 // Will be generated at use site.
940}
941
942void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
943 LocationSummary* locations =
944 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
945 locations->SetOut(Location::ConstantLocation(constant));
946}
947
948void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
949 // Will be generated at use site.
950}
951
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000952void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000953 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000954}
955
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000956void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
957 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000958}
959
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000960void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100961 LocationSummary* locations =
962 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000963 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000964}
965
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000966void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000967 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000968}
969
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000970void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100971 HandleInvoke(invoke);
972}
973
974void InstructionCodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100975 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100976}
977
978void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100979 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100980 uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>);
981 size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).Int32Value() +
982 invoke->GetIndexInDexCache() * kArmWordSize;
983
984 // TODO: Implement all kinds of calls:
985 // 1) boot -> boot
986 // 2) app -> boot
987 // 3) app -> app
988 //
989 // Currently we implement the app -> app logic, which looks up in the resolve cache.
990
991 // temp = method;
992 LoadCurrentMethod(temp);
993 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100994 __ LoadFromOffset(kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100995 // temp = temp[index_in_cache]
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100996 __ LoadFromOffset(kLoadWord, temp, temp, index_in_cache);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100997 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100998 __ LoadFromOffset(kLoadWord, LR, temp,
999 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001000 // LR()
1001 __ blx(LR);
1002
1003 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1004 DCHECK(!codegen_->IsLeafMethod());
1005}
1006
1007void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1008 HandleInvoke(invoke);
1009}
1010
1011void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001012 LocationSummary* locations =
1013 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001014 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001015
1016 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001017 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001018 HInstruction* input = invoke->InputAt(i);
1019 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1020 }
1021
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001022 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001023}
1024
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001025
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001026void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001027 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001028 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1029 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1030 LocationSummary* locations = invoke->GetLocations();
1031 Location receiver = locations->InAt(0);
1032 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1033 // temp = object->GetClass();
1034 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001035 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1036 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001037 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001038 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001039 }
1040 // temp = temp->GetMethodAt(method_offset);
1041 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001042 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001043 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001044 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001045 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001046 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001047 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001048 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001049}
1050
Roland Levillain88cb1752014-10-20 16:36:47 +01001051void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1052 LocationSummary* locations =
1053 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1054 switch (neg->GetResultType()) {
1055 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001056 case Primitive::kPrimLong: {
1057 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001058 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001059 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001060 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001061 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001062
Roland Levillain88cb1752014-10-20 16:36:47 +01001063 case Primitive::kPrimFloat:
1064 case Primitive::kPrimDouble:
1065 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1066 break;
1067
1068 default:
1069 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1070 }
1071}
1072
1073void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1074 LocationSummary* locations = neg->GetLocations();
1075 Location out = locations->Out();
1076 Location in = locations->InAt(0);
1077 switch (neg->GetResultType()) {
1078 case Primitive::kPrimInt:
1079 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001080 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001081 break;
1082
1083 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001084 DCHECK(in.IsRegisterPair());
1085 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1086 __ rsbs(out.AsRegisterPairLow<Register>(),
1087 in.AsRegisterPairLow<Register>(),
1088 ShifterOperand(0));
1089 // We cannot emit an RSC (Reverse Subtract with Carry)
1090 // instruction here, as it does not exist in the Thumb-2
1091 // instruction set. We use the following approach
1092 // using SBC and SUB instead.
1093 //
1094 // out.hi = -C
1095 __ sbc(out.AsRegisterPairHigh<Register>(),
1096 out.AsRegisterPairHigh<Register>(),
1097 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1098 // out.hi = out.hi - in.hi
1099 __ sub(out.AsRegisterPairHigh<Register>(),
1100 out.AsRegisterPairHigh<Register>(),
1101 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1102 break;
1103
Roland Levillain88cb1752014-10-20 16:36:47 +01001104 case Primitive::kPrimFloat:
1105 case Primitive::kPrimDouble:
1106 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1107 break;
1108
1109 default:
1110 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1111 }
1112}
1113
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001114void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001115 LocationSummary* locations =
1116 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001117 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001118 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001119 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001120 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1121 locations->SetInAt(0, Location::RequiresRegister());
1122 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1123 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001124 break;
1125 }
1126
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001127 case Primitive::kPrimFloat:
1128 case Primitive::kPrimDouble: {
1129 locations->SetInAt(0, Location::RequiresFpuRegister());
1130 locations->SetInAt(1, Location::RequiresFpuRegister());
1131 locations->SetOut(Location::RequiresFpuRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001132 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001133 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001134
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001135 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001136 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001137 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001138}
1139
1140void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1141 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001142 Location out = locations->Out();
1143 Location first = locations->InAt(0);
1144 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001145 switch (add->GetResultType()) {
1146 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001147 if (second.IsRegister()) {
1148 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001149 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001150 __ AddConstant(out.As<Register>(),
1151 first.As<Register>(),
1152 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001153 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001154 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001155
1156 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001157 __ adds(out.AsRegisterPairLow<Register>(),
1158 first.AsRegisterPairLow<Register>(),
1159 ShifterOperand(second.AsRegisterPairLow<Register>()));
1160 __ adc(out.AsRegisterPairHigh<Register>(),
1161 first.AsRegisterPairHigh<Register>(),
1162 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001163 break;
1164
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001165 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001166 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001167 break;
1168
1169 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001170 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1171 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1172 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001173 break;
1174
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001175 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001176 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001177 }
1178}
1179
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001180void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001181 LocationSummary* locations =
1182 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001183 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001184 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001185 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001186 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1187 locations->SetInAt(0, Location::RequiresRegister());
1188 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1189 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001190 break;
1191 }
Calin Juravle11351682014-10-23 15:38:15 +01001192 case Primitive::kPrimFloat:
1193 case Primitive::kPrimDouble: {
1194 locations->SetInAt(0, Location::RequiresFpuRegister());
1195 locations->SetInAt(1, Location::RequiresFpuRegister());
1196 locations->SetOut(Location::RequiresFpuRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001197 break;
Calin Juravle11351682014-10-23 15:38:15 +01001198 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001199 default:
Calin Juravle11351682014-10-23 15:38:15 +01001200 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001201 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001202}
1203
1204void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1205 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001206 Location out = locations->Out();
1207 Location first = locations->InAt(0);
1208 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001209 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001210 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001211 if (second.IsRegister()) {
1212 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001213 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001214 __ AddConstant(out.As<Register>(),
1215 first.As<Register>(),
1216 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001217 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001218 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001219 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001220
Calin Juravle11351682014-10-23 15:38:15 +01001221 case Primitive::kPrimLong: {
1222 __ subs(out.AsRegisterPairLow<Register>(),
1223 first.AsRegisterPairLow<Register>(),
1224 ShifterOperand(second.AsRegisterPairLow<Register>()));
1225 __ sbc(out.AsRegisterPairHigh<Register>(),
1226 first.AsRegisterPairHigh<Register>(),
1227 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001228 break;
Calin Juravle11351682014-10-23 15:38:15 +01001229 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001230
Calin Juravle11351682014-10-23 15:38:15 +01001231 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001232 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001233 break;
Calin Juravle11351682014-10-23 15:38:15 +01001234 }
1235
1236 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001237 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1238 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1239 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001240 break;
1241 }
1242
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001243
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001244 default:
Calin Juravle11351682014-10-23 15:38:15 +01001245 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001246 }
1247}
1248
Calin Juravle34bacdf2014-10-07 20:23:36 +01001249void LocationsBuilderARM::VisitMul(HMul* mul) {
1250 LocationSummary* locations =
1251 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1252 switch (mul->GetResultType()) {
1253 case Primitive::kPrimInt:
1254 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001255 locations->SetInAt(0, Location::RequiresRegister());
1256 locations->SetInAt(1, Location::RequiresRegister());
1257 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001258 break;
1259 }
1260
Calin Juravleb5bfa962014-10-21 18:02:24 +01001261 case Primitive::kPrimFloat:
1262 case Primitive::kPrimDouble: {
1263 locations->SetInAt(0, Location::RequiresFpuRegister());
1264 locations->SetInAt(1, Location::RequiresFpuRegister());
1265 locations->SetOut(Location::RequiresFpuRegister());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001266 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001267 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001268
1269 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001270 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001271 }
1272}
1273
1274void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1275 LocationSummary* locations = mul->GetLocations();
1276 Location out = locations->Out();
1277 Location first = locations->InAt(0);
1278 Location second = locations->InAt(1);
1279 switch (mul->GetResultType()) {
1280 case Primitive::kPrimInt: {
1281 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1282 break;
1283 }
1284 case Primitive::kPrimLong: {
1285 Register out_hi = out.AsRegisterPairHigh<Register>();
1286 Register out_lo = out.AsRegisterPairLow<Register>();
1287 Register in1_hi = first.AsRegisterPairHigh<Register>();
1288 Register in1_lo = first.AsRegisterPairLow<Register>();
1289 Register in2_hi = second.AsRegisterPairHigh<Register>();
1290 Register in2_lo = second.AsRegisterPairLow<Register>();
1291
1292 // Extra checks to protect caused by the existence of R1_R2.
1293 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1294 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1295 DCHECK_NE(out_hi, in1_lo);
1296 DCHECK_NE(out_hi, in2_lo);
1297
1298 // input: in1 - 64 bits, in2 - 64 bits
1299 // output: out
1300 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1301 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1302 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1303
1304 // IP <- in1.lo * in2.hi
1305 __ mul(IP, in1_lo, in2_hi);
1306 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1307 __ mla(out_hi, in1_hi, in2_lo, IP);
1308 // out.lo <- (in1.lo * in2.lo)[31:0];
1309 __ umull(out_lo, IP, in1_lo, in2_lo);
1310 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1311 __ add(out_hi, out_hi, ShifterOperand(IP));
1312 break;
1313 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001314
1315 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001316 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001317 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001318 }
1319
1320 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001321 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1322 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1323 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001324 break;
1325 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001326
1327 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001328 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001329 }
1330}
1331
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001332void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001333 LocationSummary* locations =
1334 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001335 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001336 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1337 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1338 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001339}
1340
1341void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1342 InvokeRuntimeCallingConvention calling_convention;
1343 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1344 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1345
Nicolas Geoffray707c8092014-04-04 10:50:14 +01001346 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocObjectWithAccessCheck).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001347 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001348 __ blx(LR);
1349
Nicolas Geoffray39468442014-09-02 15:17:15 +01001350 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001351 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001352}
1353
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001354void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1355 LocationSummary* locations =
1356 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1357 InvokeRuntimeCallingConvention calling_convention;
1358 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1359 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1360 locations->SetOut(Location::RegisterLocation(R0));
1361 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1362}
1363
1364void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1365 InvokeRuntimeCallingConvention calling_convention;
1366 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1367 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1368
1369 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocArrayWithAccessCheck).Int32Value();
1370 __ LoadFromOffset(kLoadWord, LR, TR, offset);
1371 __ blx(LR);
1372
1373 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
1374 DCHECK(!codegen_->IsLeafMethod());
1375}
1376
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001377void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001378 LocationSummary* locations =
1379 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001380 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1381 if (location.IsStackSlot()) {
1382 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1383 } else if (location.IsDoubleStackSlot()) {
1384 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001385 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001386 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001387}
1388
1389void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001390 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001391}
1392
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001393void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001394 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001395 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001396 locations->SetInAt(0, Location::RequiresRegister());
1397 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001398}
1399
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001400void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1401 LocationSummary* locations = not_->GetLocations();
1402 Location out = locations->Out();
1403 Location in = locations->InAt(0);
1404 switch (not_->InputAt(0)->GetType()) {
1405 case Primitive::kPrimBoolean:
1406 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1407 break;
1408
1409 case Primitive::kPrimInt:
1410 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1411 break;
1412
1413 case Primitive::kPrimLong:
1414 LOG(FATAL) << "Not yet implemented type for not operation " << not_->GetResultType();
1415 break;
1416
1417 default:
1418 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1419 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001420}
1421
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001422void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001423 LocationSummary* locations =
1424 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001425 locations->SetInAt(0, Location::RequiresRegister());
1426 locations->SetInAt(1, Location::RequiresRegister());
1427 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001428}
1429
1430void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1431 Label greater, done;
1432 LocationSummary* locations = compare->GetLocations();
1433 switch (compare->InputAt(0)->GetType()) {
1434 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001435 Register output = locations->Out().As<Register>();
1436 Location left = locations->InAt(0);
1437 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001438 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001439 __ cmp(left.AsRegisterPairHigh<Register>(),
1440 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001441 __ b(&less, LT);
1442 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001443 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1444 // the status flags.
1445 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001446 __ cmp(left.AsRegisterPairLow<Register>(),
1447 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001448 __ b(&done, EQ);
1449 __ b(&less, CC);
1450
1451 __ Bind(&greater);
1452 __ LoadImmediate(output, 1);
1453 __ b(&done);
1454
1455 __ Bind(&less);
1456 __ LoadImmediate(output, -1);
1457
1458 __ Bind(&done);
1459 break;
1460 }
1461 default:
1462 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1463 }
1464}
1465
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001466void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001467 LocationSummary* locations =
1468 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001469 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1470 locations->SetInAt(i, Location::Any());
1471 }
1472 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001473}
1474
1475void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001476 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001477}
1478
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001479void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001480 LocationSummary* locations =
1481 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001482 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001483 locations->SetInAt(0, Location::RequiresRegister());
1484 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001485 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001486 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001487 locations->AddTemp(Location::RequiresRegister());
1488 locations->AddTemp(Location::RequiresRegister());
1489 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001490}
1491
1492void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1493 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001494 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001495 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001496 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001497
1498 switch (field_type) {
1499 case Primitive::kPrimBoolean:
1500 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001501 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001502 __ StoreToOffset(kStoreByte, value, obj, offset);
1503 break;
1504 }
1505
1506 case Primitive::kPrimShort:
1507 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001508 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001509 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1510 break;
1511 }
1512
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001513 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001514 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001515 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001516 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001517 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001518 Register temp = locations->GetTemp(0).As<Register>();
1519 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001520 codegen_->MarkGCCard(temp, card, obj, value);
1521 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001522 break;
1523 }
1524
1525 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001526 Location value = locations->InAt(1);
1527 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001528 break;
1529 }
1530
1531 case Primitive::kPrimFloat:
1532 case Primitive::kPrimDouble:
1533 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001534 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001535 case Primitive::kPrimVoid:
1536 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001537 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001538 }
1539}
1540
1541void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001542 LocationSummary* locations =
1543 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001544 locations->SetInAt(0, Location::RequiresRegister());
1545 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001546}
1547
1548void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1549 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001550 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001551 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1552
1553 switch (instruction->GetType()) {
1554 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001555 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001556 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1557 break;
1558 }
1559
1560 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001561 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001562 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1563 break;
1564 }
1565
1566 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001567 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001568 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1569 break;
1570 }
1571
1572 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001573 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001574 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1575 break;
1576 }
1577
1578 case Primitive::kPrimInt:
1579 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001580 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001581 __ LoadFromOffset(kLoadWord, out, obj, offset);
1582 break;
1583 }
1584
1585 case Primitive::kPrimLong: {
1586 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001587 Location out = locations->Out();
1588 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001589 break;
1590 }
1591
1592 case Primitive::kPrimFloat:
1593 case Primitive::kPrimDouble:
1594 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001595 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001596 case Primitive::kPrimVoid:
1597 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001598 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001599 }
1600}
1601
1602void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001603 LocationSummary* locations =
1604 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001605 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001606 if (instruction->HasUses()) {
1607 locations->SetOut(Location::SameAsFirstInput());
1608 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001609}
1610
1611void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001612 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001613 codegen_->AddSlowPath(slow_path);
1614
1615 LocationSummary* locations = instruction->GetLocations();
1616 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001617
1618 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001619 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001620 __ b(slow_path->GetEntryLabel(), EQ);
1621 } else {
1622 DCHECK(obj.IsConstant()) << obj;
1623 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1624 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001625 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001626}
1627
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001628void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001629 LocationSummary* locations =
1630 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001631 locations->SetInAt(0, Location::RequiresRegister());
1632 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1633 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001634}
1635
1636void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1637 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001638 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001639 Location index = locations->InAt(1);
1640
1641 switch (instruction->GetType()) {
1642 case Primitive::kPrimBoolean: {
1643 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001644 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001645 if (index.IsConstant()) {
1646 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1647 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1648 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001649 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001650 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1651 }
1652 break;
1653 }
1654
1655 case Primitive::kPrimByte: {
1656 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001657 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001658 if (index.IsConstant()) {
1659 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1660 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1661 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001662 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001663 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1664 }
1665 break;
1666 }
1667
1668 case Primitive::kPrimShort: {
1669 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001670 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001671 if (index.IsConstant()) {
1672 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1673 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1674 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001675 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001676 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1677 }
1678 break;
1679 }
1680
1681 case Primitive::kPrimChar: {
1682 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001683 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001684 if (index.IsConstant()) {
1685 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1686 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1687 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001688 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001689 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1690 }
1691 break;
1692 }
1693
1694 case Primitive::kPrimInt:
1695 case Primitive::kPrimNot: {
1696 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1697 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001698 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001699 if (index.IsConstant()) {
1700 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1701 __ LoadFromOffset(kLoadWord, out, obj, offset);
1702 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001703 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001704 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1705 }
1706 break;
1707 }
1708
1709 case Primitive::kPrimLong: {
1710 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001711 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001712 if (index.IsConstant()) {
1713 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001714 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001715 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001716 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1717 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001718 }
1719 break;
1720 }
1721
1722 case Primitive::kPrimFloat:
1723 case Primitive::kPrimDouble:
1724 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001725 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001726 case Primitive::kPrimVoid:
1727 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001728 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001729 }
1730}
1731
1732void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001733 Primitive::Type value_type = instruction->GetComponentType();
1734 bool is_object = value_type == Primitive::kPrimNot;
1735 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1736 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1737 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001738 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001739 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1740 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1741 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001742 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001743 locations->SetInAt(0, Location::RequiresRegister());
1744 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1745 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001746 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001747}
1748
1749void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1750 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001751 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001752 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001753 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001754
1755 switch (value_type) {
1756 case Primitive::kPrimBoolean:
1757 case Primitive::kPrimByte: {
1758 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001759 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001760 if (index.IsConstant()) {
1761 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1762 __ StoreToOffset(kStoreByte, value, obj, offset);
1763 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001764 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001765 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1766 }
1767 break;
1768 }
1769
1770 case Primitive::kPrimShort:
1771 case Primitive::kPrimChar: {
1772 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001773 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001774 if (index.IsConstant()) {
1775 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1776 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1777 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001778 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001779 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1780 }
1781 break;
1782 }
1783
1784 case Primitive::kPrimInt: {
1785 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001786 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001787 if (index.IsConstant()) {
1788 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1789 __ StoreToOffset(kStoreWord, value, obj, offset);
1790 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001791 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001792 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1793 }
1794 break;
1795 }
1796
1797 case Primitive::kPrimNot: {
1798 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAputObject).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001799 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001800 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001801 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001802 DCHECK(!codegen_->IsLeafMethod());
1803 break;
1804 }
1805
1806 case Primitive::kPrimLong: {
1807 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001808 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001809 if (index.IsConstant()) {
1810 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001811 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001812 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001813 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1814 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001815 }
1816 break;
1817 }
1818
1819 case Primitive::kPrimFloat:
1820 case Primitive::kPrimDouble:
1821 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001822 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001823 case Primitive::kPrimVoid:
1824 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001825 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001826 }
1827}
1828
1829void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001830 LocationSummary* locations =
1831 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001832 locations->SetInAt(0, Location::RequiresRegister());
1833 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001834}
1835
1836void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1837 LocationSummary* locations = instruction->GetLocations();
1838 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001839 Register obj = locations->InAt(0).As<Register>();
1840 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001841 __ LoadFromOffset(kLoadWord, out, obj, offset);
1842}
1843
1844void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001845 LocationSummary* locations =
1846 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001847 locations->SetInAt(0, Location::RequiresRegister());
1848 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001849 if (instruction->HasUses()) {
1850 locations->SetOut(Location::SameAsFirstInput());
1851 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001852}
1853
1854void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1855 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001856 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001857 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001858 codegen_->AddSlowPath(slow_path);
1859
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001860 Register index = locations->InAt(0).As<Register>();
1861 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001862
1863 __ cmp(index, ShifterOperand(length));
1864 __ b(slow_path->GetEntryLabel(), CS);
1865}
1866
1867void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1868 Label is_null;
1869 __ CompareAndBranchIfZero(value, &is_null);
1870 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1871 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1872 __ strb(card, Address(card, temp));
1873 __ Bind(&is_null);
1874}
1875
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001876void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1877 temp->SetLocations(nullptr);
1878}
1879
1880void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1881 // Nothing to do, this is driven by the code generator.
1882}
1883
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001884void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001885 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001886}
1887
1888void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001889 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1890}
1891
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001892void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
1893 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1894}
1895
1896void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001897 HBasicBlock* block = instruction->GetBlock();
1898 if (block->GetLoopInformation() != nullptr) {
1899 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1900 // The back edge will generate the suspend check.
1901 return;
1902 }
1903 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1904 // The goto will generate the suspend check.
1905 return;
1906 }
1907 GenerateSuspendCheck(instruction, nullptr);
1908}
1909
1910void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
1911 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001912 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001913 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001914 codegen_->AddSlowPath(slow_path);
1915
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001916 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001917 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001918 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001919 __ Bind(slow_path->GetReturnLabel());
1920 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001921 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001922 __ b(slow_path->GetEntryLabel());
1923 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001924}
1925
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001926ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
1927 return codegen_->GetAssembler();
1928}
1929
1930void ParallelMoveResolverARM::EmitMove(size_t index) {
1931 MoveOperands* move = moves_.Get(index);
1932 Location source = move->GetSource();
1933 Location destination = move->GetDestination();
1934
1935 if (source.IsRegister()) {
1936 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001937 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001938 } else {
1939 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001940 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001941 SP, destination.GetStackIndex());
1942 }
1943 } else if (source.IsStackSlot()) {
1944 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001945 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001946 SP, source.GetStackIndex());
1947 } else {
1948 DCHECK(destination.IsStackSlot());
1949 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1950 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
1951 }
1952 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001953 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01001954 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001955 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
1956 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001957 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001958 } else {
1959 DCHECK(destination.IsStackSlot());
1960 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001961 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001962 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001963 }
1964}
1965
1966void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
1967 __ Mov(IP, reg);
1968 __ LoadFromOffset(kLoadWord, reg, SP, mem);
1969 __ StoreToOffset(kStoreWord, IP, SP, mem);
1970}
1971
1972void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
1973 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
1974 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
1975 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
1976 SP, mem1 + stack_offset);
1977 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
1978 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
1979 SP, mem2 + stack_offset);
1980 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
1981}
1982
1983void ParallelMoveResolverARM::EmitSwap(size_t index) {
1984 MoveOperands* move = moves_.Get(index);
1985 Location source = move->GetSource();
1986 Location destination = move->GetDestination();
1987
1988 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001989 DCHECK_NE(source.As<Register>(), IP);
1990 DCHECK_NE(destination.As<Register>(), IP);
1991 __ Mov(IP, source.As<Register>());
1992 __ Mov(source.As<Register>(), destination.As<Register>());
1993 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001994 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001995 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001996 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001997 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001998 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
1999 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2000 } else {
2001 LOG(FATAL) << "Unimplemented";
2002 }
2003}
2004
2005void ParallelMoveResolverARM::SpillScratch(int reg) {
2006 __ Push(static_cast<Register>(reg));
2007}
2008
2009void ParallelMoveResolverARM::RestoreScratch(int reg) {
2010 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002011}
2012
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002013} // namespace arm
2014} // namespace art