blob: 39e564a7c4b9f993dfd22cdc0b78bdc339caa325 [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
Roland Levillaindff1f282014-11-05 14:15:05 +00001226void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1227 LocationSummary* locations =
1228 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1229 Primitive::Type result_type = conversion->GetResultType();
1230 Primitive::Type input_type = conversion->GetInputType();
1231 switch (result_type) {
1232 case Primitive::kPrimLong:
1233 switch (input_type) {
1234 case Primitive::kPrimByte:
1235 case Primitive::kPrimShort:
1236 case Primitive::kPrimInt:
1237 // int-to-long conversion.
1238 locations->SetInAt(0, Location::RequiresRegister());
1239 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1240 break;
1241
1242 case Primitive::kPrimFloat:
1243 case Primitive::kPrimDouble:
1244 LOG(FATAL) << "Type conversion from " << input_type << " to "
1245 << result_type << " not yet implemented";
1246 break;
1247
1248 default:
1249 LOG(FATAL) << "Unexpected type conversion from " << input_type
1250 << " to " << result_type;
1251 }
1252 break;
1253
1254 case Primitive::kPrimInt:
1255 case Primitive::kPrimFloat:
1256 case Primitive::kPrimDouble:
1257 LOG(FATAL) << "Type conversion from " << input_type
1258 << " to " << result_type << " not yet implemented";
1259 break;
1260
1261 default:
1262 LOG(FATAL) << "Unexpected type conversion from " << input_type
1263 << " to " << result_type;
1264 }
1265}
1266
1267void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1268 LocationSummary* locations = conversion->GetLocations();
1269 Location out = locations->Out();
1270 Location in = locations->InAt(0);
1271 Primitive::Type result_type = conversion->GetResultType();
1272 Primitive::Type input_type = conversion->GetInputType();
1273 switch (result_type) {
1274 case Primitive::kPrimLong:
1275 switch (input_type) {
1276 case Primitive::kPrimByte:
1277 case Primitive::kPrimShort:
1278 case Primitive::kPrimInt:
1279 // int-to-long conversion.
1280 DCHECK(out.IsRegisterPair());
1281 DCHECK(in.IsRegister());
1282 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1283 // Sign extension.
1284 __ Asr(out.AsRegisterPairHigh<Register>(),
1285 out.AsRegisterPairLow<Register>(),
1286 31);
1287 break;
1288
1289 case Primitive::kPrimFloat:
1290 case Primitive::kPrimDouble:
1291 LOG(FATAL) << "Type conversion from " << input_type << " to "
1292 << result_type << " not yet implemented";
1293 break;
1294
1295 default:
1296 LOG(FATAL) << "Unexpected type conversion from " << input_type
1297 << " to " << result_type;
1298 }
1299 break;
1300
1301 case Primitive::kPrimInt:
1302 case Primitive::kPrimFloat:
1303 case Primitive::kPrimDouble:
1304 LOG(FATAL) << "Type conversion from " << input_type
1305 << " to " << result_type << " not yet implemented";
1306 break;
1307
1308 default:
1309 LOG(FATAL) << "Unexpected type conversion from " << input_type
1310 << " to " << result_type;
1311 }
1312}
1313
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001314void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001315 LocationSummary* locations =
1316 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001317 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001318 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001319 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001320 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1321 locations->SetInAt(0, Location::RequiresRegister());
1322 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1323 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001324 break;
1325 }
1326
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001327 case Primitive::kPrimFloat:
1328 case Primitive::kPrimDouble: {
1329 locations->SetInAt(0, Location::RequiresFpuRegister());
1330 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001331 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001332 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001333 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001334
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001335 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001336 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001337 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001338}
1339
1340void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1341 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001342 Location out = locations->Out();
1343 Location first = locations->InAt(0);
1344 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001345 switch (add->GetResultType()) {
1346 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001347 if (second.IsRegister()) {
1348 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001349 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001350 __ AddConstant(out.As<Register>(),
1351 first.As<Register>(),
1352 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001353 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001354 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001355
1356 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001357 __ adds(out.AsRegisterPairLow<Register>(),
1358 first.AsRegisterPairLow<Register>(),
1359 ShifterOperand(second.AsRegisterPairLow<Register>()));
1360 __ adc(out.AsRegisterPairHigh<Register>(),
1361 first.AsRegisterPairHigh<Register>(),
1362 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001363 break;
1364
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001365 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001366 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001367 break;
1368
1369 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001370 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1371 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1372 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001373 break;
1374
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001375 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001376 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001377 }
1378}
1379
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001380void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001381 LocationSummary* locations =
1382 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001383 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001384 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001385 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001386 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1387 locations->SetInAt(0, Location::RequiresRegister());
1388 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1389 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001390 break;
1391 }
Calin Juravle11351682014-10-23 15:38:15 +01001392 case Primitive::kPrimFloat:
1393 case Primitive::kPrimDouble: {
1394 locations->SetInAt(0, Location::RequiresFpuRegister());
1395 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001396 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001397 break;
Calin Juravle11351682014-10-23 15:38:15 +01001398 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001399 default:
Calin Juravle11351682014-10-23 15:38:15 +01001400 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001401 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001402}
1403
1404void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1405 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001406 Location out = locations->Out();
1407 Location first = locations->InAt(0);
1408 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001409 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001410 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001411 if (second.IsRegister()) {
1412 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001413 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001414 __ AddConstant(out.As<Register>(),
1415 first.As<Register>(),
1416 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001417 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001418 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001419 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001420
Calin Juravle11351682014-10-23 15:38:15 +01001421 case Primitive::kPrimLong: {
1422 __ subs(out.AsRegisterPairLow<Register>(),
1423 first.AsRegisterPairLow<Register>(),
1424 ShifterOperand(second.AsRegisterPairLow<Register>()));
1425 __ sbc(out.AsRegisterPairHigh<Register>(),
1426 first.AsRegisterPairHigh<Register>(),
1427 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001428 break;
Calin Juravle11351682014-10-23 15:38:15 +01001429 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001430
Calin Juravle11351682014-10-23 15:38:15 +01001431 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001432 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001433 break;
Calin Juravle11351682014-10-23 15:38:15 +01001434 }
1435
1436 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001437 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1438 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1439 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001440 break;
1441 }
1442
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001443
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001444 default:
Calin Juravle11351682014-10-23 15:38:15 +01001445 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001446 }
1447}
1448
Calin Juravle34bacdf2014-10-07 20:23:36 +01001449void LocationsBuilderARM::VisitMul(HMul* mul) {
1450 LocationSummary* locations =
1451 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1452 switch (mul->GetResultType()) {
1453 case Primitive::kPrimInt:
1454 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001455 locations->SetInAt(0, Location::RequiresRegister());
1456 locations->SetInAt(1, Location::RequiresRegister());
1457 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001458 break;
1459 }
1460
Calin Juravleb5bfa962014-10-21 18:02:24 +01001461 case Primitive::kPrimFloat:
1462 case Primitive::kPrimDouble: {
1463 locations->SetInAt(0, Location::RequiresFpuRegister());
1464 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001465 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001466 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001467 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001468
1469 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001470 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001471 }
1472}
1473
1474void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1475 LocationSummary* locations = mul->GetLocations();
1476 Location out = locations->Out();
1477 Location first = locations->InAt(0);
1478 Location second = locations->InAt(1);
1479 switch (mul->GetResultType()) {
1480 case Primitive::kPrimInt: {
1481 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1482 break;
1483 }
1484 case Primitive::kPrimLong: {
1485 Register out_hi = out.AsRegisterPairHigh<Register>();
1486 Register out_lo = out.AsRegisterPairLow<Register>();
1487 Register in1_hi = first.AsRegisterPairHigh<Register>();
1488 Register in1_lo = first.AsRegisterPairLow<Register>();
1489 Register in2_hi = second.AsRegisterPairHigh<Register>();
1490 Register in2_lo = second.AsRegisterPairLow<Register>();
1491
1492 // Extra checks to protect caused by the existence of R1_R2.
1493 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1494 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1495 DCHECK_NE(out_hi, in1_lo);
1496 DCHECK_NE(out_hi, in2_lo);
1497
1498 // input: in1 - 64 bits, in2 - 64 bits
1499 // output: out
1500 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1501 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1502 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1503
1504 // IP <- in1.lo * in2.hi
1505 __ mul(IP, in1_lo, in2_hi);
1506 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1507 __ mla(out_hi, in1_hi, in2_lo, IP);
1508 // out.lo <- (in1.lo * in2.lo)[31:0];
1509 __ umull(out_lo, IP, in1_lo, in2_lo);
1510 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1511 __ add(out_hi, out_hi, ShifterOperand(IP));
1512 break;
1513 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001514
1515 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001516 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001517 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001518 }
1519
1520 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001521 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1522 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1523 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001524 break;
1525 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001526
1527 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001528 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001529 }
1530}
1531
Calin Juravle7c4954d2014-10-28 16:57:40 +00001532void LocationsBuilderARM::VisitDiv(HDiv* div) {
1533 LocationSummary* locations =
1534 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1535 switch (div->GetResultType()) {
1536 case Primitive::kPrimInt:
1537 case Primitive::kPrimLong: {
1538 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1539 break;
1540 }
1541 case Primitive::kPrimFloat:
1542 case Primitive::kPrimDouble: {
1543 locations->SetInAt(0, Location::RequiresFpuRegister());
1544 locations->SetInAt(1, Location::RequiresFpuRegister());
1545 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1546 break;
1547 }
1548
1549 default:
1550 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1551 }
1552}
1553
1554void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1555 LocationSummary* locations = div->GetLocations();
1556 Location out = locations->Out();
1557 Location first = locations->InAt(0);
1558 Location second = locations->InAt(1);
1559
1560 switch (div->GetResultType()) {
1561 case Primitive::kPrimInt:
1562 case Primitive::kPrimLong: {
1563 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1564 break;
1565 }
1566
1567 case Primitive::kPrimFloat: {
1568 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1569 break;
1570 }
1571
1572 case Primitive::kPrimDouble: {
1573 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1574 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1575 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1576 break;
1577 }
1578
1579 default:
1580 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1581 }
1582}
1583
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001584void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001585 LocationSummary* locations =
1586 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001587 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001588 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1589 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1590 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001591}
1592
1593void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1594 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001595 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001596 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001597 codegen_->InvokeRuntime(
1598 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001599}
1600
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001601void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1602 LocationSummary* locations =
1603 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1604 InvokeRuntimeCallingConvention calling_convention;
1605 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1606 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1607 locations->SetOut(Location::RegisterLocation(R0));
1608 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1609}
1610
1611void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1612 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001613 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001614 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001615 codegen_->InvokeRuntime(
1616 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001617}
1618
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001619void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001620 LocationSummary* locations =
1621 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001622 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1623 if (location.IsStackSlot()) {
1624 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1625 } else if (location.IsDoubleStackSlot()) {
1626 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001627 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001628 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001629}
1630
1631void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001632 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001633 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001634}
1635
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001636void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001637 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001638 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001639 locations->SetInAt(0, Location::RequiresRegister());
1640 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001641}
1642
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001643void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1644 LocationSummary* locations = not_->GetLocations();
1645 Location out = locations->Out();
1646 Location in = locations->InAt(0);
1647 switch (not_->InputAt(0)->GetType()) {
1648 case Primitive::kPrimBoolean:
1649 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1650 break;
1651
1652 case Primitive::kPrimInt:
1653 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1654 break;
1655
1656 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001657 __ mvn(out.AsRegisterPairLow<Register>(),
1658 ShifterOperand(in.AsRegisterPairLow<Register>()));
1659 __ mvn(out.AsRegisterPairHigh<Register>(),
1660 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001661 break;
1662
1663 default:
1664 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1665 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001666}
1667
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001668void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001669 LocationSummary* locations =
1670 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001671 locations->SetInAt(0, Location::RequiresRegister());
1672 locations->SetInAt(1, Location::RequiresRegister());
1673 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001674}
1675
1676void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001677 LocationSummary* locations = compare->GetLocations();
1678 switch (compare->InputAt(0)->GetType()) {
1679 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001680 Register output = locations->Out().As<Register>();
1681 Location left = locations->InAt(0);
1682 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001683 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001684 __ cmp(left.AsRegisterPairHigh<Register>(),
1685 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001686 __ b(&less, LT);
1687 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001688 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1689 // the status flags.
1690 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001691 __ cmp(left.AsRegisterPairLow<Register>(),
1692 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001693 __ b(&done, EQ);
1694 __ b(&less, CC);
1695
1696 __ Bind(&greater);
1697 __ LoadImmediate(output, 1);
1698 __ b(&done);
1699
1700 __ Bind(&less);
1701 __ LoadImmediate(output, -1);
1702
1703 __ Bind(&done);
1704 break;
1705 }
1706 default:
1707 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1708 }
1709}
1710
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001711void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001712 LocationSummary* locations =
1713 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001714 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1715 locations->SetInAt(i, Location::Any());
1716 }
1717 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001718}
1719
1720void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001721 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001722 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001723}
1724
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001725void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001726 LocationSummary* locations =
1727 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001728 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001729 locations->SetInAt(0, Location::RequiresRegister());
1730 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001731 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001732 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001733 locations->AddTemp(Location::RequiresRegister());
1734 locations->AddTemp(Location::RequiresRegister());
1735 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001736}
1737
1738void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1739 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001740 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001741 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001742 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001743
1744 switch (field_type) {
1745 case Primitive::kPrimBoolean:
1746 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001747 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001748 __ StoreToOffset(kStoreByte, value, obj, offset);
1749 break;
1750 }
1751
1752 case Primitive::kPrimShort:
1753 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001754 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001755 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1756 break;
1757 }
1758
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001759 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001760 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001761 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001762 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001763 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001764 Register temp = locations->GetTemp(0).As<Register>();
1765 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001766 codegen_->MarkGCCard(temp, card, obj, value);
1767 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001768 break;
1769 }
1770
1771 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001772 Location value = locations->InAt(1);
1773 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001774 break;
1775 }
1776
1777 case Primitive::kPrimFloat:
1778 case Primitive::kPrimDouble:
1779 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001780 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001781 case Primitive::kPrimVoid:
1782 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001783 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001784 }
1785}
1786
1787void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* 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->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001792}
1793
1794void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1795 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001796 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001797 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1798
1799 switch (instruction->GetType()) {
1800 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001801 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001802 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1803 break;
1804 }
1805
1806 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001807 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001808 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1809 break;
1810 }
1811
1812 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001813 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001814 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1815 break;
1816 }
1817
1818 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001819 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001820 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1821 break;
1822 }
1823
1824 case Primitive::kPrimInt:
1825 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001826 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001827 __ LoadFromOffset(kLoadWord, out, obj, offset);
1828 break;
1829 }
1830
1831 case Primitive::kPrimLong: {
1832 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001833 Location out = locations->Out();
1834 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001835 break;
1836 }
1837
1838 case Primitive::kPrimFloat:
1839 case Primitive::kPrimDouble:
1840 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001841 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001842 case Primitive::kPrimVoid:
1843 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001844 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001845 }
1846}
1847
1848void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001849 LocationSummary* locations =
1850 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001851 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001852 if (instruction->HasUses()) {
1853 locations->SetOut(Location::SameAsFirstInput());
1854 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001855}
1856
1857void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001858 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001859 codegen_->AddSlowPath(slow_path);
1860
1861 LocationSummary* locations = instruction->GetLocations();
1862 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001863
1864 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001865 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001866 __ b(slow_path->GetEntryLabel(), EQ);
1867 } else {
1868 DCHECK(obj.IsConstant()) << obj;
1869 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1870 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001871 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001872}
1873
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001874void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001875 LocationSummary* locations =
1876 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001877 locations->SetInAt(0, Location::RequiresRegister());
1878 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1879 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001880}
1881
1882void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
1883 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001884 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001885 Location index = locations->InAt(1);
1886
1887 switch (instruction->GetType()) {
1888 case Primitive::kPrimBoolean: {
1889 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001890 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001891 if (index.IsConstant()) {
1892 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1893 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1894 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001895 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001896 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
1897 }
1898 break;
1899 }
1900
1901 case Primitive::kPrimByte: {
1902 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001903 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001904 if (index.IsConstant()) {
1905 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
1906 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1907 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001908 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001909 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
1910 }
1911 break;
1912 }
1913
1914 case Primitive::kPrimShort: {
1915 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001916 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001917 if (index.IsConstant()) {
1918 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1919 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1920 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001921 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001922 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
1923 }
1924 break;
1925 }
1926
1927 case Primitive::kPrimChar: {
1928 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001929 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001930 if (index.IsConstant()) {
1931 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
1932 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1933 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001934 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001935 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
1936 }
1937 break;
1938 }
1939
1940 case Primitive::kPrimInt:
1941 case Primitive::kPrimNot: {
1942 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1943 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001944 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001945 if (index.IsConstant()) {
1946 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
1947 __ LoadFromOffset(kLoadWord, out, obj, offset);
1948 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001949 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001950 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
1951 }
1952 break;
1953 }
1954
1955 case Primitive::kPrimLong: {
1956 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001957 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001958 if (index.IsConstant()) {
1959 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001960 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001961 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001962 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
1963 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001964 }
1965 break;
1966 }
1967
1968 case Primitive::kPrimFloat:
1969 case Primitive::kPrimDouble:
1970 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001971 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001972 case Primitive::kPrimVoid:
1973 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001974 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001975 }
1976}
1977
1978void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001979 Primitive::Type value_type = instruction->GetComponentType();
1980 bool is_object = value_type == Primitive::kPrimNot;
1981 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1982 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1983 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001984 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001985 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1986 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1987 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001988 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001989 locations->SetInAt(0, Location::RequiresRegister());
1990 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1991 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001992 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001993}
1994
1995void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
1996 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001997 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001998 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001999 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002000
2001 switch (value_type) {
2002 case Primitive::kPrimBoolean:
2003 case Primitive::kPrimByte: {
2004 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002005 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002006 if (index.IsConstant()) {
2007 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2008 __ StoreToOffset(kStoreByte, value, obj, offset);
2009 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002010 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002011 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2012 }
2013 break;
2014 }
2015
2016 case Primitive::kPrimShort:
2017 case Primitive::kPrimChar: {
2018 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002019 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002020 if (index.IsConstant()) {
2021 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2022 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2023 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002024 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002025 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2026 }
2027 break;
2028 }
2029
2030 case Primitive::kPrimInt: {
2031 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002032 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002033 if (index.IsConstant()) {
2034 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2035 __ StoreToOffset(kStoreWord, value, obj, offset);
2036 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002037 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002038 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2039 }
2040 break;
2041 }
2042
2043 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002044 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002045 break;
2046 }
2047
2048 case Primitive::kPrimLong: {
2049 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002050 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002051 if (index.IsConstant()) {
2052 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002053 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002054 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002055 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2056 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002057 }
2058 break;
2059 }
2060
2061 case Primitive::kPrimFloat:
2062 case Primitive::kPrimDouble:
2063 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002064 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002065 case Primitive::kPrimVoid:
2066 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002067 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002068 }
2069}
2070
2071void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002072 LocationSummary* locations =
2073 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002074 locations->SetInAt(0, Location::RequiresRegister());
2075 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002076}
2077
2078void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2079 LocationSummary* locations = instruction->GetLocations();
2080 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002081 Register obj = locations->InAt(0).As<Register>();
2082 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002083 __ LoadFromOffset(kLoadWord, out, obj, offset);
2084}
2085
2086void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002087 LocationSummary* locations =
2088 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002089 locations->SetInAt(0, Location::RequiresRegister());
2090 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002091 if (instruction->HasUses()) {
2092 locations->SetOut(Location::SameAsFirstInput());
2093 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002094}
2095
2096void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2097 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002098 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002099 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002100 codegen_->AddSlowPath(slow_path);
2101
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002102 Register index = locations->InAt(0).As<Register>();
2103 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002104
2105 __ cmp(index, ShifterOperand(length));
2106 __ b(slow_path->GetEntryLabel(), CS);
2107}
2108
2109void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2110 Label is_null;
2111 __ CompareAndBranchIfZero(value, &is_null);
2112 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2113 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2114 __ strb(card, Address(card, temp));
2115 __ Bind(&is_null);
2116}
2117
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002118void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2119 temp->SetLocations(nullptr);
2120}
2121
2122void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2123 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002124 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002125}
2126
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002127void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002128 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002129 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002130}
2131
2132void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002133 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2134}
2135
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002136void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2137 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2138}
2139
2140void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002141 HBasicBlock* block = instruction->GetBlock();
2142 if (block->GetLoopInformation() != nullptr) {
2143 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2144 // The back edge will generate the suspend check.
2145 return;
2146 }
2147 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2148 // The goto will generate the suspend check.
2149 return;
2150 }
2151 GenerateSuspendCheck(instruction, nullptr);
2152}
2153
2154void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2155 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002156 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002157 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002158 codegen_->AddSlowPath(slow_path);
2159
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002160 __ subs(R4, R4, ShifterOperand(1));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002161 if (successor == nullptr) {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002162 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002163 __ Bind(slow_path->GetReturnLabel());
2164 } else {
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002165 __ b(codegen_->GetLabelOf(successor), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002166 __ b(slow_path->GetEntryLabel());
2167 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002168}
2169
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002170ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2171 return codegen_->GetAssembler();
2172}
2173
2174void ParallelMoveResolverARM::EmitMove(size_t index) {
2175 MoveOperands* move = moves_.Get(index);
2176 Location source = move->GetSource();
2177 Location destination = move->GetDestination();
2178
2179 if (source.IsRegister()) {
2180 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002181 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002182 } else {
2183 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002184 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002185 SP, destination.GetStackIndex());
2186 }
2187 } else if (source.IsStackSlot()) {
2188 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002189 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002190 SP, source.GetStackIndex());
2191 } else {
2192 DCHECK(destination.IsStackSlot());
2193 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2194 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2195 }
2196 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002197 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002198 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002199 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2200 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002201 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002202 } else {
2203 DCHECK(destination.IsStackSlot());
2204 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002205 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002206 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002207 }
2208}
2209
2210void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2211 __ Mov(IP, reg);
2212 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2213 __ StoreToOffset(kStoreWord, IP, SP, mem);
2214}
2215
2216void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2217 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2218 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2219 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2220 SP, mem1 + stack_offset);
2221 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2222 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2223 SP, mem2 + stack_offset);
2224 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2225}
2226
2227void ParallelMoveResolverARM::EmitSwap(size_t index) {
2228 MoveOperands* move = moves_.Get(index);
2229 Location source = move->GetSource();
2230 Location destination = move->GetDestination();
2231
2232 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002233 DCHECK_NE(source.As<Register>(), IP);
2234 DCHECK_NE(destination.As<Register>(), IP);
2235 __ Mov(IP, source.As<Register>());
2236 __ Mov(source.As<Register>(), destination.As<Register>());
2237 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002238 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002239 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002240 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002241 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002242 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2243 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2244 } else {
2245 LOG(FATAL) << "Unimplemented";
2246 }
2247}
2248
2249void ParallelMoveResolverARM::SpillScratch(int reg) {
2250 __ Push(static_cast<Register>(reg));
2251}
2252
2253void ParallelMoveResolverARM::RestoreScratch(int reg) {
2254 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002255}
2256
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002257void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002258 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2259 ? LocationSummary::kCallOnSlowPath
2260 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002261 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002262 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002263 locations->SetOut(Location::RequiresRegister());
2264}
2265
2266void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2267 Register out = cls->GetLocations()->Out().As<Register>();
2268 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002269 DCHECK(!cls->CanCallRuntime());
2270 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002271 codegen_->LoadCurrentMethod(out);
2272 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2273 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002274 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002275 codegen_->LoadCurrentMethod(out);
2276 __ LoadFromOffset(
2277 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2278 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002279
2280 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2281 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2282 codegen_->AddSlowPath(slow_path);
2283 __ cmp(out, ShifterOperand(0));
2284 __ b(slow_path->GetEntryLabel(), EQ);
2285 if (cls->MustGenerateClinitCheck()) {
2286 GenerateClassInitializationCheck(slow_path, out);
2287 } else {
2288 __ Bind(slow_path->GetExitLabel());
2289 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002290 }
2291}
2292
2293void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2294 LocationSummary* locations =
2295 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2296 locations->SetInAt(0, Location::RequiresRegister());
2297 if (check->HasUses()) {
2298 locations->SetOut(Location::SameAsFirstInput());
2299 }
2300}
2301
2302void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002303 // We assume the class is not null.
2304 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2305 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002306 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002307 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2308}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002309
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002310void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2311 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002312 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2313 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2314 __ b(slow_path->GetEntryLabel(), LT);
2315 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2316 // properly. Therefore, we do a memory fence.
2317 __ dmb(ISH);
2318 __ Bind(slow_path->GetExitLabel());
2319}
2320
2321void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2322 LocationSummary* locations =
2323 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2324 locations->SetInAt(0, Location::RequiresRegister());
2325 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2326}
2327
2328void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2329 LocationSummary* locations = instruction->GetLocations();
2330 Register cls = locations->InAt(0).As<Register>();
2331 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2332
2333 switch (instruction->GetType()) {
2334 case Primitive::kPrimBoolean: {
2335 Register out = locations->Out().As<Register>();
2336 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2337 break;
2338 }
2339
2340 case Primitive::kPrimByte: {
2341 Register out = locations->Out().As<Register>();
2342 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2343 break;
2344 }
2345
2346 case Primitive::kPrimShort: {
2347 Register out = locations->Out().As<Register>();
2348 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2349 break;
2350 }
2351
2352 case Primitive::kPrimChar: {
2353 Register out = locations->Out().As<Register>();
2354 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2355 break;
2356 }
2357
2358 case Primitive::kPrimInt:
2359 case Primitive::kPrimNot: {
2360 Register out = locations->Out().As<Register>();
2361 __ LoadFromOffset(kLoadWord, out, cls, offset);
2362 break;
2363 }
2364
2365 case Primitive::kPrimLong: {
2366 // TODO: support volatile.
2367 Location out = locations->Out();
2368 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2369 break;
2370 }
2371
2372 case Primitive::kPrimFloat:
2373 case Primitive::kPrimDouble:
2374 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2375 UNREACHABLE();
2376 case Primitive::kPrimVoid:
2377 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2378 UNREACHABLE();
2379 }
2380}
2381
2382void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2383 LocationSummary* locations =
2384 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2385 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2386 locations->SetInAt(0, Location::RequiresRegister());
2387 locations->SetInAt(1, Location::RequiresRegister());
2388 // Temporary registers for the write barrier.
2389 if (is_object_type) {
2390 locations->AddTemp(Location::RequiresRegister());
2391 locations->AddTemp(Location::RequiresRegister());
2392 }
2393}
2394
2395void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2396 LocationSummary* locations = instruction->GetLocations();
2397 Register cls = locations->InAt(0).As<Register>();
2398 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2399 Primitive::Type field_type = instruction->GetFieldType();
2400
2401 switch (field_type) {
2402 case Primitive::kPrimBoolean:
2403 case Primitive::kPrimByte: {
2404 Register value = locations->InAt(1).As<Register>();
2405 __ StoreToOffset(kStoreByte, value, cls, offset);
2406 break;
2407 }
2408
2409 case Primitive::kPrimShort:
2410 case Primitive::kPrimChar: {
2411 Register value = locations->InAt(1).As<Register>();
2412 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2413 break;
2414 }
2415
2416 case Primitive::kPrimInt:
2417 case Primitive::kPrimNot: {
2418 Register value = locations->InAt(1).As<Register>();
2419 __ StoreToOffset(kStoreWord, value, cls, offset);
2420 if (field_type == Primitive::kPrimNot) {
2421 Register temp = locations->GetTemp(0).As<Register>();
2422 Register card = locations->GetTemp(1).As<Register>();
2423 codegen_->MarkGCCard(temp, card, cls, value);
2424 }
2425 break;
2426 }
2427
2428 case Primitive::kPrimLong: {
2429 Location value = locations->InAt(1);
2430 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2431 break;
2432 }
2433
2434 case Primitive::kPrimFloat:
2435 case Primitive::kPrimDouble:
2436 LOG(FATAL) << "Unimplemented register type " << field_type;
2437 UNREACHABLE();
2438 case Primitive::kPrimVoid:
2439 LOG(FATAL) << "Unreachable type " << field_type;
2440 UNREACHABLE();
2441 }
2442}
2443
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002444void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2445 LocationSummary* locations =
2446 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2447 locations->SetOut(Location::RequiresRegister());
2448}
2449
2450void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2451 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2452 codegen_->AddSlowPath(slow_path);
2453
2454 Register out = load->GetLocations()->Out().As<Register>();
2455 codegen_->LoadCurrentMethod(out);
2456 __ LoadFromOffset(
2457 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2458 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2459 __ cmp(out, ShifterOperand(0));
2460 __ b(slow_path->GetEntryLabel(), EQ);
2461 __ Bind(slow_path->GetExitLabel());
2462}
2463
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002464} // namespace arm
2465} // namespace art