blob: 0cec4b404addd0f3581ad9f31a3953f1f5fe8966 [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) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700797 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000798 if (kIsDebugBuild) {
799 __ Comment("Unreachable");
800 __ bkpt(0);
801 }
802}
803
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000804void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100805 LocationSummary* locations =
806 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100807 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100808 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100809 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100810 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000811}
812
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000813void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700814 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100815 if (cond->IsIntConstant()) {
816 // Constant condition, statically compared against 1.
817 int32_t cond_value = cond->AsIntConstant()->GetValue();
818 if (cond_value == 1) {
819 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
820 if_instr->IfTrueSuccessor())) {
821 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100822 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100823 return;
824 } else {
825 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100826 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100827 } else {
828 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
829 // Condition has been materialized, compare the output to 0
830 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
831 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
832 ShifterOperand(0));
833 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
834 } else {
835 // Condition has not been materialized, use its inputs as the
836 // comparison and its condition as the branch condition.
837 LocationSummary* locations = cond->GetLocations();
838 if (locations->InAt(1).IsRegister()) {
839 __ cmp(locations->InAt(0).As<Register>(),
840 ShifterOperand(locations->InAt(1).As<Register>()));
841 } else {
842 DCHECK(locations->InAt(1).IsConstant());
843 int32_t value =
844 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
845 ShifterOperand operand;
846 if (ShifterOperand::CanHoldArm(value, &operand)) {
847 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
848 } else {
849 Register temp = IP;
850 __ LoadImmediate(temp, value);
851 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
852 }
853 }
854 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
855 ARMCondition(cond->AsCondition()->GetCondition()));
856 }
Dave Allison20dfc792014-06-16 20:44:29 -0700857 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100858 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
859 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700860 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000861 }
862}
863
Dave Allison20dfc792014-06-16 20:44:29 -0700864
865void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100866 LocationSummary* locations =
867 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100868 locations->SetInAt(0, Location::RequiresRegister());
869 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100870 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100871 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100872 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000873}
874
Dave Allison20dfc792014-06-16 20:44:29 -0700875void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100876 if (!comp->NeedsMaterialization()) return;
877
878 LocationSummary* locations = comp->GetLocations();
879 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100880 __ cmp(locations->InAt(0).As<Register>(),
881 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100882 } else {
883 DCHECK(locations->InAt(1).IsConstant());
884 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
885 ShifterOperand operand;
886 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100887 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100888 } else {
889 Register temp = IP;
890 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100891 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100892 }
Dave Allison20dfc792014-06-16 20:44:29 -0700893 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100894 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100895 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100896 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100897 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100898 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700899}
900
901void LocationsBuilderARM::VisitEqual(HEqual* comp) {
902 VisitCondition(comp);
903}
904
905void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
906 VisitCondition(comp);
907}
908
909void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
910 VisitCondition(comp);
911}
912
913void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
914 VisitCondition(comp);
915}
916
917void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
918 VisitCondition(comp);
919}
920
921void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
922 VisitCondition(comp);
923}
924
925void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
926 VisitCondition(comp);
927}
928
929void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
930 VisitCondition(comp);
931}
932
933void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
934 VisitCondition(comp);
935}
936
937void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
938 VisitCondition(comp);
939}
940
941void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
942 VisitCondition(comp);
943}
944
945void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
946 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000947}
948
949void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000950 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000951}
952
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000953void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
954 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000955}
956
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000957void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100958 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000959}
960
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000961void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100962 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700963 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000964}
965
966void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100967 LocationSummary* locations =
968 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100969 switch (store->InputAt(1)->GetType()) {
970 case Primitive::kPrimBoolean:
971 case Primitive::kPrimByte:
972 case Primitive::kPrimChar:
973 case Primitive::kPrimShort:
974 case Primitive::kPrimInt:
975 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100976 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100977 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
978 break;
979
980 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100981 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100982 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
983 break;
984
985 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100986 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100987 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000988}
989
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000990void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700991 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000992}
993
994void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100995 LocationSummary* locations =
996 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000998}
999
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001000void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001001 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001002 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001003}
1004
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001005void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001006 LocationSummary* locations =
1007 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001008 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001009}
1010
1011void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1012 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001013 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001014}
1015
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001016void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1017 LocationSummary* locations =
1018 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1019 locations->SetOut(Location::ConstantLocation(constant));
1020}
1021
1022void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1023 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001024 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001025}
1026
1027void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1028 LocationSummary* locations =
1029 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1030 locations->SetOut(Location::ConstantLocation(constant));
1031}
1032
1033void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1034 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001035 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001036}
1037
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001038void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001039 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001040}
1041
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001042void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001043 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001044 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001045}
1046
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001047void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001048 LocationSummary* locations =
1049 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001050 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001051}
1052
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001053void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001054 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001055 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001056}
1057
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001058void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001059 HandleInvoke(invoke);
1060}
1061
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001062void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001063 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001064}
1065
1066void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001067 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001068
1069 // TODO: Implement all kinds of calls:
1070 // 1) boot -> boot
1071 // 2) app -> boot
1072 // 3) app -> app
1073 //
1074 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1075
1076 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001077 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001078 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001079 __ LoadFromOffset(
1080 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001081 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001082 __ LoadFromOffset(
1083 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001084 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001085 __ LoadFromOffset(kLoadWord, LR, temp,
1086 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001087 // LR()
1088 __ blx(LR);
1089
1090 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1091 DCHECK(!codegen_->IsLeafMethod());
1092}
1093
1094void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1095 HandleInvoke(invoke);
1096}
1097
1098void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001099 LocationSummary* locations =
1100 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001101 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001102
1103 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001104 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001105 HInstruction* input = invoke->InputAt(i);
1106 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1107 }
1108
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001109 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001110}
1111
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001112
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001113void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001114 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001115 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1116 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1117 LocationSummary* locations = invoke->GetLocations();
1118 Location receiver = locations->InAt(0);
1119 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1120 // temp = object->GetClass();
1121 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001122 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1123 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001124 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001125 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001126 }
1127 // temp = temp->GetMethodAt(method_offset);
1128 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001129 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001130 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001131 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001132 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001133 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001134 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001135 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001136}
1137
Roland Levillain88cb1752014-10-20 16:36:47 +01001138void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1139 LocationSummary* locations =
1140 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1141 switch (neg->GetResultType()) {
1142 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001143 case Primitive::kPrimLong: {
1144 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001145 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001146 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001147 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001148 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001149
Roland Levillain88cb1752014-10-20 16:36:47 +01001150 case Primitive::kPrimFloat:
1151 case Primitive::kPrimDouble:
1152 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1153 break;
1154
1155 default:
1156 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1157 }
1158}
1159
1160void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1161 LocationSummary* locations = neg->GetLocations();
1162 Location out = locations->Out();
1163 Location in = locations->InAt(0);
1164 switch (neg->GetResultType()) {
1165 case Primitive::kPrimInt:
1166 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001167 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001168 break;
1169
1170 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001171 DCHECK(in.IsRegisterPair());
1172 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1173 __ rsbs(out.AsRegisterPairLow<Register>(),
1174 in.AsRegisterPairLow<Register>(),
1175 ShifterOperand(0));
1176 // We cannot emit an RSC (Reverse Subtract with Carry)
1177 // instruction here, as it does not exist in the Thumb-2
1178 // instruction set. We use the following approach
1179 // using SBC and SUB instead.
1180 //
1181 // out.hi = -C
1182 __ sbc(out.AsRegisterPairHigh<Register>(),
1183 out.AsRegisterPairHigh<Register>(),
1184 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1185 // out.hi = out.hi - in.hi
1186 __ sub(out.AsRegisterPairHigh<Register>(),
1187 out.AsRegisterPairHigh<Register>(),
1188 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1189 break;
1190
Roland Levillain88cb1752014-10-20 16:36:47 +01001191 case Primitive::kPrimFloat:
1192 case Primitive::kPrimDouble:
1193 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1194 break;
1195
1196 default:
1197 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1198 }
1199}
1200
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001201void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001202 LocationSummary* locations =
1203 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001204 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001205 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001206 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001207 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1208 locations->SetInAt(0, Location::RequiresRegister());
1209 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1210 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001211 break;
1212 }
1213
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001214 case Primitive::kPrimFloat:
1215 case Primitive::kPrimDouble: {
1216 locations->SetInAt(0, Location::RequiresFpuRegister());
1217 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001218 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001219 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001220 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001221
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001222 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001223 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001224 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001225}
1226
1227void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1228 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001229 Location out = locations->Out();
1230 Location first = locations->InAt(0);
1231 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001232 switch (add->GetResultType()) {
1233 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001234 if (second.IsRegister()) {
1235 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001236 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001237 __ AddConstant(out.As<Register>(),
1238 first.As<Register>(),
1239 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001240 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001241 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001242
1243 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001244 __ adds(out.AsRegisterPairLow<Register>(),
1245 first.AsRegisterPairLow<Register>(),
1246 ShifterOperand(second.AsRegisterPairLow<Register>()));
1247 __ adc(out.AsRegisterPairHigh<Register>(),
1248 first.AsRegisterPairHigh<Register>(),
1249 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001250 break;
1251
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001252 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001253 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001254 break;
1255
1256 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001257 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1258 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1259 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001260 break;
1261
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001262 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001263 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001264 }
1265}
1266
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001267void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001268 LocationSummary* locations =
1269 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001270 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001271 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001272 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001273 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1274 locations->SetInAt(0, Location::RequiresRegister());
1275 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1276 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001277 break;
1278 }
Calin Juravle11351682014-10-23 15:38:15 +01001279 case Primitive::kPrimFloat:
1280 case Primitive::kPrimDouble: {
1281 locations->SetInAt(0, Location::RequiresFpuRegister());
1282 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001283 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001284 break;
Calin Juravle11351682014-10-23 15:38:15 +01001285 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001286 default:
Calin Juravle11351682014-10-23 15:38:15 +01001287 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001288 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001289}
1290
1291void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1292 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001293 Location out = locations->Out();
1294 Location first = locations->InAt(0);
1295 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001296 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001297 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001298 if (second.IsRegister()) {
1299 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001300 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001301 __ AddConstant(out.As<Register>(),
1302 first.As<Register>(),
1303 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001304 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001305 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001306 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001307
Calin Juravle11351682014-10-23 15:38:15 +01001308 case Primitive::kPrimLong: {
1309 __ subs(out.AsRegisterPairLow<Register>(),
1310 first.AsRegisterPairLow<Register>(),
1311 ShifterOperand(second.AsRegisterPairLow<Register>()));
1312 __ sbc(out.AsRegisterPairHigh<Register>(),
1313 first.AsRegisterPairHigh<Register>(),
1314 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001315 break;
Calin Juravle11351682014-10-23 15:38:15 +01001316 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001317
Calin Juravle11351682014-10-23 15:38:15 +01001318 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001319 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001320 break;
Calin Juravle11351682014-10-23 15:38:15 +01001321 }
1322
1323 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001324 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1325 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1326 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001327 break;
1328 }
1329
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001330
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001331 default:
Calin Juravle11351682014-10-23 15:38:15 +01001332 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001333 }
1334}
1335
Calin Juravle34bacdf2014-10-07 20:23:36 +01001336void LocationsBuilderARM::VisitMul(HMul* mul) {
1337 LocationSummary* locations =
1338 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1339 switch (mul->GetResultType()) {
1340 case Primitive::kPrimInt:
1341 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001342 locations->SetInAt(0, Location::RequiresRegister());
1343 locations->SetInAt(1, Location::RequiresRegister());
1344 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001345 break;
1346 }
1347
Calin Juravleb5bfa962014-10-21 18:02:24 +01001348 case Primitive::kPrimFloat:
1349 case Primitive::kPrimDouble: {
1350 locations->SetInAt(0, Location::RequiresFpuRegister());
1351 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001352 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001353 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001354 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001355
1356 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001357 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001358 }
1359}
1360
1361void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1362 LocationSummary* locations = mul->GetLocations();
1363 Location out = locations->Out();
1364 Location first = locations->InAt(0);
1365 Location second = locations->InAt(1);
1366 switch (mul->GetResultType()) {
1367 case Primitive::kPrimInt: {
1368 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1369 break;
1370 }
1371 case Primitive::kPrimLong: {
1372 Register out_hi = out.AsRegisterPairHigh<Register>();
1373 Register out_lo = out.AsRegisterPairLow<Register>();
1374 Register in1_hi = first.AsRegisterPairHigh<Register>();
1375 Register in1_lo = first.AsRegisterPairLow<Register>();
1376 Register in2_hi = second.AsRegisterPairHigh<Register>();
1377 Register in2_lo = second.AsRegisterPairLow<Register>();
1378
1379 // Extra checks to protect caused by the existence of R1_R2.
1380 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1381 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1382 DCHECK_NE(out_hi, in1_lo);
1383 DCHECK_NE(out_hi, in2_lo);
1384
1385 // input: in1 - 64 bits, in2 - 64 bits
1386 // output: out
1387 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1388 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1389 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1390
1391 // IP <- in1.lo * in2.hi
1392 __ mul(IP, in1_lo, in2_hi);
1393 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1394 __ mla(out_hi, in1_hi, in2_lo, IP);
1395 // out.lo <- (in1.lo * in2.lo)[31:0];
1396 __ umull(out_lo, IP, in1_lo, in2_lo);
1397 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1398 __ add(out_hi, out_hi, ShifterOperand(IP));
1399 break;
1400 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001401
1402 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001403 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001404 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001405 }
1406
1407 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001408 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1409 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1410 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001411 break;
1412 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001413
1414 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001415 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001416 }
1417}
1418
Calin Juravle7c4954d2014-10-28 16:57:40 +00001419void LocationsBuilderARM::VisitDiv(HDiv* div) {
1420 LocationSummary* locations =
1421 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1422 switch (div->GetResultType()) {
1423 case Primitive::kPrimInt:
1424 case Primitive::kPrimLong: {
1425 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1426 break;
1427 }
1428 case Primitive::kPrimFloat:
1429 case Primitive::kPrimDouble: {
1430 locations->SetInAt(0, Location::RequiresFpuRegister());
1431 locations->SetInAt(1, Location::RequiresFpuRegister());
1432 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1433 break;
1434 }
1435
1436 default:
1437 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1438 }
1439}
1440
1441void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1442 LocationSummary* locations = div->GetLocations();
1443 Location out = locations->Out();
1444 Location first = locations->InAt(0);
1445 Location second = locations->InAt(1);
1446
1447 switch (div->GetResultType()) {
1448 case Primitive::kPrimInt:
1449 case Primitive::kPrimLong: {
1450 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1451 break;
1452 }
1453
1454 case Primitive::kPrimFloat: {
1455 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1456 break;
1457 }
1458
1459 case Primitive::kPrimDouble: {
1460 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1461 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1462 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1463 break;
1464 }
1465
1466 default:
1467 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1468 }
1469}
1470
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001471void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001472 LocationSummary* locations =
1473 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001474 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001475 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1476 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1477 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001478}
1479
1480void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1481 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001482 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001483 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001484 codegen_->InvokeRuntime(
1485 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001486}
1487
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001488void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1489 LocationSummary* locations =
1490 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1491 InvokeRuntimeCallingConvention calling_convention;
1492 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1493 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1494 locations->SetOut(Location::RegisterLocation(R0));
1495 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1496}
1497
1498void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1499 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001500 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001501 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001502 codegen_->InvokeRuntime(
1503 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001504}
1505
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001506void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001507 LocationSummary* locations =
1508 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001509 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1510 if (location.IsStackSlot()) {
1511 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1512 } else if (location.IsDoubleStackSlot()) {
1513 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001514 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001515 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001516}
1517
1518void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001519 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001520 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001521}
1522
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001523void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001524 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001525 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001526 locations->SetInAt(0, Location::RequiresRegister());
1527 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001528}
1529
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001530void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1531 LocationSummary* locations = not_->GetLocations();
1532 Location out = locations->Out();
1533 Location in = locations->InAt(0);
1534 switch (not_->InputAt(0)->GetType()) {
1535 case Primitive::kPrimBoolean:
1536 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1537 break;
1538
1539 case Primitive::kPrimInt:
1540 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1541 break;
1542
1543 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001544 __ mvn(out.AsRegisterPairLow<Register>(),
1545 ShifterOperand(in.AsRegisterPairLow<Register>()));
1546 __ mvn(out.AsRegisterPairHigh<Register>(),
1547 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001548 break;
1549
1550 default:
1551 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1552 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001553}
1554
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001555void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001556 LocationSummary* locations =
1557 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001558 locations->SetInAt(0, Location::RequiresRegister());
1559 locations->SetInAt(1, Location::RequiresRegister());
1560 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001561}
1562
1563void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1564 Label greater, done;
1565 LocationSummary* locations = compare->GetLocations();
1566 switch (compare->InputAt(0)->GetType()) {
1567 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001568 Register output = locations->Out().As<Register>();
1569 Location left = locations->InAt(0);
1570 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001571 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001572 __ cmp(left.AsRegisterPairHigh<Register>(),
1573 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001574 __ b(&less, LT);
1575 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001576 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1577 // the status flags.
1578 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001579 __ cmp(left.AsRegisterPairLow<Register>(),
1580 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001581 __ b(&done, EQ);
1582 __ b(&less, CC);
1583
1584 __ Bind(&greater);
1585 __ LoadImmediate(output, 1);
1586 __ b(&done);
1587
1588 __ Bind(&less);
1589 __ LoadImmediate(output, -1);
1590
1591 __ Bind(&done);
1592 break;
1593 }
1594 default:
1595 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1596 }
1597}
1598
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001599void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001600 LocationSummary* locations =
1601 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001602 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1603 locations->SetInAt(i, Location::Any());
1604 }
1605 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001606}
1607
1608void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001609 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001610 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001611}
1612
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001613void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001614 LocationSummary* locations =
1615 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001616 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001617 locations->SetInAt(0, Location::RequiresRegister());
1618 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001619 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001620 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001621 locations->AddTemp(Location::RequiresRegister());
1622 locations->AddTemp(Location::RequiresRegister());
1623 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001624}
1625
1626void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1627 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001628 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001629 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001630 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001631
1632 switch (field_type) {
1633 case Primitive::kPrimBoolean:
1634 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001635 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001636 __ StoreToOffset(kStoreByte, value, obj, offset);
1637 break;
1638 }
1639
1640 case Primitive::kPrimShort:
1641 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001642 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001643 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1644 break;
1645 }
1646
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001647 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001648 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001649 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001650 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001651 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001652 Register temp = locations->GetTemp(0).As<Register>();
1653 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001654 codegen_->MarkGCCard(temp, card, obj, value);
1655 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001656 break;
1657 }
1658
1659 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001660 Location value = locations->InAt(1);
1661 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001662 break;
1663 }
1664
1665 case Primitive::kPrimFloat:
1666 case Primitive::kPrimDouble:
1667 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001668 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001669 case Primitive::kPrimVoid:
1670 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001671 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001672 }
1673}
1674
1675void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001676 LocationSummary* locations =
1677 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001678 locations->SetInAt(0, Location::RequiresRegister());
1679 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001680}
1681
1682void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1683 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001684 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001685 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1686
1687 switch (instruction->GetType()) {
1688 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001689 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001690 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1691 break;
1692 }
1693
1694 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001695 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001696 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1697 break;
1698 }
1699
1700 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001701 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001702 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1703 break;
1704 }
1705
1706 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001707 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001708 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1709 break;
1710 }
1711
1712 case Primitive::kPrimInt:
1713 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001714 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001715 __ LoadFromOffset(kLoadWord, out, obj, offset);
1716 break;
1717 }
1718
1719 case Primitive::kPrimLong: {
1720 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001721 Location out = locations->Out();
1722 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001723 break;
1724 }
1725
1726 case Primitive::kPrimFloat:
1727 case Primitive::kPrimDouble:
1728 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001729 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001730 case Primitive::kPrimVoid:
1731 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001732 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001733 }
1734}
1735
1736void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001737 LocationSummary* locations =
1738 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001739 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001740 if (instruction->HasUses()) {
1741 locations->SetOut(Location::SameAsFirstInput());
1742 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001743}
1744
1745void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001746 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001747 codegen_->AddSlowPath(slow_path);
1748
1749 LocationSummary* locations = instruction->GetLocations();
1750 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001751
1752 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001753 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001754 __ b(slow_path->GetEntryLabel(), EQ);
1755 } else {
1756 DCHECK(obj.IsConstant()) << obj;
1757 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1758 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001759 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001760}
1761
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001762void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001763 LocationSummary* locations =
1764 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001765 locations->SetInAt(0, Location::RequiresRegister());
1766 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1767 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001768}
1769
1770void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1771 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001772 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001773 Location index = locations->InAt(1);
1774
1775 switch (instruction->GetType()) {
1776 case Primitive::kPrimBoolean: {
1777 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001778 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001779 if (index.IsConstant()) {
1780 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1781 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1782 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001783 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001784 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1785 }
1786 break;
1787 }
1788
1789 case Primitive::kPrimByte: {
1790 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001791 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001792 if (index.IsConstant()) {
1793 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1794 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1795 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001796 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001797 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1798 }
1799 break;
1800 }
1801
1802 case Primitive::kPrimShort: {
1803 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001804 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001805 if (index.IsConstant()) {
1806 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1807 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1808 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001809 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001810 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1811 }
1812 break;
1813 }
1814
1815 case Primitive::kPrimChar: {
1816 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001817 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001818 if (index.IsConstant()) {
1819 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1820 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1821 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001822 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001823 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1824 }
1825 break;
1826 }
1827
1828 case Primitive::kPrimInt:
1829 case Primitive::kPrimNot: {
1830 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1831 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001832 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001833 if (index.IsConstant()) {
1834 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1835 __ LoadFromOffset(kLoadWord, out, obj, offset);
1836 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001837 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001838 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1839 }
1840 break;
1841 }
1842
1843 case Primitive::kPrimLong: {
1844 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001845 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001846 if (index.IsConstant()) {
1847 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001848 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001849 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001850 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1851 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001852 }
1853 break;
1854 }
1855
1856 case Primitive::kPrimFloat:
1857 case Primitive::kPrimDouble:
1858 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001859 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001860 case Primitive::kPrimVoid:
1861 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001862 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001863 }
1864}
1865
1866void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001867 Primitive::Type value_type = instruction->GetComponentType();
1868 bool is_object = value_type == Primitive::kPrimNot;
1869 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1870 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1871 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001872 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001873 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1874 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1875 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001876 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001877 locations->SetInAt(0, Location::RequiresRegister());
1878 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1879 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001880 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001881}
1882
1883void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1884 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001885 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001886 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001887 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001888
1889 switch (value_type) {
1890 case Primitive::kPrimBoolean:
1891 case Primitive::kPrimByte: {
1892 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001893 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001894 if (index.IsConstant()) {
1895 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1896 __ StoreToOffset(kStoreByte, value, obj, offset);
1897 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001898 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001899 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1900 }
1901 break;
1902 }
1903
1904 case Primitive::kPrimShort:
1905 case Primitive::kPrimChar: {
1906 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001907 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001908 if (index.IsConstant()) {
1909 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1910 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1911 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001912 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001913 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1914 }
1915 break;
1916 }
1917
1918 case Primitive::kPrimInt: {
1919 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001920 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001921 if (index.IsConstant()) {
1922 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1923 __ StoreToOffset(kStoreWord, value, obj, offset);
1924 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001925 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001926 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1927 }
1928 break;
1929 }
1930
1931 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001932 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001933 break;
1934 }
1935
1936 case Primitive::kPrimLong: {
1937 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001938 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001939 if (index.IsConstant()) {
1940 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001941 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001942 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001943 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1944 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001945 }
1946 break;
1947 }
1948
1949 case Primitive::kPrimFloat:
1950 case Primitive::kPrimDouble:
1951 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001952 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001953 case Primitive::kPrimVoid:
1954 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001955 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001956 }
1957}
1958
1959void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001960 LocationSummary* locations =
1961 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001962 locations->SetInAt(0, Location::RequiresRegister());
1963 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001964}
1965
1966void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1967 LocationSummary* locations = instruction->GetLocations();
1968 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001969 Register obj = locations->InAt(0).As<Register>();
1970 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001971 __ LoadFromOffset(kLoadWord, out, obj, offset);
1972}
1973
1974void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001975 LocationSummary* locations =
1976 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001977 locations->SetInAt(0, Location::RequiresRegister());
1978 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001979 if (instruction->HasUses()) {
1980 locations->SetOut(Location::SameAsFirstInput());
1981 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001982}
1983
1984void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1985 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001986 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001987 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001988 codegen_->AddSlowPath(slow_path);
1989
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001990 Register index = locations->InAt(0).As<Register>();
1991 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001992
1993 __ cmp(index, ShifterOperand(length));
1994 __ b(slow_path->GetEntryLabel(), CS);
1995}
1996
1997void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1998 Label is_null;
1999 __ CompareAndBranchIfZero(value, &is_null);
2000 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2001 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2002 __ strb(card, Address(card, temp));
2003 __ Bind(&is_null);
2004}
2005
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002006void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2007 temp->SetLocations(nullptr);
2008}
2009
2010void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2011 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002012 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002013}
2014
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002015void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002016 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002017 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002018}
2019
2020void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002021 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2022}
2023
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002024void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2025 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2026}
2027
2028void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002029 HBasicBlock* block = instruction->GetBlock();
2030 if (block->GetLoopInformation() != nullptr) {
2031 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2032 // The back edge will generate the suspend check.
2033 return;
2034 }
2035 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2036 // The goto will generate the suspend check.
2037 return;
2038 }
2039 GenerateSuspendCheck(instruction, nullptr);
2040}
2041
2042void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2043 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002044 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002045 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002046 codegen_->AddSlowPath(slow_path);
2047
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002048 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002049 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002050 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002051 __ Bind(slow_path->GetReturnLabel());
2052 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002053 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002054 __ b(slow_path->GetEntryLabel());
2055 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002056}
2057
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002058ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2059 return codegen_->GetAssembler();
2060}
2061
2062void ParallelMoveResolverARM::EmitMove(size_t index) {
2063 MoveOperands* move = moves_.Get(index);
2064 Location source = move->GetSource();
2065 Location destination = move->GetDestination();
2066
2067 if (source.IsRegister()) {
2068 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002069 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002070 } else {
2071 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002072 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002073 SP, destination.GetStackIndex());
2074 }
2075 } else if (source.IsStackSlot()) {
2076 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002077 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002078 SP, source.GetStackIndex());
2079 } else {
2080 DCHECK(destination.IsStackSlot());
2081 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2082 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2083 }
2084 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002085 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002086 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002087 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2088 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002089 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002090 } else {
2091 DCHECK(destination.IsStackSlot());
2092 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002093 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002094 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002095 }
2096}
2097
2098void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2099 __ Mov(IP, reg);
2100 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2101 __ StoreToOffset(kStoreWord, IP, SP, mem);
2102}
2103
2104void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2105 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2106 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2107 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2108 SP, mem1 + stack_offset);
2109 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2110 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2111 SP, mem2 + stack_offset);
2112 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2113}
2114
2115void ParallelMoveResolverARM::EmitSwap(size_t index) {
2116 MoveOperands* move = moves_.Get(index);
2117 Location source = move->GetSource();
2118 Location destination = move->GetDestination();
2119
2120 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002121 DCHECK_NE(source.As<Register>(), IP);
2122 DCHECK_NE(destination.As<Register>(), IP);
2123 __ Mov(IP, source.As<Register>());
2124 __ Mov(source.As<Register>(), destination.As<Register>());
2125 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002126 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002127 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002128 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002129 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002130 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2131 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2132 } else {
2133 LOG(FATAL) << "Unimplemented";
2134 }
2135}
2136
2137void ParallelMoveResolverARM::SpillScratch(int reg) {
2138 __ Push(static_cast<Register>(reg));
2139}
2140
2141void ParallelMoveResolverARM::RestoreScratch(int reg) {
2142 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002143}
2144
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002145void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
2146 LocationSummary* locations =
2147 new (GetGraph()->GetArena()) LocationSummary(cls, LocationSummary::kNoCall);
2148 locations->SetOut(Location::RequiresRegister());
2149}
2150
2151void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2152 Register out = cls->GetLocations()->Out().As<Register>();
2153 if (cls->IsReferrersClass()) {
2154 codegen_->LoadCurrentMethod(out);
2155 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2156 } else {
2157 codegen_->LoadCurrentMethod(out);
2158 __ LoadFromOffset(
2159 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2160 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
2161 }
2162}
2163
2164void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2165 LocationSummary* locations =
2166 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2167 locations->SetInAt(0, Location::RequiresRegister());
2168 if (check->HasUses()) {
2169 locations->SetOut(Location::SameAsFirstInput());
2170 }
2171}
2172
2173void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
2174 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ClinitCheckSlowPathARM(check);
2175 codegen_->AddSlowPath(slow_path);
2176
2177 LocationSummary* locations = check->GetLocations();
2178 // We remove the class as a live register, we know it's null or unused in the slow path.
2179 RegisterSet* register_set = locations->GetLiveRegisters();
2180 register_set->Remove(locations->InAt(0));
2181
2182 Register class_reg = locations->InAt(0).As<Register>();
2183 __ cmp(class_reg, ShifterOperand(0));
2184 __ b(slow_path->GetEntryLabel(), EQ);
2185 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2186 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2187 __ b(slow_path->GetEntryLabel(), LT);
2188 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2189 // properly. Therefore, we do a memory fence.
2190 __ dmb(ISH);
2191 __ Bind(slow_path->GetExitLabel());
2192}
2193
2194void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2195 LocationSummary* locations =
2196 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2197 locations->SetInAt(0, Location::RequiresRegister());
2198 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2199}
2200
2201void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2202 LocationSummary* locations = instruction->GetLocations();
2203 Register cls = locations->InAt(0).As<Register>();
2204 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2205
2206 switch (instruction->GetType()) {
2207 case Primitive::kPrimBoolean: {
2208 Register out = locations->Out().As<Register>();
2209 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2210 break;
2211 }
2212
2213 case Primitive::kPrimByte: {
2214 Register out = locations->Out().As<Register>();
2215 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2216 break;
2217 }
2218
2219 case Primitive::kPrimShort: {
2220 Register out = locations->Out().As<Register>();
2221 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2222 break;
2223 }
2224
2225 case Primitive::kPrimChar: {
2226 Register out = locations->Out().As<Register>();
2227 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2228 break;
2229 }
2230
2231 case Primitive::kPrimInt:
2232 case Primitive::kPrimNot: {
2233 Register out = locations->Out().As<Register>();
2234 __ LoadFromOffset(kLoadWord, out, cls, offset);
2235 break;
2236 }
2237
2238 case Primitive::kPrimLong: {
2239 // TODO: support volatile.
2240 Location out = locations->Out();
2241 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2242 break;
2243 }
2244
2245 case Primitive::kPrimFloat:
2246 case Primitive::kPrimDouble:
2247 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2248 UNREACHABLE();
2249 case Primitive::kPrimVoid:
2250 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2251 UNREACHABLE();
2252 }
2253}
2254
2255void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2256 LocationSummary* locations =
2257 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2258 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2259 locations->SetInAt(0, Location::RequiresRegister());
2260 locations->SetInAt(1, Location::RequiresRegister());
2261 // Temporary registers for the write barrier.
2262 if (is_object_type) {
2263 locations->AddTemp(Location::RequiresRegister());
2264 locations->AddTemp(Location::RequiresRegister());
2265 }
2266}
2267
2268void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2269 LocationSummary* locations = instruction->GetLocations();
2270 Register cls = locations->InAt(0).As<Register>();
2271 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2272 Primitive::Type field_type = instruction->GetFieldType();
2273
2274 switch (field_type) {
2275 case Primitive::kPrimBoolean:
2276 case Primitive::kPrimByte: {
2277 Register value = locations->InAt(1).As<Register>();
2278 __ StoreToOffset(kStoreByte, value, cls, offset);
2279 break;
2280 }
2281
2282 case Primitive::kPrimShort:
2283 case Primitive::kPrimChar: {
2284 Register value = locations->InAt(1).As<Register>();
2285 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2286 break;
2287 }
2288
2289 case Primitive::kPrimInt:
2290 case Primitive::kPrimNot: {
2291 Register value = locations->InAt(1).As<Register>();
2292 __ StoreToOffset(kStoreWord, value, cls, offset);
2293 if (field_type == Primitive::kPrimNot) {
2294 Register temp = locations->GetTemp(0).As<Register>();
2295 Register card = locations->GetTemp(1).As<Register>();
2296 codegen_->MarkGCCard(temp, card, cls, value);
2297 }
2298 break;
2299 }
2300
2301 case Primitive::kPrimLong: {
2302 Location value = locations->InAt(1);
2303 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2304 break;
2305 }
2306
2307 case Primitive::kPrimFloat:
2308 case Primitive::kPrimDouble:
2309 LOG(FATAL) << "Unimplemented register type " << field_type;
2310 UNREACHABLE();
2311 case Primitive::kPrimVoid:
2312 LOG(FATAL) << "Unreachable type " << field_type;
2313 UNREACHABLE();
2314 }
2315}
2316
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002317void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2318 LocationSummary* locations =
2319 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2320 locations->SetOut(Location::RequiresRegister());
2321}
2322
2323void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2324 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2325 codegen_->AddSlowPath(slow_path);
2326
2327 Register out = load->GetLocations()->Out().As<Register>();
2328 codegen_->LoadCurrentMethod(out);
2329 __ LoadFromOffset(
2330 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2331 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2332 __ cmp(out, ShifterOperand(0));
2333 __ b(slow_path->GetEntryLabel(), EQ);
2334 __ Bind(slow_path->GetExitLabel());
2335}
2336
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002337} // namespace arm
2338} // namespace art