blob: 92974752876298e05acab3cf9795020cab37a371 [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: {
330 int reg = FindTwoFreeConsecutiveEntries(blocked_fpu_registers_, kNumberOfSRegisters);
331 return Location::FpuRegisterPairLocation(reg, reg + 1);
332 }
333
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100334 case Primitive::kPrimVoid:
335 LOG(FATAL) << "Unreachable type " << type;
336 }
337
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100338 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100339}
340
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100341void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100342 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100343 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100344
345 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100346 blocked_core_registers_[SP] = true;
347 blocked_core_registers_[LR] = true;
348 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100349
350 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100351 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100352
353 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100354 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100355
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100356 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100357 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100358
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100359 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100360 // We always save and restore R6 and R7 to make sure we can use three
361 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100362 blocked_core_registers_[R5] = true;
363 blocked_core_registers_[R8] = true;
364 blocked_core_registers_[R10] = true;
365 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100366
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000367 blocked_fpu_registers_[S16] = true;
368 blocked_fpu_registers_[S17] = true;
369 blocked_fpu_registers_[S18] = true;
370 blocked_fpu_registers_[S19] = true;
371 blocked_fpu_registers_[S20] = true;
372 blocked_fpu_registers_[S21] = true;
373 blocked_fpu_registers_[S22] = true;
374 blocked_fpu_registers_[S23] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100375
376 UpdateBlockedPairRegisters();
377}
378
379void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
380 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
381 ArmManagedRegister current =
382 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
383 if (blocked_core_registers_[current.AsRegisterPairLow()]
384 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
385 blocked_register_pairs_[i] = true;
386 }
387 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100388}
389
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100390InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
391 : HGraphVisitor(graph),
392 assembler_(codegen->GetAssembler()),
393 codegen_(codegen) {}
394
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000395void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700396 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100397 if (!skip_overflow_check) {
398 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100399 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100400 AddSlowPath(slow_path);
401
402 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
403 __ cmp(SP, ShifterOperand(IP));
404 __ b(slow_path->GetEntryLabel(), CC);
405 } else {
406 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100407 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100408 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100409 }
410 }
411
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100412 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
413 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000414
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100415 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100416 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100417 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000418}
419
420void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100421 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100422 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000423}
424
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100425void CodeGeneratorARM::Bind(HBasicBlock* block) {
426 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000427}
428
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100429Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
430 switch (load->GetType()) {
431 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100432 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100433 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
434 break;
435
436 case Primitive::kPrimInt:
437 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100439 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440
441 case Primitive::kPrimBoolean:
442 case Primitive::kPrimByte:
443 case Primitive::kPrimChar:
444 case Primitive::kPrimShort:
445 case Primitive::kPrimVoid:
446 LOG(FATAL) << "Unexpected type " << load->GetType();
447 }
448
449 LOG(FATAL) << "Unreachable";
450 return Location();
451}
452
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100453Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
454 switch (type) {
455 case Primitive::kPrimBoolean:
456 case Primitive::kPrimByte:
457 case Primitive::kPrimChar:
458 case Primitive::kPrimShort:
459 case Primitive::kPrimInt:
460 case Primitive::kPrimNot: {
461 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000462 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100463 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100464 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100465 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000466 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100467 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100468 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100469
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000470 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100471 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000472 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100473 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000474 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100475 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100476 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
477 calling_convention.GetRegisterPairAt(index));
478 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100479 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000480 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100481 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000482 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
483 }
484 }
485
486 case Primitive::kPrimFloat: {
487 uint32_t stack_index = stack_index_++;
488 if (float_index_ % 2 == 0) {
489 float_index_ = std::max(double_index_, float_index_);
490 }
491 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
492 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
493 } else {
494 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
495 }
496 }
497
498 case Primitive::kPrimDouble: {
499 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
500 uint32_t stack_index = stack_index_;
501 stack_index_ += 2;
502 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
503 uint32_t index = double_index_;
504 double_index_ += 2;
505 return Location::FpuRegisterPairLocation(
506 calling_convention.GetFpuRegisterAt(index),
507 calling_convention.GetFpuRegisterAt(index + 1));
508 } else {
509 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100510 }
511 }
512
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100513 case Primitive::kPrimVoid:
514 LOG(FATAL) << "Unexpected parameter type " << type;
515 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100516 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100517 return Location();
518}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100519
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000520Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
521 switch (type) {
522 case Primitive::kPrimBoolean:
523 case Primitive::kPrimByte:
524 case Primitive::kPrimChar:
525 case Primitive::kPrimShort:
526 case Primitive::kPrimInt:
527 case Primitive::kPrimNot: {
528 return Location::RegisterLocation(R0);
529 }
530
531 case Primitive::kPrimFloat: {
532 return Location::FpuRegisterLocation(S0);
533 }
534
535 case Primitive::kPrimLong: {
536 return Location::RegisterPairLocation(R0, R1);
537 }
538
539 case Primitive::kPrimDouble: {
540 return Location::FpuRegisterPairLocation(S0, S1);
541 }
542
543 case Primitive::kPrimVoid:
544 return Location();
545 }
546 UNREACHABLE();
547 return Location();
548}
549
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100550void CodeGeneratorARM::Move32(Location destination, Location source) {
551 if (source.Equals(destination)) {
552 return;
553 }
554 if (destination.IsRegister()) {
555 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100556 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100557 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000558 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100559 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100560 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100561 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100562 } else if (destination.IsFpuRegister()) {
563 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000564 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100565 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000566 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100567 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000568 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100569 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100570 } else {
571 DCHECK(destination.IsStackSlot());
572 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100573 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100574 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000575 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100576 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100577 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100578 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
579 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100580 }
581 }
582}
583
584void CodeGeneratorARM::Move64(Location destination, Location source) {
585 if (source.Equals(destination)) {
586 return;
587 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100588 if (destination.IsRegisterPair()) {
589 if (source.IsRegisterPair()) {
590 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
591 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100592 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000593 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100594 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000595 uint16_t register_index = source.GetQuickParameterRegisterIndex();
596 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100597 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100598 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000599 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100600 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000601 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100602 } else {
603 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100604 if (destination.AsRegisterPairLow<Register>() == R1) {
605 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100606 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
607 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100608 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100609 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100610 SP, source.GetStackIndex());
611 }
612 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000613 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100614 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000615 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
616 SP,
617 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100618 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000619 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100620 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100621 } else if (destination.IsQuickParameter()) {
622 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000623 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
624 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100625 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000626 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100627 source.AsRegisterPairLow<Register>());
628 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000629 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100630 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000631 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100632 } else {
633 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000634 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000635 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100636 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000637 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100638 }
639 } else {
640 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100641 if (source.IsRegisterPair()) {
642 if (source.AsRegisterPairLow<Register>() == R1) {
643 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100644 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
645 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100646 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100647 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100648 SP, destination.GetStackIndex());
649 }
650 } else if (source.IsQuickParameter()) {
651 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000652 uint16_t register_index = source.GetQuickParameterRegisterIndex();
653 uint16_t stack_index = source.GetQuickParameterStackIndex();
654 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100655 SP, destination.GetStackIndex());
656 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000657 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100658 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000659 } else if (source.IsFpuRegisterPair()) {
660 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
661 SP,
662 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100663 } else {
664 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100665 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
666 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
667 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
668 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100669 }
670 }
671}
672
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100673void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100674 LocationSummary* locations = instruction->GetLocations();
675 if (locations != nullptr && locations->Out().Equals(location)) {
676 return;
677 }
678
Roland Levillain476df552014-10-09 17:51:36 +0100679 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680 int32_t value = instruction->AsIntConstant()->GetValue();
681 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100682 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100683 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100684 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100685 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100686 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100687 }
Roland Levillain476df552014-10-09 17:51:36 +0100688 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100690 if (location.IsRegisterPair()) {
691 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
692 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100693 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100694 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100695 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100696 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100697 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100698 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100699 }
Roland Levillain476df552014-10-09 17:51:36 +0100700 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100701 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
702 switch (instruction->GetType()) {
703 case Primitive::kPrimBoolean:
704 case Primitive::kPrimByte:
705 case Primitive::kPrimChar:
706 case Primitive::kPrimShort:
707 case Primitive::kPrimInt:
708 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100709 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710 Move32(location, Location::StackSlot(stack_slot));
711 break;
712
713 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100714 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100715 Move64(location, Location::DoubleStackSlot(stack_slot));
716 break;
717
718 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100719 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100720 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000721 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100722 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100723 switch (instruction->GetType()) {
724 case Primitive::kPrimBoolean:
725 case Primitive::kPrimByte:
726 case Primitive::kPrimChar:
727 case Primitive::kPrimShort:
728 case Primitive::kPrimNot:
729 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100730 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100731 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100732 break;
733
734 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100735 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100736 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100737 break;
738
739 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100740 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100741 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000742 }
743}
744
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100745void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
746 HInstruction* instruction,
747 uint32_t dex_pc) {
748 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
749 __ blx(LR);
750 RecordPcInfo(instruction, dex_pc);
751 DCHECK(instruction->IsSuspendCheck()
752 || instruction->IsBoundsCheck()
753 || instruction->IsNullCheck()
754 || !IsLeafMethod());
755}
756
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000757void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000758 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000759}
760
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000761void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000762 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100763 DCHECK(!successor->IsExitBlock());
764
765 HBasicBlock* block = got->GetBlock();
766 HInstruction* previous = got->GetPrevious();
767
768 HLoopInformation* info = block->GetLoopInformation();
769 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
770 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
771 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
772 return;
773 }
774
775 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
776 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
777 }
778 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000779 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000780 }
781}
782
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000783void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000784 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000785}
786
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000787void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000788 if (kIsDebugBuild) {
789 __ Comment("Unreachable");
790 __ bkpt(0);
791 }
792}
793
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000794void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100795 LocationSummary* locations =
796 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100797 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100798 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100799 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100800 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000801}
802
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000803void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700804 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100805 if (cond->IsIntConstant()) {
806 // Constant condition, statically compared against 1.
807 int32_t cond_value = cond->AsIntConstant()->GetValue();
808 if (cond_value == 1) {
809 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
810 if_instr->IfTrueSuccessor())) {
811 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100812 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100813 return;
814 } else {
815 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100816 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100817 } else {
818 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
819 // Condition has been materialized, compare the output to 0
820 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
821 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
822 ShifterOperand(0));
823 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
824 } else {
825 // Condition has not been materialized, use its inputs as the
826 // comparison and its condition as the branch condition.
827 LocationSummary* locations = cond->GetLocations();
828 if (locations->InAt(1).IsRegister()) {
829 __ cmp(locations->InAt(0).As<Register>(),
830 ShifterOperand(locations->InAt(1).As<Register>()));
831 } else {
832 DCHECK(locations->InAt(1).IsConstant());
833 int32_t value =
834 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
835 ShifterOperand operand;
836 if (ShifterOperand::CanHoldArm(value, &operand)) {
837 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
838 } else {
839 Register temp = IP;
840 __ LoadImmediate(temp, value);
841 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
842 }
843 }
844 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
845 ARMCondition(cond->AsCondition()->GetCondition()));
846 }
Dave Allison20dfc792014-06-16 20:44:29 -0700847 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100848 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
849 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700850 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000851 }
852}
853
Dave Allison20dfc792014-06-16 20:44:29 -0700854
855void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100856 LocationSummary* locations =
857 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100858 locations->SetInAt(0, Location::RequiresRegister());
859 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100860 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100861 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100862 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000863}
864
Dave Allison20dfc792014-06-16 20:44:29 -0700865void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100866 if (!comp->NeedsMaterialization()) return;
867
868 LocationSummary* locations = comp->GetLocations();
869 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100870 __ cmp(locations->InAt(0).As<Register>(),
871 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100872 } else {
873 DCHECK(locations->InAt(1).IsConstant());
874 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
875 ShifterOperand operand;
876 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100877 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100878 } else {
879 Register temp = IP;
880 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100881 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100882 }
Dave Allison20dfc792014-06-16 20:44:29 -0700883 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100884 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100885 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100886 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100887 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100888 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700889}
890
891void LocationsBuilderARM::VisitEqual(HEqual* comp) {
892 VisitCondition(comp);
893}
894
895void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
896 VisitCondition(comp);
897}
898
899void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
900 VisitCondition(comp);
901}
902
903void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
904 VisitCondition(comp);
905}
906
907void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
908 VisitCondition(comp);
909}
910
911void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
912 VisitCondition(comp);
913}
914
915void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
916 VisitCondition(comp);
917}
918
919void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
920 VisitCondition(comp);
921}
922
923void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
924 VisitCondition(comp);
925}
926
927void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
928 VisitCondition(comp);
929}
930
931void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
932 VisitCondition(comp);
933}
934
935void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
936 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000937}
938
939void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000940 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000941}
942
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000943void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
944 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000945}
946
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000947void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100948 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000949}
950
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000951void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100952 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000953}
954
955void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100956 LocationSummary* locations =
957 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100958 switch (store->InputAt(1)->GetType()) {
959 case Primitive::kPrimBoolean:
960 case Primitive::kPrimByte:
961 case Primitive::kPrimChar:
962 case Primitive::kPrimShort:
963 case Primitive::kPrimInt:
964 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100965 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100966 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
967 break;
968
969 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100970 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100971 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
972 break;
973
974 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100975 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100976 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000977}
978
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000979void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000980}
981
982void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100983 LocationSummary* locations =
984 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100985 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000986}
987
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000988void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100989 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000990}
991
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100992void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100993 LocationSummary* locations =
994 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100995 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100996}
997
998void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
999 // Will be generated at use site.
1000}
1001
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001002void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1003 LocationSummary* locations =
1004 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1005 locations->SetOut(Location::ConstantLocation(constant));
1006}
1007
1008void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1009 // Will be generated at use site.
1010}
1011
1012void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1013 LocationSummary* locations =
1014 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1015 locations->SetOut(Location::ConstantLocation(constant));
1016}
1017
1018void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1019 // Will be generated at use site.
1020}
1021
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001022void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001023 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001024}
1025
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001026void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
1027 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001028}
1029
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001030void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001031 LocationSummary* locations =
1032 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001033 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001034}
1035
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001036void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001037 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001038}
1039
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001040void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001041 HandleInvoke(invoke);
1042}
1043
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001044void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001045 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001046}
1047
1048void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001049 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001050
1051 // TODO: Implement all kinds of calls:
1052 // 1) boot -> boot
1053 // 2) app -> boot
1054 // 3) app -> app
1055 //
1056 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1057
1058 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001059 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001060 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001061 __ LoadFromOffset(
1062 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001063 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001064 __ LoadFromOffset(
1065 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001066 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001067 __ LoadFromOffset(kLoadWord, LR, temp,
1068 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001069 // LR()
1070 __ blx(LR);
1071
1072 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1073 DCHECK(!codegen_->IsLeafMethod());
1074}
1075
1076void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1077 HandleInvoke(invoke);
1078}
1079
1080void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001081 LocationSummary* locations =
1082 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001083 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001084
1085 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001086 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001087 HInstruction* input = invoke->InputAt(i);
1088 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1089 }
1090
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001091 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001092}
1093
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001094
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001095void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001096 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001097 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1098 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1099 LocationSummary* locations = invoke->GetLocations();
1100 Location receiver = locations->InAt(0);
1101 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1102 // temp = object->GetClass();
1103 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001104 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1105 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001106 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001107 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001108 }
1109 // temp = temp->GetMethodAt(method_offset);
1110 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001111 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001112 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001113 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001114 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001115 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001116 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001117 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001118}
1119
Roland Levillain88cb1752014-10-20 16:36:47 +01001120void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1121 LocationSummary* locations =
1122 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1123 switch (neg->GetResultType()) {
1124 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001125 case Primitive::kPrimLong: {
1126 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001127 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001128 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001129 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001130 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001131
Roland Levillain88cb1752014-10-20 16:36:47 +01001132 case Primitive::kPrimFloat:
1133 case Primitive::kPrimDouble:
1134 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1135 break;
1136
1137 default:
1138 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1139 }
1140}
1141
1142void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1143 LocationSummary* locations = neg->GetLocations();
1144 Location out = locations->Out();
1145 Location in = locations->InAt(0);
1146 switch (neg->GetResultType()) {
1147 case Primitive::kPrimInt:
1148 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001149 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001150 break;
1151
1152 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001153 DCHECK(in.IsRegisterPair());
1154 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1155 __ rsbs(out.AsRegisterPairLow<Register>(),
1156 in.AsRegisterPairLow<Register>(),
1157 ShifterOperand(0));
1158 // We cannot emit an RSC (Reverse Subtract with Carry)
1159 // instruction here, as it does not exist in the Thumb-2
1160 // instruction set. We use the following approach
1161 // using SBC and SUB instead.
1162 //
1163 // out.hi = -C
1164 __ sbc(out.AsRegisterPairHigh<Register>(),
1165 out.AsRegisterPairHigh<Register>(),
1166 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1167 // out.hi = out.hi - in.hi
1168 __ sub(out.AsRegisterPairHigh<Register>(),
1169 out.AsRegisterPairHigh<Register>(),
1170 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1171 break;
1172
Roland Levillain88cb1752014-10-20 16:36:47 +01001173 case Primitive::kPrimFloat:
1174 case Primitive::kPrimDouble:
1175 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1176 break;
1177
1178 default:
1179 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1180 }
1181}
1182
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001183void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001184 LocationSummary* locations =
1185 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001186 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001187 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001188 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001189 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1190 locations->SetInAt(0, Location::RequiresRegister());
1191 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1192 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001193 break;
1194 }
1195
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001196 case Primitive::kPrimFloat:
1197 case Primitive::kPrimDouble: {
1198 locations->SetInAt(0, Location::RequiresFpuRegister());
1199 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001200 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001201 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001202 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001203
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001204 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001205 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001206 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001207}
1208
1209void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1210 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001211 Location out = locations->Out();
1212 Location first = locations->InAt(0);
1213 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001214 switch (add->GetResultType()) {
1215 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001216 if (second.IsRegister()) {
1217 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001218 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001219 __ AddConstant(out.As<Register>(),
1220 first.As<Register>(),
1221 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001222 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001223 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001224
1225 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001226 __ adds(out.AsRegisterPairLow<Register>(),
1227 first.AsRegisterPairLow<Register>(),
1228 ShifterOperand(second.AsRegisterPairLow<Register>()));
1229 __ adc(out.AsRegisterPairHigh<Register>(),
1230 first.AsRegisterPairHigh<Register>(),
1231 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001232 break;
1233
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001234 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001235 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001236 break;
1237
1238 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001239 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1240 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1241 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001242 break;
1243
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001244 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001245 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001246 }
1247}
1248
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001249void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001250 LocationSummary* locations =
1251 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001252 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001253 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001254 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001255 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1256 locations->SetInAt(0, Location::RequiresRegister());
1257 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1258 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001259 break;
1260 }
Calin Juravle11351682014-10-23 15:38:15 +01001261 case Primitive::kPrimFloat:
1262 case Primitive::kPrimDouble: {
1263 locations->SetInAt(0, Location::RequiresFpuRegister());
1264 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001265 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001266 break;
Calin Juravle11351682014-10-23 15:38:15 +01001267 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001268 default:
Calin Juravle11351682014-10-23 15:38:15 +01001269 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001270 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001271}
1272
1273void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1274 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001275 Location out = locations->Out();
1276 Location first = locations->InAt(0);
1277 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001278 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001279 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001280 if (second.IsRegister()) {
1281 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001282 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001283 __ AddConstant(out.As<Register>(),
1284 first.As<Register>(),
1285 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001286 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001287 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001288 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001289
Calin Juravle11351682014-10-23 15:38:15 +01001290 case Primitive::kPrimLong: {
1291 __ subs(out.AsRegisterPairLow<Register>(),
1292 first.AsRegisterPairLow<Register>(),
1293 ShifterOperand(second.AsRegisterPairLow<Register>()));
1294 __ sbc(out.AsRegisterPairHigh<Register>(),
1295 first.AsRegisterPairHigh<Register>(),
1296 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001297 break;
Calin Juravle11351682014-10-23 15:38:15 +01001298 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001299
Calin Juravle11351682014-10-23 15:38:15 +01001300 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001301 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001302 break;
Calin Juravle11351682014-10-23 15:38:15 +01001303 }
1304
1305 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001306 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1307 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1308 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001309 break;
1310 }
1311
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001312
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001313 default:
Calin Juravle11351682014-10-23 15:38:15 +01001314 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001315 }
1316}
1317
Calin Juravle34bacdf2014-10-07 20:23:36 +01001318void LocationsBuilderARM::VisitMul(HMul* mul) {
1319 LocationSummary* locations =
1320 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1321 switch (mul->GetResultType()) {
1322 case Primitive::kPrimInt:
1323 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001324 locations->SetInAt(0, Location::RequiresRegister());
1325 locations->SetInAt(1, Location::RequiresRegister());
1326 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001327 break;
1328 }
1329
Calin Juravleb5bfa962014-10-21 18:02:24 +01001330 case Primitive::kPrimFloat:
1331 case Primitive::kPrimDouble: {
1332 locations->SetInAt(0, Location::RequiresFpuRegister());
1333 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001334 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001335 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001336 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001337
1338 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001339 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001340 }
1341}
1342
1343void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1344 LocationSummary* locations = mul->GetLocations();
1345 Location out = locations->Out();
1346 Location first = locations->InAt(0);
1347 Location second = locations->InAt(1);
1348 switch (mul->GetResultType()) {
1349 case Primitive::kPrimInt: {
1350 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1351 break;
1352 }
1353 case Primitive::kPrimLong: {
1354 Register out_hi = out.AsRegisterPairHigh<Register>();
1355 Register out_lo = out.AsRegisterPairLow<Register>();
1356 Register in1_hi = first.AsRegisterPairHigh<Register>();
1357 Register in1_lo = first.AsRegisterPairLow<Register>();
1358 Register in2_hi = second.AsRegisterPairHigh<Register>();
1359 Register in2_lo = second.AsRegisterPairLow<Register>();
1360
1361 // Extra checks to protect caused by the existence of R1_R2.
1362 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1363 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1364 DCHECK_NE(out_hi, in1_lo);
1365 DCHECK_NE(out_hi, in2_lo);
1366
1367 // input: in1 - 64 bits, in2 - 64 bits
1368 // output: out
1369 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1370 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1371 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1372
1373 // IP <- in1.lo * in2.hi
1374 __ mul(IP, in1_lo, in2_hi);
1375 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1376 __ mla(out_hi, in1_hi, in2_lo, IP);
1377 // out.lo <- (in1.lo * in2.lo)[31:0];
1378 __ umull(out_lo, IP, in1_lo, in2_lo);
1379 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1380 __ add(out_hi, out_hi, ShifterOperand(IP));
1381 break;
1382 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001383
1384 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001385 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001386 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001387 }
1388
1389 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001390 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1391 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1392 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001393 break;
1394 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001395
1396 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001397 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001398 }
1399}
1400
Calin Juravle7c4954d2014-10-28 16:57:40 +00001401void LocationsBuilderARM::VisitDiv(HDiv* div) {
1402 LocationSummary* locations =
1403 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1404 switch (div->GetResultType()) {
1405 case Primitive::kPrimInt:
1406 case Primitive::kPrimLong: {
1407 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1408 break;
1409 }
1410 case Primitive::kPrimFloat:
1411 case Primitive::kPrimDouble: {
1412 locations->SetInAt(0, Location::RequiresFpuRegister());
1413 locations->SetInAt(1, Location::RequiresFpuRegister());
1414 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1415 break;
1416 }
1417
1418 default:
1419 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1420 }
1421}
1422
1423void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1424 LocationSummary* locations = div->GetLocations();
1425 Location out = locations->Out();
1426 Location first = locations->InAt(0);
1427 Location second = locations->InAt(1);
1428
1429 switch (div->GetResultType()) {
1430 case Primitive::kPrimInt:
1431 case Primitive::kPrimLong: {
1432 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1433 break;
1434 }
1435
1436 case Primitive::kPrimFloat: {
1437 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1438 break;
1439 }
1440
1441 case Primitive::kPrimDouble: {
1442 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1443 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1444 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1445 break;
1446 }
1447
1448 default:
1449 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1450 }
1451}
1452
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001453void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001454 LocationSummary* locations =
1455 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001456 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001457 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1458 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1459 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001460}
1461
1462void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1463 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001464 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001465 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001466 codegen_->InvokeRuntime(
1467 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001468}
1469
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001470void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1471 LocationSummary* locations =
1472 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1473 InvokeRuntimeCallingConvention calling_convention;
1474 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1475 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1476 locations->SetOut(Location::RegisterLocation(R0));
1477 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1478}
1479
1480void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1481 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001482 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001483 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001484 codegen_->InvokeRuntime(
1485 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001486}
1487
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001488void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001489 LocationSummary* locations =
1490 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001491 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1492 if (location.IsStackSlot()) {
1493 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1494 } else if (location.IsDoubleStackSlot()) {
1495 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001496 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001497 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001498}
1499
1500void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001501 // Nothing to do, the parameter is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001502}
1503
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001504void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001505 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001506 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001507 locations->SetInAt(0, Location::RequiresRegister());
1508 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001509}
1510
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001511void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1512 LocationSummary* locations = not_->GetLocations();
1513 Location out = locations->Out();
1514 Location in = locations->InAt(0);
1515 switch (not_->InputAt(0)->GetType()) {
1516 case Primitive::kPrimBoolean:
1517 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1518 break;
1519
1520 case Primitive::kPrimInt:
1521 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1522 break;
1523
1524 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001525 __ mvn(out.AsRegisterPairLow<Register>(),
1526 ShifterOperand(in.AsRegisterPairLow<Register>()));
1527 __ mvn(out.AsRegisterPairHigh<Register>(),
1528 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001529 break;
1530
1531 default:
1532 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1533 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001534}
1535
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001536void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001537 LocationSummary* locations =
1538 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001539 locations->SetInAt(0, Location::RequiresRegister());
1540 locations->SetInAt(1, Location::RequiresRegister());
1541 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001542}
1543
1544void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1545 Label greater, done;
1546 LocationSummary* locations = compare->GetLocations();
1547 switch (compare->InputAt(0)->GetType()) {
1548 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001549 Register output = locations->Out().As<Register>();
1550 Location left = locations->InAt(0);
1551 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001552 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001553 __ cmp(left.AsRegisterPairHigh<Register>(),
1554 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001555 __ b(&less, LT);
1556 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001557 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1558 // the status flags.
1559 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001560 __ cmp(left.AsRegisterPairLow<Register>(),
1561 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001562 __ b(&done, EQ);
1563 __ b(&less, CC);
1564
1565 __ Bind(&greater);
1566 __ LoadImmediate(output, 1);
1567 __ b(&done);
1568
1569 __ Bind(&less);
1570 __ LoadImmediate(output, -1);
1571
1572 __ Bind(&done);
1573 break;
1574 }
1575 default:
1576 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1577 }
1578}
1579
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001580void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001581 LocationSummary* locations =
1582 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001583 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1584 locations->SetInAt(i, Location::Any());
1585 }
1586 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001587}
1588
1589void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001590 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001591}
1592
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001593void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001594 LocationSummary* locations =
1595 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001596 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001597 locations->SetInAt(0, Location::RequiresRegister());
1598 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001599 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001600 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001601 locations->AddTemp(Location::RequiresRegister());
1602 locations->AddTemp(Location::RequiresRegister());
1603 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001604}
1605
1606void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1607 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001608 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001609 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001610 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001611
1612 switch (field_type) {
1613 case Primitive::kPrimBoolean:
1614 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001615 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001616 __ StoreToOffset(kStoreByte, value, obj, offset);
1617 break;
1618 }
1619
1620 case Primitive::kPrimShort:
1621 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001622 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001623 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1624 break;
1625 }
1626
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001627 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001628 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001629 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001630 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001631 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001632 Register temp = locations->GetTemp(0).As<Register>();
1633 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001634 codegen_->MarkGCCard(temp, card, obj, value);
1635 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001636 break;
1637 }
1638
1639 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001640 Location value = locations->InAt(1);
1641 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001642 break;
1643 }
1644
1645 case Primitive::kPrimFloat:
1646 case Primitive::kPrimDouble:
1647 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001648 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001649 case Primitive::kPrimVoid:
1650 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001651 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001652 }
1653}
1654
1655void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001656 LocationSummary* locations =
1657 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001658 locations->SetInAt(0, Location::RequiresRegister());
1659 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001660}
1661
1662void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1663 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001664 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001665 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1666
1667 switch (instruction->GetType()) {
1668 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001669 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001670 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1671 break;
1672 }
1673
1674 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001675 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001676 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1677 break;
1678 }
1679
1680 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001681 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001682 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1683 break;
1684 }
1685
1686 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001687 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001688 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1689 break;
1690 }
1691
1692 case Primitive::kPrimInt:
1693 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001694 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001695 __ LoadFromOffset(kLoadWord, out, obj, offset);
1696 break;
1697 }
1698
1699 case Primitive::kPrimLong: {
1700 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001701 Location out = locations->Out();
1702 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001703 break;
1704 }
1705
1706 case Primitive::kPrimFloat:
1707 case Primitive::kPrimDouble:
1708 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001709 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001710 case Primitive::kPrimVoid:
1711 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001712 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001713 }
1714}
1715
1716void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001717 LocationSummary* locations =
1718 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001719 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001720 if (instruction->HasUses()) {
1721 locations->SetOut(Location::SameAsFirstInput());
1722 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001723}
1724
1725void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001726 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001727 codegen_->AddSlowPath(slow_path);
1728
1729 LocationSummary* locations = instruction->GetLocations();
1730 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001731
1732 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001733 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001734 __ b(slow_path->GetEntryLabel(), EQ);
1735 } else {
1736 DCHECK(obj.IsConstant()) << obj;
1737 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1738 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001739 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001740}
1741
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001742void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001743 LocationSummary* locations =
1744 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001745 locations->SetInAt(0, Location::RequiresRegister());
1746 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1747 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001748}
1749
1750void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1751 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001752 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001753 Location index = locations->InAt(1);
1754
1755 switch (instruction->GetType()) {
1756 case Primitive::kPrimBoolean: {
1757 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001758 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001759 if (index.IsConstant()) {
1760 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1761 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1762 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001763 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001764 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1765 }
1766 break;
1767 }
1768
1769 case Primitive::kPrimByte: {
1770 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001771 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001772 if (index.IsConstant()) {
1773 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1774 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1775 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001776 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001777 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1778 }
1779 break;
1780 }
1781
1782 case Primitive::kPrimShort: {
1783 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001784 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001785 if (index.IsConstant()) {
1786 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1787 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1788 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001789 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001790 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1791 }
1792 break;
1793 }
1794
1795 case Primitive::kPrimChar: {
1796 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001797 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001798 if (index.IsConstant()) {
1799 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1800 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1801 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001802 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001803 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1804 }
1805 break;
1806 }
1807
1808 case Primitive::kPrimInt:
1809 case Primitive::kPrimNot: {
1810 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1811 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001812 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001813 if (index.IsConstant()) {
1814 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1815 __ LoadFromOffset(kLoadWord, out, obj, offset);
1816 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001817 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001818 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1819 }
1820 break;
1821 }
1822
1823 case Primitive::kPrimLong: {
1824 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001825 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001826 if (index.IsConstant()) {
1827 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001828 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001829 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001830 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1831 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001832 }
1833 break;
1834 }
1835
1836 case Primitive::kPrimFloat:
1837 case Primitive::kPrimDouble:
1838 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001839 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001840 case Primitive::kPrimVoid:
1841 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001842 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001843 }
1844}
1845
1846void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001847 Primitive::Type value_type = instruction->GetComponentType();
1848 bool is_object = value_type == Primitive::kPrimNot;
1849 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1850 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1851 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001852 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001853 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1854 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1855 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001856 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001857 locations->SetInAt(0, Location::RequiresRegister());
1858 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1859 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001860 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001861}
1862
1863void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1864 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001865 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001866 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001867 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001868
1869 switch (value_type) {
1870 case Primitive::kPrimBoolean:
1871 case Primitive::kPrimByte: {
1872 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001873 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001874 if (index.IsConstant()) {
1875 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1876 __ StoreToOffset(kStoreByte, value, obj, offset);
1877 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001878 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001879 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1880 }
1881 break;
1882 }
1883
1884 case Primitive::kPrimShort:
1885 case Primitive::kPrimChar: {
1886 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001887 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001888 if (index.IsConstant()) {
1889 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1890 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1891 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001892 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001893 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1894 }
1895 break;
1896 }
1897
1898 case Primitive::kPrimInt: {
1899 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001900 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001901 if (index.IsConstant()) {
1902 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1903 __ StoreToOffset(kStoreWord, value, obj, offset);
1904 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001905 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001906 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1907 }
1908 break;
1909 }
1910
1911 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001912 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001913 break;
1914 }
1915
1916 case Primitive::kPrimLong: {
1917 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001918 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001919 if (index.IsConstant()) {
1920 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001921 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001922 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001923 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1924 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001925 }
1926 break;
1927 }
1928
1929 case Primitive::kPrimFloat:
1930 case Primitive::kPrimDouble:
1931 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001932 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001933 case Primitive::kPrimVoid:
1934 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001935 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001936 }
1937}
1938
1939void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001940 LocationSummary* locations =
1941 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001942 locations->SetInAt(0, Location::RequiresRegister());
1943 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001944}
1945
1946void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1947 LocationSummary* locations = instruction->GetLocations();
1948 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001949 Register obj = locations->InAt(0).As<Register>();
1950 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001951 __ LoadFromOffset(kLoadWord, out, obj, offset);
1952}
1953
1954void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001955 LocationSummary* locations =
1956 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001957 locations->SetInAt(0, Location::RequiresRegister());
1958 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001959 if (instruction->HasUses()) {
1960 locations->SetOut(Location::SameAsFirstInput());
1961 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001962}
1963
1964void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
1965 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001966 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001967 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001968 codegen_->AddSlowPath(slow_path);
1969
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001970 Register index = locations->InAt(0).As<Register>();
1971 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001972
1973 __ cmp(index, ShifterOperand(length));
1974 __ b(slow_path->GetEntryLabel(), CS);
1975}
1976
1977void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
1978 Label is_null;
1979 __ CompareAndBranchIfZero(value, &is_null);
1980 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
1981 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
1982 __ strb(card, Address(card, temp));
1983 __ Bind(&is_null);
1984}
1985
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001986void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
1987 temp->SetLocations(nullptr);
1988}
1989
1990void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
1991 // Nothing to do, this is driven by the code generator.
1992}
1993
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001994void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001995 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01001996}
1997
1998void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001999 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2000}
2001
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002002void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2003 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2004}
2005
2006void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002007 HBasicBlock* block = instruction->GetBlock();
2008 if (block->GetLoopInformation() != nullptr) {
2009 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2010 // The back edge will generate the suspend check.
2011 return;
2012 }
2013 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2014 // The goto will generate the suspend check.
2015 return;
2016 }
2017 GenerateSuspendCheck(instruction, nullptr);
2018}
2019
2020void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2021 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002022 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002023 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002024 codegen_->AddSlowPath(slow_path);
2025
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002026 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002027 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002028 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002029 __ Bind(slow_path->GetReturnLabel());
2030 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002031 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002032 __ b(slow_path->GetEntryLabel());
2033 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002034}
2035
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002036ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2037 return codegen_->GetAssembler();
2038}
2039
2040void ParallelMoveResolverARM::EmitMove(size_t index) {
2041 MoveOperands* move = moves_.Get(index);
2042 Location source = move->GetSource();
2043 Location destination = move->GetDestination();
2044
2045 if (source.IsRegister()) {
2046 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002047 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002048 } else {
2049 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002050 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002051 SP, destination.GetStackIndex());
2052 }
2053 } else if (source.IsStackSlot()) {
2054 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002055 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002056 SP, source.GetStackIndex());
2057 } else {
2058 DCHECK(destination.IsStackSlot());
2059 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2060 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2061 }
2062 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002063 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002064 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002065 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2066 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002067 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002068 } else {
2069 DCHECK(destination.IsStackSlot());
2070 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002071 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002072 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002073 }
2074}
2075
2076void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2077 __ Mov(IP, reg);
2078 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2079 __ StoreToOffset(kStoreWord, IP, SP, mem);
2080}
2081
2082void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2083 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2084 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2085 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2086 SP, mem1 + stack_offset);
2087 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2088 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2089 SP, mem2 + stack_offset);
2090 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2091}
2092
2093void ParallelMoveResolverARM::EmitSwap(size_t index) {
2094 MoveOperands* move = moves_.Get(index);
2095 Location source = move->GetSource();
2096 Location destination = move->GetDestination();
2097
2098 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002099 DCHECK_NE(source.As<Register>(), IP);
2100 DCHECK_NE(destination.As<Register>(), IP);
2101 __ Mov(IP, source.As<Register>());
2102 __ Mov(source.As<Register>(), destination.As<Register>());
2103 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002104 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002105 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002106 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002107 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002108 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2109 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2110 } else {
2111 LOG(FATAL) << "Unimplemented";
2112 }
2113}
2114
2115void ParallelMoveResolverARM::SpillScratch(int reg) {
2116 __ Push(static_cast<Register>(reg));
2117}
2118
2119void ParallelMoveResolverARM::RestoreScratch(int reg) {
2120 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002121}
2122
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002123void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
2124 LocationSummary* locations =
2125 new (GetGraph()->GetArena()) LocationSummary(cls, LocationSummary::kNoCall);
2126 locations->SetOut(Location::RequiresRegister());
2127}
2128
2129void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2130 Register out = cls->GetLocations()->Out().As<Register>();
2131 if (cls->IsReferrersClass()) {
2132 codegen_->LoadCurrentMethod(out);
2133 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2134 } else {
2135 codegen_->LoadCurrentMethod(out);
2136 __ LoadFromOffset(
2137 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2138 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
2139 }
2140}
2141
2142void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2143 LocationSummary* locations =
2144 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2145 locations->SetInAt(0, Location::RequiresRegister());
2146 if (check->HasUses()) {
2147 locations->SetOut(Location::SameAsFirstInput());
2148 }
2149}
2150
2151void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
2152 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ClinitCheckSlowPathARM(check);
2153 codegen_->AddSlowPath(slow_path);
2154
2155 LocationSummary* locations = check->GetLocations();
2156 // We remove the class as a live register, we know it's null or unused in the slow path.
2157 RegisterSet* register_set = locations->GetLiveRegisters();
2158 register_set->Remove(locations->InAt(0));
2159
2160 Register class_reg = locations->InAt(0).As<Register>();
2161 __ cmp(class_reg, ShifterOperand(0));
2162 __ b(slow_path->GetEntryLabel(), EQ);
2163 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2164 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2165 __ b(slow_path->GetEntryLabel(), LT);
2166 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2167 // properly. Therefore, we do a memory fence.
2168 __ dmb(ISH);
2169 __ Bind(slow_path->GetExitLabel());
2170}
2171
2172void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2173 LocationSummary* locations =
2174 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2175 locations->SetInAt(0, Location::RequiresRegister());
2176 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2177}
2178
2179void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2180 LocationSummary* locations = instruction->GetLocations();
2181 Register cls = locations->InAt(0).As<Register>();
2182 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2183
2184 switch (instruction->GetType()) {
2185 case Primitive::kPrimBoolean: {
2186 Register out = locations->Out().As<Register>();
2187 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2188 break;
2189 }
2190
2191 case Primitive::kPrimByte: {
2192 Register out = locations->Out().As<Register>();
2193 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2194 break;
2195 }
2196
2197 case Primitive::kPrimShort: {
2198 Register out = locations->Out().As<Register>();
2199 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2200 break;
2201 }
2202
2203 case Primitive::kPrimChar: {
2204 Register out = locations->Out().As<Register>();
2205 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2206 break;
2207 }
2208
2209 case Primitive::kPrimInt:
2210 case Primitive::kPrimNot: {
2211 Register out = locations->Out().As<Register>();
2212 __ LoadFromOffset(kLoadWord, out, cls, offset);
2213 break;
2214 }
2215
2216 case Primitive::kPrimLong: {
2217 // TODO: support volatile.
2218 Location out = locations->Out();
2219 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2220 break;
2221 }
2222
2223 case Primitive::kPrimFloat:
2224 case Primitive::kPrimDouble:
2225 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2226 UNREACHABLE();
2227 case Primitive::kPrimVoid:
2228 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2229 UNREACHABLE();
2230 }
2231}
2232
2233void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2234 LocationSummary* locations =
2235 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2236 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2237 locations->SetInAt(0, Location::RequiresRegister());
2238 locations->SetInAt(1, Location::RequiresRegister());
2239 // Temporary registers for the write barrier.
2240 if (is_object_type) {
2241 locations->AddTemp(Location::RequiresRegister());
2242 locations->AddTemp(Location::RequiresRegister());
2243 }
2244}
2245
2246void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2247 LocationSummary* locations = instruction->GetLocations();
2248 Register cls = locations->InAt(0).As<Register>();
2249 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2250 Primitive::Type field_type = instruction->GetFieldType();
2251
2252 switch (field_type) {
2253 case Primitive::kPrimBoolean:
2254 case Primitive::kPrimByte: {
2255 Register value = locations->InAt(1).As<Register>();
2256 __ StoreToOffset(kStoreByte, value, cls, offset);
2257 break;
2258 }
2259
2260 case Primitive::kPrimShort:
2261 case Primitive::kPrimChar: {
2262 Register value = locations->InAt(1).As<Register>();
2263 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2264 break;
2265 }
2266
2267 case Primitive::kPrimInt:
2268 case Primitive::kPrimNot: {
2269 Register value = locations->InAt(1).As<Register>();
2270 __ StoreToOffset(kStoreWord, value, cls, offset);
2271 if (field_type == Primitive::kPrimNot) {
2272 Register temp = locations->GetTemp(0).As<Register>();
2273 Register card = locations->GetTemp(1).As<Register>();
2274 codegen_->MarkGCCard(temp, card, cls, value);
2275 }
2276 break;
2277 }
2278
2279 case Primitive::kPrimLong: {
2280 Location value = locations->InAt(1);
2281 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2282 break;
2283 }
2284
2285 case Primitive::kPrimFloat:
2286 case Primitive::kPrimDouble:
2287 LOG(FATAL) << "Unimplemented register type " << field_type;
2288 UNREACHABLE();
2289 case Primitive::kPrimVoid:
2290 LOG(FATAL) << "Unreachable type " << field_type;
2291 UNREACHABLE();
2292 }
2293}
2294
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002295void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2296 LocationSummary* locations =
2297 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2298 locations->SetOut(Location::RequiresRegister());
2299}
2300
2301void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2302 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2303 codegen_->AddSlowPath(slow_path);
2304
2305 Register out = load->GetLocations()->Out().As<Register>();
2306 codegen_->LoadCurrentMethod(out);
2307 __ LoadFromOffset(
2308 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2309 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2310 __ cmp(out, ShifterOperand(0));
2311 __ b(slow_path->GetEntryLabel(), EQ);
2312 __ Bind(slow_path->GetExitLabel());
2313}
2314
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002315} // namespace arm
2316} // namespace art