blob: d50150e17bb17f7dc920ba9b070876cac089b705 [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: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000275 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
276 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000277 return Location::FpuRegisterPairLocation(reg, reg + 1);
278 }
279
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100280 case Primitive::kPrimVoid:
281 LOG(FATAL) << "Unreachable type " << type;
282 }
283
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100284 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100285}
286
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100287void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100288 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100289 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100290
291 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100292 blocked_core_registers_[SP] = true;
293 blocked_core_registers_[LR] = true;
294 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100295
296 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100297 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100298
299 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100300 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100301
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100302 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100303 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100304
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100305 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100306 // We always save and restore R6 and R7 to make sure we can use three
307 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100308 blocked_core_registers_[R5] = true;
309 blocked_core_registers_[R8] = true;
310 blocked_core_registers_[R10] = true;
311 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100312
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000313 blocked_fpu_registers_[S16] = true;
314 blocked_fpu_registers_[S17] = true;
315 blocked_fpu_registers_[S18] = true;
316 blocked_fpu_registers_[S19] = true;
317 blocked_fpu_registers_[S20] = true;
318 blocked_fpu_registers_[S21] = true;
319 blocked_fpu_registers_[S22] = true;
320 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000321 blocked_fpu_registers_[S24] = true;
322 blocked_fpu_registers_[S25] = true;
323 blocked_fpu_registers_[S26] = true;
324 blocked_fpu_registers_[S27] = true;
325 blocked_fpu_registers_[S28] = true;
326 blocked_fpu_registers_[S29] = true;
327 blocked_fpu_registers_[S30] = true;
328 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100329
330 UpdateBlockedPairRegisters();
331}
332
333void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
334 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
335 ArmManagedRegister current =
336 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
337 if (blocked_core_registers_[current.AsRegisterPairLow()]
338 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
339 blocked_register_pairs_[i] = true;
340 }
341 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100342}
343
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100344InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
345 : HGraphVisitor(graph),
346 assembler_(codegen->GetAssembler()),
347 codegen_(codegen) {}
348
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000349void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700350 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100351 if (!skip_overflow_check) {
352 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100353 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100354 AddSlowPath(slow_path);
355
356 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
357 __ cmp(SP, ShifterOperand(IP));
358 __ b(slow_path->GetEntryLabel(), CC);
359 } else {
360 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100361 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100362 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100363 }
364 }
365
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100366 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
367 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000368
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100369 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100370 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100371 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000372}
373
374void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100375 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100376 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000377}
378
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100379void CodeGeneratorARM::Bind(HBasicBlock* block) {
380 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000381}
382
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100383Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
384 switch (load->GetType()) {
385 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100386 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100387 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
388 break;
389
390 case Primitive::kPrimInt:
391 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100393 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100394
395 case Primitive::kPrimBoolean:
396 case Primitive::kPrimByte:
397 case Primitive::kPrimChar:
398 case Primitive::kPrimShort:
399 case Primitive::kPrimVoid:
400 LOG(FATAL) << "Unexpected type " << load->GetType();
401 }
402
403 LOG(FATAL) << "Unreachable";
404 return Location();
405}
406
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100407Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
408 switch (type) {
409 case Primitive::kPrimBoolean:
410 case Primitive::kPrimByte:
411 case Primitive::kPrimChar:
412 case Primitive::kPrimShort:
413 case Primitive::kPrimInt:
414 case Primitive::kPrimNot: {
415 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000416 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100417 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100418 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100419 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000420 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100421 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100422 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100423
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000424 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100425 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000426 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100427 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000428 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100429 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100430 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
431 calling_convention.GetRegisterPairAt(index));
432 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100433 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000434 return Location::QuickParameter(stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100435 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000436 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
437 }
438 }
439
440 case Primitive::kPrimFloat: {
441 uint32_t stack_index = stack_index_++;
442 if (float_index_ % 2 == 0) {
443 float_index_ = std::max(double_index_, float_index_);
444 }
445 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
446 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
447 } else {
448 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
449 }
450 }
451
452 case Primitive::kPrimDouble: {
453 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
454 uint32_t stack_index = stack_index_;
455 stack_index_ += 2;
456 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
457 uint32_t index = double_index_;
458 double_index_ += 2;
459 return Location::FpuRegisterPairLocation(
460 calling_convention.GetFpuRegisterAt(index),
461 calling_convention.GetFpuRegisterAt(index + 1));
462 } else {
463 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100464 }
465 }
466
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100467 case Primitive::kPrimVoid:
468 LOG(FATAL) << "Unexpected parameter type " << type;
469 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100470 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100471 return Location();
472}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100473
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000474Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
475 switch (type) {
476 case Primitive::kPrimBoolean:
477 case Primitive::kPrimByte:
478 case Primitive::kPrimChar:
479 case Primitive::kPrimShort:
480 case Primitive::kPrimInt:
481 case Primitive::kPrimNot: {
482 return Location::RegisterLocation(R0);
483 }
484
485 case Primitive::kPrimFloat: {
486 return Location::FpuRegisterLocation(S0);
487 }
488
489 case Primitive::kPrimLong: {
490 return Location::RegisterPairLocation(R0, R1);
491 }
492
493 case Primitive::kPrimDouble: {
494 return Location::FpuRegisterPairLocation(S0, S1);
495 }
496
497 case Primitive::kPrimVoid:
498 return Location();
499 }
500 UNREACHABLE();
501 return Location();
502}
503
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100504void CodeGeneratorARM::Move32(Location destination, Location source) {
505 if (source.Equals(destination)) {
506 return;
507 }
508 if (destination.IsRegister()) {
509 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100510 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100511 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000512 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100513 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100514 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100515 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100516 } else if (destination.IsFpuRegister()) {
517 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000518 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100519 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000520 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100521 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000522 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100523 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100524 } else {
525 DCHECK(destination.IsStackSlot());
526 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100527 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100528 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000529 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100530 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100531 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100532 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
533 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100534 }
535 }
536}
537
538void CodeGeneratorARM::Move64(Location destination, Location source) {
539 if (source.Equals(destination)) {
540 return;
541 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100542 if (destination.IsRegisterPair()) {
543 if (source.IsRegisterPair()) {
544 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
545 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100546 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000547 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100548 } else if (source.IsQuickParameter()) {
549 uint32_t argument_index = source.GetQuickParameterIndex();
550 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100551 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100552 calling_convention.GetRegisterAt(argument_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100553 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
554 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100555 } else {
556 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100557 if (destination.AsRegisterPairLow<Register>() == R1) {
558 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100559 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
560 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100561 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100562 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100563 SP, source.GetStackIndex());
564 }
565 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000566 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100567 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000568 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
569 SP,
570 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100571 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000572 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100573 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100574 } else if (destination.IsQuickParameter()) {
575 InvokeDexCallingConvention calling_convention;
576 uint32_t argument_index = destination.GetQuickParameterIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100577 if (source.IsRegisterPair()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100578 __ Mov(calling_convention.GetRegisterAt(argument_index),
579 source.AsRegisterPairLow<Register>());
580 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
581 SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100582 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000583 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100584 } else {
585 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000586 __ LoadFromOffset(
587 kLoadWord, calling_convention.GetRegisterAt(argument_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100588 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
589 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(argument_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100590 }
591 } else {
592 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100593 if (source.IsRegisterPair()) {
594 if (source.AsRegisterPairLow<Register>() == R1) {
595 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100596 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
597 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100598 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100599 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100600 SP, destination.GetStackIndex());
601 }
602 } else if (source.IsQuickParameter()) {
603 InvokeDexCallingConvention calling_convention;
604 uint32_t argument_index = source.GetQuickParameterIndex();
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100605 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(argument_index),
606 SP, destination.GetStackIndex());
607 __ LoadFromOffset(kLoadWord, R0,
608 SP, calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize());
609 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000610 } else if (source.IsFpuRegisterPair()) {
611 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
612 SP,
613 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100614 } else {
615 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100616 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
617 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
618 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
619 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100620 }
621 }
622}
623
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100624void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100625 LocationSummary* locations = instruction->GetLocations();
626 if (locations != nullptr && locations->Out().Equals(location)) {
627 return;
628 }
629
Roland Levillain476df552014-10-09 17:51:36 +0100630 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100631 int32_t value = instruction->AsIntConstant()->GetValue();
632 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100633 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100634 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100635 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100636 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100637 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100638 }
Roland Levillain476df552014-10-09 17:51:36 +0100639 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100640 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100641 if (location.IsRegisterPair()) {
642 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
643 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100644 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100645 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100646 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100647 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100648 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100649 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100650 }
Roland Levillain476df552014-10-09 17:51:36 +0100651 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100652 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
653 switch (instruction->GetType()) {
654 case Primitive::kPrimBoolean:
655 case Primitive::kPrimByte:
656 case Primitive::kPrimChar:
657 case Primitive::kPrimShort:
658 case Primitive::kPrimInt:
659 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100660 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100661 Move32(location, Location::StackSlot(stack_slot));
662 break;
663
664 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100665 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100666 Move64(location, Location::DoubleStackSlot(stack_slot));
667 break;
668
669 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100670 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100671 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000672 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100673 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100674 switch (instruction->GetType()) {
675 case Primitive::kPrimBoolean:
676 case Primitive::kPrimByte:
677 case Primitive::kPrimChar:
678 case Primitive::kPrimShort:
679 case Primitive::kPrimNot:
680 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100681 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100682 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100683 break;
684
685 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100686 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100687 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100688 break;
689
690 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100691 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100692 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000693 }
694}
695
696void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000697 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000698}
699
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000700void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000701 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100702 DCHECK(!successor->IsExitBlock());
703
704 HBasicBlock* block = got->GetBlock();
705 HInstruction* previous = got->GetPrevious();
706
707 HLoopInformation* info = block->GetLoopInformation();
708 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
709 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
710 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
711 return;
712 }
713
714 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
715 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
716 }
717 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000718 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000719 }
720}
721
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000722void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000723 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000724}
725
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000726void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000727 if (kIsDebugBuild) {
728 __ Comment("Unreachable");
729 __ bkpt(0);
730 }
731}
732
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000733void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100734 LocationSummary* locations =
735 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100736 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100737 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100738 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100739 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000740}
741
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000742void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700743 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100744 if (cond->IsIntConstant()) {
745 // Constant condition, statically compared against 1.
746 int32_t cond_value = cond->AsIntConstant()->GetValue();
747 if (cond_value == 1) {
748 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
749 if_instr->IfTrueSuccessor())) {
750 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100751 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100752 return;
753 } else {
754 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100755 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100756 } else {
757 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
758 // Condition has been materialized, compare the output to 0
759 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
760 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
761 ShifterOperand(0));
762 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
763 } else {
764 // Condition has not been materialized, use its inputs as the
765 // comparison and its condition as the branch condition.
766 LocationSummary* locations = cond->GetLocations();
767 if (locations->InAt(1).IsRegister()) {
768 __ cmp(locations->InAt(0).As<Register>(),
769 ShifterOperand(locations->InAt(1).As<Register>()));
770 } else {
771 DCHECK(locations->InAt(1).IsConstant());
772 int32_t value =
773 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
774 ShifterOperand operand;
775 if (ShifterOperand::CanHoldArm(value, &operand)) {
776 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
777 } else {
778 Register temp = IP;
779 __ LoadImmediate(temp, value);
780 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
781 }
782 }
783 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
784 ARMCondition(cond->AsCondition()->GetCondition()));
785 }
Dave Allison20dfc792014-06-16 20:44:29 -0700786 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100787 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
788 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700789 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000790 }
791}
792
Dave Allison20dfc792014-06-16 20:44:29 -0700793
794void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100795 LocationSummary* locations =
796 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100797 locations->SetInAt(0, Location::RequiresRegister());
798 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100799 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100800 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100801 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000802}
803
Dave Allison20dfc792014-06-16 20:44:29 -0700804void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100805 if (!comp->NeedsMaterialization()) return;
806
807 LocationSummary* locations = comp->GetLocations();
808 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100809 __ cmp(locations->InAt(0).As<Register>(),
810 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100811 } else {
812 DCHECK(locations->InAt(1).IsConstant());
813 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
814 ShifterOperand operand;
815 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100816 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100817 } else {
818 Register temp = IP;
819 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100820 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100821 }
Dave Allison20dfc792014-06-16 20:44:29 -0700822 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100823 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100824 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100825 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100826 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100827 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700828}
829
830void LocationsBuilderARM::VisitEqual(HEqual* comp) {
831 VisitCondition(comp);
832}
833
834void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
835 VisitCondition(comp);
836}
837
838void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
839 VisitCondition(comp);
840}
841
842void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
843 VisitCondition(comp);
844}
845
846void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
847 VisitCondition(comp);
848}
849
850void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
851 VisitCondition(comp);
852}
853
854void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
855 VisitCondition(comp);
856}
857
858void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
859 VisitCondition(comp);
860}
861
862void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
863 VisitCondition(comp);
864}
865
866void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
867 VisitCondition(comp);
868}
869
870void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
871 VisitCondition(comp);
872}
873
874void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
875 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000876}
877
878void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000879 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000880}
881
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000882void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
883 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000884}
885
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000886void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100887 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000888}
889
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000890void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100891 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000892}
893
894void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100895 LocationSummary* locations =
896 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100897 switch (store->InputAt(1)->GetType()) {
898 case Primitive::kPrimBoolean:
899 case Primitive::kPrimByte:
900 case Primitive::kPrimChar:
901 case Primitive::kPrimShort:
902 case Primitive::kPrimInt:
903 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100904 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100905 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
906 break;
907
908 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100909 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100910 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
911 break;
912
913 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100914 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100915 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000916}
917
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000918void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000919}
920
921void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100922 LocationSummary* locations =
923 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100924 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000925}
926
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000927void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100928 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000929}
930
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100931void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100932 LocationSummary* locations =
933 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100934 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100935}
936
937void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
938 // Will be generated at use site.
939}
940
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100941void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
942 LocationSummary* locations =
943 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
944 locations->SetOut(Location::ConstantLocation(constant));
945}
946
947void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
948 // Will be generated at use site.
949}
950
951void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
952 LocationSummary* locations =
953 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
954 locations->SetOut(Location::ConstantLocation(constant));
955}
956
957void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
958 // Will be generated at use site.
959}
960
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000961void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000962 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000963}
964
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000965void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
966 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000967}
968
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000969void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100970 LocationSummary* locations =
971 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000972 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000973}
974
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000975void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000976 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000977}
978
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000979void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100980 HandleInvoke(invoke);
981}
982
983void InstructionCodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100984 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100985}
986
987void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100988 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100989 uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>);
990 size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).Int32Value() +
991 invoke->GetIndexInDexCache() * kArmWordSize;
992
993 // TODO: Implement all kinds of calls:
994 // 1) boot -> boot
995 // 2) app -> boot
996 // 3) app -> app
997 //
998 // Currently we implement the app -> app logic, which looks up in the resolve cache.
999
1000 // temp = method;
1001 LoadCurrentMethod(temp);
1002 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001003 __ LoadFromOffset(kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001004 // temp = temp[index_in_cache]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001005 __ LoadFromOffset(kLoadWord, temp, temp, index_in_cache);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001006 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001007 __ LoadFromOffset(kLoadWord, LR, temp,
1008 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001009 // LR()
1010 __ blx(LR);
1011
1012 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1013 DCHECK(!codegen_->IsLeafMethod());
1014}
1015
1016void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1017 HandleInvoke(invoke);
1018}
1019
1020void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001021 LocationSummary* locations =
1022 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001023 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001024
1025 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001026 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001027 HInstruction* input = invoke->InputAt(i);
1028 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1029 }
1030
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001031 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001032}
1033
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001034
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001035void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001036 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001037 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1038 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1039 LocationSummary* locations = invoke->GetLocations();
1040 Location receiver = locations->InAt(0);
1041 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1042 // temp = object->GetClass();
1043 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001044 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1045 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001046 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001047 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001048 }
1049 // temp = temp->GetMethodAt(method_offset);
1050 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001051 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001052 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001053 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001054 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001055 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001056 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001057 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001058}
1059
Roland Levillain88cb1752014-10-20 16:36:47 +01001060void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1061 LocationSummary* locations =
1062 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1063 switch (neg->GetResultType()) {
1064 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001065 case Primitive::kPrimLong: {
1066 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001067 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001068 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001069 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001070 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001071
Roland Levillain88cb1752014-10-20 16:36:47 +01001072 case Primitive::kPrimFloat:
1073 case Primitive::kPrimDouble:
1074 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1075 break;
1076
1077 default:
1078 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1079 }
1080}
1081
1082void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1083 LocationSummary* locations = neg->GetLocations();
1084 Location out = locations->Out();
1085 Location in = locations->InAt(0);
1086 switch (neg->GetResultType()) {
1087 case Primitive::kPrimInt:
1088 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001089 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001090 break;
1091
1092 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001093 DCHECK(in.IsRegisterPair());
1094 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1095 __ rsbs(out.AsRegisterPairLow<Register>(),
1096 in.AsRegisterPairLow<Register>(),
1097 ShifterOperand(0));
1098 // We cannot emit an RSC (Reverse Subtract with Carry)
1099 // instruction here, as it does not exist in the Thumb-2
1100 // instruction set. We use the following approach
1101 // using SBC and SUB instead.
1102 //
1103 // out.hi = -C
1104 __ sbc(out.AsRegisterPairHigh<Register>(),
1105 out.AsRegisterPairHigh<Register>(),
1106 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1107 // out.hi = out.hi - in.hi
1108 __ sub(out.AsRegisterPairHigh<Register>(),
1109 out.AsRegisterPairHigh<Register>(),
1110 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1111 break;
1112
Roland Levillain88cb1752014-10-20 16:36:47 +01001113 case Primitive::kPrimFloat:
1114 case Primitive::kPrimDouble:
1115 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1116 break;
1117
1118 default:
1119 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1120 }
1121}
1122
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001123void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001124 LocationSummary* locations =
1125 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001126 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001127 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001128 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001129 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1130 locations->SetInAt(0, Location::RequiresRegister());
1131 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1132 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001133 break;
1134 }
1135
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001136 case Primitive::kPrimFloat:
1137 case Primitive::kPrimDouble: {
1138 locations->SetInAt(0, Location::RequiresFpuRegister());
1139 locations->SetInAt(1, Location::RequiresFpuRegister());
1140 locations->SetOut(Location::RequiresFpuRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001141 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001142 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001143
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001144 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001145 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001146 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001147}
1148
1149void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1150 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001151 Location out = locations->Out();
1152 Location first = locations->InAt(0);
1153 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001154 switch (add->GetResultType()) {
1155 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001156 if (second.IsRegister()) {
1157 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001158 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001159 __ AddConstant(out.As<Register>(),
1160 first.As<Register>(),
1161 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001162 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001163 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001164
1165 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001166 __ adds(out.AsRegisterPairLow<Register>(),
1167 first.AsRegisterPairLow<Register>(),
1168 ShifterOperand(second.AsRegisterPairLow<Register>()));
1169 __ adc(out.AsRegisterPairHigh<Register>(),
1170 first.AsRegisterPairHigh<Register>(),
1171 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001172 break;
1173
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001174 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001175 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001176 break;
1177
1178 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001179 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1180 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1181 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001182 break;
1183
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001184 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001185 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001186 }
1187}
1188
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001189void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001190 LocationSummary* locations =
1191 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001192 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001193 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001194 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001195 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1196 locations->SetInAt(0, Location::RequiresRegister());
1197 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1198 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001199 break;
1200 }
Calin Juravle11351682014-10-23 15:38:15 +01001201 case Primitive::kPrimFloat:
1202 case Primitive::kPrimDouble: {
1203 locations->SetInAt(0, Location::RequiresFpuRegister());
1204 locations->SetInAt(1, Location::RequiresFpuRegister());
1205 locations->SetOut(Location::RequiresFpuRegister());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001206 break;
Calin Juravle11351682014-10-23 15:38:15 +01001207 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001208 default:
Calin Juravle11351682014-10-23 15:38:15 +01001209 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001210 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001211}
1212
1213void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1214 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001215 Location out = locations->Out();
1216 Location first = locations->InAt(0);
1217 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001218 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001219 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001220 if (second.IsRegister()) {
1221 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001222 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001223 __ AddConstant(out.As<Register>(),
1224 first.As<Register>(),
1225 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001226 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001227 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001228 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001229
Calin Juravle11351682014-10-23 15:38:15 +01001230 case Primitive::kPrimLong: {
1231 __ subs(out.AsRegisterPairLow<Register>(),
1232 first.AsRegisterPairLow<Register>(),
1233 ShifterOperand(second.AsRegisterPairLow<Register>()));
1234 __ sbc(out.AsRegisterPairHigh<Register>(),
1235 first.AsRegisterPairHigh<Register>(),
1236 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001237 break;
Calin Juravle11351682014-10-23 15:38:15 +01001238 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001239
Calin Juravle11351682014-10-23 15:38:15 +01001240 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001241 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001242 break;
Calin Juravle11351682014-10-23 15:38:15 +01001243 }
1244
1245 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001246 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1247 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1248 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001249 break;
1250 }
1251
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001252
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001253 default:
Calin Juravle11351682014-10-23 15:38:15 +01001254 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001255 }
1256}
1257
Calin Juravle34bacdf2014-10-07 20:23:36 +01001258void LocationsBuilderARM::VisitMul(HMul* mul) {
1259 LocationSummary* locations =
1260 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1261 switch (mul->GetResultType()) {
1262 case Primitive::kPrimInt:
1263 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001264 locations->SetInAt(0, Location::RequiresRegister());
1265 locations->SetInAt(1, Location::RequiresRegister());
1266 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001267 break;
1268 }
1269
Calin Juravleb5bfa962014-10-21 18:02:24 +01001270 case Primitive::kPrimFloat:
1271 case Primitive::kPrimDouble: {
1272 locations->SetInAt(0, Location::RequiresFpuRegister());
1273 locations->SetInAt(1, Location::RequiresFpuRegister());
1274 locations->SetOut(Location::RequiresFpuRegister());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001275 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001276 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001277
1278 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001279 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001280 }
1281}
1282
1283void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1284 LocationSummary* locations = mul->GetLocations();
1285 Location out = locations->Out();
1286 Location first = locations->InAt(0);
1287 Location second = locations->InAt(1);
1288 switch (mul->GetResultType()) {
1289 case Primitive::kPrimInt: {
1290 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1291 break;
1292 }
1293 case Primitive::kPrimLong: {
1294 Register out_hi = out.AsRegisterPairHigh<Register>();
1295 Register out_lo = out.AsRegisterPairLow<Register>();
1296 Register in1_hi = first.AsRegisterPairHigh<Register>();
1297 Register in1_lo = first.AsRegisterPairLow<Register>();
1298 Register in2_hi = second.AsRegisterPairHigh<Register>();
1299 Register in2_lo = second.AsRegisterPairLow<Register>();
1300
1301 // Extra checks to protect caused by the existence of R1_R2.
1302 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1303 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1304 DCHECK_NE(out_hi, in1_lo);
1305 DCHECK_NE(out_hi, in2_lo);
1306
1307 // input: in1 - 64 bits, in2 - 64 bits
1308 // output: out
1309 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1310 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1311 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1312
1313 // IP <- in1.lo * in2.hi
1314 __ mul(IP, in1_lo, in2_hi);
1315 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1316 __ mla(out_hi, in1_hi, in2_lo, IP);
1317 // out.lo <- (in1.lo * in2.lo)[31:0];
1318 __ umull(out_lo, IP, in1_lo, in2_lo);
1319 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1320 __ add(out_hi, out_hi, ShifterOperand(IP));
1321 break;
1322 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001323
1324 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001325 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001326 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001327 }
1328
1329 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001330 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1331 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1332 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001333 break;
1334 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001335
1336 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001337 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001338 }
1339}
1340
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001341void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001342 LocationSummary* locations =
1343 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001344 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001345 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1346 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1347 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001348}
1349
1350void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1351 InvokeRuntimeCallingConvention calling_convention;
1352 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1353 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1354
Nicolas Geoffray707c8092014-04-04 10:50:14 +01001355 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocObjectWithAccessCheck).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001356 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001357 __ blx(LR);
1358
Nicolas Geoffray39468442014-09-02 15:17:15 +01001359 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001360 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001361}
1362
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001363void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1364 LocationSummary* locations =
1365 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1366 InvokeRuntimeCallingConvention calling_convention;
1367 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1368 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1369 locations->SetOut(Location::RegisterLocation(R0));
1370 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1371}
1372
1373void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1374 InvokeRuntimeCallingConvention calling_convention;
1375 LoadCurrentMethod(calling_convention.GetRegisterAt(1));
1376 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
1377
1378 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocArrayWithAccessCheck).Int32Value();
1379 __ LoadFromOffset(kLoadWord, LR, TR, offset);
1380 __ blx(LR);
1381
1382 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
1383 DCHECK(!codegen_->IsLeafMethod());
1384}
1385
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001386void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001387 LocationSummary* locations =
1388 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001389 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1390 if (location.IsStackSlot()) {
1391 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1392 } else if (location.IsDoubleStackSlot()) {
1393 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001394 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001395 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001396}
1397
1398void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001399 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001400}
1401
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001402void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001403 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001404 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001405 locations->SetInAt(0, Location::RequiresRegister());
1406 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001407}
1408
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001409void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1410 LocationSummary* locations = not_->GetLocations();
1411 Location out = locations->Out();
1412 Location in = locations->InAt(0);
1413 switch (not_->InputAt(0)->GetType()) {
1414 case Primitive::kPrimBoolean:
1415 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1416 break;
1417
1418 case Primitive::kPrimInt:
1419 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1420 break;
1421
1422 case Primitive::kPrimLong:
1423 LOG(FATAL) << "Not yet implemented type for not operation " << not_->GetResultType();
1424 break;
1425
1426 default:
1427 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1428 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001429}
1430
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001431void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001432 LocationSummary* locations =
1433 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001434 locations->SetInAt(0, Location::RequiresRegister());
1435 locations->SetInAt(1, Location::RequiresRegister());
1436 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001437}
1438
1439void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1440 Label greater, done;
1441 LocationSummary* locations = compare->GetLocations();
1442 switch (compare->InputAt(0)->GetType()) {
1443 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001444 Register output = locations->Out().As<Register>();
1445 Location left = locations->InAt(0);
1446 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001447 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001448 __ cmp(left.AsRegisterPairHigh<Register>(),
1449 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001450 __ b(&less, LT);
1451 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001452 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1453 // the status flags.
1454 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001455 __ cmp(left.AsRegisterPairLow<Register>(),
1456 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001457 __ b(&done, EQ);
1458 __ b(&less, CC);
1459
1460 __ Bind(&greater);
1461 __ LoadImmediate(output, 1);
1462 __ b(&done);
1463
1464 __ Bind(&less);
1465 __ LoadImmediate(output, -1);
1466
1467 __ Bind(&done);
1468 break;
1469 }
1470 default:
1471 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1472 }
1473}
1474
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001475void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001476 LocationSummary* locations =
1477 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001478 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1479 locations->SetInAt(i, Location::Any());
1480 }
1481 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001482}
1483
1484void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001485 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001486}
1487
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001488void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001489 LocationSummary* locations =
1490 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001491 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001492 locations->SetInAt(0, Location::RequiresRegister());
1493 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001494 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001495 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001496 locations->AddTemp(Location::RequiresRegister());
1497 locations->AddTemp(Location::RequiresRegister());
1498 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001499}
1500
1501void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1502 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001503 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001504 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001505 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001506
1507 switch (field_type) {
1508 case Primitive::kPrimBoolean:
1509 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001510 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001511 __ StoreToOffset(kStoreByte, value, obj, offset);
1512 break;
1513 }
1514
1515 case Primitive::kPrimShort:
1516 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001517 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001518 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1519 break;
1520 }
1521
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001522 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001523 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001524 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001525 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001526 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001527 Register temp = locations->GetTemp(0).As<Register>();
1528 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001529 codegen_->MarkGCCard(temp, card, obj, value);
1530 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001531 break;
1532 }
1533
1534 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001535 Location value = locations->InAt(1);
1536 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001537 break;
1538 }
1539
1540 case Primitive::kPrimFloat:
1541 case Primitive::kPrimDouble:
1542 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001543 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001544 case Primitive::kPrimVoid:
1545 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001546 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001547 }
1548}
1549
1550void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001551 LocationSummary* locations =
1552 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001553 locations->SetInAt(0, Location::RequiresRegister());
1554 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001555}
1556
1557void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1558 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001559 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001560 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1561
1562 switch (instruction->GetType()) {
1563 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001564 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001565 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1566 break;
1567 }
1568
1569 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001570 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001571 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1572 break;
1573 }
1574
1575 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001576 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001577 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1578 break;
1579 }
1580
1581 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001582 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001583 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1584 break;
1585 }
1586
1587 case Primitive::kPrimInt:
1588 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001589 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001590 __ LoadFromOffset(kLoadWord, out, obj, offset);
1591 break;
1592 }
1593
1594 case Primitive::kPrimLong: {
1595 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001596 Location out = locations->Out();
1597 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001598 break;
1599 }
1600
1601 case Primitive::kPrimFloat:
1602 case Primitive::kPrimDouble:
1603 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001604 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001605 case Primitive::kPrimVoid:
1606 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001607 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001608 }
1609}
1610
1611void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001612 LocationSummary* locations =
1613 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001614 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001615 if (instruction->HasUses()) {
1616 locations->SetOut(Location::SameAsFirstInput());
1617 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001618}
1619
1620void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001621 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001622 codegen_->AddSlowPath(slow_path);
1623
1624 LocationSummary* locations = instruction->GetLocations();
1625 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001626
1627 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001628 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001629 __ b(slow_path->GetEntryLabel(), EQ);
1630 } else {
1631 DCHECK(obj.IsConstant()) << obj;
1632 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1633 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001634 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001635}
1636
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001637void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001638 LocationSummary* locations =
1639 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001640 locations->SetInAt(0, Location::RequiresRegister());
1641 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1642 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001643}
1644
1645void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1646 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001647 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001648 Location index = locations->InAt(1);
1649
1650 switch (instruction->GetType()) {
1651 case Primitive::kPrimBoolean: {
1652 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001653 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001654 if (index.IsConstant()) {
1655 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1656 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1657 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001658 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001659 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1660 }
1661 break;
1662 }
1663
1664 case Primitive::kPrimByte: {
1665 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001666 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001667 if (index.IsConstant()) {
1668 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1669 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1670 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001671 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001672 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1673 }
1674 break;
1675 }
1676
1677 case Primitive::kPrimShort: {
1678 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001679 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001680 if (index.IsConstant()) {
1681 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1682 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1683 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001684 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001685 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1686 }
1687 break;
1688 }
1689
1690 case Primitive::kPrimChar: {
1691 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001692 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001693 if (index.IsConstant()) {
1694 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1695 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1696 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001697 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001698 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1699 }
1700 break;
1701 }
1702
1703 case Primitive::kPrimInt:
1704 case Primitive::kPrimNot: {
1705 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1706 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001707 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001708 if (index.IsConstant()) {
1709 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1710 __ LoadFromOffset(kLoadWord, out, obj, offset);
1711 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001712 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001713 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1714 }
1715 break;
1716 }
1717
1718 case Primitive::kPrimLong: {
1719 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001720 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001721 if (index.IsConstant()) {
1722 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001723 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001724 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001725 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1726 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001727 }
1728 break;
1729 }
1730
1731 case Primitive::kPrimFloat:
1732 case Primitive::kPrimDouble:
1733 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001734 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001735 case Primitive::kPrimVoid:
1736 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001737 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001738 }
1739}
1740
1741void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001742 Primitive::Type value_type = instruction->GetComponentType();
1743 bool is_object = value_type == Primitive::kPrimNot;
1744 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1745 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1746 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001747 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001748 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1749 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1750 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001751 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001752 locations->SetInAt(0, Location::RequiresRegister());
1753 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1754 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001755 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001756}
1757
1758void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1759 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001760 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001761 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001762 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001763
1764 switch (value_type) {
1765 case Primitive::kPrimBoolean:
1766 case Primitive::kPrimByte: {
1767 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001768 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001769 if (index.IsConstant()) {
1770 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1771 __ StoreToOffset(kStoreByte, value, obj, offset);
1772 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001773 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001774 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1775 }
1776 break;
1777 }
1778
1779 case Primitive::kPrimShort:
1780 case Primitive::kPrimChar: {
1781 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001782 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001783 if (index.IsConstant()) {
1784 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1785 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1786 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001787 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001788 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1789 }
1790 break;
1791 }
1792
1793 case Primitive::kPrimInt: {
1794 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001795 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001796 if (index.IsConstant()) {
1797 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1798 __ StoreToOffset(kStoreWord, value, obj, offset);
1799 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001800 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001801 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1802 }
1803 break;
1804 }
1805
1806 case Primitive::kPrimNot: {
1807 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAputObject).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001808 __ LoadFromOffset(kLoadWord, LR, TR, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001809 __ blx(LR);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001810 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001811 DCHECK(!codegen_->IsLeafMethod());
1812 break;
1813 }
1814
1815 case Primitive::kPrimLong: {
1816 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001817 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001818 if (index.IsConstant()) {
1819 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001820 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001821 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001822 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1823 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001824 }
1825 break;
1826 }
1827
1828 case Primitive::kPrimFloat:
1829 case Primitive::kPrimDouble:
1830 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001831 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001832 case Primitive::kPrimVoid:
1833 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001834 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001835 }
1836}
1837
1838void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001839 LocationSummary* locations =
1840 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001841 locations->SetInAt(0, Location::RequiresRegister());
1842 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001843}
1844
1845void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1846 LocationSummary* locations = instruction->GetLocations();
1847 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001848 Register obj = locations->InAt(0).As<Register>();
1849 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001850 __ LoadFromOffset(kLoadWord, out, obj, offset);
1851}
1852
1853void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001854 LocationSummary* locations =
1855 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001856 locations->SetInAt(0, Location::RequiresRegister());
1857 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001858 if (instruction->HasUses()) {
1859 locations->SetOut(Location::SameAsFirstInput());
1860 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001861}
1862
1863void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1864 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001865 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001866 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001867 codegen_->AddSlowPath(slow_path);
1868
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001869 Register index = locations->InAt(0).As<Register>();
1870 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001871
1872 __ cmp(index, ShifterOperand(length));
1873 __ b(slow_path->GetEntryLabel(), CS);
1874}
1875
1876void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1877 Label is_null;
1878 __ CompareAndBranchIfZero(value, &is_null);
1879 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1880 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1881 __ strb(card, Address(card, temp));
1882 __ Bind(&is_null);
1883}
1884
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001885void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1886 temp->SetLocations(nullptr);
1887}
1888
1889void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1890 // Nothing to do, this is driven by the code generator.
1891}
1892
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001893void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001894 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001895}
1896
1897void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001898 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1899}
1900
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001901void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
1902 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1903}
1904
1905void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001906 HBasicBlock* block = instruction->GetBlock();
1907 if (block->GetLoopInformation() != nullptr) {
1908 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1909 // The back edge will generate the suspend check.
1910 return;
1911 }
1912 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1913 // The goto will generate the suspend check.
1914 return;
1915 }
1916 GenerateSuspendCheck(instruction, nullptr);
1917}
1918
1919void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
1920 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001921 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001922 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001923 codegen_->AddSlowPath(slow_path);
1924
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001925 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001926 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001927 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001928 __ Bind(slow_path->GetReturnLabel());
1929 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001930 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001931 __ b(slow_path->GetEntryLabel());
1932 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001933}
1934
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001935ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
1936 return codegen_->GetAssembler();
1937}
1938
1939void ParallelMoveResolverARM::EmitMove(size_t index) {
1940 MoveOperands* move = moves_.Get(index);
1941 Location source = move->GetSource();
1942 Location destination = move->GetDestination();
1943
1944 if (source.IsRegister()) {
1945 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001946 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001947 } else {
1948 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001949 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001950 SP, destination.GetStackIndex());
1951 }
1952 } else if (source.IsStackSlot()) {
1953 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001954 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001955 SP, source.GetStackIndex());
1956 } else {
1957 DCHECK(destination.IsStackSlot());
1958 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
1959 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
1960 }
1961 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001962 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01001963 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001964 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
1965 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001966 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001967 } else {
1968 DCHECK(destination.IsStackSlot());
1969 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001970 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001971 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001972 }
1973}
1974
1975void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
1976 __ Mov(IP, reg);
1977 __ LoadFromOffset(kLoadWord, reg, SP, mem);
1978 __ StoreToOffset(kStoreWord, IP, SP, mem);
1979}
1980
1981void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
1982 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
1983 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
1984 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
1985 SP, mem1 + stack_offset);
1986 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
1987 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
1988 SP, mem2 + stack_offset);
1989 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
1990}
1991
1992void ParallelMoveResolverARM::EmitSwap(size_t index) {
1993 MoveOperands* move = moves_.Get(index);
1994 Location source = move->GetSource();
1995 Location destination = move->GetDestination();
1996
1997 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001998 DCHECK_NE(source.As<Register>(), IP);
1999 DCHECK_NE(destination.As<Register>(), IP);
2000 __ Mov(IP, source.As<Register>());
2001 __ Mov(source.As<Register>(), destination.As<Register>());
2002 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002003 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002004 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002005 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002006 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002007 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2008 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2009 } else {
2010 LOG(FATAL) << "Unimplemented";
2011 }
2012}
2013
2014void ParallelMoveResolverARM::SpillScratch(int reg) {
2015 __ Push(static_cast<Register>(reg));
2016}
2017
2018void ParallelMoveResolverARM::RestoreScratch(int reg) {
2019 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002020}
2021
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002022} // namespace arm
2023} // namespace art