blob: 8c54cdfcf338ecde8e2d8f94db9f09eb2fc28fe2 [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
Calin Juravled0d48522014-11-04 16:40:20 +000095class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
96 public:
97 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
98
99 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
100 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
101 __ Bind(GetEntryLabel());
102 arm_codegen->InvokeRuntime(
103 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
104 }
105
106 private:
107 HDivZeroCheck* const instruction_;
108 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
109};
110
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100111class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100112 public:
113 StackOverflowCheckSlowPathARM() {}
114
115 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
116 __ Bind(GetEntryLabel());
117 __ LoadFromOffset(kLoadWord, PC, TR,
118 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
119 }
120
121 private:
122 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
123};
124
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100125class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100127 explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
128 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000129
130 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100131 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100133 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100134 arm_codegen->InvokeRuntime(
135 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100136 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100137 if (successor_ == nullptr) {
138 __ b(GetReturnLabel());
139 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100140 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100141 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000142 }
143
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100144 Label* GetReturnLabel() {
145 DCHECK(successor_ == nullptr);
146 return &return_label_;
147 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000148
149 private:
150 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100151 // If not null, the block to branch to after the suspend check.
152 HBasicBlock* const successor_;
153
154 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000155 Label return_label_;
156
157 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
158};
159
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100160class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100161 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100162 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
163 Location index_location,
164 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100165 : instruction_(instruction),
166 index_location_(index_location),
167 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168
169 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100170 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100171 __ Bind(GetEntryLabel());
172 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100173 arm_codegen->Move32(
174 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
175 arm_codegen->Move32(
176 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
177 arm_codegen->InvokeRuntime(
178 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100179 }
180
181 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100182 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 const Location index_location_;
184 const Location length_location_;
185
186 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
187};
188
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 LoadClassSlowPathARM(HLoadClass* cls,
192 HInstruction* at,
193 uint32_t dex_pc,
194 bool do_clinit)
195 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
196 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
197 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
199 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 LocationSummary* locations = at_->GetLocations();
201
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
203 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000209 int32_t entry_point_offset = do_clinit_
210 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
211 : QUICK_ENTRY_POINT(pInitializeType);
212 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
213
214 // Move the class to the desired location.
215 if (locations->Out().IsValid()) {
216 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
217 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
218 }
219 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100220 __ b(GetExitLabel());
221 }
222
223 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000224 // The class this slow path will load.
225 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100226
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000227 // The instruction where this slow path is happening.
228 // (Might be the load class or an initialization check).
229 HInstruction* const at_;
230
231 // The dex PC of `at_`.
232 const uint32_t dex_pc_;
233
234 // Whether to initialize the class.
235 const bool do_clinit_;
236
237 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100238};
239
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000240class LoadStringSlowPathARM : public SlowPathCodeARM {
241 public:
242 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
243
244 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
245 LocationSummary* locations = instruction_->GetLocations();
246 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
247
248 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
249 __ Bind(GetEntryLabel());
250 codegen->SaveLiveRegisters(locations);
251
252 InvokeRuntimeCallingConvention calling_convention;
253 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
254 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
255 arm_codegen->InvokeRuntime(
256 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
257 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
258
259 codegen->RestoreLiveRegisters(locations);
260 __ b(GetExitLabel());
261 }
262
263 private:
264 HLoadString* const instruction_;
265
266 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
267};
268
269#undef __
270
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100271#undef __
272#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700273
274inline Condition ARMCondition(IfCondition cond) {
275 switch (cond) {
276 case kCondEQ: return EQ;
277 case kCondNE: return NE;
278 case kCondLT: return LT;
279 case kCondLE: return LE;
280 case kCondGT: return GT;
281 case kCondGE: return GE;
282 default:
283 LOG(FATAL) << "Unknown if condition";
284 }
285 return EQ; // Unreachable.
286}
287
288inline Condition ARMOppositeCondition(IfCondition cond) {
289 switch (cond) {
290 case kCondEQ: return NE;
291 case kCondNE: return EQ;
292 case kCondLT: return GE;
293 case kCondLE: return GT;
294 case kCondGT: return LE;
295 case kCondGE: return LT;
296 default:
297 LOG(FATAL) << "Unknown if condition";
298 }
299 return EQ; // Unreachable.
300}
301
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100302void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
303 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
304}
305
306void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000307 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100308}
309
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100310size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
311 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
312 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100313}
314
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100315size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
316 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
317 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100318}
319
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100320CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000321 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100322 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100323 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100324 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100325 move_resolver_(graph->GetArena(), this),
326 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100327
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100328size_t CodeGeneratorARM::FrameEntrySpillSize() const {
329 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
330}
331
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100332Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100333 switch (type) {
334 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100335 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100336 ArmManagedRegister pair =
337 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100338 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
339 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
340
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100341 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
342 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100343 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100344 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100345 }
346
347 case Primitive::kPrimByte:
348 case Primitive::kPrimBoolean:
349 case Primitive::kPrimChar:
350 case Primitive::kPrimShort:
351 case Primitive::kPrimInt:
352 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100353 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100354 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100355 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
356 ArmManagedRegister current =
357 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
358 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100359 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100360 }
361 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100362 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100363 }
364
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000365 case Primitive::kPrimFloat: {
366 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100367 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100368 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100369
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000370 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000371 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
372 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000373 return Location::FpuRegisterPairLocation(reg, reg + 1);
374 }
375
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100376 case Primitive::kPrimVoid:
377 LOG(FATAL) << "Unreachable type " << type;
378 }
379
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100380 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100381}
382
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100383void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100384 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100385 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100386
387 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100388 blocked_core_registers_[SP] = true;
389 blocked_core_registers_[LR] = true;
390 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100391
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100393 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100394
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100395 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100396 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100397
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100398 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100399 // We always save and restore R6 and R7 to make sure we can use three
400 // register pairs for long operations.
Nicolas Geoffray44b819e2014-11-06 12:00:54 +0000401 blocked_core_registers_[R4] = true;
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100402 blocked_core_registers_[R5] = true;
403 blocked_core_registers_[R8] = true;
404 blocked_core_registers_[R10] = true;
405 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100406
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000407 blocked_fpu_registers_[S16] = true;
408 blocked_fpu_registers_[S17] = true;
409 blocked_fpu_registers_[S18] = true;
410 blocked_fpu_registers_[S19] = true;
411 blocked_fpu_registers_[S20] = true;
412 blocked_fpu_registers_[S21] = true;
413 blocked_fpu_registers_[S22] = true;
414 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000415 blocked_fpu_registers_[S24] = true;
416 blocked_fpu_registers_[S25] = true;
417 blocked_fpu_registers_[S26] = true;
418 blocked_fpu_registers_[S27] = true;
419 blocked_fpu_registers_[S28] = true;
420 blocked_fpu_registers_[S29] = true;
421 blocked_fpu_registers_[S30] = true;
422 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100423
424 UpdateBlockedPairRegisters();
425}
426
427void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
428 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
429 ArmManagedRegister current =
430 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
431 if (blocked_core_registers_[current.AsRegisterPairLow()]
432 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
433 blocked_register_pairs_[i] = true;
434 }
435 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100436}
437
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100438InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
439 : HGraphVisitor(graph),
440 assembler_(codegen->GetAssembler()),
441 codegen_(codegen) {}
442
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000443void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700444 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100445 if (!skip_overflow_check) {
446 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100447 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100448 AddSlowPath(slow_path);
449
450 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
451 __ cmp(SP, ShifterOperand(IP));
452 __ b(slow_path->GetEntryLabel(), CC);
453 } else {
454 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100455 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100456 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100457 }
458 }
459
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100460 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
461 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000462
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100463 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100464 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100465 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000466}
467
468void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100469 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100470 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000471}
472
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100473void CodeGeneratorARM::Bind(HBasicBlock* block) {
474 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000475}
476
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100477Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
478 switch (load->GetType()) {
479 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100480 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100481 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
482 break;
483
484 case Primitive::kPrimInt:
485 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100486 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100487 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100488
489 case Primitive::kPrimBoolean:
490 case Primitive::kPrimByte:
491 case Primitive::kPrimChar:
492 case Primitive::kPrimShort:
493 case Primitive::kPrimVoid:
494 LOG(FATAL) << "Unexpected type " << load->GetType();
495 }
496
497 LOG(FATAL) << "Unreachable";
498 return Location();
499}
500
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100501Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
502 switch (type) {
503 case Primitive::kPrimBoolean:
504 case Primitive::kPrimByte:
505 case Primitive::kPrimChar:
506 case Primitive::kPrimShort:
507 case Primitive::kPrimInt:
508 case Primitive::kPrimNot: {
509 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000510 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100511 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100512 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100513 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000514 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100515 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100516 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100517
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000518 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100519 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000520 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100521 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000522 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100523 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100524 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
525 calling_convention.GetRegisterPairAt(index));
526 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100527 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000528 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100529 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000530 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
531 }
532 }
533
534 case Primitive::kPrimFloat: {
535 uint32_t stack_index = stack_index_++;
536 if (float_index_ % 2 == 0) {
537 float_index_ = std::max(double_index_, float_index_);
538 }
539 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
540 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
541 } else {
542 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
543 }
544 }
545
546 case Primitive::kPrimDouble: {
547 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
548 uint32_t stack_index = stack_index_;
549 stack_index_ += 2;
550 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
551 uint32_t index = double_index_;
552 double_index_ += 2;
553 return Location::FpuRegisterPairLocation(
554 calling_convention.GetFpuRegisterAt(index),
555 calling_convention.GetFpuRegisterAt(index + 1));
556 } else {
557 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100558 }
559 }
560
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100561 case Primitive::kPrimVoid:
562 LOG(FATAL) << "Unexpected parameter type " << type;
563 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100564 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100565 return Location();
566}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100567
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000568Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
569 switch (type) {
570 case Primitive::kPrimBoolean:
571 case Primitive::kPrimByte:
572 case Primitive::kPrimChar:
573 case Primitive::kPrimShort:
574 case Primitive::kPrimInt:
575 case Primitive::kPrimNot: {
576 return Location::RegisterLocation(R0);
577 }
578
579 case Primitive::kPrimFloat: {
580 return Location::FpuRegisterLocation(S0);
581 }
582
583 case Primitive::kPrimLong: {
584 return Location::RegisterPairLocation(R0, R1);
585 }
586
587 case Primitive::kPrimDouble: {
588 return Location::FpuRegisterPairLocation(S0, S1);
589 }
590
591 case Primitive::kPrimVoid:
592 return Location();
593 }
594 UNREACHABLE();
595 return Location();
596}
597
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100598void CodeGeneratorARM::Move32(Location destination, Location source) {
599 if (source.Equals(destination)) {
600 return;
601 }
602 if (destination.IsRegister()) {
603 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100604 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100605 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000606 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100607 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100608 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100609 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100610 } else if (destination.IsFpuRegister()) {
611 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000612 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100613 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000614 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100615 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000616 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100617 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100618 } else {
619 DCHECK(destination.IsStackSlot());
620 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100621 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100622 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000623 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100624 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100625 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100626 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
627 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100628 }
629 }
630}
631
632void CodeGeneratorARM::Move64(Location destination, Location source) {
633 if (source.Equals(destination)) {
634 return;
635 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100636 if (destination.IsRegisterPair()) {
637 if (source.IsRegisterPair()) {
638 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
639 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100640 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000641 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100642 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000643 uint16_t register_index = source.GetQuickParameterRegisterIndex();
644 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100645 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100646 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000647 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100648 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000649 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100650 } else {
651 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100652 if (destination.AsRegisterPairLow<Register>() == R1) {
653 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100654 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
655 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100656 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100657 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100658 SP, source.GetStackIndex());
659 }
660 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000661 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100662 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000663 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
664 SP,
665 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100666 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000667 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100668 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100669 } else if (destination.IsQuickParameter()) {
670 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000671 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
672 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100673 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000674 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100675 source.AsRegisterPairLow<Register>());
676 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000677 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100678 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000679 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680 } else {
681 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000682 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000683 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100684 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000685 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100686 }
687 } else {
688 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100689 if (source.IsRegisterPair()) {
690 if (source.AsRegisterPairLow<Register>() == R1) {
691 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100692 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
693 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100694 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100695 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100696 SP, destination.GetStackIndex());
697 }
698 } else if (source.IsQuickParameter()) {
699 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000700 uint16_t register_index = source.GetQuickParameterRegisterIndex();
701 uint16_t stack_index = source.GetQuickParameterStackIndex();
702 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100703 SP, destination.GetStackIndex());
704 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000705 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100706 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000707 } else if (source.IsFpuRegisterPair()) {
708 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
709 SP,
710 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100711 } else {
712 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100713 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
714 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
715 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
716 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100717 }
718 }
719}
720
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100721void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100722 LocationSummary* locations = instruction->GetLocations();
723 if (locations != nullptr && locations->Out().Equals(location)) {
724 return;
725 }
726
Roland Levillain476df552014-10-09 17:51:36 +0100727 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100728 int32_t value = instruction->AsIntConstant()->GetValue();
729 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100730 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100731 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100732 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100733 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100734 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100735 }
Roland Levillain476df552014-10-09 17:51:36 +0100736 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100737 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100738 if (location.IsRegisterPair()) {
739 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
740 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100741 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100742 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100743 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100744 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100745 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100746 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100747 }
Roland Levillain476df552014-10-09 17:51:36 +0100748 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100749 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
750 switch (instruction->GetType()) {
751 case Primitive::kPrimBoolean:
752 case Primitive::kPrimByte:
753 case Primitive::kPrimChar:
754 case Primitive::kPrimShort:
755 case Primitive::kPrimInt:
756 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100757 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100758 Move32(location, Location::StackSlot(stack_slot));
759 break;
760
761 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100762 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100763 Move64(location, Location::DoubleStackSlot(stack_slot));
764 break;
765
766 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100767 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000769 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100770 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100771 switch (instruction->GetType()) {
772 case Primitive::kPrimBoolean:
773 case Primitive::kPrimByte:
774 case Primitive::kPrimChar:
775 case Primitive::kPrimShort:
776 case Primitive::kPrimNot:
777 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100778 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100779 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100780 break;
781
782 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100783 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100784 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100785 break;
786
787 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100788 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100789 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000790 }
791}
792
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100793void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
794 HInstruction* instruction,
795 uint32_t dex_pc) {
796 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
797 __ blx(LR);
798 RecordPcInfo(instruction, dex_pc);
799 DCHECK(instruction->IsSuspendCheck()
800 || instruction->IsBoundsCheck()
801 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000802 || instruction->IsDivZeroCheck()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100803 || !IsLeafMethod());
804}
805
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000806void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000807 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000808}
809
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000810void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000811 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100812 DCHECK(!successor->IsExitBlock());
813
814 HBasicBlock* block = got->GetBlock();
815 HInstruction* previous = got->GetPrevious();
816
817 HLoopInformation* info = block->GetLoopInformation();
818 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
819 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
820 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
821 return;
822 }
823
824 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
825 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
826 }
827 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000828 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000829 }
830}
831
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000832void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000833 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000834}
835
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000836void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700837 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000838 if (kIsDebugBuild) {
839 __ Comment("Unreachable");
840 __ bkpt(0);
841 }
842}
843
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000844void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100845 LocationSummary* locations =
846 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100847 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100848 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100849 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100850 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000851}
852
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000853void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700854 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100855 if (cond->IsIntConstant()) {
856 // Constant condition, statically compared against 1.
857 int32_t cond_value = cond->AsIntConstant()->GetValue();
858 if (cond_value == 1) {
859 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
860 if_instr->IfTrueSuccessor())) {
861 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100862 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100863 return;
864 } else {
865 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100866 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100867 } else {
868 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
869 // Condition has been materialized, compare the output to 0
870 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
871 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
872 ShifterOperand(0));
873 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
874 } else {
875 // Condition has not been materialized, use its inputs as the
876 // comparison and its condition as the branch condition.
877 LocationSummary* locations = cond->GetLocations();
878 if (locations->InAt(1).IsRegister()) {
879 __ cmp(locations->InAt(0).As<Register>(),
880 ShifterOperand(locations->InAt(1).As<Register>()));
881 } else {
882 DCHECK(locations->InAt(1).IsConstant());
883 int32_t value =
884 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
885 ShifterOperand operand;
886 if (ShifterOperand::CanHoldArm(value, &operand)) {
887 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
888 } else {
889 Register temp = IP;
890 __ LoadImmediate(temp, value);
891 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
892 }
893 }
894 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
895 ARMCondition(cond->AsCondition()->GetCondition()));
896 }
Dave Allison20dfc792014-06-16 20:44:29 -0700897 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100898 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
899 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700900 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000901 }
902}
903
Dave Allison20dfc792014-06-16 20:44:29 -0700904
905void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100906 LocationSummary* locations =
907 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100908 locations->SetInAt(0, Location::RequiresRegister());
909 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100910 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100911 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100912 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000913}
914
Dave Allison20dfc792014-06-16 20:44:29 -0700915void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100916 if (!comp->NeedsMaterialization()) return;
917
918 LocationSummary* locations = comp->GetLocations();
919 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100920 __ cmp(locations->InAt(0).As<Register>(),
921 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100922 } else {
923 DCHECK(locations->InAt(1).IsConstant());
924 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
925 ShifterOperand operand;
926 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100927 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100928 } else {
929 Register temp = IP;
930 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100931 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100932 }
Dave Allison20dfc792014-06-16 20:44:29 -0700933 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100934 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100935 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100936 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100937 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100938 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700939}
940
941void LocationsBuilderARM::VisitEqual(HEqual* comp) {
942 VisitCondition(comp);
943}
944
945void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
946 VisitCondition(comp);
947}
948
949void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
950 VisitCondition(comp);
951}
952
953void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
954 VisitCondition(comp);
955}
956
957void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
958 VisitCondition(comp);
959}
960
961void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
962 VisitCondition(comp);
963}
964
965void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
966 VisitCondition(comp);
967}
968
969void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
970 VisitCondition(comp);
971}
972
973void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
974 VisitCondition(comp);
975}
976
977void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
978 VisitCondition(comp);
979}
980
981void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
982 VisitCondition(comp);
983}
984
985void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
986 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000987}
988
989void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000990 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000991}
992
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000993void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
994 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000995}
996
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000997void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100998 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000999}
1000
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001001void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001002 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001003 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001004}
1005
1006void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001007 LocationSummary* locations =
1008 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001009 switch (store->InputAt(1)->GetType()) {
1010 case Primitive::kPrimBoolean:
1011 case Primitive::kPrimByte:
1012 case Primitive::kPrimChar:
1013 case Primitive::kPrimShort:
1014 case Primitive::kPrimInt:
1015 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001016 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001017 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1018 break;
1019
1020 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001021 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001022 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1023 break;
1024
1025 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001026 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001027 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001028}
1029
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001030void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001031 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001032}
1033
1034void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001035 LocationSummary* locations =
1036 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001037 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001038}
1039
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001040void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001041 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001042 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001043}
1044
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001045void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001046 LocationSummary* locations =
1047 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001048 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001049}
1050
1051void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1052 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001053 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001054}
1055
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001056void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1057 LocationSummary* locations =
1058 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1059 locations->SetOut(Location::ConstantLocation(constant));
1060}
1061
1062void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1063 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001064 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001065}
1066
1067void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1068 LocationSummary* locations =
1069 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1070 locations->SetOut(Location::ConstantLocation(constant));
1071}
1072
1073void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1074 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001075 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001076}
1077
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001078void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001079 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001080}
1081
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001082void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001083 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001084 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001085}
1086
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001087void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001088 LocationSummary* locations =
1089 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001090 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001091}
1092
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001093void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001094 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001095 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001096}
1097
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001098void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001099 HandleInvoke(invoke);
1100}
1101
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001102void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001103 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001104}
1105
1106void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001107 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001108
1109 // TODO: Implement all kinds of calls:
1110 // 1) boot -> boot
1111 // 2) app -> boot
1112 // 3) app -> app
1113 //
1114 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1115
1116 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001117 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001118 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001119 __ LoadFromOffset(
1120 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001121 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001122 __ LoadFromOffset(
1123 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001124 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001125 __ LoadFromOffset(kLoadWord, LR, temp,
1126 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001127 // LR()
1128 __ blx(LR);
1129
1130 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1131 DCHECK(!codegen_->IsLeafMethod());
1132}
1133
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001134void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001135 LocationSummary* locations =
1136 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001137 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001138
1139 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001140 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001141 HInstruction* input = invoke->InputAt(i);
1142 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1143 }
1144
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001145 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001146}
1147
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001148void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1149 HandleInvoke(invoke);
1150}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001151
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001152void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001153 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001154 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1155 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1156 LocationSummary* locations = invoke->GetLocations();
1157 Location receiver = locations->InAt(0);
1158 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1159 // temp = object->GetClass();
1160 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001161 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1162 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001163 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001164 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001165 }
1166 // temp = temp->GetMethodAt(method_offset);
1167 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001168 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001169 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001170 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001171 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001172 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001173 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001174 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001175}
1176
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001177void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1178 HandleInvoke(invoke);
1179 // Add the hidden argument.
1180 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1181}
1182
1183void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1184 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1185 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
1186 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1187 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1188 LocationSummary* locations = invoke->GetLocations();
1189 Location receiver = locations->InAt(0);
1190 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1191
1192 // Set the hidden argument.
1193 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex());
1194
1195 // temp = object->GetClass();
1196 if (receiver.IsStackSlot()) {
1197 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1198 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1199 } else {
1200 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
1201 }
1202 // temp = temp->GetImtEntryAt(method_offset);
1203 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
1204 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1205 // LR = temp->GetEntryPoint();
1206 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1207 // LR();
1208 __ blx(LR);
1209 DCHECK(!codegen_->IsLeafMethod());
1210 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1211}
1212
Roland Levillain88cb1752014-10-20 16:36:47 +01001213void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1214 LocationSummary* locations =
1215 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1216 switch (neg->GetResultType()) {
1217 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001218 case Primitive::kPrimLong: {
1219 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001220 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001221 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001222 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001223 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001224
Roland Levillain88cb1752014-10-20 16:36:47 +01001225 case Primitive::kPrimFloat:
1226 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001227 locations->SetInAt(0, Location::RequiresFpuRegister());
1228 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001229 break;
1230
1231 default:
1232 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1233 }
1234}
1235
1236void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1237 LocationSummary* locations = neg->GetLocations();
1238 Location out = locations->Out();
1239 Location in = locations->InAt(0);
1240 switch (neg->GetResultType()) {
1241 case Primitive::kPrimInt:
1242 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001243 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001244 break;
1245
1246 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001247 DCHECK(in.IsRegisterPair());
1248 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1249 __ rsbs(out.AsRegisterPairLow<Register>(),
1250 in.AsRegisterPairLow<Register>(),
1251 ShifterOperand(0));
1252 // We cannot emit an RSC (Reverse Subtract with Carry)
1253 // instruction here, as it does not exist in the Thumb-2
1254 // instruction set. We use the following approach
1255 // using SBC and SUB instead.
1256 //
1257 // out.hi = -C
1258 __ sbc(out.AsRegisterPairHigh<Register>(),
1259 out.AsRegisterPairHigh<Register>(),
1260 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1261 // out.hi = out.hi - in.hi
1262 __ sub(out.AsRegisterPairHigh<Register>(),
1263 out.AsRegisterPairHigh<Register>(),
1264 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1265 break;
1266
Roland Levillain88cb1752014-10-20 16:36:47 +01001267 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001268 DCHECK(in.IsFpuRegister());
1269 __ vnegs(out.As<SRegister>(), in.As<SRegister>());
1270 break;
1271
Roland Levillain88cb1752014-10-20 16:36:47 +01001272 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001273 DCHECK(in.IsFpuRegisterPair());
1274 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1275 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001276 break;
1277
1278 default:
1279 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1280 }
1281}
1282
Roland Levillaindff1f282014-11-05 14:15:05 +00001283void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1284 LocationSummary* locations =
1285 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1286 Primitive::Type result_type = conversion->GetResultType();
1287 Primitive::Type input_type = conversion->GetInputType();
1288 switch (result_type) {
1289 case Primitive::kPrimLong:
1290 switch (input_type) {
1291 case Primitive::kPrimByte:
1292 case Primitive::kPrimShort:
1293 case Primitive::kPrimInt:
1294 // int-to-long conversion.
1295 locations->SetInAt(0, Location::RequiresRegister());
1296 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1297 break;
1298
1299 case Primitive::kPrimFloat:
1300 case Primitive::kPrimDouble:
1301 LOG(FATAL) << "Type conversion from " << input_type << " to "
1302 << result_type << " not yet implemented";
1303 break;
1304
1305 default:
1306 LOG(FATAL) << "Unexpected type conversion from " << input_type
1307 << " to " << result_type;
1308 }
1309 break;
1310
1311 case Primitive::kPrimInt:
1312 case Primitive::kPrimFloat:
1313 case Primitive::kPrimDouble:
1314 LOG(FATAL) << "Type conversion from " << input_type
1315 << " to " << result_type << " not yet implemented";
1316 break;
1317
1318 default:
1319 LOG(FATAL) << "Unexpected type conversion from " << input_type
1320 << " to " << result_type;
1321 }
1322}
1323
1324void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1325 LocationSummary* locations = conversion->GetLocations();
1326 Location out = locations->Out();
1327 Location in = locations->InAt(0);
1328 Primitive::Type result_type = conversion->GetResultType();
1329 Primitive::Type input_type = conversion->GetInputType();
1330 switch (result_type) {
1331 case Primitive::kPrimLong:
1332 switch (input_type) {
1333 case Primitive::kPrimByte:
1334 case Primitive::kPrimShort:
1335 case Primitive::kPrimInt:
1336 // int-to-long conversion.
1337 DCHECK(out.IsRegisterPair());
1338 DCHECK(in.IsRegister());
1339 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1340 // Sign extension.
1341 __ Asr(out.AsRegisterPairHigh<Register>(),
1342 out.AsRegisterPairLow<Register>(),
1343 31);
1344 break;
1345
1346 case Primitive::kPrimFloat:
1347 case Primitive::kPrimDouble:
1348 LOG(FATAL) << "Type conversion from " << input_type << " to "
1349 << result_type << " not yet implemented";
1350 break;
1351
1352 default:
1353 LOG(FATAL) << "Unexpected type conversion from " << input_type
1354 << " to " << result_type;
1355 }
1356 break;
1357
1358 case Primitive::kPrimInt:
1359 case Primitive::kPrimFloat:
1360 case Primitive::kPrimDouble:
1361 LOG(FATAL) << "Type conversion from " << input_type
1362 << " to " << result_type << " not yet implemented";
1363 break;
1364
1365 default:
1366 LOG(FATAL) << "Unexpected type conversion from " << input_type
1367 << " to " << result_type;
1368 }
1369}
1370
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001371void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001372 LocationSummary* locations =
1373 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001374 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001375 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001376 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001377 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1378 locations->SetInAt(0, Location::RequiresRegister());
1379 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1380 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001381 break;
1382 }
1383
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001384 case Primitive::kPrimFloat:
1385 case Primitive::kPrimDouble: {
1386 locations->SetInAt(0, Location::RequiresFpuRegister());
1387 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001388 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001389 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001390 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001391
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001392 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001393 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001394 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001395}
1396
1397void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1398 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001399 Location out = locations->Out();
1400 Location first = locations->InAt(0);
1401 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001402 switch (add->GetResultType()) {
1403 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001404 if (second.IsRegister()) {
1405 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001406 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001407 __ AddConstant(out.As<Register>(),
1408 first.As<Register>(),
1409 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001410 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001411 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001412
1413 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001414 __ adds(out.AsRegisterPairLow<Register>(),
1415 first.AsRegisterPairLow<Register>(),
1416 ShifterOperand(second.AsRegisterPairLow<Register>()));
1417 __ adc(out.AsRegisterPairHigh<Register>(),
1418 first.AsRegisterPairHigh<Register>(),
1419 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001420 break;
1421
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001422 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001423 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001424 break;
1425
1426 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001427 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1428 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1429 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001430 break;
1431
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001432 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001433 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001434 }
1435}
1436
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001437void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001438 LocationSummary* locations =
1439 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001440 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001441 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001442 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001443 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1444 locations->SetInAt(0, Location::RequiresRegister());
1445 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1446 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001447 break;
1448 }
Calin Juravle11351682014-10-23 15:38:15 +01001449 case Primitive::kPrimFloat:
1450 case Primitive::kPrimDouble: {
1451 locations->SetInAt(0, Location::RequiresFpuRegister());
1452 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001453 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001454 break;
Calin Juravle11351682014-10-23 15:38:15 +01001455 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001456 default:
Calin Juravle11351682014-10-23 15:38:15 +01001457 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001458 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001459}
1460
1461void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1462 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001463 Location out = locations->Out();
1464 Location first = locations->InAt(0);
1465 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001466 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001467 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001468 if (second.IsRegister()) {
1469 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001470 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001471 __ AddConstant(out.As<Register>(),
1472 first.As<Register>(),
1473 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001474 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001475 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001476 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001477
Calin Juravle11351682014-10-23 15:38:15 +01001478 case Primitive::kPrimLong: {
1479 __ subs(out.AsRegisterPairLow<Register>(),
1480 first.AsRegisterPairLow<Register>(),
1481 ShifterOperand(second.AsRegisterPairLow<Register>()));
1482 __ sbc(out.AsRegisterPairHigh<Register>(),
1483 first.AsRegisterPairHigh<Register>(),
1484 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001485 break;
Calin Juravle11351682014-10-23 15:38:15 +01001486 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001487
Calin Juravle11351682014-10-23 15:38:15 +01001488 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001489 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001490 break;
Calin Juravle11351682014-10-23 15:38:15 +01001491 }
1492
1493 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001494 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1495 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1496 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001497 break;
1498 }
1499
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001500
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001501 default:
Calin Juravle11351682014-10-23 15:38:15 +01001502 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001503 }
1504}
1505
Calin Juravle34bacdf2014-10-07 20:23:36 +01001506void LocationsBuilderARM::VisitMul(HMul* mul) {
1507 LocationSummary* locations =
1508 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1509 switch (mul->GetResultType()) {
1510 case Primitive::kPrimInt:
1511 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001512 locations->SetInAt(0, Location::RequiresRegister());
1513 locations->SetInAt(1, Location::RequiresRegister());
1514 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001515 break;
1516 }
1517
Calin Juravleb5bfa962014-10-21 18:02:24 +01001518 case Primitive::kPrimFloat:
1519 case Primitive::kPrimDouble: {
1520 locations->SetInAt(0, Location::RequiresFpuRegister());
1521 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001522 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001523 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001524 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001525
1526 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001527 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001528 }
1529}
1530
1531void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1532 LocationSummary* locations = mul->GetLocations();
1533 Location out = locations->Out();
1534 Location first = locations->InAt(0);
1535 Location second = locations->InAt(1);
1536 switch (mul->GetResultType()) {
1537 case Primitive::kPrimInt: {
1538 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1539 break;
1540 }
1541 case Primitive::kPrimLong: {
1542 Register out_hi = out.AsRegisterPairHigh<Register>();
1543 Register out_lo = out.AsRegisterPairLow<Register>();
1544 Register in1_hi = first.AsRegisterPairHigh<Register>();
1545 Register in1_lo = first.AsRegisterPairLow<Register>();
1546 Register in2_hi = second.AsRegisterPairHigh<Register>();
1547 Register in2_lo = second.AsRegisterPairLow<Register>();
1548
1549 // Extra checks to protect caused by the existence of R1_R2.
1550 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1551 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1552 DCHECK_NE(out_hi, in1_lo);
1553 DCHECK_NE(out_hi, in2_lo);
1554
1555 // input: in1 - 64 bits, in2 - 64 bits
1556 // output: out
1557 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1558 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1559 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1560
1561 // IP <- in1.lo * in2.hi
1562 __ mul(IP, in1_lo, in2_hi);
1563 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1564 __ mla(out_hi, in1_hi, in2_lo, IP);
1565 // out.lo <- (in1.lo * in2.lo)[31:0];
1566 __ umull(out_lo, IP, in1_lo, in2_lo);
1567 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1568 __ add(out_hi, out_hi, ShifterOperand(IP));
1569 break;
1570 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001571
1572 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001573 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001574 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001575 }
1576
1577 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001578 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1579 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1580 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001581 break;
1582 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001583
1584 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001585 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001586 }
1587}
1588
Calin Juravle7c4954d2014-10-28 16:57:40 +00001589void LocationsBuilderARM::VisitDiv(HDiv* div) {
1590 LocationSummary* locations =
1591 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1592 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001593 case Primitive::kPrimInt: {
1594 locations->SetInAt(0, Location::RequiresRegister());
1595 locations->SetInAt(1, Location::RequiresRegister());
1596 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1597 break;
1598 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001599 case Primitive::kPrimLong: {
1600 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1601 break;
1602 }
1603 case Primitive::kPrimFloat:
1604 case Primitive::kPrimDouble: {
1605 locations->SetInAt(0, Location::RequiresFpuRegister());
1606 locations->SetInAt(1, Location::RequiresFpuRegister());
1607 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1608 break;
1609 }
1610
1611 default:
1612 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1613 }
1614}
1615
1616void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1617 LocationSummary* locations = div->GetLocations();
1618 Location out = locations->Out();
1619 Location first = locations->InAt(0);
1620 Location second = locations->InAt(1);
1621
1622 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001623 case Primitive::kPrimInt: {
1624 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>());
1625 break;
1626 }
1627
Calin Juravle7c4954d2014-10-28 16:57:40 +00001628 case Primitive::kPrimLong: {
1629 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1630 break;
1631 }
1632
1633 case Primitive::kPrimFloat: {
1634 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1635 break;
1636 }
1637
1638 case Primitive::kPrimDouble: {
1639 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1640 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1641 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1642 break;
1643 }
1644
1645 default:
1646 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1647 }
1648}
1649
Calin Juravled0d48522014-11-04 16:40:20 +00001650void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1651 LocationSummary* locations =
1652 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1653 locations->SetInAt(0, Location::RequiresRegister());
1654 if (instruction->HasUses()) {
1655 locations->SetOut(Location::SameAsFirstInput());
1656 }
1657}
1658
1659void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1660 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
1661 codegen_->AddSlowPath(slow_path);
1662
1663 LocationSummary* locations = instruction->GetLocations();
1664 Location value = locations->InAt(0);
1665
1666 DCHECK(value.IsRegister()) << value;
1667 __ cmp(value.As<Register>(), ShifterOperand(0));
1668 __ b(slow_path->GetEntryLabel(), EQ);
1669}
1670
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001671void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001672 LocationSummary* locations =
1673 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001674 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001675 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1676 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1677 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001678}
1679
1680void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1681 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001682 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001683 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001684 codegen_->InvokeRuntime(
1685 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001686}
1687
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001688void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1689 LocationSummary* locations =
1690 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1691 InvokeRuntimeCallingConvention calling_convention;
1692 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1693 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1694 locations->SetOut(Location::RegisterLocation(R0));
1695 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1696}
1697
1698void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1699 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001700 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001701 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001702 codegen_->InvokeRuntime(
1703 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001704}
1705
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001706void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001707 LocationSummary* locations =
1708 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001709 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1710 if (location.IsStackSlot()) {
1711 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1712 } else if (location.IsDoubleStackSlot()) {
1713 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001714 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001715 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001716}
1717
1718void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001719 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001720 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001721}
1722
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001723void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001724 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001725 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001726 locations->SetInAt(0, Location::RequiresRegister());
1727 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001728}
1729
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001730void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1731 LocationSummary* locations = not_->GetLocations();
1732 Location out = locations->Out();
1733 Location in = locations->InAt(0);
1734 switch (not_->InputAt(0)->GetType()) {
1735 case Primitive::kPrimBoolean:
1736 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1737 break;
1738
1739 case Primitive::kPrimInt:
1740 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1741 break;
1742
1743 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001744 __ mvn(out.AsRegisterPairLow<Register>(),
1745 ShifterOperand(in.AsRegisterPairLow<Register>()));
1746 __ mvn(out.AsRegisterPairHigh<Register>(),
1747 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001748 break;
1749
1750 default:
1751 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1752 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001753}
1754
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001755void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001756 LocationSummary* locations =
1757 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001758 locations->SetInAt(0, Location::RequiresRegister());
1759 locations->SetInAt(1, Location::RequiresRegister());
1760 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001761}
1762
1763void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001764 LocationSummary* locations = compare->GetLocations();
1765 switch (compare->InputAt(0)->GetType()) {
1766 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001767 Register output = locations->Out().As<Register>();
1768 Location left = locations->InAt(0);
1769 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001770 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001771 __ cmp(left.AsRegisterPairHigh<Register>(),
1772 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001773 __ b(&less, LT);
1774 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001775 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1776 // the status flags.
1777 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001778 __ cmp(left.AsRegisterPairLow<Register>(),
1779 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001780 __ b(&done, EQ);
1781 __ b(&less, CC);
1782
1783 __ Bind(&greater);
1784 __ LoadImmediate(output, 1);
1785 __ b(&done);
1786
1787 __ Bind(&less);
1788 __ LoadImmediate(output, -1);
1789
1790 __ Bind(&done);
1791 break;
1792 }
1793 default:
1794 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1795 }
1796}
1797
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001798void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001799 LocationSummary* locations =
1800 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001801 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1802 locations->SetInAt(i, Location::Any());
1803 }
1804 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001805}
1806
1807void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001808 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001809 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001810}
1811
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001812void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001813 LocationSummary* locations =
1814 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001815 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001816 locations->SetInAt(0, Location::RequiresRegister());
1817 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001818 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001819 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001820 locations->AddTemp(Location::RequiresRegister());
1821 locations->AddTemp(Location::RequiresRegister());
1822 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001823}
1824
1825void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1826 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001827 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001828 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001829 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001830
1831 switch (field_type) {
1832 case Primitive::kPrimBoolean:
1833 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001834 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001835 __ StoreToOffset(kStoreByte, value, obj, offset);
1836 break;
1837 }
1838
1839 case Primitive::kPrimShort:
1840 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001841 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001842 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1843 break;
1844 }
1845
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001846 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001847 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001848 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001849 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001850 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001851 Register temp = locations->GetTemp(0).As<Register>();
1852 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001853 codegen_->MarkGCCard(temp, card, obj, value);
1854 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001855 break;
1856 }
1857
1858 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001859 Location value = locations->InAt(1);
1860 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001861 break;
1862 }
1863
1864 case Primitive::kPrimFloat:
1865 case Primitive::kPrimDouble:
1866 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001867 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001868 case Primitive::kPrimVoid:
1869 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001870 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001871 }
1872}
1873
1874void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001875 LocationSummary* locations =
1876 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001877 locations->SetInAt(0, Location::RequiresRegister());
1878 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001879}
1880
1881void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1882 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001883 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001884 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1885
1886 switch (instruction->GetType()) {
1887 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001888 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001889 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1890 break;
1891 }
1892
1893 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001894 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001895 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1896 break;
1897 }
1898
1899 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001900 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001901 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1902 break;
1903 }
1904
1905 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001906 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001907 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1908 break;
1909 }
1910
1911 case Primitive::kPrimInt:
1912 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001913 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001914 __ LoadFromOffset(kLoadWord, out, obj, offset);
1915 break;
1916 }
1917
1918 case Primitive::kPrimLong: {
1919 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001920 Location out = locations->Out();
1921 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001922 break;
1923 }
1924
1925 case Primitive::kPrimFloat:
1926 case Primitive::kPrimDouble:
1927 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001928 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001929 case Primitive::kPrimVoid:
1930 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001931 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001932 }
1933}
1934
1935void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001936 LocationSummary* locations =
1937 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001938 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001939 if (instruction->HasUses()) {
1940 locations->SetOut(Location::SameAsFirstInput());
1941 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001942}
1943
1944void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001945 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001946 codegen_->AddSlowPath(slow_path);
1947
1948 LocationSummary* locations = instruction->GetLocations();
1949 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001950
1951 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001952 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001953 __ b(slow_path->GetEntryLabel(), EQ);
1954 } else {
1955 DCHECK(obj.IsConstant()) << obj;
1956 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1957 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001958 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001959}
1960
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001961void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001962 LocationSummary* locations =
1963 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001964 locations->SetInAt(0, Location::RequiresRegister());
1965 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1966 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001967}
1968
1969void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1970 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001971 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001972 Location index = locations->InAt(1);
1973
1974 switch (instruction->GetType()) {
1975 case Primitive::kPrimBoolean: {
1976 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001977 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001978 if (index.IsConstant()) {
1979 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1980 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1981 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001982 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001983 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1984 }
1985 break;
1986 }
1987
1988 case Primitive::kPrimByte: {
1989 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001990 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001991 if (index.IsConstant()) {
1992 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1993 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1994 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001995 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001996 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1997 }
1998 break;
1999 }
2000
2001 case Primitive::kPrimShort: {
2002 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002003 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002004 if (index.IsConstant()) {
2005 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2006 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2007 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002008 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002009 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2010 }
2011 break;
2012 }
2013
2014 case Primitive::kPrimChar: {
2015 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002016 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002017 if (index.IsConstant()) {
2018 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2019 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2020 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002021 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002022 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2023 }
2024 break;
2025 }
2026
2027 case Primitive::kPrimInt:
2028 case Primitive::kPrimNot: {
2029 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2030 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002031 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002032 if (index.IsConstant()) {
2033 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2034 __ LoadFromOffset(kLoadWord, out, obj, offset);
2035 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002036 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002037 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2038 }
2039 break;
2040 }
2041
2042 case Primitive::kPrimLong: {
2043 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002044 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002045 if (index.IsConstant()) {
2046 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002047 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002048 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002049 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2050 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002051 }
2052 break;
2053 }
2054
2055 case Primitive::kPrimFloat:
2056 case Primitive::kPrimDouble:
2057 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002058 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002059 case Primitive::kPrimVoid:
2060 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002061 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002062 }
2063}
2064
2065void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002066 Primitive::Type value_type = instruction->GetComponentType();
2067 bool is_object = value_type == Primitive::kPrimNot;
2068 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2069 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
2070 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002071 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002072 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2073 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2074 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002075 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002076 locations->SetInAt(0, Location::RequiresRegister());
2077 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2078 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002079 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002080}
2081
2082void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2083 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002084 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002085 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002086 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002087
2088 switch (value_type) {
2089 case Primitive::kPrimBoolean:
2090 case Primitive::kPrimByte: {
2091 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002092 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002093 if (index.IsConstant()) {
2094 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2095 __ StoreToOffset(kStoreByte, value, obj, offset);
2096 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002097 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002098 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2099 }
2100 break;
2101 }
2102
2103 case Primitive::kPrimShort:
2104 case Primitive::kPrimChar: {
2105 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002106 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002107 if (index.IsConstant()) {
2108 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2109 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2110 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002111 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002112 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2113 }
2114 break;
2115 }
2116
2117 case Primitive::kPrimInt: {
2118 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002119 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002120 if (index.IsConstant()) {
2121 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2122 __ StoreToOffset(kStoreWord, value, obj, offset);
2123 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002124 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002125 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2126 }
2127 break;
2128 }
2129
2130 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002131 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002132 break;
2133 }
2134
2135 case Primitive::kPrimLong: {
2136 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002137 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002138 if (index.IsConstant()) {
2139 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002140 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002141 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002142 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2143 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002144 }
2145 break;
2146 }
2147
2148 case Primitive::kPrimFloat:
2149 case Primitive::kPrimDouble:
2150 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002151 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002152 case Primitive::kPrimVoid:
2153 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002154 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002155 }
2156}
2157
2158void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002159 LocationSummary* locations =
2160 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002161 locations->SetInAt(0, Location::RequiresRegister());
2162 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002163}
2164
2165void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2166 LocationSummary* locations = instruction->GetLocations();
2167 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002168 Register obj = locations->InAt(0).As<Register>();
2169 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002170 __ LoadFromOffset(kLoadWord, out, obj, offset);
2171}
2172
2173void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002174 LocationSummary* locations =
2175 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002176 locations->SetInAt(0, Location::RequiresRegister());
2177 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002178 if (instruction->HasUses()) {
2179 locations->SetOut(Location::SameAsFirstInput());
2180 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002181}
2182
2183void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2184 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002185 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002186 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002187 codegen_->AddSlowPath(slow_path);
2188
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002189 Register index = locations->InAt(0).As<Register>();
2190 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002191
2192 __ cmp(index, ShifterOperand(length));
2193 __ b(slow_path->GetEntryLabel(), CS);
2194}
2195
2196void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2197 Label is_null;
2198 __ CompareAndBranchIfZero(value, &is_null);
2199 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2200 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2201 __ strb(card, Address(card, temp));
2202 __ Bind(&is_null);
2203}
2204
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002205void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2206 temp->SetLocations(nullptr);
2207}
2208
2209void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2210 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002211 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002212}
2213
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002214void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002215 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002216 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002217}
2218
2219void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002220 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2221}
2222
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002223void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2224 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2225}
2226
2227void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002228 HBasicBlock* block = instruction->GetBlock();
2229 if (block->GetLoopInformation() != nullptr) {
2230 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2231 // The back edge will generate the suspend check.
2232 return;
2233 }
2234 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2235 // The goto will generate the suspend check.
2236 return;
2237 }
2238 GenerateSuspendCheck(instruction, nullptr);
2239}
2240
2241void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2242 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002243 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002244 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002245 codegen_->AddSlowPath(slow_path);
2246
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002247 __ LoadFromOffset(
2248 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2249 __ cmp(IP, ShifterOperand(0));
2250 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002251 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002252 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002253 __ Bind(slow_path->GetReturnLabel());
2254 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002255 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002256 __ b(slow_path->GetEntryLabel());
2257 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002258}
2259
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002260ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2261 return codegen_->GetAssembler();
2262}
2263
2264void ParallelMoveResolverARM::EmitMove(size_t index) {
2265 MoveOperands* move = moves_.Get(index);
2266 Location source = move->GetSource();
2267 Location destination = move->GetDestination();
2268
2269 if (source.IsRegister()) {
2270 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002271 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002272 } else {
2273 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002274 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002275 SP, destination.GetStackIndex());
2276 }
2277 } else if (source.IsStackSlot()) {
2278 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002279 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002280 SP, source.GetStackIndex());
2281 } else {
2282 DCHECK(destination.IsStackSlot());
2283 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2284 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2285 }
2286 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002287 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002288 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002289 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2290 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002291 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002292 } else {
2293 DCHECK(destination.IsStackSlot());
2294 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002295 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002296 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002297 }
2298}
2299
2300void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2301 __ Mov(IP, reg);
2302 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2303 __ StoreToOffset(kStoreWord, IP, SP, mem);
2304}
2305
2306void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2307 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2308 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2309 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2310 SP, mem1 + stack_offset);
2311 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2312 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2313 SP, mem2 + stack_offset);
2314 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2315}
2316
2317void ParallelMoveResolverARM::EmitSwap(size_t index) {
2318 MoveOperands* move = moves_.Get(index);
2319 Location source = move->GetSource();
2320 Location destination = move->GetDestination();
2321
2322 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002323 DCHECK_NE(source.As<Register>(), IP);
2324 DCHECK_NE(destination.As<Register>(), IP);
2325 __ Mov(IP, source.As<Register>());
2326 __ Mov(source.As<Register>(), destination.As<Register>());
2327 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002328 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002329 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002330 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002331 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002332 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2333 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2334 } else {
2335 LOG(FATAL) << "Unimplemented";
2336 }
2337}
2338
2339void ParallelMoveResolverARM::SpillScratch(int reg) {
2340 __ Push(static_cast<Register>(reg));
2341}
2342
2343void ParallelMoveResolverARM::RestoreScratch(int reg) {
2344 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002345}
2346
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002347void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002348 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2349 ? LocationSummary::kCallOnSlowPath
2350 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002351 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002352 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002353 locations->SetOut(Location::RequiresRegister());
2354}
2355
2356void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2357 Register out = cls->GetLocations()->Out().As<Register>();
2358 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002359 DCHECK(!cls->CanCallRuntime());
2360 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002361 codegen_->LoadCurrentMethod(out);
2362 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2363 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002364 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002365 codegen_->LoadCurrentMethod(out);
2366 __ LoadFromOffset(
2367 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2368 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002369
2370 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2371 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2372 codegen_->AddSlowPath(slow_path);
2373 __ cmp(out, ShifterOperand(0));
2374 __ b(slow_path->GetEntryLabel(), EQ);
2375 if (cls->MustGenerateClinitCheck()) {
2376 GenerateClassInitializationCheck(slow_path, out);
2377 } else {
2378 __ Bind(slow_path->GetExitLabel());
2379 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002380 }
2381}
2382
2383void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2384 LocationSummary* locations =
2385 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2386 locations->SetInAt(0, Location::RequiresRegister());
2387 if (check->HasUses()) {
2388 locations->SetOut(Location::SameAsFirstInput());
2389 }
2390}
2391
2392void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002393 // We assume the class is not null.
2394 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2395 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002396 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002397 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2398}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002399
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002400void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2401 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002402 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2403 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2404 __ b(slow_path->GetEntryLabel(), LT);
2405 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2406 // properly. Therefore, we do a memory fence.
2407 __ dmb(ISH);
2408 __ Bind(slow_path->GetExitLabel());
2409}
2410
2411void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2412 LocationSummary* locations =
2413 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2414 locations->SetInAt(0, Location::RequiresRegister());
2415 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2416}
2417
2418void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2419 LocationSummary* locations = instruction->GetLocations();
2420 Register cls = locations->InAt(0).As<Register>();
2421 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2422
2423 switch (instruction->GetType()) {
2424 case Primitive::kPrimBoolean: {
2425 Register out = locations->Out().As<Register>();
2426 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2427 break;
2428 }
2429
2430 case Primitive::kPrimByte: {
2431 Register out = locations->Out().As<Register>();
2432 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2433 break;
2434 }
2435
2436 case Primitive::kPrimShort: {
2437 Register out = locations->Out().As<Register>();
2438 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2439 break;
2440 }
2441
2442 case Primitive::kPrimChar: {
2443 Register out = locations->Out().As<Register>();
2444 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2445 break;
2446 }
2447
2448 case Primitive::kPrimInt:
2449 case Primitive::kPrimNot: {
2450 Register out = locations->Out().As<Register>();
2451 __ LoadFromOffset(kLoadWord, out, cls, offset);
2452 break;
2453 }
2454
2455 case Primitive::kPrimLong: {
2456 // TODO: support volatile.
2457 Location out = locations->Out();
2458 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2459 break;
2460 }
2461
2462 case Primitive::kPrimFloat:
2463 case Primitive::kPrimDouble:
2464 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2465 UNREACHABLE();
2466 case Primitive::kPrimVoid:
2467 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2468 UNREACHABLE();
2469 }
2470}
2471
2472void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2473 LocationSummary* locations =
2474 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2475 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2476 locations->SetInAt(0, Location::RequiresRegister());
2477 locations->SetInAt(1, Location::RequiresRegister());
2478 // Temporary registers for the write barrier.
2479 if (is_object_type) {
2480 locations->AddTemp(Location::RequiresRegister());
2481 locations->AddTemp(Location::RequiresRegister());
2482 }
2483}
2484
2485void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2486 LocationSummary* locations = instruction->GetLocations();
2487 Register cls = locations->InAt(0).As<Register>();
2488 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2489 Primitive::Type field_type = instruction->GetFieldType();
2490
2491 switch (field_type) {
2492 case Primitive::kPrimBoolean:
2493 case Primitive::kPrimByte: {
2494 Register value = locations->InAt(1).As<Register>();
2495 __ StoreToOffset(kStoreByte, value, cls, offset);
2496 break;
2497 }
2498
2499 case Primitive::kPrimShort:
2500 case Primitive::kPrimChar: {
2501 Register value = locations->InAt(1).As<Register>();
2502 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2503 break;
2504 }
2505
2506 case Primitive::kPrimInt:
2507 case Primitive::kPrimNot: {
2508 Register value = locations->InAt(1).As<Register>();
2509 __ StoreToOffset(kStoreWord, value, cls, offset);
2510 if (field_type == Primitive::kPrimNot) {
2511 Register temp = locations->GetTemp(0).As<Register>();
2512 Register card = locations->GetTemp(1).As<Register>();
2513 codegen_->MarkGCCard(temp, card, cls, value);
2514 }
2515 break;
2516 }
2517
2518 case Primitive::kPrimLong: {
2519 Location value = locations->InAt(1);
2520 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2521 break;
2522 }
2523
2524 case Primitive::kPrimFloat:
2525 case Primitive::kPrimDouble:
2526 LOG(FATAL) << "Unimplemented register type " << field_type;
2527 UNREACHABLE();
2528 case Primitive::kPrimVoid:
2529 LOG(FATAL) << "Unreachable type " << field_type;
2530 UNREACHABLE();
2531 }
2532}
2533
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002534void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2535 LocationSummary* locations =
2536 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2537 locations->SetOut(Location::RequiresRegister());
2538}
2539
2540void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2541 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2542 codegen_->AddSlowPath(slow_path);
2543
2544 Register out = load->GetLocations()->Out().As<Register>();
2545 codegen_->LoadCurrentMethod(out);
2546 __ LoadFromOffset(
2547 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2548 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2549 __ cmp(out, ShifterOperand(0));
2550 __ b(slow_path->GetEntryLabel(), EQ);
2551 __ Bind(slow_path->GetExitLabel());
2552}
2553
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002554void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
2555 LocationSummary* locations =
2556 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2557 locations->SetOut(Location::RequiresRegister());
2558}
2559
2560void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
2561 Register out = load->GetLocations()->Out().As<Register>();
2562 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
2563 __ LoadFromOffset(kLoadWord, out, TR, offset);
2564 __ LoadImmediate(IP, 0);
2565 __ StoreToOffset(kStoreWord, IP, TR, offset);
2566}
2567
2568void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
2569 LocationSummary* locations =
2570 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2571 InvokeRuntimeCallingConvention calling_convention;
2572 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2573}
2574
2575void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
2576 codegen_->InvokeRuntime(
2577 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
2578}
2579
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002580} // namespace arm
2581} // namespace art