blob: c812f6b416b6975ed9f8ed96ef742cec3967e663 [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())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010063#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010065class SlowPathCodeARM : public SlowPathCode {
66 public:
67 SlowPathCodeARM() : entry_label_(), exit_label_() {}
68
69 Label* GetEntryLabel() { return &entry_label_; }
70 Label* GetExitLabel() { return &exit_label_; }
71
72 private:
73 Label entry_label_;
74 Label exit_label_;
75
76 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
77};
78
79class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010081 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082
83 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010086 arm_codegen->InvokeRuntime(
87 QUICK_ENTRY_POINT(pThrowNullPointer), 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 Geoffray19a19cf2014-10-22 16:07:05 +0100118 arm_codegen->InvokeRuntime(
119 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100120 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121 if (successor_ == nullptr) {
122 __ b(GetReturnLabel());
123 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100124 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 }
127
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100128 Label* GetReturnLabel() {
129 DCHECK(successor_ == nullptr);
130 return &return_label_;
131 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132
133 private:
134 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100135 // If not null, the block to branch to after the suspend check.
136 HBasicBlock* const successor_;
137
138 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000139 Label return_label_;
140
141 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
142};
143
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100144class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100145 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100146 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
147 Location index_location,
148 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100149 : instruction_(instruction),
150 index_location_(index_location),
151 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152
153 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100154 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155 __ Bind(GetEntryLabel());
156 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100157 arm_codegen->Move32(
158 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
159 arm_codegen->Move32(
160 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
161 arm_codegen->InvokeRuntime(
162 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 }
164
165 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100166 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100167 const Location index_location_;
168 const Location length_location_;
169
170 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
171};
172
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100173class ClinitCheckSlowPathARM : public SlowPathCodeARM {
174 public:
175 explicit ClinitCheckSlowPathARM(HClinitCheck* instruction) : instruction_(instruction) {}
176
177 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
178 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
179 __ Bind(GetEntryLabel());
180 codegen->SaveLiveRegisters(instruction_->GetLocations());
181
182 HLoadClass* cls = instruction_->GetLoadClass();
183 InvokeRuntimeCallingConvention calling_convention;
184 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls->GetTypeIndex());
185 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
186 arm_codegen->InvokeRuntime(
187 QUICK_ENTRY_POINT(pInitializeStaticStorage), instruction_, instruction_->GetDexPc());
188 arm_codegen->Move32(instruction_->GetLocations()->InAt(0), Location::RegisterLocation(R0));
189 codegen->RestoreLiveRegisters(instruction_->GetLocations());
190 __ b(GetExitLabel());
191 }
192
193 private:
194 HClinitCheck* const instruction_;
195
196 DISALLOW_COPY_AND_ASSIGN(ClinitCheckSlowPathARM);
197};
198
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000199class LoadStringSlowPathARM : public SlowPathCodeARM {
200 public:
201 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
202
203 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
204 LocationSummary* locations = instruction_->GetLocations();
205 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
206
207 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
208 __ Bind(GetEntryLabel());
209 codegen->SaveLiveRegisters(locations);
210
211 InvokeRuntimeCallingConvention calling_convention;
212 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
213 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
214 arm_codegen->InvokeRuntime(
215 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
216 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
217
218 codegen->RestoreLiveRegisters(locations);
219 __ b(GetExitLabel());
220 }
221
222 private:
223 HLoadString* const instruction_;
224
225 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
226};
227
228#undef __
229
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100230#undef __
231#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700232
233inline Condition ARMCondition(IfCondition cond) {
234 switch (cond) {
235 case kCondEQ: return EQ;
236 case kCondNE: return NE;
237 case kCondLT: return LT;
238 case kCondLE: return LE;
239 case kCondGT: return GT;
240 case kCondGE: return GE;
241 default:
242 LOG(FATAL) << "Unknown if condition";
243 }
244 return EQ; // Unreachable.
245}
246
247inline Condition ARMOppositeCondition(IfCondition cond) {
248 switch (cond) {
249 case kCondEQ: return NE;
250 case kCondNE: return EQ;
251 case kCondLT: return GE;
252 case kCondLE: return GT;
253 case kCondGT: return LE;
254 case kCondGE: return LT;
255 default:
256 LOG(FATAL) << "Unknown if condition";
257 }
258 return EQ; // Unreachable.
259}
260
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100261void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
262 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
263}
264
265void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000266 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100267}
268
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100269size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
270 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
271 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100272}
273
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100274size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
275 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
276 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100277}
278
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100279CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000280 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100281 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100282 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100283 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100284 move_resolver_(graph->GetArena(), this),
285 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100286
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100287size_t CodeGeneratorARM::FrameEntrySpillSize() const {
288 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
289}
290
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100291Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100292 switch (type) {
293 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100294 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100295 ArmManagedRegister pair =
296 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100297 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
298 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
299
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100300 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
301 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100302 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100303 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100304 }
305
306 case Primitive::kPrimByte:
307 case Primitive::kPrimBoolean:
308 case Primitive::kPrimChar:
309 case Primitive::kPrimShort:
310 case Primitive::kPrimInt:
311 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100312 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100313 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100314 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
315 ArmManagedRegister current =
316 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
317 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100318 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100319 }
320 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100321 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100322 }
323
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000324 case Primitive::kPrimFloat: {
325 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100326 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100327 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100328
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000329 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000330 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
331 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000332 return Location::FpuRegisterPairLocation(reg, reg + 1);
333 }
334
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100335 case Primitive::kPrimVoid:
336 LOG(FATAL) << "Unreachable type " << type;
337 }
338
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100339 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100340}
341
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100342void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100343 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100344 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100345
346 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100347 blocked_core_registers_[SP] = true;
348 blocked_core_registers_[LR] = true;
349 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100350
351 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100352 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100353
354 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100355 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100356
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100357 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100358 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100359
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100360 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100361 // We always save and restore R6 and R7 to make sure we can use three
362 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100363 blocked_core_registers_[R5] = true;
364 blocked_core_registers_[R8] = true;
365 blocked_core_registers_[R10] = true;
366 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100367
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000368 blocked_fpu_registers_[S16] = true;
369 blocked_fpu_registers_[S17] = true;
370 blocked_fpu_registers_[S18] = true;
371 blocked_fpu_registers_[S19] = true;
372 blocked_fpu_registers_[S20] = true;
373 blocked_fpu_registers_[S21] = true;
374 blocked_fpu_registers_[S22] = true;
375 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000376 blocked_fpu_registers_[S24] = true;
377 blocked_fpu_registers_[S25] = true;
378 blocked_fpu_registers_[S26] = true;
379 blocked_fpu_registers_[S27] = true;
380 blocked_fpu_registers_[S28] = true;
381 blocked_fpu_registers_[S29] = true;
382 blocked_fpu_registers_[S30] = true;
383 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100384
385 UpdateBlockedPairRegisters();
386}
387
388void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
389 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
390 ArmManagedRegister current =
391 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
392 if (blocked_core_registers_[current.AsRegisterPairLow()]
393 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
394 blocked_register_pairs_[i] = true;
395 }
396 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100397}
398
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100399InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
400 : HGraphVisitor(graph),
401 assembler_(codegen->GetAssembler()),
402 codegen_(codegen) {}
403
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000404void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700405 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100406 if (!skip_overflow_check) {
407 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100408 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100409 AddSlowPath(slow_path);
410
411 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
412 __ cmp(SP, ShifterOperand(IP));
413 __ b(slow_path->GetEntryLabel(), CC);
414 } else {
415 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100416 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100417 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100418 }
419 }
420
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100421 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
422 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000423
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100424 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100425 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100426 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000427}
428
429void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100430 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100431 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000432}
433
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100434void CodeGeneratorARM::Bind(HBasicBlock* block) {
435 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000436}
437
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
439 switch (load->GetType()) {
440 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100441 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
443 break;
444
445 case Primitive::kPrimInt:
446 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100448 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100449
450 case Primitive::kPrimBoolean:
451 case Primitive::kPrimByte:
452 case Primitive::kPrimChar:
453 case Primitive::kPrimShort:
454 case Primitive::kPrimVoid:
455 LOG(FATAL) << "Unexpected type " << load->GetType();
456 }
457
458 LOG(FATAL) << "Unreachable";
459 return Location();
460}
461
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100462Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
463 switch (type) {
464 case Primitive::kPrimBoolean:
465 case Primitive::kPrimByte:
466 case Primitive::kPrimChar:
467 case Primitive::kPrimShort:
468 case Primitive::kPrimInt:
469 case Primitive::kPrimNot: {
470 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000471 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100472 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100473 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100474 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000475 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100476 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100477 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100478
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000479 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100480 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000481 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100482 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000483 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100484 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100485 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
486 calling_convention.GetRegisterPairAt(index));
487 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100488 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000489 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100490 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000491 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
492 }
493 }
494
495 case Primitive::kPrimFloat: {
496 uint32_t stack_index = stack_index_++;
497 if (float_index_ % 2 == 0) {
498 float_index_ = std::max(double_index_, float_index_);
499 }
500 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
501 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
502 } else {
503 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
504 }
505 }
506
507 case Primitive::kPrimDouble: {
508 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
509 uint32_t stack_index = stack_index_;
510 stack_index_ += 2;
511 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
512 uint32_t index = double_index_;
513 double_index_ += 2;
514 return Location::FpuRegisterPairLocation(
515 calling_convention.GetFpuRegisterAt(index),
516 calling_convention.GetFpuRegisterAt(index + 1));
517 } else {
518 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100519 }
520 }
521
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100522 case Primitive::kPrimVoid:
523 LOG(FATAL) << "Unexpected parameter type " << type;
524 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100525 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100526 return Location();
527}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100528
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000529Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
530 switch (type) {
531 case Primitive::kPrimBoolean:
532 case Primitive::kPrimByte:
533 case Primitive::kPrimChar:
534 case Primitive::kPrimShort:
535 case Primitive::kPrimInt:
536 case Primitive::kPrimNot: {
537 return Location::RegisterLocation(R0);
538 }
539
540 case Primitive::kPrimFloat: {
541 return Location::FpuRegisterLocation(S0);
542 }
543
544 case Primitive::kPrimLong: {
545 return Location::RegisterPairLocation(R0, R1);
546 }
547
548 case Primitive::kPrimDouble: {
549 return Location::FpuRegisterPairLocation(S0, S1);
550 }
551
552 case Primitive::kPrimVoid:
553 return Location();
554 }
555 UNREACHABLE();
556 return Location();
557}
558
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100559void CodeGeneratorARM::Move32(Location destination, Location source) {
560 if (source.Equals(destination)) {
561 return;
562 }
563 if (destination.IsRegister()) {
564 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100565 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100566 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000567 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100568 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100569 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100570 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100571 } else if (destination.IsFpuRegister()) {
572 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000573 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100574 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000575 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100576 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000577 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100578 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100579 } else {
580 DCHECK(destination.IsStackSlot());
581 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100582 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100583 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000584 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100585 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100586 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100587 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
588 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100589 }
590 }
591}
592
593void CodeGeneratorARM::Move64(Location destination, Location source) {
594 if (source.Equals(destination)) {
595 return;
596 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100597 if (destination.IsRegisterPair()) {
598 if (source.IsRegisterPair()) {
599 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
600 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100601 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000602 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100603 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000604 uint16_t register_index = source.GetQuickParameterRegisterIndex();
605 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100606 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100607 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000608 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100609 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000610 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100611 } else {
612 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100613 if (destination.AsRegisterPairLow<Register>() == R1) {
614 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100615 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
616 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100617 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100618 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100619 SP, source.GetStackIndex());
620 }
621 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000622 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100623 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000624 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
625 SP,
626 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100627 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000628 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100629 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100630 } else if (destination.IsQuickParameter()) {
631 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000632 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
633 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100634 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000635 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100636 source.AsRegisterPairLow<Register>());
637 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000638 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100639 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000640 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100641 } else {
642 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000643 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000644 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100645 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000646 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100647 }
648 } else {
649 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100650 if (source.IsRegisterPair()) {
651 if (source.AsRegisterPairLow<Register>() == R1) {
652 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100653 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
654 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100655 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100656 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100657 SP, destination.GetStackIndex());
658 }
659 } else if (source.IsQuickParameter()) {
660 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000661 uint16_t register_index = source.GetQuickParameterRegisterIndex();
662 uint16_t stack_index = source.GetQuickParameterStackIndex();
663 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100664 SP, destination.GetStackIndex());
665 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000666 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100667 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 } else if (source.IsFpuRegisterPair()) {
669 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
670 SP,
671 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100672 } else {
673 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100674 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
675 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
676 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
677 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100678 }
679 }
680}
681
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100682void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100683 LocationSummary* locations = instruction->GetLocations();
684 if (locations != nullptr && locations->Out().Equals(location)) {
685 return;
686 }
687
Roland Levillain476df552014-10-09 17:51:36 +0100688 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 int32_t value = instruction->AsIntConstant()->GetValue();
690 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100691 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100692 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100693 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100694 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100695 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100696 }
Roland Levillain476df552014-10-09 17:51:36 +0100697 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100698 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100699 if (location.IsRegisterPair()) {
700 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
701 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100702 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100703 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100704 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100705 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100706 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100707 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100708 }
Roland Levillain476df552014-10-09 17:51:36 +0100709 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
711 switch (instruction->GetType()) {
712 case Primitive::kPrimBoolean:
713 case Primitive::kPrimByte:
714 case Primitive::kPrimChar:
715 case Primitive::kPrimShort:
716 case Primitive::kPrimInt:
717 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100718 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100719 Move32(location, Location::StackSlot(stack_slot));
720 break;
721
722 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100723 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100724 Move64(location, Location::DoubleStackSlot(stack_slot));
725 break;
726
727 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100728 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100729 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000730 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100731 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100732 switch (instruction->GetType()) {
733 case Primitive::kPrimBoolean:
734 case Primitive::kPrimByte:
735 case Primitive::kPrimChar:
736 case Primitive::kPrimShort:
737 case Primitive::kPrimNot:
738 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100739 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100740 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100741 break;
742
743 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100744 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100745 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100746 break;
747
748 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100749 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100750 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000751 }
752}
753
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100754void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
755 HInstruction* instruction,
756 uint32_t dex_pc) {
757 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
758 __ blx(LR);
759 RecordPcInfo(instruction, dex_pc);
760 DCHECK(instruction->IsSuspendCheck()
761 || instruction->IsBoundsCheck()
762 || instruction->IsNullCheck()
763 || !IsLeafMethod());
764}
765
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000766void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000767 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000768}
769
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000770void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000771 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100772 DCHECK(!successor->IsExitBlock());
773
774 HBasicBlock* block = got->GetBlock();
775 HInstruction* previous = got->GetPrevious();
776
777 HLoopInformation* info = block->GetLoopInformation();
778 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
779 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
780 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
781 return;
782 }
783
784 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
785 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
786 }
787 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000788 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000789 }
790}
791
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000792void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000793 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000794}
795
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000796void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000797 if (kIsDebugBuild) {
798 __ Comment("Unreachable");
799 __ bkpt(0);
800 }
801}
802
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000803void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100804 LocationSummary* locations =
805 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100806 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100807 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100808 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100809 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000810}
811
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000812void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700813 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100814 if (cond->IsIntConstant()) {
815 // Constant condition, statically compared against 1.
816 int32_t cond_value = cond->AsIntConstant()->GetValue();
817 if (cond_value == 1) {
818 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
819 if_instr->IfTrueSuccessor())) {
820 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100821 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100822 return;
823 } else {
824 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100825 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100826 } else {
827 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
828 // Condition has been materialized, compare the output to 0
829 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
830 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
831 ShifterOperand(0));
832 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
833 } else {
834 // Condition has not been materialized, use its inputs as the
835 // comparison and its condition as the branch condition.
836 LocationSummary* locations = cond->GetLocations();
837 if (locations->InAt(1).IsRegister()) {
838 __ cmp(locations->InAt(0).As<Register>(),
839 ShifterOperand(locations->InAt(1).As<Register>()));
840 } else {
841 DCHECK(locations->InAt(1).IsConstant());
842 int32_t value =
843 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
844 ShifterOperand operand;
845 if (ShifterOperand::CanHoldArm(value, &operand)) {
846 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
847 } else {
848 Register temp = IP;
849 __ LoadImmediate(temp, value);
850 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
851 }
852 }
853 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
854 ARMCondition(cond->AsCondition()->GetCondition()));
855 }
Dave Allison20dfc792014-06-16 20:44:29 -0700856 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100857 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
858 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700859 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000860 }
861}
862
Dave Allison20dfc792014-06-16 20:44:29 -0700863
864void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100865 LocationSummary* locations =
866 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100867 locations->SetInAt(0, Location::RequiresRegister());
868 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100869 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100870 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100871 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000872}
873
Dave Allison20dfc792014-06-16 20:44:29 -0700874void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100875 if (!comp->NeedsMaterialization()) return;
876
877 LocationSummary* locations = comp->GetLocations();
878 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100879 __ cmp(locations->InAt(0).As<Register>(),
880 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100881 } else {
882 DCHECK(locations->InAt(1).IsConstant());
883 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
884 ShifterOperand operand;
885 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100886 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100887 } else {
888 Register temp = IP;
889 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100890 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100891 }
Dave Allison20dfc792014-06-16 20:44:29 -0700892 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100893 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100894 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100895 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100896 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100897 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700898}
899
900void LocationsBuilderARM::VisitEqual(HEqual* comp) {
901 VisitCondition(comp);
902}
903
904void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
905 VisitCondition(comp);
906}
907
908void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
909 VisitCondition(comp);
910}
911
912void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
913 VisitCondition(comp);
914}
915
916void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
917 VisitCondition(comp);
918}
919
920void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
921 VisitCondition(comp);
922}
923
924void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
925 VisitCondition(comp);
926}
927
928void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
929 VisitCondition(comp);
930}
931
932void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
933 VisitCondition(comp);
934}
935
936void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
937 VisitCondition(comp);
938}
939
940void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
941 VisitCondition(comp);
942}
943
944void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
945 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000946}
947
948void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000949 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000950}
951
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000952void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
953 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000954}
955
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000956void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100957 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000958}
959
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000960void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100961 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000962}
963
964void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100965 LocationSummary* locations =
966 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100967 switch (store->InputAt(1)->GetType()) {
968 case Primitive::kPrimBoolean:
969 case Primitive::kPrimByte:
970 case Primitive::kPrimChar:
971 case Primitive::kPrimShort:
972 case Primitive::kPrimInt:
973 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100974 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100975 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
976 break;
977
978 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100979 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100980 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
981 break;
982
983 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100984 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100985 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000986}
987
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000988void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000989}
990
991void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100992 LocationSummary* locations =
993 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100994 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000995}
996
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000997void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100998 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000999}
1000
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001001void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001002 LocationSummary* locations =
1003 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001004 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001005}
1006
1007void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1008 // Will be generated at use site.
1009}
1010
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001011void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1012 LocationSummary* locations =
1013 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1014 locations->SetOut(Location::ConstantLocation(constant));
1015}
1016
1017void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1018 // Will be generated at use site.
1019}
1020
1021void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1022 LocationSummary* locations =
1023 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1024 locations->SetOut(Location::ConstantLocation(constant));
1025}
1026
1027void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1028 // Will be generated at use site.
1029}
1030
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001031void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001032 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001033}
1034
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001035void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
1036 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001037}
1038
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001039void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001040 LocationSummary* locations =
1041 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001042 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001043}
1044
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001045void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001046 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001047}
1048
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001049void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001050 HandleInvoke(invoke);
1051}
1052
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001053void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001054 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001055}
1056
1057void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001058 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001059
1060 // TODO: Implement all kinds of calls:
1061 // 1) boot -> boot
1062 // 2) app -> boot
1063 // 3) app -> app
1064 //
1065 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1066
1067 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001068 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001069 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001070 __ LoadFromOffset(
1071 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001072 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001073 __ LoadFromOffset(
1074 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001075 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001076 __ LoadFromOffset(kLoadWord, LR, temp,
1077 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001078 // LR()
1079 __ blx(LR);
1080
1081 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1082 DCHECK(!codegen_->IsLeafMethod());
1083}
1084
1085void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1086 HandleInvoke(invoke);
1087}
1088
1089void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001090 LocationSummary* locations =
1091 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001092 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001093
1094 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001095 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001096 HInstruction* input = invoke->InputAt(i);
1097 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1098 }
1099
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001100 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001101}
1102
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001103
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001104void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001105 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001106 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1107 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1108 LocationSummary* locations = invoke->GetLocations();
1109 Location receiver = locations->InAt(0);
1110 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1111 // temp = object->GetClass();
1112 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001113 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1114 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001115 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001116 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001117 }
1118 // temp = temp->GetMethodAt(method_offset);
1119 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001120 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001121 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001122 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001123 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001124 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001125 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001126 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001127}
1128
Roland Levillain88cb1752014-10-20 16:36:47 +01001129void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1130 LocationSummary* locations =
1131 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1132 switch (neg->GetResultType()) {
1133 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001134 case Primitive::kPrimLong: {
1135 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001136 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001137 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001138 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001139 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001140
Roland Levillain88cb1752014-10-20 16:36:47 +01001141 case Primitive::kPrimFloat:
1142 case Primitive::kPrimDouble:
1143 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1144 break;
1145
1146 default:
1147 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1148 }
1149}
1150
1151void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1152 LocationSummary* locations = neg->GetLocations();
1153 Location out = locations->Out();
1154 Location in = locations->InAt(0);
1155 switch (neg->GetResultType()) {
1156 case Primitive::kPrimInt:
1157 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001158 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001159 break;
1160
1161 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001162 DCHECK(in.IsRegisterPair());
1163 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1164 __ rsbs(out.AsRegisterPairLow<Register>(),
1165 in.AsRegisterPairLow<Register>(),
1166 ShifterOperand(0));
1167 // We cannot emit an RSC (Reverse Subtract with Carry)
1168 // instruction here, as it does not exist in the Thumb-2
1169 // instruction set. We use the following approach
1170 // using SBC and SUB instead.
1171 //
1172 // out.hi = -C
1173 __ sbc(out.AsRegisterPairHigh<Register>(),
1174 out.AsRegisterPairHigh<Register>(),
1175 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1176 // out.hi = out.hi - in.hi
1177 __ sub(out.AsRegisterPairHigh<Register>(),
1178 out.AsRegisterPairHigh<Register>(),
1179 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1180 break;
1181
Roland Levillain88cb1752014-10-20 16:36:47 +01001182 case Primitive::kPrimFloat:
1183 case Primitive::kPrimDouble:
1184 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1185 break;
1186
1187 default:
1188 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1189 }
1190}
1191
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001192void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001193 LocationSummary* locations =
1194 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001195 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001196 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001197 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001198 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1199 locations->SetInAt(0, Location::RequiresRegister());
1200 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1201 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001202 break;
1203 }
1204
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001205 case Primitive::kPrimFloat:
1206 case Primitive::kPrimDouble: {
1207 locations->SetInAt(0, Location::RequiresFpuRegister());
1208 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001209 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001210 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001211 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001212
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001213 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001214 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001215 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001216}
1217
1218void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1219 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001220 Location out = locations->Out();
1221 Location first = locations->InAt(0);
1222 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001223 switch (add->GetResultType()) {
1224 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001225 if (second.IsRegister()) {
1226 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001227 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001228 __ AddConstant(out.As<Register>(),
1229 first.As<Register>(),
1230 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001231 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001232 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001233
1234 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001235 __ adds(out.AsRegisterPairLow<Register>(),
1236 first.AsRegisterPairLow<Register>(),
1237 ShifterOperand(second.AsRegisterPairLow<Register>()));
1238 __ adc(out.AsRegisterPairHigh<Register>(),
1239 first.AsRegisterPairHigh<Register>(),
1240 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001241 break;
1242
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001243 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001244 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001245 break;
1246
1247 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001248 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1249 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1250 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001251 break;
1252
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001253 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001254 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001255 }
1256}
1257
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001258void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001259 LocationSummary* locations =
1260 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001261 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001262 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001263 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001264 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1265 locations->SetInAt(0, Location::RequiresRegister());
1266 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1267 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001268 break;
1269 }
Calin Juravle11351682014-10-23 15:38:15 +01001270 case Primitive::kPrimFloat:
1271 case Primitive::kPrimDouble: {
1272 locations->SetInAt(0, Location::RequiresFpuRegister());
1273 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001274 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001275 break;
Calin Juravle11351682014-10-23 15:38:15 +01001276 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001277 default:
Calin Juravle11351682014-10-23 15:38:15 +01001278 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001279 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001280}
1281
1282void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1283 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001284 Location out = locations->Out();
1285 Location first = locations->InAt(0);
1286 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001287 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001288 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001289 if (second.IsRegister()) {
1290 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001291 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001292 __ AddConstant(out.As<Register>(),
1293 first.As<Register>(),
1294 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001295 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001296 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001297 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001298
Calin Juravle11351682014-10-23 15:38:15 +01001299 case Primitive::kPrimLong: {
1300 __ subs(out.AsRegisterPairLow<Register>(),
1301 first.AsRegisterPairLow<Register>(),
1302 ShifterOperand(second.AsRegisterPairLow<Register>()));
1303 __ sbc(out.AsRegisterPairHigh<Register>(),
1304 first.AsRegisterPairHigh<Register>(),
1305 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001306 break;
Calin Juravle11351682014-10-23 15:38:15 +01001307 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001308
Calin Juravle11351682014-10-23 15:38:15 +01001309 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001310 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001311 break;
Calin Juravle11351682014-10-23 15:38:15 +01001312 }
1313
1314 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001315 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1316 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1317 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001318 break;
1319 }
1320
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001321
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001322 default:
Calin Juravle11351682014-10-23 15:38:15 +01001323 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001324 }
1325}
1326
Calin Juravle34bacdf2014-10-07 20:23:36 +01001327void LocationsBuilderARM::VisitMul(HMul* mul) {
1328 LocationSummary* locations =
1329 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1330 switch (mul->GetResultType()) {
1331 case Primitive::kPrimInt:
1332 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001333 locations->SetInAt(0, Location::RequiresRegister());
1334 locations->SetInAt(1, Location::RequiresRegister());
1335 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001336 break;
1337 }
1338
Calin Juravleb5bfa962014-10-21 18:02:24 +01001339 case Primitive::kPrimFloat:
1340 case Primitive::kPrimDouble: {
1341 locations->SetInAt(0, Location::RequiresFpuRegister());
1342 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001343 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001344 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001345 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001346
1347 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001348 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001349 }
1350}
1351
1352void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1353 LocationSummary* locations = mul->GetLocations();
1354 Location out = locations->Out();
1355 Location first = locations->InAt(0);
1356 Location second = locations->InAt(1);
1357 switch (mul->GetResultType()) {
1358 case Primitive::kPrimInt: {
1359 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1360 break;
1361 }
1362 case Primitive::kPrimLong: {
1363 Register out_hi = out.AsRegisterPairHigh<Register>();
1364 Register out_lo = out.AsRegisterPairLow<Register>();
1365 Register in1_hi = first.AsRegisterPairHigh<Register>();
1366 Register in1_lo = first.AsRegisterPairLow<Register>();
1367 Register in2_hi = second.AsRegisterPairHigh<Register>();
1368 Register in2_lo = second.AsRegisterPairLow<Register>();
1369
1370 // Extra checks to protect caused by the existence of R1_R2.
1371 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1372 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1373 DCHECK_NE(out_hi, in1_lo);
1374 DCHECK_NE(out_hi, in2_lo);
1375
1376 // input: in1 - 64 bits, in2 - 64 bits
1377 // output: out
1378 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1379 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1380 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1381
1382 // IP <- in1.lo * in2.hi
1383 __ mul(IP, in1_lo, in2_hi);
1384 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1385 __ mla(out_hi, in1_hi, in2_lo, IP);
1386 // out.lo <- (in1.lo * in2.lo)[31:0];
1387 __ umull(out_lo, IP, in1_lo, in2_lo);
1388 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1389 __ add(out_hi, out_hi, ShifterOperand(IP));
1390 break;
1391 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001392
1393 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001394 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001395 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001396 }
1397
1398 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001399 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1400 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1401 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001402 break;
1403 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001404
1405 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001406 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001407 }
1408}
1409
Calin Juravle7c4954d2014-10-28 16:57:40 +00001410void LocationsBuilderARM::VisitDiv(HDiv* div) {
1411 LocationSummary* locations =
1412 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1413 switch (div->GetResultType()) {
1414 case Primitive::kPrimInt:
1415 case Primitive::kPrimLong: {
1416 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1417 break;
1418 }
1419 case Primitive::kPrimFloat:
1420 case Primitive::kPrimDouble: {
1421 locations->SetInAt(0, Location::RequiresFpuRegister());
1422 locations->SetInAt(1, Location::RequiresFpuRegister());
1423 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1424 break;
1425 }
1426
1427 default:
1428 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1429 }
1430}
1431
1432void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1433 LocationSummary* locations = div->GetLocations();
1434 Location out = locations->Out();
1435 Location first = locations->InAt(0);
1436 Location second = locations->InAt(1);
1437
1438 switch (div->GetResultType()) {
1439 case Primitive::kPrimInt:
1440 case Primitive::kPrimLong: {
1441 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1442 break;
1443 }
1444
1445 case Primitive::kPrimFloat: {
1446 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1447 break;
1448 }
1449
1450 case Primitive::kPrimDouble: {
1451 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1452 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1453 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1454 break;
1455 }
1456
1457 default:
1458 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1459 }
1460}
1461
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001462void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001463 LocationSummary* locations =
1464 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001465 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001466 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1467 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1468 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001469}
1470
1471void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1472 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001473 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001474 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001475 codegen_->InvokeRuntime(
1476 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001477}
1478
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001479void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1480 LocationSummary* locations =
1481 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1482 InvokeRuntimeCallingConvention calling_convention;
1483 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1484 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1485 locations->SetOut(Location::RegisterLocation(R0));
1486 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1487}
1488
1489void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1490 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001491 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001492 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001493 codegen_->InvokeRuntime(
1494 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001495}
1496
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001497void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001498 LocationSummary* locations =
1499 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001500 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1501 if (location.IsStackSlot()) {
1502 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1503 } else if (location.IsDoubleStackSlot()) {
1504 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001505 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001506 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001507}
1508
1509void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001510 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001511}
1512
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001513void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001514 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001515 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001516 locations->SetInAt(0, Location::RequiresRegister());
1517 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001518}
1519
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001520void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1521 LocationSummary* locations = not_->GetLocations();
1522 Location out = locations->Out();
1523 Location in = locations->InAt(0);
1524 switch (not_->InputAt(0)->GetType()) {
1525 case Primitive::kPrimBoolean:
1526 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1527 break;
1528
1529 case Primitive::kPrimInt:
1530 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1531 break;
1532
1533 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001534 __ mvn(out.AsRegisterPairLow<Register>(),
1535 ShifterOperand(in.AsRegisterPairLow<Register>()));
1536 __ mvn(out.AsRegisterPairHigh<Register>(),
1537 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001538 break;
1539
1540 default:
1541 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1542 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001543}
1544
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001545void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001546 LocationSummary* locations =
1547 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001548 locations->SetInAt(0, Location::RequiresRegister());
1549 locations->SetInAt(1, Location::RequiresRegister());
1550 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001551}
1552
1553void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1554 Label greater, done;
1555 LocationSummary* locations = compare->GetLocations();
1556 switch (compare->InputAt(0)->GetType()) {
1557 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001558 Register output = locations->Out().As<Register>();
1559 Location left = locations->InAt(0);
1560 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001561 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001562 __ cmp(left.AsRegisterPairHigh<Register>(),
1563 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001564 __ b(&less, LT);
1565 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001566 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1567 // the status flags.
1568 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001569 __ cmp(left.AsRegisterPairLow<Register>(),
1570 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001571 __ b(&done, EQ);
1572 __ b(&less, CC);
1573
1574 __ Bind(&greater);
1575 __ LoadImmediate(output, 1);
1576 __ b(&done);
1577
1578 __ Bind(&less);
1579 __ LoadImmediate(output, -1);
1580
1581 __ Bind(&done);
1582 break;
1583 }
1584 default:
1585 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1586 }
1587}
1588
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001589void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001590 LocationSummary* locations =
1591 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001592 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1593 locations->SetInAt(i, Location::Any());
1594 }
1595 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001596}
1597
1598void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001599 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001600}
1601
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001602void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001603 LocationSummary* locations =
1604 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001605 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001606 locations->SetInAt(0, Location::RequiresRegister());
1607 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001608 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001609 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001610 locations->AddTemp(Location::RequiresRegister());
1611 locations->AddTemp(Location::RequiresRegister());
1612 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001613}
1614
1615void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1616 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001617 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001618 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001619 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001620
1621 switch (field_type) {
1622 case Primitive::kPrimBoolean:
1623 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001624 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001625 __ StoreToOffset(kStoreByte, value, obj, offset);
1626 break;
1627 }
1628
1629 case Primitive::kPrimShort:
1630 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001631 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001632 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1633 break;
1634 }
1635
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001636 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001637 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001638 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001639 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001640 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001641 Register temp = locations->GetTemp(0).As<Register>();
1642 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001643 codegen_->MarkGCCard(temp, card, obj, value);
1644 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001645 break;
1646 }
1647
1648 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001649 Location value = locations->InAt(1);
1650 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001651 break;
1652 }
1653
1654 case Primitive::kPrimFloat:
1655 case Primitive::kPrimDouble:
1656 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001657 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001658 case Primitive::kPrimVoid:
1659 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001660 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001661 }
1662}
1663
1664void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001665 LocationSummary* locations =
1666 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001667 locations->SetInAt(0, Location::RequiresRegister());
1668 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001669}
1670
1671void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1672 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001673 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001674 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1675
1676 switch (instruction->GetType()) {
1677 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001678 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001679 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1680 break;
1681 }
1682
1683 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001684 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001685 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1686 break;
1687 }
1688
1689 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001690 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001691 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1692 break;
1693 }
1694
1695 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001696 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001697 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1698 break;
1699 }
1700
1701 case Primitive::kPrimInt:
1702 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001703 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001704 __ LoadFromOffset(kLoadWord, out, obj, offset);
1705 break;
1706 }
1707
1708 case Primitive::kPrimLong: {
1709 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001710 Location out = locations->Out();
1711 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001712 break;
1713 }
1714
1715 case Primitive::kPrimFloat:
1716 case Primitive::kPrimDouble:
1717 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001718 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001719 case Primitive::kPrimVoid:
1720 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001721 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001722 }
1723}
1724
1725void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001726 LocationSummary* locations =
1727 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001728 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001729 if (instruction->HasUses()) {
1730 locations->SetOut(Location::SameAsFirstInput());
1731 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001732}
1733
1734void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001735 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001736 codegen_->AddSlowPath(slow_path);
1737
1738 LocationSummary* locations = instruction->GetLocations();
1739 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001740
1741 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001742 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001743 __ b(slow_path->GetEntryLabel(), EQ);
1744 } else {
1745 DCHECK(obj.IsConstant()) << obj;
1746 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1747 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001748 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001749}
1750
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001751void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001752 LocationSummary* locations =
1753 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001754 locations->SetInAt(0, Location::RequiresRegister());
1755 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1756 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001757}
1758
1759void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1760 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001761 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001762 Location index = locations->InAt(1);
1763
1764 switch (instruction->GetType()) {
1765 case Primitive::kPrimBoolean: {
1766 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001767 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001768 if (index.IsConstant()) {
1769 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1770 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1771 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001772 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001773 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1774 }
1775 break;
1776 }
1777
1778 case Primitive::kPrimByte: {
1779 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001780 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001781 if (index.IsConstant()) {
1782 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1783 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1784 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001785 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001786 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1787 }
1788 break;
1789 }
1790
1791 case Primitive::kPrimShort: {
1792 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001793 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001794 if (index.IsConstant()) {
1795 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1796 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1797 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001798 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001799 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1800 }
1801 break;
1802 }
1803
1804 case Primitive::kPrimChar: {
1805 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001806 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001807 if (index.IsConstant()) {
1808 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1809 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1810 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001811 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001812 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1813 }
1814 break;
1815 }
1816
1817 case Primitive::kPrimInt:
1818 case Primitive::kPrimNot: {
1819 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1820 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001821 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001822 if (index.IsConstant()) {
1823 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1824 __ LoadFromOffset(kLoadWord, out, obj, offset);
1825 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001826 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001827 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1828 }
1829 break;
1830 }
1831
1832 case Primitive::kPrimLong: {
1833 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001834 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001835 if (index.IsConstant()) {
1836 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001837 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001838 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001839 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1840 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001841 }
1842 break;
1843 }
1844
1845 case Primitive::kPrimFloat:
1846 case Primitive::kPrimDouble:
1847 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001848 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001849 case Primitive::kPrimVoid:
1850 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001851 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001852 }
1853}
1854
1855void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001856 Primitive::Type value_type = instruction->GetComponentType();
1857 bool is_object = value_type == Primitive::kPrimNot;
1858 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1859 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1860 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001861 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001862 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1863 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1864 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001865 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001866 locations->SetInAt(0, Location::RequiresRegister());
1867 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1868 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001869 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001870}
1871
1872void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1873 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001874 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001875 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001876 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001877
1878 switch (value_type) {
1879 case Primitive::kPrimBoolean:
1880 case Primitive::kPrimByte: {
1881 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001882 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001883 if (index.IsConstant()) {
1884 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1885 __ StoreToOffset(kStoreByte, value, obj, offset);
1886 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001887 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001888 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1889 }
1890 break;
1891 }
1892
1893 case Primitive::kPrimShort:
1894 case Primitive::kPrimChar: {
1895 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001896 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001897 if (index.IsConstant()) {
1898 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1899 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1900 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001901 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001902 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1903 }
1904 break;
1905 }
1906
1907 case Primitive::kPrimInt: {
1908 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001909 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001910 if (index.IsConstant()) {
1911 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1912 __ StoreToOffset(kStoreWord, value, obj, offset);
1913 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001914 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001915 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1916 }
1917 break;
1918 }
1919
1920 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001921 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001922 break;
1923 }
1924
1925 case Primitive::kPrimLong: {
1926 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001927 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001928 if (index.IsConstant()) {
1929 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001930 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001931 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001932 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1933 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001934 }
1935 break;
1936 }
1937
1938 case Primitive::kPrimFloat:
1939 case Primitive::kPrimDouble:
1940 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001941 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001942 case Primitive::kPrimVoid:
1943 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001944 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001945 }
1946}
1947
1948void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001949 LocationSummary* locations =
1950 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001951 locations->SetInAt(0, Location::RequiresRegister());
1952 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001953}
1954
1955void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1956 LocationSummary* locations = instruction->GetLocations();
1957 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001958 Register obj = locations->InAt(0).As<Register>();
1959 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001960 __ LoadFromOffset(kLoadWord, out, obj, offset);
1961}
1962
1963void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001964 LocationSummary* locations =
1965 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001966 locations->SetInAt(0, Location::RequiresRegister());
1967 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001968 if (instruction->HasUses()) {
1969 locations->SetOut(Location::SameAsFirstInput());
1970 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001971}
1972
1973void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1974 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001975 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001976 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001977 codegen_->AddSlowPath(slow_path);
1978
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001979 Register index = locations->InAt(0).As<Register>();
1980 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001981
1982 __ cmp(index, ShifterOperand(length));
1983 __ b(slow_path->GetEntryLabel(), CS);
1984}
1985
1986void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1987 Label is_null;
1988 __ CompareAndBranchIfZero(value, &is_null);
1989 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1990 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1991 __ strb(card, Address(card, temp));
1992 __ Bind(&is_null);
1993}
1994
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001995void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1996 temp->SetLocations(nullptr);
1997}
1998
1999void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2000 // Nothing to do, this is driven by the code generator.
2001}
2002
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002003void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002004 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002005}
2006
2007void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002008 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2009}
2010
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002011void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2012 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2013}
2014
2015void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002016 HBasicBlock* block = instruction->GetBlock();
2017 if (block->GetLoopInformation() != nullptr) {
2018 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2019 // The back edge will generate the suspend check.
2020 return;
2021 }
2022 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2023 // The goto will generate the suspend check.
2024 return;
2025 }
2026 GenerateSuspendCheck(instruction, nullptr);
2027}
2028
2029void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2030 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002031 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002032 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002033 codegen_->AddSlowPath(slow_path);
2034
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002035 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002036 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002037 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002038 __ Bind(slow_path->GetReturnLabel());
2039 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002040 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002041 __ b(slow_path->GetEntryLabel());
2042 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002043}
2044
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002045ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2046 return codegen_->GetAssembler();
2047}
2048
2049void ParallelMoveResolverARM::EmitMove(size_t index) {
2050 MoveOperands* move = moves_.Get(index);
2051 Location source = move->GetSource();
2052 Location destination = move->GetDestination();
2053
2054 if (source.IsRegister()) {
2055 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002056 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002057 } else {
2058 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002059 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002060 SP, destination.GetStackIndex());
2061 }
2062 } else if (source.IsStackSlot()) {
2063 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002064 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002065 SP, source.GetStackIndex());
2066 } else {
2067 DCHECK(destination.IsStackSlot());
2068 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2069 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2070 }
2071 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002072 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002073 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002074 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2075 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002076 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002077 } else {
2078 DCHECK(destination.IsStackSlot());
2079 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002080 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002081 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002082 }
2083}
2084
2085void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2086 __ Mov(IP, reg);
2087 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2088 __ StoreToOffset(kStoreWord, IP, SP, mem);
2089}
2090
2091void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2092 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2093 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2094 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2095 SP, mem1 + stack_offset);
2096 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2097 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2098 SP, mem2 + stack_offset);
2099 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2100}
2101
2102void ParallelMoveResolverARM::EmitSwap(size_t index) {
2103 MoveOperands* move = moves_.Get(index);
2104 Location source = move->GetSource();
2105 Location destination = move->GetDestination();
2106
2107 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002108 DCHECK_NE(source.As<Register>(), IP);
2109 DCHECK_NE(destination.As<Register>(), IP);
2110 __ Mov(IP, source.As<Register>());
2111 __ Mov(source.As<Register>(), destination.As<Register>());
2112 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002113 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002114 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002115 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002116 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002117 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2118 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2119 } else {
2120 LOG(FATAL) << "Unimplemented";
2121 }
2122}
2123
2124void ParallelMoveResolverARM::SpillScratch(int reg) {
2125 __ Push(static_cast<Register>(reg));
2126}
2127
2128void ParallelMoveResolverARM::RestoreScratch(int reg) {
2129 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002130}
2131
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002132void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
2133 LocationSummary* locations =
2134 new (GetGraph()->GetArena()) LocationSummary(cls, LocationSummary::kNoCall);
2135 locations->SetOut(Location::RequiresRegister());
2136}
2137
2138void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2139 Register out = cls->GetLocations()->Out().As<Register>();
2140 if (cls->IsReferrersClass()) {
2141 codegen_->LoadCurrentMethod(out);
2142 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2143 } else {
2144 codegen_->LoadCurrentMethod(out);
2145 __ LoadFromOffset(
2146 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2147 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
2148 }
2149}
2150
2151void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2152 LocationSummary* locations =
2153 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2154 locations->SetInAt(0, Location::RequiresRegister());
2155 if (check->HasUses()) {
2156 locations->SetOut(Location::SameAsFirstInput());
2157 }
2158}
2159
2160void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
2161 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ClinitCheckSlowPathARM(check);
2162 codegen_->AddSlowPath(slow_path);
2163
2164 LocationSummary* locations = check->GetLocations();
2165 // We remove the class as a live register, we know it's null or unused in the slow path.
2166 RegisterSet* register_set = locations->GetLiveRegisters();
2167 register_set->Remove(locations->InAt(0));
2168
2169 Register class_reg = locations->InAt(0).As<Register>();
2170 __ cmp(class_reg, ShifterOperand(0));
2171 __ b(slow_path->GetEntryLabel(), EQ);
2172 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2173 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2174 __ b(slow_path->GetEntryLabel(), LT);
2175 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2176 // properly. Therefore, we do a memory fence.
2177 __ dmb(ISH);
2178 __ Bind(slow_path->GetExitLabel());
2179}
2180
2181void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2182 LocationSummary* locations =
2183 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2184 locations->SetInAt(0, Location::RequiresRegister());
2185 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2186}
2187
2188void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2189 LocationSummary* locations = instruction->GetLocations();
2190 Register cls = locations->InAt(0).As<Register>();
2191 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2192
2193 switch (instruction->GetType()) {
2194 case Primitive::kPrimBoolean: {
2195 Register out = locations->Out().As<Register>();
2196 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2197 break;
2198 }
2199
2200 case Primitive::kPrimByte: {
2201 Register out = locations->Out().As<Register>();
2202 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2203 break;
2204 }
2205
2206 case Primitive::kPrimShort: {
2207 Register out = locations->Out().As<Register>();
2208 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2209 break;
2210 }
2211
2212 case Primitive::kPrimChar: {
2213 Register out = locations->Out().As<Register>();
2214 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2215 break;
2216 }
2217
2218 case Primitive::kPrimInt:
2219 case Primitive::kPrimNot: {
2220 Register out = locations->Out().As<Register>();
2221 __ LoadFromOffset(kLoadWord, out, cls, offset);
2222 break;
2223 }
2224
2225 case Primitive::kPrimLong: {
2226 // TODO: support volatile.
2227 Location out = locations->Out();
2228 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2229 break;
2230 }
2231
2232 case Primitive::kPrimFloat:
2233 case Primitive::kPrimDouble:
2234 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2235 UNREACHABLE();
2236 case Primitive::kPrimVoid:
2237 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2238 UNREACHABLE();
2239 }
2240}
2241
2242void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2243 LocationSummary* locations =
2244 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2245 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2246 locations->SetInAt(0, Location::RequiresRegister());
2247 locations->SetInAt(1, Location::RequiresRegister());
2248 // Temporary registers for the write barrier.
2249 if (is_object_type) {
2250 locations->AddTemp(Location::RequiresRegister());
2251 locations->AddTemp(Location::RequiresRegister());
2252 }
2253}
2254
2255void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2256 LocationSummary* locations = instruction->GetLocations();
2257 Register cls = locations->InAt(0).As<Register>();
2258 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2259 Primitive::Type field_type = instruction->GetFieldType();
2260
2261 switch (field_type) {
2262 case Primitive::kPrimBoolean:
2263 case Primitive::kPrimByte: {
2264 Register value = locations->InAt(1).As<Register>();
2265 __ StoreToOffset(kStoreByte, value, cls, offset);
2266 break;
2267 }
2268
2269 case Primitive::kPrimShort:
2270 case Primitive::kPrimChar: {
2271 Register value = locations->InAt(1).As<Register>();
2272 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2273 break;
2274 }
2275
2276 case Primitive::kPrimInt:
2277 case Primitive::kPrimNot: {
2278 Register value = locations->InAt(1).As<Register>();
2279 __ StoreToOffset(kStoreWord, value, cls, offset);
2280 if (field_type == Primitive::kPrimNot) {
2281 Register temp = locations->GetTemp(0).As<Register>();
2282 Register card = locations->GetTemp(1).As<Register>();
2283 codegen_->MarkGCCard(temp, card, cls, value);
2284 }
2285 break;
2286 }
2287
2288 case Primitive::kPrimLong: {
2289 Location value = locations->InAt(1);
2290 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2291 break;
2292 }
2293
2294 case Primitive::kPrimFloat:
2295 case Primitive::kPrimDouble:
2296 LOG(FATAL) << "Unimplemented register type " << field_type;
2297 UNREACHABLE();
2298 case Primitive::kPrimVoid:
2299 LOG(FATAL) << "Unreachable type " << field_type;
2300 UNREACHABLE();
2301 }
2302}
2303
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002304void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2305 LocationSummary* locations =
2306 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2307 locations->SetOut(Location::RequiresRegister());
2308}
2309
2310void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2311 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2312 codegen_->AddSlowPath(slow_path);
2313
2314 Register out = load->GetLocations()->Out().As<Register>();
2315 codegen_->LoadCurrentMethod(out);
2316 __ LoadFromOffset(
2317 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2318 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2319 __ cmp(out, ShifterOperand(0));
2320 __ b(slow_path->GetEntryLabel(), EQ);
2321 __ Bind(slow_path->GetExitLabel());
2322}
2323
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002324} // namespace arm
2325} // namespace art