blob: 0b55f87c69fbbd7a433c13bfd5e47221d22fe4d0 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070019#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010020#include "gc/accounting/card_table.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070021#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000022#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010023#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070024#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010025#include "utils/assembler.h"
26#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010028#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000029
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000030namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010031
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032namespace arm {
33
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000034static DRegister FromLowSToD(SRegister reg) {
35 DCHECK_EQ(reg % 2, 0);
36 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010037}
38
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010039static constexpr bool kExplicitStackOverflowCheck = false;
40
41static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
42static constexpr int kCurrentMethodStackOffset = 0;
43
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2 };
45static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { };
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010048static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010049
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000050class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051 public:
52 InvokeRuntimeCallingConvention()
53 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 kRuntimeParameterCoreRegistersLength,
55 kRuntimeParameterFpuRegisters,
56 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010057
58 private:
59 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
60};
61
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010063#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010065class SlowPathCodeARM : public SlowPathCode {
66 public:
67 SlowPathCodeARM() : entry_label_(), exit_label_() {}
68
69 Label* GetEntryLabel() { return &entry_label_; }
70 Label* GetExitLabel() { return &exit_label_; }
71
72 private:
73 Label entry_label_;
74 Label exit_label_;
75
76 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
77};
78
79class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010081 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082
83 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010086 arm_codegen->InvokeRuntime(
87 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 }
89
90 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010091 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010092 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
93};
94
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010095class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010096 public:
97 StackOverflowCheckSlowPathARM() {}
98
99 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
100 __ Bind(GetEntryLabel());
101 __ LoadFromOffset(kLoadWord, PC, TR,
102 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
103 }
104
105 private:
106 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
107};
108
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100109class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000110 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100111 explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
112 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000113
114 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100117 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100118 arm_codegen->InvokeRuntime(
119 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100120 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121 if (successor_ == nullptr) {
122 __ b(GetReturnLabel());
123 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100124 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 }
127
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100128 Label* GetReturnLabel() {
129 DCHECK(successor_ == nullptr);
130 return &return_label_;
131 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132
133 private:
134 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100135 // If not null, the block to branch to after the suspend check.
136 HBasicBlock* const successor_;
137
138 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000139 Label return_label_;
140
141 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
142};
143
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100144class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100145 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100146 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
147 Location index_location,
148 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100149 : instruction_(instruction),
150 index_location_(index_location),
151 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152
153 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100154 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155 __ Bind(GetEntryLabel());
156 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100157 arm_codegen->Move32(
158 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
159 arm_codegen->Move32(
160 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
161 arm_codegen->InvokeRuntime(
162 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 }
164
165 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100166 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100167 const Location index_location_;
168 const Location length_location_;
169
170 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
171};
172
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000173class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100174 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000175 LoadClassSlowPathARM(HLoadClass* cls,
176 HInstruction* at,
177 uint32_t dex_pc,
178 bool do_clinit)
179 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
180 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
181 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100182
183 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000184 LocationSummary* locations = at_->GetLocations();
185
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100186 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
187 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000188 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100189
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100192 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000193 int32_t entry_point_offset = do_clinit_
194 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
195 : QUICK_ENTRY_POINT(pInitializeType);
196 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
197
198 // Move the class to the desired location.
199 if (locations->Out().IsValid()) {
200 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
201 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
202 }
203 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100204 __ b(GetExitLabel());
205 }
206
207 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000208 // The class this slow path will load.
209 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 // The instruction where this slow path is happening.
212 // (Might be the load class or an initialization check).
213 HInstruction* const at_;
214
215 // The dex PC of `at_`.
216 const uint32_t dex_pc_;
217
218 // Whether to initialize the class.
219 const bool do_clinit_;
220
221 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100222};
223
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000224class LoadStringSlowPathARM : public SlowPathCodeARM {
225 public:
226 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
227
228 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
229 LocationSummary* locations = instruction_->GetLocations();
230 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
231
232 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
233 __ Bind(GetEntryLabel());
234 codegen->SaveLiveRegisters(locations);
235
236 InvokeRuntimeCallingConvention calling_convention;
237 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
238 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
239 arm_codegen->InvokeRuntime(
240 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
241 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
242
243 codegen->RestoreLiveRegisters(locations);
244 __ b(GetExitLabel());
245 }
246
247 private:
248 HLoadString* const instruction_;
249
250 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
251};
252
253#undef __
254
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100255#undef __
256#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700257
258inline Condition ARMCondition(IfCondition cond) {
259 switch (cond) {
260 case kCondEQ: return EQ;
261 case kCondNE: return NE;
262 case kCondLT: return LT;
263 case kCondLE: return LE;
264 case kCondGT: return GT;
265 case kCondGE: return GE;
266 default:
267 LOG(FATAL) << "Unknown if condition";
268 }
269 return EQ; // Unreachable.
270}
271
272inline Condition ARMOppositeCondition(IfCondition cond) {
273 switch (cond) {
274 case kCondEQ: return NE;
275 case kCondNE: return EQ;
276 case kCondLT: return GE;
277 case kCondLE: return GT;
278 case kCondGT: return LE;
279 case kCondGE: return LT;
280 default:
281 LOG(FATAL) << "Unknown if condition";
282 }
283 return EQ; // Unreachable.
284}
285
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100286void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
287 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
288}
289
290void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000291 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100292}
293
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100294size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
295 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
296 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100297}
298
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100299size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
300 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
301 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100302}
303
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100304CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000305 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100306 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100307 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100308 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100309 move_resolver_(graph->GetArena(), this),
310 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100311
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100312size_t CodeGeneratorARM::FrameEntrySpillSize() const {
313 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
314}
315
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100316Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100317 switch (type) {
318 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100319 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100320 ArmManagedRegister pair =
321 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100322 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
323 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
324
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100325 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
326 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100327 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100328 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100329 }
330
331 case Primitive::kPrimByte:
332 case Primitive::kPrimBoolean:
333 case Primitive::kPrimChar:
334 case Primitive::kPrimShort:
335 case Primitive::kPrimInt:
336 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100337 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100338 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100339 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
340 ArmManagedRegister current =
341 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
342 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100343 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100344 }
345 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100346 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100347 }
348
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000349 case Primitive::kPrimFloat: {
350 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100351 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100352 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100353
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000354 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000355 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
356 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000357 return Location::FpuRegisterPairLocation(reg, reg + 1);
358 }
359
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100360 case Primitive::kPrimVoid:
361 LOG(FATAL) << "Unreachable type " << type;
362 }
363
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100364 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100365}
366
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100367void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100368 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100369 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100370
371 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100372 blocked_core_registers_[SP] = true;
373 blocked_core_registers_[LR] = true;
374 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100375
376 // Reserve R4 for suspend check.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100377 blocked_core_registers_[R4] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100378
379 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100380 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100381
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100382 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100383 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100384
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100385 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100386 // We always save and restore R6 and R7 to make sure we can use three
387 // register pairs for long operations.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100388 blocked_core_registers_[R5] = true;
389 blocked_core_registers_[R8] = true;
390 blocked_core_registers_[R10] = true;
391 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100392
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000393 blocked_fpu_registers_[S16] = true;
394 blocked_fpu_registers_[S17] = true;
395 blocked_fpu_registers_[S18] = true;
396 blocked_fpu_registers_[S19] = true;
397 blocked_fpu_registers_[S20] = true;
398 blocked_fpu_registers_[S21] = true;
399 blocked_fpu_registers_[S22] = true;
400 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000401 blocked_fpu_registers_[S24] = true;
402 blocked_fpu_registers_[S25] = true;
403 blocked_fpu_registers_[S26] = true;
404 blocked_fpu_registers_[S27] = true;
405 blocked_fpu_registers_[S28] = true;
406 blocked_fpu_registers_[S29] = true;
407 blocked_fpu_registers_[S30] = true;
408 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100409
410 UpdateBlockedPairRegisters();
411}
412
413void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
414 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
415 ArmManagedRegister current =
416 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
417 if (blocked_core_registers_[current.AsRegisterPairLow()]
418 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
419 blocked_register_pairs_[i] = true;
420 }
421 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100422}
423
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100424InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
425 : HGraphVisitor(graph),
426 assembler_(codegen->GetAssembler()),
427 codegen_(codegen) {}
428
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000429void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700430 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100431 if (!skip_overflow_check) {
432 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100433 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100434 AddSlowPath(slow_path);
435
436 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
437 __ cmp(SP, ShifterOperand(IP));
438 __ b(slow_path->GetEntryLabel(), CC);
439 } else {
440 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100441 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100442 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100443 }
444 }
445
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100446 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
447 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000448
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100449 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100450 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100451 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000452}
453
454void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100455 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100456 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000457}
458
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100459void CodeGeneratorARM::Bind(HBasicBlock* block) {
460 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000461}
462
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
464 switch (load->GetType()) {
465 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100466 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100467 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
468 break;
469
470 case Primitive::kPrimInt:
471 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100472 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100473 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100474
475 case Primitive::kPrimBoolean:
476 case Primitive::kPrimByte:
477 case Primitive::kPrimChar:
478 case Primitive::kPrimShort:
479 case Primitive::kPrimVoid:
480 LOG(FATAL) << "Unexpected type " << load->GetType();
481 }
482
483 LOG(FATAL) << "Unreachable";
484 return Location();
485}
486
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100487Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
488 switch (type) {
489 case Primitive::kPrimBoolean:
490 case Primitive::kPrimByte:
491 case Primitive::kPrimChar:
492 case Primitive::kPrimShort:
493 case Primitive::kPrimInt:
494 case Primitive::kPrimNot: {
495 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000496 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100497 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100498 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100499 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000500 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100501 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100502 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100503
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000504 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100505 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000506 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100507 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000508 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100509 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100510 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
511 calling_convention.GetRegisterPairAt(index));
512 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100513 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000514 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100515 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000516 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
517 }
518 }
519
520 case Primitive::kPrimFloat: {
521 uint32_t stack_index = stack_index_++;
522 if (float_index_ % 2 == 0) {
523 float_index_ = std::max(double_index_, float_index_);
524 }
525 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
526 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
527 } else {
528 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
529 }
530 }
531
532 case Primitive::kPrimDouble: {
533 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
534 uint32_t stack_index = stack_index_;
535 stack_index_ += 2;
536 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
537 uint32_t index = double_index_;
538 double_index_ += 2;
539 return Location::FpuRegisterPairLocation(
540 calling_convention.GetFpuRegisterAt(index),
541 calling_convention.GetFpuRegisterAt(index + 1));
542 } else {
543 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100544 }
545 }
546
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100547 case Primitive::kPrimVoid:
548 LOG(FATAL) << "Unexpected parameter type " << type;
549 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100550 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100551 return Location();
552}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100553
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000554Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
555 switch (type) {
556 case Primitive::kPrimBoolean:
557 case Primitive::kPrimByte:
558 case Primitive::kPrimChar:
559 case Primitive::kPrimShort:
560 case Primitive::kPrimInt:
561 case Primitive::kPrimNot: {
562 return Location::RegisterLocation(R0);
563 }
564
565 case Primitive::kPrimFloat: {
566 return Location::FpuRegisterLocation(S0);
567 }
568
569 case Primitive::kPrimLong: {
570 return Location::RegisterPairLocation(R0, R1);
571 }
572
573 case Primitive::kPrimDouble: {
574 return Location::FpuRegisterPairLocation(S0, S1);
575 }
576
577 case Primitive::kPrimVoid:
578 return Location();
579 }
580 UNREACHABLE();
581 return Location();
582}
583
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100584void CodeGeneratorARM::Move32(Location destination, Location source) {
585 if (source.Equals(destination)) {
586 return;
587 }
588 if (destination.IsRegister()) {
589 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100590 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100591 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000592 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100593 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100594 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100595 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100596 } else if (destination.IsFpuRegister()) {
597 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000598 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100599 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000600 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100601 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000602 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100603 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100604 } else {
605 DCHECK(destination.IsStackSlot());
606 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100607 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100608 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000609 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100610 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100611 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100612 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
613 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100614 }
615 }
616}
617
618void CodeGeneratorARM::Move64(Location destination, Location source) {
619 if (source.Equals(destination)) {
620 return;
621 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100622 if (destination.IsRegisterPair()) {
623 if (source.IsRegisterPair()) {
624 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
625 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100626 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000627 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100628 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000629 uint16_t register_index = source.GetQuickParameterRegisterIndex();
630 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100631 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100632 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000633 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100634 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000635 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100636 } else {
637 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100638 if (destination.AsRegisterPairLow<Register>() == R1) {
639 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100640 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
641 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100642 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100643 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100644 SP, source.GetStackIndex());
645 }
646 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000647 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100648 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000649 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
650 SP,
651 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100652 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000653 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100654 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100655 } else if (destination.IsQuickParameter()) {
656 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000657 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
658 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100659 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000660 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100661 source.AsRegisterPairLow<Register>());
662 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000663 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100664 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000665 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100666 } else {
667 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000669 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100670 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000671 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100672 }
673 } else {
674 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100675 if (source.IsRegisterPair()) {
676 if (source.AsRegisterPairLow<Register>() == R1) {
677 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100678 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
679 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100681 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100682 SP, destination.GetStackIndex());
683 }
684 } else if (source.IsQuickParameter()) {
685 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000686 uint16_t register_index = source.GetQuickParameterRegisterIndex();
687 uint16_t stack_index = source.GetQuickParameterStackIndex();
688 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100689 SP, destination.GetStackIndex());
690 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000691 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100692 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000693 } else if (source.IsFpuRegisterPair()) {
694 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
695 SP,
696 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100697 } else {
698 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100699 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
700 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
701 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
702 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100703 }
704 }
705}
706
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100707void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100708 LocationSummary* locations = instruction->GetLocations();
709 if (locations != nullptr && locations->Out().Equals(location)) {
710 return;
711 }
712
Roland Levillain476df552014-10-09 17:51:36 +0100713 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100714 int32_t value = instruction->AsIntConstant()->GetValue();
715 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100716 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100717 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100718 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100719 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100720 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100721 }
Roland Levillain476df552014-10-09 17:51:36 +0100722 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100723 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100724 if (location.IsRegisterPair()) {
725 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
726 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100727 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100728 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100729 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100730 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100731 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100732 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100733 }
Roland Levillain476df552014-10-09 17:51:36 +0100734 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100735 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
736 switch (instruction->GetType()) {
737 case Primitive::kPrimBoolean:
738 case Primitive::kPrimByte:
739 case Primitive::kPrimChar:
740 case Primitive::kPrimShort:
741 case Primitive::kPrimInt:
742 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100743 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100744 Move32(location, Location::StackSlot(stack_slot));
745 break;
746
747 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100748 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100749 Move64(location, Location::DoubleStackSlot(stack_slot));
750 break;
751
752 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100753 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100754 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000755 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100756 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100757 switch (instruction->GetType()) {
758 case Primitive::kPrimBoolean:
759 case Primitive::kPrimByte:
760 case Primitive::kPrimChar:
761 case Primitive::kPrimShort:
762 case Primitive::kPrimNot:
763 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100764 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100765 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100766 break;
767
768 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100769 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100770 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100771 break;
772
773 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100774 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100775 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000776 }
777}
778
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100779void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
780 HInstruction* instruction,
781 uint32_t dex_pc) {
782 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
783 __ blx(LR);
784 RecordPcInfo(instruction, dex_pc);
785 DCHECK(instruction->IsSuspendCheck()
786 || instruction->IsBoundsCheck()
787 || instruction->IsNullCheck()
788 || !IsLeafMethod());
789}
790
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000791void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000792 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000793}
794
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000795void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000796 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100797 DCHECK(!successor->IsExitBlock());
798
799 HBasicBlock* block = got->GetBlock();
800 HInstruction* previous = got->GetPrevious();
801
802 HLoopInformation* info = block->GetLoopInformation();
803 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
804 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
805 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
806 return;
807 }
808
809 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
810 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
811 }
812 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000813 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000814 }
815}
816
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000817void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000818 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000819}
820
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000821void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700822 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000823 if (kIsDebugBuild) {
824 __ Comment("Unreachable");
825 __ bkpt(0);
826 }
827}
828
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000829void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100830 LocationSummary* locations =
831 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100832 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100833 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100834 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100835 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000836}
837
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000838void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700839 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100840 if (cond->IsIntConstant()) {
841 // Constant condition, statically compared against 1.
842 int32_t cond_value = cond->AsIntConstant()->GetValue();
843 if (cond_value == 1) {
844 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
845 if_instr->IfTrueSuccessor())) {
846 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100847 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100848 return;
849 } else {
850 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100851 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100852 } else {
853 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
854 // Condition has been materialized, compare the output to 0
855 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
856 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
857 ShifterOperand(0));
858 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
859 } else {
860 // Condition has not been materialized, use its inputs as the
861 // comparison and its condition as the branch condition.
862 LocationSummary* locations = cond->GetLocations();
863 if (locations->InAt(1).IsRegister()) {
864 __ cmp(locations->InAt(0).As<Register>(),
865 ShifterOperand(locations->InAt(1).As<Register>()));
866 } else {
867 DCHECK(locations->InAt(1).IsConstant());
868 int32_t value =
869 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
870 ShifterOperand operand;
871 if (ShifterOperand::CanHoldArm(value, &operand)) {
872 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
873 } else {
874 Register temp = IP;
875 __ LoadImmediate(temp, value);
876 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
877 }
878 }
879 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
880 ARMCondition(cond->AsCondition()->GetCondition()));
881 }
Dave Allison20dfc792014-06-16 20:44:29 -0700882 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100883 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
884 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700885 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000886 }
887}
888
Dave Allison20dfc792014-06-16 20:44:29 -0700889
890void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100891 LocationSummary* locations =
892 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100893 locations->SetInAt(0, Location::RequiresRegister());
894 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100895 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100896 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100897 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000898}
899
Dave Allison20dfc792014-06-16 20:44:29 -0700900void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100901 if (!comp->NeedsMaterialization()) return;
902
903 LocationSummary* locations = comp->GetLocations();
904 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100905 __ cmp(locations->InAt(0).As<Register>(),
906 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100907 } else {
908 DCHECK(locations->InAt(1).IsConstant());
909 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
910 ShifterOperand operand;
911 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100912 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100913 } else {
914 Register temp = IP;
915 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100916 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100917 }
Dave Allison20dfc792014-06-16 20:44:29 -0700918 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100919 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100920 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100921 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100922 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100923 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700924}
925
926void LocationsBuilderARM::VisitEqual(HEqual* comp) {
927 VisitCondition(comp);
928}
929
930void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
931 VisitCondition(comp);
932}
933
934void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
935 VisitCondition(comp);
936}
937
938void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
939 VisitCondition(comp);
940}
941
942void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
943 VisitCondition(comp);
944}
945
946void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
947 VisitCondition(comp);
948}
949
950void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
951 VisitCondition(comp);
952}
953
954void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
955 VisitCondition(comp);
956}
957
958void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
959 VisitCondition(comp);
960}
961
962void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
963 VisitCondition(comp);
964}
965
966void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
967 VisitCondition(comp);
968}
969
970void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
971 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000972}
973
974void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000975 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000976}
977
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000978void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
979 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000980}
981
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000982void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100983 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000984}
985
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000986void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100987 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700988 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000989}
990
991void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100992 LocationSummary* locations =
993 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100994 switch (store->InputAt(1)->GetType()) {
995 case Primitive::kPrimBoolean:
996 case Primitive::kPrimByte:
997 case Primitive::kPrimChar:
998 case Primitive::kPrimShort:
999 case Primitive::kPrimInt:
1000 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001001 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001002 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1003 break;
1004
1005 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001006 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001007 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1008 break;
1009
1010 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001011 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001012 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001013}
1014
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001015void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001016 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001017}
1018
1019void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001020 LocationSummary* locations =
1021 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001022 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001023}
1024
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001025void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001026 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001027 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001028}
1029
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001030void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001031 LocationSummary* locations =
1032 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001033 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001034}
1035
1036void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1037 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001038 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001039}
1040
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001041void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1042 LocationSummary* locations =
1043 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1044 locations->SetOut(Location::ConstantLocation(constant));
1045}
1046
1047void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1048 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001049 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001050}
1051
1052void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1053 LocationSummary* locations =
1054 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1055 locations->SetOut(Location::ConstantLocation(constant));
1056}
1057
1058void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1059 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001060 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001061}
1062
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001063void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001064 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001065}
1066
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001067void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001068 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001069 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001070}
1071
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001072void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001073 LocationSummary* locations =
1074 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001075 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001076}
1077
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001078void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001079 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001080 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001081}
1082
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001083void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001084 HandleInvoke(invoke);
1085}
1086
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001087void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001088 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001089}
1090
1091void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001092 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001093
1094 // TODO: Implement all kinds of calls:
1095 // 1) boot -> boot
1096 // 2) app -> boot
1097 // 3) app -> app
1098 //
1099 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1100
1101 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001102 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001103 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001104 __ LoadFromOffset(
1105 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001106 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001107 __ LoadFromOffset(
1108 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001109 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001110 __ LoadFromOffset(kLoadWord, LR, temp,
1111 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001112 // LR()
1113 __ blx(LR);
1114
1115 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1116 DCHECK(!codegen_->IsLeafMethod());
1117}
1118
1119void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1120 HandleInvoke(invoke);
1121}
1122
1123void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001124 LocationSummary* locations =
1125 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001126 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001127
1128 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001129 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001130 HInstruction* input = invoke->InputAt(i);
1131 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1132 }
1133
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001134 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001135}
1136
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001137
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001138void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001139 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001140 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1141 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1142 LocationSummary* locations = invoke->GetLocations();
1143 Location receiver = locations->InAt(0);
1144 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1145 // temp = object->GetClass();
1146 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001147 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1148 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001149 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001150 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001151 }
1152 // temp = temp->GetMethodAt(method_offset);
1153 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001154 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001155 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001156 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001157 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001158 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001159 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001160 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001161}
1162
Roland Levillain88cb1752014-10-20 16:36:47 +01001163void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1164 LocationSummary* locations =
1165 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1166 switch (neg->GetResultType()) {
1167 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001168 case Primitive::kPrimLong: {
1169 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001170 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001171 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001172 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001173 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001174
Roland Levillain88cb1752014-10-20 16:36:47 +01001175 case Primitive::kPrimFloat:
1176 case Primitive::kPrimDouble:
1177 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1178 break;
1179
1180 default:
1181 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1182 }
1183}
1184
1185void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1186 LocationSummary* locations = neg->GetLocations();
1187 Location out = locations->Out();
1188 Location in = locations->InAt(0);
1189 switch (neg->GetResultType()) {
1190 case Primitive::kPrimInt:
1191 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001192 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001193 break;
1194
1195 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001196 DCHECK(in.IsRegisterPair());
1197 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1198 __ rsbs(out.AsRegisterPairLow<Register>(),
1199 in.AsRegisterPairLow<Register>(),
1200 ShifterOperand(0));
1201 // We cannot emit an RSC (Reverse Subtract with Carry)
1202 // instruction here, as it does not exist in the Thumb-2
1203 // instruction set. We use the following approach
1204 // using SBC and SUB instead.
1205 //
1206 // out.hi = -C
1207 __ sbc(out.AsRegisterPairHigh<Register>(),
1208 out.AsRegisterPairHigh<Register>(),
1209 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1210 // out.hi = out.hi - in.hi
1211 __ sub(out.AsRegisterPairHigh<Register>(),
1212 out.AsRegisterPairHigh<Register>(),
1213 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1214 break;
1215
Roland Levillain88cb1752014-10-20 16:36:47 +01001216 case Primitive::kPrimFloat:
1217 case Primitive::kPrimDouble:
1218 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1219 break;
1220
1221 default:
1222 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1223 }
1224}
1225
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001226void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001227 LocationSummary* locations =
1228 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001229 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001230 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001231 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001232 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1233 locations->SetInAt(0, Location::RequiresRegister());
1234 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1235 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001236 break;
1237 }
1238
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001239 case Primitive::kPrimFloat:
1240 case Primitive::kPrimDouble: {
1241 locations->SetInAt(0, Location::RequiresFpuRegister());
1242 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001243 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001244 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001245 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001246
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001247 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001248 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001249 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001250}
1251
1252void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1253 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001254 Location out = locations->Out();
1255 Location first = locations->InAt(0);
1256 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001257 switch (add->GetResultType()) {
1258 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001259 if (second.IsRegister()) {
1260 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001261 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001262 __ AddConstant(out.As<Register>(),
1263 first.As<Register>(),
1264 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001265 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001266 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001267
1268 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001269 __ adds(out.AsRegisterPairLow<Register>(),
1270 first.AsRegisterPairLow<Register>(),
1271 ShifterOperand(second.AsRegisterPairLow<Register>()));
1272 __ adc(out.AsRegisterPairHigh<Register>(),
1273 first.AsRegisterPairHigh<Register>(),
1274 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001275 break;
1276
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001277 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001278 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001279 break;
1280
1281 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001282 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1283 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1284 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001285 break;
1286
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001287 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001288 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001289 }
1290}
1291
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001292void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001293 LocationSummary* locations =
1294 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001295 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001296 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001297 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001298 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1299 locations->SetInAt(0, Location::RequiresRegister());
1300 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1301 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001302 break;
1303 }
Calin Juravle11351682014-10-23 15:38:15 +01001304 case Primitive::kPrimFloat:
1305 case Primitive::kPrimDouble: {
1306 locations->SetInAt(0, Location::RequiresFpuRegister());
1307 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001308 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001309 break;
Calin Juravle11351682014-10-23 15:38:15 +01001310 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001311 default:
Calin Juravle11351682014-10-23 15:38:15 +01001312 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001313 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001314}
1315
1316void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1317 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001318 Location out = locations->Out();
1319 Location first = locations->InAt(0);
1320 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001321 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001322 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001323 if (second.IsRegister()) {
1324 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001325 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001326 __ AddConstant(out.As<Register>(),
1327 first.As<Register>(),
1328 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001329 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001330 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001331 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001332
Calin Juravle11351682014-10-23 15:38:15 +01001333 case Primitive::kPrimLong: {
1334 __ subs(out.AsRegisterPairLow<Register>(),
1335 first.AsRegisterPairLow<Register>(),
1336 ShifterOperand(second.AsRegisterPairLow<Register>()));
1337 __ sbc(out.AsRegisterPairHigh<Register>(),
1338 first.AsRegisterPairHigh<Register>(),
1339 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001340 break;
Calin Juravle11351682014-10-23 15:38:15 +01001341 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001342
Calin Juravle11351682014-10-23 15:38:15 +01001343 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001344 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001345 break;
Calin Juravle11351682014-10-23 15:38:15 +01001346 }
1347
1348 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001349 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1350 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1351 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001352 break;
1353 }
1354
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001355
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001356 default:
Calin Juravle11351682014-10-23 15:38:15 +01001357 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001358 }
1359}
1360
Calin Juravle34bacdf2014-10-07 20:23:36 +01001361void LocationsBuilderARM::VisitMul(HMul* mul) {
1362 LocationSummary* locations =
1363 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1364 switch (mul->GetResultType()) {
1365 case Primitive::kPrimInt:
1366 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001367 locations->SetInAt(0, Location::RequiresRegister());
1368 locations->SetInAt(1, Location::RequiresRegister());
1369 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001370 break;
1371 }
1372
Calin Juravleb5bfa962014-10-21 18:02:24 +01001373 case Primitive::kPrimFloat:
1374 case Primitive::kPrimDouble: {
1375 locations->SetInAt(0, Location::RequiresFpuRegister());
1376 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001377 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001378 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001379 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001380
1381 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001382 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001383 }
1384}
1385
1386void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1387 LocationSummary* locations = mul->GetLocations();
1388 Location out = locations->Out();
1389 Location first = locations->InAt(0);
1390 Location second = locations->InAt(1);
1391 switch (mul->GetResultType()) {
1392 case Primitive::kPrimInt: {
1393 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1394 break;
1395 }
1396 case Primitive::kPrimLong: {
1397 Register out_hi = out.AsRegisterPairHigh<Register>();
1398 Register out_lo = out.AsRegisterPairLow<Register>();
1399 Register in1_hi = first.AsRegisterPairHigh<Register>();
1400 Register in1_lo = first.AsRegisterPairLow<Register>();
1401 Register in2_hi = second.AsRegisterPairHigh<Register>();
1402 Register in2_lo = second.AsRegisterPairLow<Register>();
1403
1404 // Extra checks to protect caused by the existence of R1_R2.
1405 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1406 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1407 DCHECK_NE(out_hi, in1_lo);
1408 DCHECK_NE(out_hi, in2_lo);
1409
1410 // input: in1 - 64 bits, in2 - 64 bits
1411 // output: out
1412 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1413 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1414 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1415
1416 // IP <- in1.lo * in2.hi
1417 __ mul(IP, in1_lo, in2_hi);
1418 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1419 __ mla(out_hi, in1_hi, in2_lo, IP);
1420 // out.lo <- (in1.lo * in2.lo)[31:0];
1421 __ umull(out_lo, IP, in1_lo, in2_lo);
1422 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1423 __ add(out_hi, out_hi, ShifterOperand(IP));
1424 break;
1425 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001426
1427 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001428 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001429 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001430 }
1431
1432 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001433 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1434 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1435 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001436 break;
1437 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001438
1439 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001440 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001441 }
1442}
1443
Calin Juravle7c4954d2014-10-28 16:57:40 +00001444void LocationsBuilderARM::VisitDiv(HDiv* div) {
1445 LocationSummary* locations =
1446 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1447 switch (div->GetResultType()) {
1448 case Primitive::kPrimInt:
1449 case Primitive::kPrimLong: {
1450 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1451 break;
1452 }
1453 case Primitive::kPrimFloat:
1454 case Primitive::kPrimDouble: {
1455 locations->SetInAt(0, Location::RequiresFpuRegister());
1456 locations->SetInAt(1, Location::RequiresFpuRegister());
1457 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1458 break;
1459 }
1460
1461 default:
1462 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1463 }
1464}
1465
1466void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1467 LocationSummary* locations = div->GetLocations();
1468 Location out = locations->Out();
1469 Location first = locations->InAt(0);
1470 Location second = locations->InAt(1);
1471
1472 switch (div->GetResultType()) {
1473 case Primitive::kPrimInt:
1474 case Primitive::kPrimLong: {
1475 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1476 break;
1477 }
1478
1479 case Primitive::kPrimFloat: {
1480 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1481 break;
1482 }
1483
1484 case Primitive::kPrimDouble: {
1485 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1486 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1487 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1488 break;
1489 }
1490
1491 default:
1492 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1493 }
1494}
1495
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001496void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001497 LocationSummary* locations =
1498 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001499 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001500 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1501 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1502 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001503}
1504
1505void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1506 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001507 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001508 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001509 codegen_->InvokeRuntime(
1510 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001511}
1512
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001513void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1514 LocationSummary* locations =
1515 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1516 InvokeRuntimeCallingConvention calling_convention;
1517 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1518 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1519 locations->SetOut(Location::RegisterLocation(R0));
1520 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1521}
1522
1523void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1524 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001525 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001526 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001527 codegen_->InvokeRuntime(
1528 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001529}
1530
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001531void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001532 LocationSummary* locations =
1533 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001534 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1535 if (location.IsStackSlot()) {
1536 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1537 } else if (location.IsDoubleStackSlot()) {
1538 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001539 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001540 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001541}
1542
1543void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001544 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001545 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001546}
1547
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001548void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001549 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001550 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001551 locations->SetInAt(0, Location::RequiresRegister());
1552 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001553}
1554
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001555void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1556 LocationSummary* locations = not_->GetLocations();
1557 Location out = locations->Out();
1558 Location in = locations->InAt(0);
1559 switch (not_->InputAt(0)->GetType()) {
1560 case Primitive::kPrimBoolean:
1561 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1562 break;
1563
1564 case Primitive::kPrimInt:
1565 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1566 break;
1567
1568 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001569 __ mvn(out.AsRegisterPairLow<Register>(),
1570 ShifterOperand(in.AsRegisterPairLow<Register>()));
1571 __ mvn(out.AsRegisterPairHigh<Register>(),
1572 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001573 break;
1574
1575 default:
1576 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1577 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001578}
1579
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001580void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001581 LocationSummary* locations =
1582 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001583 locations->SetInAt(0, Location::RequiresRegister());
1584 locations->SetInAt(1, Location::RequiresRegister());
1585 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001586}
1587
1588void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
1589 Label greater, done;
1590 LocationSummary* locations = compare->GetLocations();
1591 switch (compare->InputAt(0)->GetType()) {
1592 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001593 Register output = locations->Out().As<Register>();
1594 Location left = locations->InAt(0);
1595 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001596 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001597 __ cmp(left.AsRegisterPairHigh<Register>(),
1598 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001599 __ b(&less, LT);
1600 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001601 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1602 // the status flags.
1603 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001604 __ cmp(left.AsRegisterPairLow<Register>(),
1605 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001606 __ b(&done, EQ);
1607 __ b(&less, CC);
1608
1609 __ Bind(&greater);
1610 __ LoadImmediate(output, 1);
1611 __ b(&done);
1612
1613 __ Bind(&less);
1614 __ LoadImmediate(output, -1);
1615
1616 __ Bind(&done);
1617 break;
1618 }
1619 default:
1620 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1621 }
1622}
1623
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001624void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001625 LocationSummary* locations =
1626 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001627 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1628 locations->SetInAt(i, Location::Any());
1629 }
1630 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001631}
1632
1633void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001634 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001635 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001636}
1637
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001638void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001639 LocationSummary* locations =
1640 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001641 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001642 locations->SetInAt(0, Location::RequiresRegister());
1643 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001644 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001645 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001646 locations->AddTemp(Location::RequiresRegister());
1647 locations->AddTemp(Location::RequiresRegister());
1648 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001649}
1650
1651void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1652 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001653 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001654 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001655 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001656
1657 switch (field_type) {
1658 case Primitive::kPrimBoolean:
1659 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001660 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001661 __ StoreToOffset(kStoreByte, value, obj, offset);
1662 break;
1663 }
1664
1665 case Primitive::kPrimShort:
1666 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001667 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001668 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1669 break;
1670 }
1671
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001672 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001673 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001674 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001675 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001676 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001677 Register temp = locations->GetTemp(0).As<Register>();
1678 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001679 codegen_->MarkGCCard(temp, card, obj, value);
1680 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001681 break;
1682 }
1683
1684 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001685 Location value = locations->InAt(1);
1686 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001687 break;
1688 }
1689
1690 case Primitive::kPrimFloat:
1691 case Primitive::kPrimDouble:
1692 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001693 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001694 case Primitive::kPrimVoid:
1695 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001696 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001697 }
1698}
1699
1700void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001701 LocationSummary* locations =
1702 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001703 locations->SetInAt(0, Location::RequiresRegister());
1704 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001705}
1706
1707void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1708 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001709 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001710 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1711
1712 switch (instruction->GetType()) {
1713 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001714 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001715 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1716 break;
1717 }
1718
1719 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001720 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001721 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1722 break;
1723 }
1724
1725 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001726 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001727 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1728 break;
1729 }
1730
1731 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001732 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001733 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1734 break;
1735 }
1736
1737 case Primitive::kPrimInt:
1738 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001739 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001740 __ LoadFromOffset(kLoadWord, out, obj, offset);
1741 break;
1742 }
1743
1744 case Primitive::kPrimLong: {
1745 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001746 Location out = locations->Out();
1747 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001748 break;
1749 }
1750
1751 case Primitive::kPrimFloat:
1752 case Primitive::kPrimDouble:
1753 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001754 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001755 case Primitive::kPrimVoid:
1756 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001757 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001758 }
1759}
1760
1761void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001762 LocationSummary* locations =
1763 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001764 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001765 if (instruction->HasUses()) {
1766 locations->SetOut(Location::SameAsFirstInput());
1767 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001768}
1769
1770void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001771 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001772 codegen_->AddSlowPath(slow_path);
1773
1774 LocationSummary* locations = instruction->GetLocations();
1775 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001776
1777 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001778 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001779 __ b(slow_path->GetEntryLabel(), EQ);
1780 } else {
1781 DCHECK(obj.IsConstant()) << obj;
1782 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1783 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001784 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001785}
1786
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001787void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001788 LocationSummary* locations =
1789 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001790 locations->SetInAt(0, Location::RequiresRegister());
1791 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1792 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001793}
1794
1795void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1796 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001797 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001798 Location index = locations->InAt(1);
1799
1800 switch (instruction->GetType()) {
1801 case Primitive::kPrimBoolean: {
1802 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001803 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001804 if (index.IsConstant()) {
1805 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1806 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1807 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001808 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001809 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1810 }
1811 break;
1812 }
1813
1814 case Primitive::kPrimByte: {
1815 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001816 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001817 if (index.IsConstant()) {
1818 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1819 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1820 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001821 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001822 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1823 }
1824 break;
1825 }
1826
1827 case Primitive::kPrimShort: {
1828 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001829 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001830 if (index.IsConstant()) {
1831 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1832 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1833 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001834 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001835 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1836 }
1837 break;
1838 }
1839
1840 case Primitive::kPrimChar: {
1841 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001842 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001843 if (index.IsConstant()) {
1844 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1845 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1846 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001847 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001848 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1849 }
1850 break;
1851 }
1852
1853 case Primitive::kPrimInt:
1854 case Primitive::kPrimNot: {
1855 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1856 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001857 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001858 if (index.IsConstant()) {
1859 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1860 __ LoadFromOffset(kLoadWord, out, obj, offset);
1861 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001862 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001863 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1864 }
1865 break;
1866 }
1867
1868 case Primitive::kPrimLong: {
1869 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001870 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001871 if (index.IsConstant()) {
1872 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001873 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001874 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001875 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1876 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001877 }
1878 break;
1879 }
1880
1881 case Primitive::kPrimFloat:
1882 case Primitive::kPrimDouble:
1883 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001884 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001885 case Primitive::kPrimVoid:
1886 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001887 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001888 }
1889}
1890
1891void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001892 Primitive::Type value_type = instruction->GetComponentType();
1893 bool is_object = value_type == Primitive::kPrimNot;
1894 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1895 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1896 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001897 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001898 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1899 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1900 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001901 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001902 locations->SetInAt(0, Location::RequiresRegister());
1903 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1904 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001905 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001906}
1907
1908void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1909 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001910 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001911 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001912 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001913
1914 switch (value_type) {
1915 case Primitive::kPrimBoolean:
1916 case Primitive::kPrimByte: {
1917 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001918 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001919 if (index.IsConstant()) {
1920 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1921 __ StoreToOffset(kStoreByte, value, obj, offset);
1922 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001923 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001924 __ StoreToOffset(kStoreByte, value, IP, data_offset);
1925 }
1926 break;
1927 }
1928
1929 case Primitive::kPrimShort:
1930 case Primitive::kPrimChar: {
1931 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001932 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001933 if (index.IsConstant()) {
1934 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1935 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1936 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001937 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001938 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
1939 }
1940 break;
1941 }
1942
1943 case Primitive::kPrimInt: {
1944 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001945 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001946 if (index.IsConstant()) {
1947 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1948 __ StoreToOffset(kStoreWord, value, obj, offset);
1949 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001950 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001951 __ StoreToOffset(kStoreWord, value, IP, data_offset);
1952 }
1953 break;
1954 }
1955
1956 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001957 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001958 break;
1959 }
1960
1961 case Primitive::kPrimLong: {
1962 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001963 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001964 if (index.IsConstant()) {
1965 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001966 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001967 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001968 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1969 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001970 }
1971 break;
1972 }
1973
1974 case Primitive::kPrimFloat:
1975 case Primitive::kPrimDouble:
1976 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001977 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001978 case Primitive::kPrimVoid:
1979 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001980 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001981 }
1982}
1983
1984void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001985 LocationSummary* locations =
1986 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001987 locations->SetInAt(0, Location::RequiresRegister());
1988 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001989}
1990
1991void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
1992 LocationSummary* locations = instruction->GetLocations();
1993 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001994 Register obj = locations->InAt(0).As<Register>();
1995 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001996 __ LoadFromOffset(kLoadWord, out, obj, offset);
1997}
1998
1999void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002000 LocationSummary* locations =
2001 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002002 locations->SetInAt(0, Location::RequiresRegister());
2003 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002004 if (instruction->HasUses()) {
2005 locations->SetOut(Location::SameAsFirstInput());
2006 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002007}
2008
2009void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2010 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002011 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002012 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002013 codegen_->AddSlowPath(slow_path);
2014
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002015 Register index = locations->InAt(0).As<Register>();
2016 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002017
2018 __ cmp(index, ShifterOperand(length));
2019 __ b(slow_path->GetEntryLabel(), CS);
2020}
2021
2022void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2023 Label is_null;
2024 __ CompareAndBranchIfZero(value, &is_null);
2025 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2026 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2027 __ strb(card, Address(card, temp));
2028 __ Bind(&is_null);
2029}
2030
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002031void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2032 temp->SetLocations(nullptr);
2033}
2034
2035void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2036 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002037 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002038}
2039
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002040void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002041 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002042 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002043}
2044
2045void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002046 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2047}
2048
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002049void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2050 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2051}
2052
2053void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002054 HBasicBlock* block = instruction->GetBlock();
2055 if (block->GetLoopInformation() != nullptr) {
2056 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2057 // The back edge will generate the suspend check.
2058 return;
2059 }
2060 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2061 // The goto will generate the suspend check.
2062 return;
2063 }
2064 GenerateSuspendCheck(instruction, nullptr);
2065}
2066
2067void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2068 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002069 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002070 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002071 codegen_->AddSlowPath(slow_path);
2072
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002073 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002074 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002075 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002076 __ Bind(slow_path->GetReturnLabel());
2077 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002078 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002079 __ b(slow_path->GetEntryLabel());
2080 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002081}
2082
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002083ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2084 return codegen_->GetAssembler();
2085}
2086
2087void ParallelMoveResolverARM::EmitMove(size_t index) {
2088 MoveOperands* move = moves_.Get(index);
2089 Location source = move->GetSource();
2090 Location destination = move->GetDestination();
2091
2092 if (source.IsRegister()) {
2093 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002094 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002095 } else {
2096 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002097 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002098 SP, destination.GetStackIndex());
2099 }
2100 } else if (source.IsStackSlot()) {
2101 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002102 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002103 SP, source.GetStackIndex());
2104 } else {
2105 DCHECK(destination.IsStackSlot());
2106 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2107 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2108 }
2109 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002110 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002111 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002112 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2113 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002114 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002115 } else {
2116 DCHECK(destination.IsStackSlot());
2117 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002118 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002119 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002120 }
2121}
2122
2123void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2124 __ Mov(IP, reg);
2125 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2126 __ StoreToOffset(kStoreWord, IP, SP, mem);
2127}
2128
2129void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2130 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2131 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2132 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2133 SP, mem1 + stack_offset);
2134 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2135 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2136 SP, mem2 + stack_offset);
2137 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2138}
2139
2140void ParallelMoveResolverARM::EmitSwap(size_t index) {
2141 MoveOperands* move = moves_.Get(index);
2142 Location source = move->GetSource();
2143 Location destination = move->GetDestination();
2144
2145 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002146 DCHECK_NE(source.As<Register>(), IP);
2147 DCHECK_NE(destination.As<Register>(), IP);
2148 __ Mov(IP, source.As<Register>());
2149 __ Mov(source.As<Register>(), destination.As<Register>());
2150 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002151 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002152 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002153 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002154 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002155 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2156 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2157 } else {
2158 LOG(FATAL) << "Unimplemented";
2159 }
2160}
2161
2162void ParallelMoveResolverARM::SpillScratch(int reg) {
2163 __ Push(static_cast<Register>(reg));
2164}
2165
2166void ParallelMoveResolverARM::RestoreScratch(int reg) {
2167 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002168}
2169
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002170void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002171 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2172 ? LocationSummary::kCallOnSlowPath
2173 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002174 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002175 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002176 locations->SetOut(Location::RequiresRegister());
2177}
2178
2179void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2180 Register out = cls->GetLocations()->Out().As<Register>();
2181 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002182 DCHECK(!cls->CanCallRuntime());
2183 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002184 codegen_->LoadCurrentMethod(out);
2185 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2186 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002187 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002188 codegen_->LoadCurrentMethod(out);
2189 __ LoadFromOffset(
2190 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2191 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002192
2193 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2194 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2195 codegen_->AddSlowPath(slow_path);
2196 __ cmp(out, ShifterOperand(0));
2197 __ b(slow_path->GetEntryLabel(), EQ);
2198 if (cls->MustGenerateClinitCheck()) {
2199 GenerateClassInitializationCheck(slow_path, out);
2200 } else {
2201 __ Bind(slow_path->GetExitLabel());
2202 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002203 }
2204}
2205
2206void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2207 LocationSummary* locations =
2208 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2209 locations->SetInAt(0, Location::RequiresRegister());
2210 if (check->HasUses()) {
2211 locations->SetOut(Location::SameAsFirstInput());
2212 }
2213}
2214
2215void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002216 // We assume the class is not null.
2217 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2218 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002219 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002220 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2221}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002222
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002223void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2224 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002225 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2226 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2227 __ b(slow_path->GetEntryLabel(), LT);
2228 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2229 // properly. Therefore, we do a memory fence.
2230 __ dmb(ISH);
2231 __ Bind(slow_path->GetExitLabel());
2232}
2233
2234void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2235 LocationSummary* locations =
2236 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2237 locations->SetInAt(0, Location::RequiresRegister());
2238 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2239}
2240
2241void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2242 LocationSummary* locations = instruction->GetLocations();
2243 Register cls = locations->InAt(0).As<Register>();
2244 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2245
2246 switch (instruction->GetType()) {
2247 case Primitive::kPrimBoolean: {
2248 Register out = locations->Out().As<Register>();
2249 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2250 break;
2251 }
2252
2253 case Primitive::kPrimByte: {
2254 Register out = locations->Out().As<Register>();
2255 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2256 break;
2257 }
2258
2259 case Primitive::kPrimShort: {
2260 Register out = locations->Out().As<Register>();
2261 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2262 break;
2263 }
2264
2265 case Primitive::kPrimChar: {
2266 Register out = locations->Out().As<Register>();
2267 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2268 break;
2269 }
2270
2271 case Primitive::kPrimInt:
2272 case Primitive::kPrimNot: {
2273 Register out = locations->Out().As<Register>();
2274 __ LoadFromOffset(kLoadWord, out, cls, offset);
2275 break;
2276 }
2277
2278 case Primitive::kPrimLong: {
2279 // TODO: support volatile.
2280 Location out = locations->Out();
2281 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2282 break;
2283 }
2284
2285 case Primitive::kPrimFloat:
2286 case Primitive::kPrimDouble:
2287 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2288 UNREACHABLE();
2289 case Primitive::kPrimVoid:
2290 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2291 UNREACHABLE();
2292 }
2293}
2294
2295void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2296 LocationSummary* locations =
2297 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2298 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2299 locations->SetInAt(0, Location::RequiresRegister());
2300 locations->SetInAt(1, Location::RequiresRegister());
2301 // Temporary registers for the write barrier.
2302 if (is_object_type) {
2303 locations->AddTemp(Location::RequiresRegister());
2304 locations->AddTemp(Location::RequiresRegister());
2305 }
2306}
2307
2308void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2309 LocationSummary* locations = instruction->GetLocations();
2310 Register cls = locations->InAt(0).As<Register>();
2311 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2312 Primitive::Type field_type = instruction->GetFieldType();
2313
2314 switch (field_type) {
2315 case Primitive::kPrimBoolean:
2316 case Primitive::kPrimByte: {
2317 Register value = locations->InAt(1).As<Register>();
2318 __ StoreToOffset(kStoreByte, value, cls, offset);
2319 break;
2320 }
2321
2322 case Primitive::kPrimShort:
2323 case Primitive::kPrimChar: {
2324 Register value = locations->InAt(1).As<Register>();
2325 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2326 break;
2327 }
2328
2329 case Primitive::kPrimInt:
2330 case Primitive::kPrimNot: {
2331 Register value = locations->InAt(1).As<Register>();
2332 __ StoreToOffset(kStoreWord, value, cls, offset);
2333 if (field_type == Primitive::kPrimNot) {
2334 Register temp = locations->GetTemp(0).As<Register>();
2335 Register card = locations->GetTemp(1).As<Register>();
2336 codegen_->MarkGCCard(temp, card, cls, value);
2337 }
2338 break;
2339 }
2340
2341 case Primitive::kPrimLong: {
2342 Location value = locations->InAt(1);
2343 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2344 break;
2345 }
2346
2347 case Primitive::kPrimFloat:
2348 case Primitive::kPrimDouble:
2349 LOG(FATAL) << "Unimplemented register type " << field_type;
2350 UNREACHABLE();
2351 case Primitive::kPrimVoid:
2352 LOG(FATAL) << "Unreachable type " << field_type;
2353 UNREACHABLE();
2354 }
2355}
2356
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002357void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2358 LocationSummary* locations =
2359 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2360 locations->SetOut(Location::RequiresRegister());
2361}
2362
2363void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2364 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2365 codegen_->AddSlowPath(slow_path);
2366
2367 Register out = load->GetLocations()->Out().As<Register>();
2368 codegen_->LoadCurrentMethod(out);
2369 __ LoadFromOffset(
2370 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2371 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2372 __ cmp(out, ShifterOperand(0));
2373 __ b(slow_path->GetEntryLabel(), EQ);
2374 __ Bind(slow_path->GetExitLabel());
2375}
2376
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002377} // namespace arm
2378} // namespace art